Skip to content

Commit

Permalink
feat: getChanges and types
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Ramos committed Jul 19, 2024
1 parent becd234 commit 3b725b2
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ napi = { version = "2.16.8", default-features = false, features = [
"serde-json",
"tokio_rt",
] }
workspace-node-tools = { version = "1.0.7", features = ["napi", "napi-derive"] }
workspace-node-tools = { version = "1.0.8", features = ["napi", "napi-derive"] }

[build-dependencies]
napi-build = "2"
Expand Down
169 changes: 158 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */
/**
* Add change
*
* # Examples
*
* ```
* const { addChange } = require('workspace-node-tools');
* addChange(Change{}, process.cwd());
* ```
*
* @param change - The change to add
* @param cwd - The root path to start searching from
*/
export declare function addChange(change: Change, cwd?: string | undefined | null): boolean

export enum Bump {
Major = 'Major',
Minor = 'Minor',
Patch = 'Patch',
Snapshot = 'Snapshot'
Snapshot = 'Snapshot',
}

export interface BumpOptions {
Expand All @@ -22,6 +37,44 @@ export interface BumpPackage {
conventional: ConventionalPackage
}

export interface Change {
package: string
releaseAs: Bump
deploy: Array<string>
}

export type ChangesData = {
[key: string]: Array<Change>
}

/**
* Change exist
*
* # Examples
*
* ```
* const { changeExist } = require('workspace-node-tools');
* const exist = changeExist("branch-name", process.cwd());
* ```
*
* @param branch_name - The branch name to check
* @param cwd - The root path to start searching from
*/
export declare function changeExist(branchName: string, cwd?: string | undefined | null): boolean

export interface Changes {
changes: ChangesData
}

export interface ChangesFileData {
message?: string
changes: ChangesData
}

export interface ChangesOptions {
message?: string
}

export interface Commit {
hash: string
authorName: string
Expand Down Expand Up @@ -70,7 +123,11 @@ export declare function detectPackageManager(root: string): PackageManager | nul
* @param branch - The branch to compare against
* @param cwd - The root path to start searching from
*/
export declare function getAllFilesChangedSinceBranch(packageInfo: Array<PackageInfo>, branch: string, cwd?: string | undefined | null): Array<string>
export declare function getAllFilesChangedSinceBranch(
packageInfo: Array<PackageInfo>,
branch: string,
cwd?: string | undefined | null,
): Array<string>

/**
* Get bumps
Expand All @@ -86,6 +143,21 @@ export declare function getAllFilesChangedSinceBranch(packageInfo: Array<Package
*/
export declare function getBumps(options: BumpOptions): Array<BumpPackage>

/**
* Get change
*
* # Examples
*
* ```
* const { getChange } = require('workspace-node-tools');
* const changes = getChange("branch-name", process.cwd());
* ```
*
* @param branch_name - The branch name to get
* @param cwd - The root path to start searching from
*/
export declare function getChange(branchName: string, cwd?: string | undefined | null): Array<Change>

/**
* Get changed packages
*
Expand All @@ -99,7 +171,24 @@ export declare function getBumps(options: BumpOptions): Array<BumpPackage>
* @param sha - The commit sha to compare against (normally main branch)
* @param cwd - The root path to start searching from
*/
export declare function getChangedPackages(sha?: string | undefined | null, cwd?: string | undefined | null): Array<PackageInfo>
export declare function getChangedPackages(
sha?: string | undefined | null,
cwd?: string | undefined | null,
): Array<PackageInfo>

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

/**
* Get commits since a commit id
Expand All @@ -115,7 +204,11 @@ export declare function getChangedPackages(sha?: string | undefined | null, cwd?
* @param since - The commit id (accepts branch, tag)
* @param relative - The relative path to search from
*/
export declare function getCommitsSince(cwd?: string | undefined | null, since?: string | undefined | null, relative?: string | undefined | null): Array<Commit>
export declare function getCommitsSince(
cwd?: string | undefined | null,
since?: string | undefined | null,
relative?: string | undefined | null,
): Array<Commit>

/**
* Get the conventional for a package
Expand All @@ -132,7 +225,12 @@ export declare function getCommitsSince(cwd?: string | undefined | null, since?:
* @param cwd - The root path to start searching from
* @param conventional_options - The conventional options
*/
export declare function getConventionalForPackage(packageInfo: PackageInfo, noFetchAll?: boolean | undefined | null, cwd?: string | undefined | null, conventionalOptions?: ConventionalPackageOptions | undefined | null): ConventionalPackage
export declare function getConventionalForPackage(
packageInfo: PackageInfo,
noFetchAll?: boolean | undefined | null,
cwd?: string | undefined | null,
conventionalOptions?: ConventionalPackageOptions | undefined | null,
): ConventionalPackage

/**
* Get the defined package manager
Expand Down Expand Up @@ -176,7 +274,10 @@ export declare function getDivergedCommit(refer: string, cwd?: string | undefine
* @param package_info - The list of package info
* @param cwd - The root path to start searching from
*/
export declare function getLastKnownPublishTagInfoForAllPackages(packageInfo: Array<PackageInfo>, cwd?: string | undefined | null): Array<PublishTagInfo | undefined | null>
export declare function getLastKnownPublishTagInfoForAllPackages(
packageInfo: Array<PackageInfo>,
cwd?: string | undefined | null,
): Array<PublishTagInfo | undefined | null>

/**
* Get the last known publish tag info for a package
Expand All @@ -191,7 +292,10 @@ export declare function getLastKnownPublishTagInfoForAllPackages(packageInfo: Ar
* @param package_info - The package info
* @param cwd - The root path to start searching from
*/
export declare function getLastKnownPublishTagInfoForPackage(packageInfo: PackageInfo, cwd?: string | undefined | null): PublishTagInfo | null
export declare function getLastKnownPublishTagInfoForPackage(
packageInfo: PackageInfo,
cwd?: string | undefined | null,
): PublishTagInfo | null

/**
* Get packages available in the monorepo
Expand Down Expand Up @@ -234,7 +338,10 @@ export declare function getProjectRootPath(root?: string | undefined | null): st
* @param cwd - The root path to start searching from
* @param local - Fetch local tags
*/
export declare function getRemoteOrLocalTags(cwd?: string | undefined | null, local?: boolean | undefined | null): Array<RemoteTags>
export declare function getRemoteOrLocalTags(
cwd?: string | undefined | null,
local?: boolean | undefined | null,
): Array<RemoteTags>

/**
* Get all files changed since a commit id
Expand Down Expand Up @@ -266,7 +373,12 @@ export declare function gitAllFilesChangedSinceSha(sha: string, cwd?: string | u
* @param footer - The commit footer
* @param cwd - The root path to start searching from
*/
export declare function gitCommit(message: string, body?: string | undefined | null, footer?: string | undefined | null, cwd?: string | undefined | null): boolean
export declare function gitCommit(
message: string,
body?: string | undefined | null,
footer?: string | undefined | null,
cwd?: string | undefined | null,
): boolean

/**
* Get the branch name from a commit id
Expand Down Expand Up @@ -383,7 +495,28 @@ export declare function gitPush(cwd?: string | undefined | null, followTags?: bo
* @param message - The tag message
* @param cwd - The root path to start searching from
*/
export declare function gitTag(tag: string, message?: string | undefined | null, cwd?: string | undefined | null): boolean
export declare function gitTag(
tag: string,
message?: string | undefined | null,
cwd?: string | undefined | null,
): boolean

/**
* Init changes
*
* # Examples
*
* ```
* const { initChanges } = require('workspace-node-tools');
* const changes = initChanges(process.cwd(), ChangesOptions{});
* ```
*
* @param cwd - The root path to start searching from
*/
export declare function initChanges(
cwd?: string | undefined | null,
changeOptions?: ChangesOptions | undefined | null,
): ChangesFileData

/**
* Check if the workdir is unclean
Expand Down Expand Up @@ -417,7 +550,7 @@ export enum PackageManager {
Npm = 'Npm',
Yarn = 'Yarn',
Pnpm = 'Pnpm',
Bun = 'Bun'
Bun = 'Bun',
}

export interface PackageRepositoryInfo {
Expand All @@ -437,3 +570,17 @@ export interface RemoteTags {
tag: string
}

/**
* Remove change
*
* # Examples
*
* ```
* const { removeChange } = require('workspace-node-tools');
* removeChange("branch-name", process.cwd());
* ```
*
* @param branch_name - The branch name to remove
* @param cwd - The root path to start searching from
*/
export declare function removeChange(branchName: string, cwd?: string | undefined | null): boolean
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,15 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

module.exports.addChange = nativeBinding.addChange
module.exports.Bump = nativeBinding.Bump
module.exports.changeExist = nativeBinding.changeExist
module.exports.detectPackageManager = nativeBinding.detectPackageManager
module.exports.getAllFilesChangedSinceBranch = nativeBinding.getAllFilesChangedSinceBranch
module.exports.getBumps = nativeBinding.getBumps
module.exports.getChange = nativeBinding.getChange
module.exports.getChangedPackages = nativeBinding.getChangedPackages
module.exports.getChanges = nativeBinding.getChanges
module.exports.getCommitsSince = nativeBinding.getCommitsSince
module.exports.getConventionalForPackage = nativeBinding.getConventionalForPackage
module.exports.getDefinedPackageManager = nativeBinding.getDefinedPackageManager
Expand All @@ -385,5 +389,7 @@ module.exports.gitFirstSha = nativeBinding.gitFirstSha
module.exports.gitPreviousSha = nativeBinding.gitPreviousSha
module.exports.gitPush = nativeBinding.gitPush
module.exports.gitTag = nativeBinding.gitTag
module.exports.initChanges = nativeBinding.initChanges
module.exports.isWorkdirUnclean = nativeBinding.isWorkdirUnclean
module.exports.PackageManager = nativeBinding.PackageManager
module.exports.removeChange = nativeBinding.removeChange
21 changes: 16 additions & 5 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, init_changes, remove_change, Change, ChangesFileData,
ChangesOptions,
add_change, change_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 @@ -516,6 +516,17 @@ pub fn js_get_change(branch_name: String, cwd: Option<String>) -> Vec<Change> {
get_change(branch_name, cwd)
}

/*pub fn js_get_changes(cwd: Option<String>) -> ChangesData {
get_changes(cwd)
}*/
/// Get changes
///
/// # Examples
///
/// ```
/// const { getChanges } = require('workspace-node-tools');
/// const changes = getChanges(process.cwd());
/// ```
///
/// @param cwd - The root path to start searching from
#[napi(js_name = "getChanges")]
pub fn js_get_changes(cwd: Option<String>) -> Changes {
get_changes(cwd)
}

0 comments on commit 3b725b2

Please sign in to comment.