Skip to content

Commit

Permalink
chore: merge pull request #19 from websublime/feature/bumps-by-changes
Browse files Browse the repository at this point in the history
feat: bumps by changes
  • Loading branch information
miguelramos authored Sep 19, 2024
2 parents 8e874ea + 4f7aa98 commit c0463df
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Miguel Ramos <[email protected]>"]
edition = "2021"
name = "websublime_workspace-tools"
version = "0.7.14"
version = "1.0.0"
exclude = ["tests/*", "examples/*", "node_modules/*", "target/*"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -11,16 +11,13 @@ exclude = ["tests/*", "examples/*", "node_modules/*", "target/*"]
crate-type = ["cdylib"]

[dependencies]
napi-derive = "2.16.11"
napi = { version = "2.16.9", default-features = false, features = [
napi-derive = "2.16.12"
napi = { version = "2.16.10", default-features = false, features = [
"napi9",
"serde-json",
"tokio_rt",
] }
workspace-node-tools = { version = "1.0.19", features = [
"napi",
"napi-derive",
] }
workspace-node-tools = { version = "2.0.0", features = ["napi", "napi-derive"] }

[build-dependencies]
napi-build = "2"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This package offer a set of functions to retrieve information about the monorepo
| `getDefinedPackageManager(root?: string): string or undefined` | Get the package manager defined in the project. |
| `detectPackageManager(root: string): PackageManager or undefined` | Detect the package manager defined in the project. |
| `getPackages(cwd?: string): Array<PackageInfo>` | Get the list of packages in the monorepo. |
| `getPackageInfo(package_name: string, cwd?: string): PackageInfo` | Get PackageInfo for a package. |
| `getChangedPackages(sha?: string, cwd: string): Array<PackageInfo>` | Get the list of packages that have changed since the given sha ('main'). |
| `git_add(file: string, cwd?: string): boolean` | Stage a file. |
| `git_add_all(cwd?: string): boolean` | Stage all files. |
Expand Down Expand Up @@ -51,6 +52,7 @@ This package offer a set of functions to retrieve information about the monorepo
| `change_exist(branch_name: string, packages_name: Array<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. |
| `get_package_change(package_name: string, branch: string, cwd?: string): Changes` | Get a change by package name. |
| `changes_file_exist(cwd?: string): boolean` | Check if `.changes.json` file exist |

## Develop requirements
Expand Down
59 changes: 55 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export enum Bump {
}

export interface BumpOptions {
packages: Array<string>
changes: Array<Change>
since?: string
releaseAs: Bump
releaseAs?: Bump
fetchAll?: boolean
fetchTags?: boolean
syncDeps?: boolean
Expand All @@ -51,8 +51,8 @@ export interface BumpOptions {
export interface BumpPackage {
from: string
to: string
releaseAs: Bump
conventional: ConventionalPackage
packageInfo: PackageInfo
conventionalCommits: any
}

export interface Change {
Expand Down Expand Up @@ -136,6 +136,11 @@ export interface ConventionalPackageOptions {
title?: string
}

export interface DependencyInfo {
name: string
version: string
}

/**
* Detect the package manager
*
Expand Down Expand Up @@ -338,6 +343,41 @@ export declare function getLastKnownPublishTagInfoForPackage(
cwd?: string | undefined | null,
): PublishTagInfo | null

/**
* Get package change
*
* # Examples
*
* ```
* const { getPackageChange } = require('workspace-node-tools');
* const change = getPackageChange("@scope/package-a", "branch-name", process.cwd());
* ```
*
* @param package_name - The package name
* @param branch - The branch name
* @param cwd - The root path to start searching from
*/
export declare function getPackageChange(
packageName: string,
branch: string,
cwd?: string | undefined | null,
): Change | null

/**
* Get PackageInfo for a package
*
* # Examples
*
* ```
* const { getPackageInfo } = require('workspace-node-tools');
* const packageInfo = getPackageInfo("package-name", process.cwd());
* ```
*
* @param package_name - The name of the package to get info for
* @param cwd - The root path to start searching from
*/
export declare function getPackageInfo(packageName: string, cwd?: string | undefined | null): PackageInfo | null

/**
* Get packages available in the monorepo
*
Expand Down Expand Up @@ -630,6 +670,7 @@ export interface PackageInfo {
url: string
repositoryInfo?: PackageRepositoryInfo
changedFiles: Array<string>
dependencies: Array<DependencyInfo>
}

export enum PackageManager {
Expand All @@ -651,6 +692,16 @@ export interface PublishTagInfo {
package: string
}

/** Struct representing the bump package. */
export interface RecommendBumpPackage {
from: string
to: string
packageInfo: PackageInfo
conventional: ConventionalPackage
changedFiles: Array<string>
deployTo: Array<string>
}

export interface RemoteTags {
hash: string
tag: string
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ module.exports.getDefinedPackageManager = nativeBinding.getDefinedPackageManager
module.exports.getDivergedCommit = nativeBinding.getDivergedCommit
module.exports.getLastKnownPublishTagInfoForAllPackages = nativeBinding.getLastKnownPublishTagInfoForAllPackages
module.exports.getLastKnownPublishTagInfoForPackage = nativeBinding.getLastKnownPublishTagInfoForPackage
module.exports.getPackageChange = nativeBinding.getPackageChange
module.exports.getPackageInfo = nativeBinding.getPackageInfo
module.exports.getPackages = nativeBinding.getPackages
module.exports.getProjectRootPath = nativeBinding.getProjectRootPath
module.exports.getRemoteOrLocalTags = nativeBinding.getRemoteOrLocalTags
Expand Down
47 changes: 42 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::{apply_bumps, get_bumps, BumpOptions, BumpPackage};
use workspace_node_tools::changes::{
add_change, change_exist, changes_file_exist, get_change, get_changes, init_changes,
remove_change, Change, Changes, ChangesFileData, ChangesOptions,
add_change, change_exist, changes_file_exist, get_change, get_changes, get_package_change,
init_changes, remove_change, Change, Changes, ChangesFileData, ChangesOptions,
};
use workspace_node_tools::conventional::{
get_conventional_for_package, ConventionalPackage, ConventionalPackageOptions,
Expand All @@ -20,7 +20,7 @@ use workspace_node_tools::git::{
};
use workspace_node_tools::manager::{detect_package_manager, PackageManager};
use workspace_node_tools::packages::{
get_changed_packages, get_monorepo_package_manager, get_packages, PackageInfo,
get_changed_packages, get_monorepo_package_manager, get_package_info, get_packages, PackageInfo,
};
use workspace_node_tools::paths::get_project_root_path;

Expand Down Expand Up @@ -90,6 +90,22 @@ pub fn js_get_packages(cwd: Option<String>) -> Vec<PackageInfo> {
get_packages(cwd)
}

/// Get PackageInfo for a package
///
/// # Examples
///
/// ```
/// const { getPackageInfo } = require('workspace-node-tools');
/// const packageInfo = getPackageInfo("package-name", process.cwd());
/// ```
///
/// @param package_name - The name of the package to get info for
/// @param cwd - The root path to start searching from
#[napi(js_name = "getPackageInfo")]
pub fn js_get_package_info(package_name: String, cwd: Option<String>) -> Option<PackageInfo> {
get_package_info(package_name, cwd)
}

/// Get changed packages
///
/// # Examples
Expand Down Expand Up @@ -495,7 +511,7 @@ pub fn js_get_conventional_for_package(
/// @param options - The bump options
#[napi(js_name = "getBumps")]
pub fn js_get_bumps(options: BumpOptions) -> Vec<BumpPackage> {
get_bumps(options)
get_bumps(&options)
}

/// Apply bumps to a package. This will update the package.json version and changelog
Expand All @@ -511,7 +527,7 @@ pub fn js_get_bumps(options: BumpOptions) -> Vec<BumpPackage> {
/// @param options - The bump options
#[napi(js_name = "applyBumps")]
pub fn js_apply_bumps(options: BumpOptions) -> Vec<BumpPackage> {
apply_bumps(options)
apply_bumps(&options)
}

/// Init changes
Expand Down Expand Up @@ -616,6 +632,27 @@ pub fn js_get_changes(cwd: Option<String>) -> Changes {
get_changes(cwd)
}

/// Get package change
///
/// # Examples
///
/// ```
/// const { getPackageChange } = require('workspace-node-tools');
/// const change = getPackageChange("@scope/package-a", "branch-name", process.cwd());
/// ```
///
/// @param package_name - The package name
/// @param branch - The branch name
/// @param cwd - The root path to start searching from
#[napi(js_name = "getPackageChange")]
pub fn js_get_package_change(
package_name: String,
branch: String,
cwd: Option<String>,
) -> Option<Change> {
get_package_change(package_name, branch, cwd)
}

/// Changes file exist
///
/// # Examples
Expand Down

0 comments on commit c0463df

Please sign in to comment.