Skip to content

Commit

Permalink
feat: add changes file exist to api
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Ramos committed Jul 22, 2024
1 parent ef1abe3 commit cf5b511
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Miguel Ramos <miguel.ramos@websublime.dev>"]
edition = "2021"
name = "websublime_workspace-tools"
version = "0.7.4"
version = "0.7.5"
exclude = ["tests/*", "examples/*", "node_modules/*", "target/*"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -17,7 +17,7 @@ napi = { version = "2.16.8", default-features = false, features = [
"serde-json",
"tokio_rt",
] }
workspace-node-tools = { version = "1.0.8", features = ["napi", "napi-derive"] }
workspace-node-tools = { version = "1.0.9", features = ["napi", "napi-derive"] }

[build-dependencies]
napi-build = "2"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This package offer a set of functions to retrieve information about the monorepo
| `change_exist(branch_name: string, cwd?: string): boolean` | Check if change already exist. |
| `get_change(branch_name: string, cwd?: string): Array<Change>` | Get the list of changes for the branch. |
| `get_changes(cwd?: string): Changes` | Get all changes. |
| `changes_file_exist(cwd?: string): boolean` | Check if `.changes.json` file exist |

## Develop requirements

Expand Down
18 changes: 16 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
export declare function addChange(change: Change, cwd?: string | undefined | null): boolean

export enum Bump {
export const enum Bump {
Major = 'Major',
Minor = 'Minor',
Patch = 'Patch',
Expand Down Expand Up @@ -71,6 +71,20 @@ export interface ChangesFileData {
changes: ChangesData
}

/**
* Changes file exist
*
* # Examples
*
* ```
* const { changesFileExist } = require('workspace-node-tools');
* const exist = changesFileExist(process.cwd());
* ```
*
* @param cwd - The root path to start searching from
*/
export declare function changesFileExist(cwd?: string | undefined | null): boolean

export interface ChangesOptions {
message?: string
}
Expand Down Expand Up @@ -546,7 +560,7 @@ export interface PackageInfo {
changedFiles: Array<string>
}

export enum PackageManager {
export const enum PackageManager {
Npm = 'Npm',
Yarn = 'Yarn',
Pnpm = 'Pnpm',
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ if (!nativeBinding) {
module.exports.addChange = nativeBinding.addChange
module.exports.Bump = nativeBinding.Bump
module.exports.changeExist = nativeBinding.changeExist
module.exports.changesFileExist = nativeBinding.changesFileExist
module.exports.detectPackageManager = nativeBinding.detectPackageManager
module.exports.getAllFilesChangedSinceBranch = nativeBinding.getAllFilesChangedSinceBranch
module.exports.getBumps = nativeBinding.getBumps
Expand Down
19 changes: 17 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::path::{Path, PathBuf};

use workspace_node_tools::bumps::{get_bumps, BumpOptions, BumpPackage};
use workspace_node_tools::changes::{
add_change, change_exist, get_change, get_changes, init_changes, remove_change, Change, Changes,
ChangesFileData, ChangesOptions,
add_change, change_exist, changes_file_exist, get_change, get_changes, init_changes,
remove_change, Change, Changes, ChangesFileData, ChangesOptions,
};
use workspace_node_tools::conventional::{
get_conventional_for_package, ConventionalPackage, ConventionalPackageOptions,
Expand Down Expand Up @@ -530,3 +530,18 @@ pub fn js_get_change(branch_name: String, cwd: Option<String>) -> Vec<Change> {
pub fn js_get_changes(cwd: Option<String>) -> Changes {
get_changes(cwd)
}

/// Changes file exist
///
/// # Examples
///
/// ```
/// const { changesFileExist } = require('workspace-node-tools');
/// const exist = changesFileExist(process.cwd());
/// ```
///
/// @param cwd - The root path to start searching from
#[napi(js_name = "changesFileExist")]
pub fn js_changes_file_exist(cwd: Option<String>) -> bool {
changes_file_exist(cwd)
}

0 comments on commit cf5b511

Please sign in to comment.