From a5823131f2c6bf1c9599fc8284eb605edccb580e Mon Sep 17 00:00:00 2001 From: Miguel Ramos Date: Mon, 8 Jul 2024 07:49:49 +0100 Subject: [PATCH] chore: update readme --- README.md | 104 ++++++++++++++++++++------- __test__/index.spec.ts | 2 +- npm/darwin-arm64/package.json | 2 +- npm/darwin-x64/package.json | 2 +- npm/linux-arm-gnueabihf/package.json | 2 +- npm/linux-arm64-gnu/package.json | 2 +- npm/linux-arm64-musl/package.json | 2 +- npm/linux-x64-gnu/package.json | 2 +- npm/linux-x64-musl/package.json | 2 +- npm/win32-arm64-msvc/package.json | 2 +- npm/win32-ia32-msvc/package.json | 2 +- npm/win32-x64-msvc/package.json | 2 +- 12 files changed, 90 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index fcac2a1..8f610c9 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,101 @@ -# `@napi-rs/package-template` +# `@websublime/workspace-tools` -![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg) +![https://github.com/websublime/workspace-node-binding-tools/actions](https://github.com/websublime/workspace-node-binding-tools/workflows/CI/badge.svg) -> Template project for writing node packages with napi-rs. - -# Usage - -1. Click **Use this template**. -2. **Clone** your project. -3. Run `pnpm install` to install dependencies. -4. Run `npx napi rename -n [name]` command under the project folder to rename your package. +> Tools to use on github actions for bumping version, changelogs on a turbo monorepo. ## Install this test package ``` -pnpm add @napi-rs/package-template +pnpm add @websublime/workspace-tools ``` ## Usage -### Build +This package offer a set of functions to retrieve information about the monorepo and the packages that contain. It support all package managers including Bun (WIP). + +## API + +### `getProjectRootPath()` + +Get the root path of the project. + +### `getDefinedAgent()` + +Get the package manager defined in the project. + +### `getMonorepoPackages()` + +Get the list of packages in the monorepo. + +### `getMonorepoChangedPackages(sha: string)` + +Get the list of packages that have changed since the given sha ('main'). + +### `executeFetchAll(cwd?: string)` + +Execute a `fetch` command to get the latest changes from the remote repository. + +### `executeFetchAllTags(cwd?: string)` + +Execute a `fetch` command to get the latest tags from the remote repository. + +### `setCommit(message: string, body?: string, footer?: string cwd?: string)` + +Commit the changes to the repository. + +### `setTag(tag: string, message?: string, cwd?: string)` + +Tag the repository with the given tag. + +### `gitPush(cwd?: string)` + +Push the changes to the remote repository. + +### `getCurrentSha(cwd?: string)` + +Get the current sha of the repository. + +### `isWorkdirUnclean(cwd?: string)` + +Check if the workdir is unclean (uncommited changes). + +### `getDivergedCommit(sha: string, cwd?: string)` + +Get the diverged commit from the given sha (main). + +### `getCommitsSince(cwd?: string, since?: string, relative?: string)` + +Get the commits since the given sha (main) for a particular package. + +### `getAllFilesChangedSinceSha(sha: string, cwd?: string)` + +Get all the files changed since the given sha (main). + +### `getAllFilesChangedSinceTagInfos(package_info: Array, tag_info: Array, cwd?: string)` + +Get all the files changed since the given tag infos. -After `pnpm build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs). +### `getAllFilesChangedSinceBranch(package_info: Array, brnach: string, cwd?: string)` -### Test +Get all the files changed since the given branch. -With [ava](https://github.com/avajs/ava), run `pnpm test` to testing native addon. You can also switch to another testing framework if you want. +### `getRemoteOrLocalTags(cwd?: string, local?: boolean)` -### CI +Get all the tags in the remote or local repository. -With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@18`, `node@20`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms. +### `getLastKnownPublishTagInfoForPackage(package_info: PackageInfo, cwd?: string)` -### Release +Get the last known publish tag info for a particular package. -Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more. +### `getLastKnownPublishTagInfoForAllPackages(package_info: Array, cwd?: string)` -With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**. +Get the last known publish tag info for all packages. -The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror). +### `getConventionalForPackage(package_info: PackageInfo, no_fetch_all?: boolean cwd?: string, conventional_options?: ConventionalPackageOptions)` -In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm. +Get the conventional commits for a particular package. -`NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `pnpm add @napi-rs/package-template` to see how it works. ## Develop requirements @@ -60,8 +114,7 @@ And you will see: ```bash $ ava --verbose - ✔ sync function from native code - ✔ sleep function from native code (201ms) + ✔ get defined package manager ─ 2 tests passed @@ -77,6 +130,7 @@ In `Settings -> Secrets`, add **NPM_TOKEN** into it. When you want to release the package: ``` +npm run build npm version [ | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=] | from-git] git push diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index a626ff6..51c874f 100644 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -2,6 +2,6 @@ import test from 'ava' import { getDefinedAgent } from '../index' -test('sync function from native code', (t) => { +test('get defined package manager', (t) => { t.is(getDefinedAgent(), 'pnpm'); }); diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index a22c956..cd785ae 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-darwin-arm64", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "arm64" ], diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index d74b600..2cd3852 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-darwin-x64", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "x64" ], diff --git a/npm/linux-arm-gnueabihf/package.json b/npm/linux-arm-gnueabihf/package.json index ed09dc5..08526b5 100644 --- a/npm/linux-arm-gnueabihf/package.json +++ b/npm/linux-arm-gnueabihf/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-linux-arm-gnueabihf", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "arm" ], diff --git a/npm/linux-arm64-gnu/package.json b/npm/linux-arm64-gnu/package.json index c0781a7..9d57270 100644 --- a/npm/linux-arm64-gnu/package.json +++ b/npm/linux-arm64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-linux-arm64-gnu", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "arm64" ], diff --git a/npm/linux-arm64-musl/package.json b/npm/linux-arm64-musl/package.json index 7eedc58..9b276ab 100644 --- a/npm/linux-arm64-musl/package.json +++ b/npm/linux-arm64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-linux-arm64-musl", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "arm64" ], diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index 97604ec..e011def 100644 --- a/npm/linux-x64-gnu/package.json +++ b/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-linux-x64-gnu", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "x64" ], diff --git a/npm/linux-x64-musl/package.json b/npm/linux-x64-musl/package.json index e1b720c..7b3987a 100644 --- a/npm/linux-x64-musl/package.json +++ b/npm/linux-x64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-linux-x64-musl", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "x64" ], diff --git a/npm/win32-arm64-msvc/package.json b/npm/win32-arm64-msvc/package.json index 6b142f2..8d19234 100644 --- a/npm/win32-arm64-msvc/package.json +++ b/npm/win32-arm64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-win32-arm64-msvc", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "arm64" ], diff --git a/npm/win32-ia32-msvc/package.json b/npm/win32-ia32-msvc/package.json index 6ec58ff..7aca21e 100644 --- a/npm/win32-ia32-msvc/package.json +++ b/npm/win32-ia32-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-win32-ia32-msvc", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "ia32" ], diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 690094d..1b393ed 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@websublime/workspace-tools-win32-x64-msvc", - "version": "0.4.1", + "version": "0.4.2", "cpu": [ "x64" ],