@doki-land/nifty 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/nifty.mjs +2 -2
- package/package.json +6 -6
- package/src/cli/authArgs.ts +29 -29
- package/src/cli/bump-cmd.ts +15 -15
- package/src/cli/bump.ts +79 -79
- package/src/cli/change-logs-cmd.ts +26 -26
- package/src/cli/cli.ts +3 -3
- package/src/cli/commit-cmd.ts +76 -78
- package/src/cli/commit-lint-report.ts +46 -48
- package/src/cli/context.ts +9 -9
- package/src/cli/format-cmd.ts +6 -6
- package/src/cli/format.ts +15 -15
- package/src/cli/install-native-cmd.ts +4 -4
- package/src/cli/install-native.ts +24 -24
- package/src/cli/lint-cmd.ts +11 -11
- package/src/cli/lint.ts +48 -52
- package/src/cli/options.ts +14 -14
- package/src/cli/publish-cmd.ts +12 -18
- package/src/cli/publish.ts +38 -38
- package/src/cli/resolveNpm.ts +3 -3
- package/src/cli/retime-cmd.ts +18 -18
- package/src/cli/trust-cmd.ts +11 -11
- package/src/cli/trust.ts +26 -26
- package/src/cli/update-cmd.ts +5 -5
- package/src/cli/update.ts +12 -12
- package/src/cli/upload-cmd.ts +17 -17
- package/src/cli/upload.ts +131 -131
- package/src/cli/workspace.ts +46 -46
- package/src/config/authorMap.ts +4 -8
- package/src/config/defineConfig.ts +5 -5
- package/src/config/detectProject.ts +46 -46
- package/src/config/formatPresets.ts +24 -24
- package/src/config/loadConfig.ts +35 -35
- package/src/config/trustPayload.ts +6 -6
- package/src/config/types.ts +37 -37
- package/src/git.ts +14 -14
- package/src/github.ts +54 -54
- package/src/gitmoji.ts +18 -18
- package/src/native.ts +595 -599
- package/src/nifty.ts +29 -31
- package/src/types.ts +17 -17
package/cli/nifty.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin /env node
|
|
2
2
|
|
|
3
3
|
import { createJiti } from "jiti";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
7
7
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const jiti = createJiti(import.meta.url, { interopDefault
|
|
8
|
+
const jiti = createJiti(import.meta.url, { interopDefault: true });
|
|
9
9
|
const { runCli } = await jiti.import(join(here, "../src/cli/main.ts"));
|
|
10
10
|
|
|
11
11
|
process.exit(await runCli(process.argv.slice(2)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doki-land/nifty",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Gitmoji-first commit conventions and release helpers (Node-API + TypeScript)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"jiti": "^2.4.2"
|
|
25
25
|
},
|
|
26
26
|
"optionalDependencies": {
|
|
27
|
-
"@doki-land/nifty-win32-x64": "0.1.
|
|
28
|
-
"@doki-land/nifty-linux-x64": "0.1.
|
|
29
|
-
"@doki-land/nifty-linux-arm64": "0.1.
|
|
30
|
-
"@doki-land/nifty-darwin-arm64": "0.1.
|
|
31
|
-
"@doki-land/nifty-darwin-x64": "0.1.
|
|
27
|
+
"@doki-land/nifty-win32-x64": "0.1.2",
|
|
28
|
+
"@doki-land/nifty-linux-x64": "0.1.2",
|
|
29
|
+
"@doki-land/nifty-linux-arm64": "0.1.2",
|
|
30
|
+
"@doki-land/nifty-darwin-arm64": "0.1.2",
|
|
31
|
+
"@doki-land/nifty-darwin-x64": "0.1.2"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
package/src/cli/authArgs.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { resolveNpmExecutable } from "./resolveNpm.js";
|
|
2
2
|
|
|
3
3
|
export type AuthCliOptions = {
|
|
4
|
-
otp
|
|
5
|
-
totpSecret
|
|
6
|
-
token
|
|
7
|
-
npm
|
|
4
|
+
otp?: string;
|
|
5
|
+
totpSecret?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
npm: string;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export function parseAuthArgs(argv
|
|
11
|
-
let otp
|
|
12
|
-
let totpSecret
|
|
13
|
-
let token
|
|
10
|
+
export function parseAuthArgs(argv: string[]): AuthCliOptions {
|
|
11
|
+
let otp: string | undefined;
|
|
12
|
+
let totpSecret: string | undefined;
|
|
13
|
+
let token: string | undefined;
|
|
14
14
|
|
|
15
|
-
for(let i = 0; i<argv.length; i += 1){
|
|
15
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
16
16
|
const arg = argv[i];
|
|
17
|
-
if(arg === "--otp"){
|
|
18
|
-
otp = argv[
|
|
19
|
-
} else if(arg === "--totp-secret"){
|
|
20
|
-
totpSecret = argv[
|
|
21
|
-
} else if(arg === "--token"){
|
|
22
|
-
token = argv[
|
|
23
|
-
} else if(arg.startsWith("--otp=")){
|
|
17
|
+
if (arg === "--otp") {
|
|
18
|
+
otp = argv[++i];
|
|
19
|
+
} else if (arg === "--totp-secret") {
|
|
20
|
+
totpSecret = argv[++i];
|
|
21
|
+
} else if (arg === "--token") {
|
|
22
|
+
token = argv[++i];
|
|
23
|
+
} else if (arg.startsWith("--otp=")) {
|
|
24
24
|
otp = arg.slice("--otp=".length);
|
|
25
|
-
} else if(arg.startsWith("--totp-secret=")){
|
|
25
|
+
} else if (arg.startsWith("--totp-secret=")) {
|
|
26
26
|
totpSecret = arg.slice("--totp-secret=".length);
|
|
27
|
-
} else if(arg.startsWith("--token=")){
|
|
27
|
+
} else if (arg.startsWith("--token=")) {
|
|
28
28
|
token = arg.slice("--token=".length);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -33,20 +33,20 @@ export function parseAuthArgs(argv : string[]) : AuthCliOptions {
|
|
|
33
33
|
otp,
|
|
34
34
|
totpSecret,
|
|
35
35
|
token,
|
|
36
|
-
npm
|
|
36
|
+
npm: resolveNpmExecutable(),
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function authPayload(options
|
|
41
|
-
otp
|
|
42
|
-
totpSecret
|
|
43
|
-
token
|
|
44
|
-
npm
|
|
45
|
-
}{
|
|
40
|
+
export function authPayload(options: AuthCliOptions): {
|
|
41
|
+
otp?: string;
|
|
42
|
+
totpSecret?: string;
|
|
43
|
+
token?: string;
|
|
44
|
+
npm: string;
|
|
45
|
+
} {
|
|
46
46
|
return {
|
|
47
|
-
...(options.otp!== undefined ? { otp
|
|
48
|
-
...(options.totpSecret!== undefined ? { totpSecret
|
|
49
|
-
...(options.token!== undefined ? { token
|
|
50
|
-
npm
|
|
47
|
+
...(options.otp !== undefined ? { otp: options.otp } : { }),
|
|
48
|
+
...(options.totpSecret !== undefined ? { totpSecret: options.totpSecret } : { }),
|
|
49
|
+
...(options.token !== undefined ? { token: options.token } : { }),
|
|
50
|
+
npm: options.npm,
|
|
51
51
|
};
|
|
52
52
|
}
|
package/src/cli/bump-cmd.ts
CHANGED
|
@@ -4,17 +4,17 @@ import { bumpWorkspace, printBumpReport, type BumpKind, type BumpOptions } from
|
|
|
4
4
|
import { bootstrapFromOptions } from "./context.js";
|
|
5
5
|
import { cwdFrom, flag, str } from "./options.js";
|
|
6
6
|
|
|
7
|
-
export function registerBumpCommand(cli
|
|
7
|
+
export function registerBumpCommand(cli: Cli): void {
|
|
8
8
|
cli.command("bump", "cli.cmd.bump")
|
|
9
9
|
.option("--dry-run", "cli.opt.dry-run")
|
|
10
10
|
.option("--version, -v <version>", "cli.opt.version")
|
|
11
11
|
.option("--patch", "cli.opt.patch")
|
|
12
12
|
.option("--minor", "cli.opt.minor")
|
|
13
13
|
.option("--major", "cli.opt.major")
|
|
14
|
-
.action(async(options) =>cmdBump(options));
|
|
14
|
+
.action(async(options) => cmdBump(options));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export async function cmdBump(options
|
|
17
|
+
export async function cmdBump(options: ParsedOptions): Promise < number> {
|
|
18
18
|
await bootstrapFromOptions(options);
|
|
19
19
|
const bumpOptions = bumpOptionsFromParsed(options);
|
|
20
20
|
const report = bumpWorkspace(bumpOptions);
|
|
@@ -22,34 +22,34 @@ export async function cmdBump(options : ParsedOptions) : Promise<number>{
|
|
|
22
22
|
return 0;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function bumpOptionsFromParsed(options
|
|
25
|
+
function bumpOptionsFromParsed(options: ParsedOptions): BumpOptions {
|
|
26
26
|
let version = str(options, "version");
|
|
27
|
-
let kind
|
|
28
|
-
if(flag(options, "major")){
|
|
27
|
+
let kind: BumpKind = "patch";
|
|
28
|
+
if (flag(options, "major")) {
|
|
29
29
|
kind = "major";
|
|
30
|
-
} else if(flag(options, "minor")){
|
|
30
|
+
} else if (flag(options, "minor")) {
|
|
31
31
|
kind = "minor";
|
|
32
|
-
} else if(flag(options, "patch")){
|
|
32
|
+
} else if (flag(options, "patch")) {
|
|
33
33
|
kind = "patch";
|
|
34
34
|
}
|
|
35
|
-
for(const positional of options._){
|
|
36
|
-
if(isBumpKind(positional)){
|
|
35
|
+
for (const positional of options._) {
|
|
36
|
+
if (isBumpKind(positional)) {
|
|
37
37
|
kind = positional;
|
|
38
|
-
} else if(positional){
|
|
38
|
+
} else if (positional) {
|
|
39
39
|
version = positional;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
if(version &&
|
|
42
|
+
if (version && !/^\d+\.\d+\.\d+(-[\w.-]+)?$/.test(version)) {
|
|
43
43
|
throw new Error(`invalid version ${version}, expected semver like 0.0.0`);
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
46
|
version,
|
|
47
47
|
kind,
|
|
48
|
-
cwd
|
|
49
|
-
dryRun
|
|
48
|
+
cwd: cwdFrom(options),
|
|
49
|
+
dryRun: flag(options, "dry-run"),
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function isBumpKind(value
|
|
53
|
+
function isBumpKind(value: string): value is BumpKind {
|
|
54
54
|
return value === "patch" || value === "minor" || value === "major";
|
|
55
55
|
}
|
package/src/cli/bump.ts
CHANGED
|
@@ -7,54 +7,54 @@ export type BumpKind = "patch" | "minor" | "major";
|
|
|
7
7
|
|
|
8
8
|
export type BumpOptions = {
|
|
9
9
|
/** Explicit target version. When set, overrides `kind`. */
|
|
10
|
-
version
|
|
11
|
-
kind
|
|
12
|
-
cwd
|
|
13
|
-
dryRun
|
|
10
|
+
version?: string;
|
|
11
|
+
kind?: BumpKind;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
dryRun?: boolean;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type BumpReport = {
|
|
17
|
-
root
|
|
18
|
-
from
|
|
19
|
-
to
|
|
20
|
-
kind
|
|
21
|
-
cargo
|
|
22
|
-
npm
|
|
17
|
+
root: string;
|
|
18
|
+
from: string;
|
|
19
|
+
to: string;
|
|
20
|
+
kind?: BumpKind;
|
|
21
|
+
cargo: string[];
|
|
22
|
+
npm: string[];
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const DEFAULT_KIND
|
|
25
|
+
const DEFAULT_KIND: BumpKind = "patch";
|
|
26
26
|
|
|
27
|
-
export async function runBump(argv
|
|
27
|
+
export async function runBump(argv: string[]): Promise < void> {
|
|
28
28
|
const options = parseBumpArgs(argv);
|
|
29
29
|
const report = bumpWorkspace(options);
|
|
30
30
|
printBumpReport(report, options.dryRun);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function parseBumpArgs(argv
|
|
34
|
-
let version
|
|
35
|
-
let kind
|
|
36
|
-
let cwd
|
|
33
|
+
function parseBumpArgs(argv: string[]): BumpOptions {
|
|
34
|
+
let version: string | undefined;
|
|
35
|
+
let kind: BumpKind = DEFAULT_KIND;
|
|
36
|
+
let cwd: string | undefined;
|
|
37
37
|
let dryRun = false;
|
|
38
38
|
|
|
39
|
-
for(let i = 0; i<argv.length; i += 1){
|
|
39
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
40
40
|
const arg = argv[i];
|
|
41
|
-
if(arg === "--dry-run"){
|
|
41
|
+
if (arg === "--dry-run") {
|
|
42
42
|
dryRun = true;
|
|
43
|
-
} else if(arg === "-C" || arg === "--cwd"){
|
|
44
|
-
cwd = argv[
|
|
45
|
-
} else if(arg === "--version" || arg === "-v"){
|
|
46
|
-
version = argv[
|
|
47
|
-
} else if(arg === "--patch"){
|
|
43
|
+
} else if (arg === "-C" || arg === "--cwd") {
|
|
44
|
+
cwd = argv[++i];
|
|
45
|
+
} else if (arg === "--version" || arg === "-v") {
|
|
46
|
+
version = argv[++i];
|
|
47
|
+
} else if (arg === "--patch") {
|
|
48
48
|
kind = "patch";
|
|
49
|
-
} else if(arg === "--minor"){
|
|
49
|
+
} else if (arg === "--minor") {
|
|
50
50
|
kind = "minor";
|
|
51
|
-
} else if(arg === "--major"){
|
|
51
|
+
} else if (arg === "--major") {
|
|
52
52
|
kind = "major";
|
|
53
|
-
} else if(arg === "-h" || arg === "--help"){
|
|
53
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
54
54
|
printBumpHelp();
|
|
55
55
|
process.exit(0);
|
|
56
|
-
} else if(!arg.startsWith("-")){
|
|
57
|
-
if(isBumpKind(arg)){
|
|
56
|
+
} else if (!arg.startsWith("-")) {
|
|
57
|
+
if (isBumpKind(arg)) {
|
|
58
58
|
kind = arg;
|
|
59
59
|
} else {
|
|
60
60
|
version = arg;
|
|
@@ -62,23 +62,23 @@ function parseBumpArgs(argv : string[]) : BumpOptions {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
if(version){
|
|
65
|
+
if (version) {
|
|
66
66
|
assertVersion(version);
|
|
67
67
|
}
|
|
68
68
|
return { version, kind, cwd, dryRun };
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function isBumpKind(value
|
|
71
|
+
function isBumpKind(value: string): value is BumpKind {
|
|
72
72
|
return value === "patch" || value === "minor" || value === "major";
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
function assertVersion(version
|
|
76
|
-
if(
|
|
75
|
+
function assertVersion(version: string): void {
|
|
76
|
+
if (!/^\d+\.\d+\.\d+(-[\w.-]+)?$/.test(version)) {
|
|
77
77
|
throw new Error(`invalid version ${version}, expected semver like 0.0.0`);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
export function bumpWorkspace(options
|
|
81
|
+
export function bumpWorkspace(options: BumpOptions): BumpReport {
|
|
82
82
|
const root = findWorkspaceRoot(options.cwd ?? process.cwd());
|
|
83
83
|
const cratesDir = join(root, "projects", "crates");
|
|
84
84
|
const packagesDir = join(root, "projects", "packages");
|
|
@@ -89,71 +89,71 @@ export function bumpWorkspace(options : BumpOptions) : BumpReport {
|
|
|
89
89
|
const to = options.version ?? bumpSemver(from, options.kind ?? DEFAULT_KIND);
|
|
90
90
|
assertVersion(to);
|
|
91
91
|
|
|
92
|
-
const cargo = cargoPaths.map((path) =>bumpCargoManifest(path, to, options.dryRun));
|
|
93
|
-
const npm = npmPaths.map((path) =>bumpPackageManifest(path, to, options.dryRun));
|
|
92
|
+
const cargo = cargoPaths.map((path) => bumpCargoManifest(path, to, options.dryRun));
|
|
93
|
+
const npm = npmPaths.map((path) => bumpPackageManifest(path, to, options.dryRun));
|
|
94
94
|
|
|
95
95
|
return {
|
|
96
96
|
root,
|
|
97
97
|
from,
|
|
98
98
|
to,
|
|
99
|
-
kind
|
|
99
|
+
kind: options.version ? undefined : options.kind ?? DEFAULT_KIND,
|
|
100
100
|
cargo,
|
|
101
101
|
npm,
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
function readWorkspaceVersion(cargoPaths
|
|
106
|
-
const versions = new Set<string>();
|
|
107
|
-
for(const path of cargoPaths){
|
|
105
|
+
function readWorkspaceVersion(cargoPaths: string[], npmPaths: string[]): string {
|
|
106
|
+
const versions = new Set < string> ();
|
|
107
|
+
for (const path of cargoPaths) {
|
|
108
108
|
versions.add(readCargoVersion(path));
|
|
109
109
|
}
|
|
110
|
-
for(const path of npmPaths){
|
|
110
|
+
for (const path of npmPaths) {
|
|
111
111
|
versions.add(readPackageVersion(path));
|
|
112
112
|
}
|
|
113
|
-
if(versions.size === 0){
|
|
113
|
+
if (versions.size === 0) {
|
|
114
114
|
throw new Error("no crate or package versions found in workspace");
|
|
115
115
|
}
|
|
116
|
-
if(versions.size>1){
|
|
116
|
+
if (versions.size > 1) {
|
|
117
117
|
throw new Error(`workspace versions are out of sync: ${[...versions].sort().join(", ")}`);
|
|
118
118
|
}
|
|
119
119
|
return[...versions][0];
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function readCargoVersion(path
|
|
122
|
+
function readCargoVersion(path: string): string {
|
|
123
123
|
const original = readFileSync(path, "utf8");
|
|
124
|
-
const match = original.match(
|
|
125
|
-
if(!match){
|
|
124
|
+
const match = original.match(/^version\s*=\s*"([^"]*)"/m);
|
|
125
|
+
if (!match) {
|
|
126
126
|
throw new Error(`no [package].version found in ${path}`);
|
|
127
127
|
}
|
|
128
128
|
return match[1];
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
function readPackageVersion(path
|
|
132
|
-
const parsed = JSON.parse(readFileSync(path, "utf8"))as { version
|
|
133
|
-
if(!parsed.version){
|
|
131
|
+
function readPackageVersion(path: string): string {
|
|
132
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"))as { version?: string };
|
|
133
|
+
if (!parsed.version) {
|
|
134
134
|
throw new Error(`no version field in ${path}`);
|
|
135
135
|
}
|
|
136
136
|
return parsed.version;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
export function bumpSemver(version
|
|
140
|
-
const match = version.match(
|
|
141
|
-
if(!match){
|
|
139
|
+
export function bumpSemver(version: string, kind: BumpKind): string {
|
|
140
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-.*)?$/);
|
|
141
|
+
if (!match) {
|
|
142
142
|
throw new Error(`cannot bump non-semver version ${version}`);
|
|
143
143
|
}
|
|
144
144
|
let major = Number(match[1]);
|
|
145
145
|
let minor = Number(match[2]);
|
|
146
146
|
let patch = Number(match[3]);
|
|
147
147
|
|
|
148
|
-
switch(kind){
|
|
149
|
-
case "patch"
|
|
148
|
+
switch (kind) {
|
|
149
|
+
case "patch":
|
|
150
150
|
patch += 1;
|
|
151
151
|
break;
|
|
152
|
-
case "minor"
|
|
152
|
+
case "minor":
|
|
153
153
|
minor += 1;
|
|
154
154
|
patch = 0;
|
|
155
155
|
break;
|
|
156
|
-
case "major"
|
|
156
|
+
case "major":
|
|
157
157
|
major += 1;
|
|
158
158
|
minor = 0;
|
|
159
159
|
patch = 0;
|
|
@@ -163,65 +163,65 @@ export function bumpSemver(version : string, kind : BumpKind) : string {
|
|
|
163
163
|
return `${major}.${minor}.${patch}`;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
function collectCargoManifests(cratesDir
|
|
167
|
-
if(!existsSync(cratesDir)){
|
|
166
|
+
function collectCargoManifests(cratesDir: string): string[] {
|
|
167
|
+
if (!existsSync(cratesDir)) {
|
|
168
168
|
return[];
|
|
169
169
|
}
|
|
170
|
-
return readdirSync(cratesDir, { withFileTypes
|
|
171
|
-
.filter((entry) =>entry.isDirectory())
|
|
172
|
-
.map((entry) =>join(cratesDir, entry.name, "Cargo.toml"))
|
|
173
|
-
.filter((path) =>existsSync(path));
|
|
170
|
+
return readdirSync(cratesDir, { withFileTypes: true })
|
|
171
|
+
.filter((entry) => entry.isDirectory())
|
|
172
|
+
.map((entry) => join(cratesDir, entry.name, "Cargo.toml"))
|
|
173
|
+
.filter((path) => existsSync(path));
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
function collectPackageManifests(packagesDir
|
|
177
|
-
if(!existsSync(packagesDir)){
|
|
176
|
+
function collectPackageManifests(packagesDir: string): string[] {
|
|
177
|
+
if (!existsSync(packagesDir)) {
|
|
178
178
|
return[];
|
|
179
179
|
}
|
|
180
|
-
return readdirSync(packagesDir, { withFileTypes
|
|
181
|
-
.filter((entry) =>entry.isDirectory() && entry.name!== "node_modules")
|
|
182
|
-
.map((entry) =>join(packagesDir, entry.name, "package.json"))
|
|
183
|
-
.filter((path) =>existsSync(path));
|
|
180
|
+
return readdirSync(packagesDir, { withFileTypes: true })
|
|
181
|
+
.filter((entry) => entry.isDirectory() && entry.name !== "node_modules")
|
|
182
|
+
.map((entry) => join(packagesDir, entry.name, "package.json"))
|
|
183
|
+
.filter((path) => existsSync(path));
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
function bumpCargoManifest(path
|
|
186
|
+
function bumpCargoManifest(path: string, version: string, dryRun?: boolean) : string {
|
|
187
187
|
const original = readFileSync(path, "utf8");
|
|
188
|
-
const next = original.replace(
|
|
189
|
-
if(next === original){
|
|
188
|
+
const next = original.replace(/^version\s*=\s*"[^"]*"/m, `version = "${version}"`);
|
|
189
|
+
if (next === original) {
|
|
190
190
|
throw new Error(`no [package].version found in ${path}`);
|
|
191
191
|
}
|
|
192
|
-
if(!dryRun){
|
|
192
|
+
if (!dryRun) {
|
|
193
193
|
writeFileSync(path, next, "utf8");
|
|
194
194
|
}
|
|
195
195
|
return path;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
function bumpPackageManifest(path
|
|
198
|
+
function bumpPackageManifest(path: string, version: string, dryRun?: boolean) : string {
|
|
199
199
|
const original = readFileSync(path, "utf8");
|
|
200
|
-
const parsed = JSON.parse(original)as { version
|
|
201
|
-
if(!parsed.version){
|
|
200
|
+
const parsed = JSON.parse(original)as { version?: string };
|
|
201
|
+
if (!parsed.version) {
|
|
202
202
|
throw new Error(`no version field in ${path}`);
|
|
203
203
|
}
|
|
204
204
|
parsed.version = version;
|
|
205
205
|
const next = `${JSON.stringify(parsed, null, 4)}\n`;
|
|
206
|
-
if(!dryRun){
|
|
206
|
+
if (!dryRun) {
|
|
207
207
|
writeFileSync(path, next, "utf8");
|
|
208
208
|
}
|
|
209
209
|
return path;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
export function printBumpReport(report
|
|
212
|
+
export function printBumpReport(report: BumpReport, dryRun?: boolean) : void {
|
|
213
213
|
const prefix = dryRun ? "would bump" : "bumped";
|
|
214
214
|
const kind = report.kind ? ` (${report.kind})` : "";
|
|
215
215
|
console.log(`${prefix} workspace ${report.root} ${report.from} -> ${report.to}${kind}`);
|
|
216
|
-
for(const path of report.cargo){
|
|
216
|
+
for (const path of report.cargo) {
|
|
217
217
|
console.log(` cargo: ${path}`);
|
|
218
218
|
}
|
|
219
|
-
for(const path of report.npm){
|
|
219
|
+
for (const path of report.npm) {
|
|
220
220
|
console.log(` npm: ${path}`);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
function printBumpHelp()
|
|
224
|
+
function printBumpHelp(): void {
|
|
225
225
|
console.log(`nifty bump — align all crate and package versions in the workspace
|
|
226
226
|
|
|
227
227
|
Usage:
|
|
@@ -9,7 +9,7 @@ import { loadNiftyNative } from "../native.js";
|
|
|
9
9
|
import { bootstrapFromOptions } from "./context.js";
|
|
10
10
|
import { cwdFrom, flag, str } from "./options.js";
|
|
11
11
|
|
|
12
|
-
export function registerChangeLogsCommand(cli
|
|
12
|
+
export function registerChangeLogsCommand(cli: Cli): void {
|
|
13
13
|
const changeLogs = cli.command("change-logs", "cli.cmd.change-logs")
|
|
14
14
|
.option("--version <version>", "cli.opt.version")
|
|
15
15
|
.option("--from <ref>", "cli.opt.from")
|
|
@@ -27,54 +27,54 @@ export function registerChangeLogsCommand(cli : Cli) : void {
|
|
|
27
27
|
.option("--map <path>", "cli.opt.author-map")
|
|
28
28
|
.option("--github-token <token>", "cli.opt.github-token")
|
|
29
29
|
.option("--fetch", "cli.opt.fetch")
|
|
30
|
-
.action(async(options) =>cmdChangeLogsLookup(options));
|
|
30
|
+
.action(async(options) => cmdChangeLogsLookup(options));
|
|
31
31
|
|
|
32
|
-
changeLogs.action(async(options) =>cmdChangeLogsRender(options));
|
|
32
|
+
changeLogs.action(async(options) => cmdChangeLogsRender(options));
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export async function cmdChangeLogsRender(options
|
|
35
|
+
export async function cmdChangeLogsRender(options: ParsedOptions): Promise < number> {
|
|
36
36
|
await bootstrapFromOptions(options);
|
|
37
37
|
const cwd = cwdFrom(options) ?? process.cwd();
|
|
38
|
-
const { config } = await loadConfig({ cwd, createIfMissing
|
|
38
|
+
const { config } = await loadConfig({ cwd, createIfMissing: false });
|
|
39
39
|
const layout = detectProjectLayout(cwd);
|
|
40
40
|
const repoRoot = config.repoRoot ?? layout.root;
|
|
41
41
|
const native = loadNiftyNative();
|
|
42
42
|
const report = native.history["changelog-render"]({
|
|
43
43
|
cwd,
|
|
44
|
-
version
|
|
45
|
-
fromRef
|
|
46
|
-
toRef
|
|
47
|
-
write
|
|
48
|
-
tags
|
|
49
|
-
repo
|
|
50
|
-
authorMap
|
|
51
|
-
releasesDir
|
|
44
|
+
version: str(options, "version"),
|
|
45
|
+
fromRef: str(options, "from"),
|
|
46
|
+
toRef: str(options, "to"),
|
|
47
|
+
write: flag(options, "write"),
|
|
48
|
+
tags: flag(options, "tags"),
|
|
49
|
+
repo: str(options, "repo") ?? config.changelog?.repo,
|
|
50
|
+
authorMap: str(options, "author-map") ?? resolveAuthorMapPath(config, repoRoot),
|
|
51
|
+
releasesDir: str(options, "releases-dir") ?? config.changelog?.releasesDir,
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
if(flag(options, "tags")){
|
|
54
|
+
if (flag(options, "tags")) {
|
|
55
55
|
console.log(report.notes);
|
|
56
56
|
return 0;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
if(report.rangeLabel){
|
|
59
|
+
if (report.rangeLabel) {
|
|
60
60
|
console.error(`change-logs: ${report.rangeLabel} — ${report.commitCount} commit(s)`);
|
|
61
61
|
}
|
|
62
|
-
if(report.writtenPath){
|
|
62
|
+
if (report.writtenPath) {
|
|
63
63
|
console.error(`change-logs: wrote ${report.writtenPath}`);
|
|
64
64
|
}
|
|
65
65
|
process.stdout.write(report.notes);
|
|
66
66
|
return 0;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export async function cmdChangeLogsLookup(options
|
|
69
|
+
export async function cmdChangeLogsLookup(options: ParsedOptions): Promise < number> {
|
|
70
70
|
await bootstrapFromOptions(options);
|
|
71
71
|
const cwd = cwdFrom(options) ?? process.cwd();
|
|
72
|
-
const { config } = await loadConfig({ cwd, createIfMissing
|
|
72
|
+
const { config } = await loadConfig({ cwd, createIfMissing: false });
|
|
73
73
|
const layout = detectProjectLayout(cwd);
|
|
74
74
|
const repoRoot = config.repoRoot ?? layout.root;
|
|
75
75
|
const email = str(options, "email");
|
|
76
76
|
const login = str(options, "login");
|
|
77
|
-
if(!email && !login){
|
|
77
|
+
if (!email && !login) {
|
|
78
78
|
throw new Error("lookup requires --email or --login");
|
|
79
79
|
}
|
|
80
80
|
const native = loadNiftyNative();
|
|
@@ -82,15 +82,15 @@ export async function cmdChangeLogsLookup(options : ParsedOptions) : Promise<num
|
|
|
82
82
|
cwd,
|
|
83
83
|
email,
|
|
84
84
|
login,
|
|
85
|
-
map
|
|
86
|
-
githubToken
|
|
87
|
-
fetch
|
|
85
|
+
map: str(options, "map") ?? resolveAuthorMapPath(config, repoRoot),
|
|
86
|
+
githubToken: str(options, "github-token") ?? config.githubToken ?? process.env.GITHUB_TOKEN,
|
|
87
|
+
fetch: flag(options, "fetch"),
|
|
88
88
|
});
|
|
89
|
-
const json
|
|
90
|
-
if(author.id!== undefined){
|
|
89
|
+
const json: Record < string, unknown > = { };
|
|
90
|
+
if (author.id !== undefined) {
|
|
91
91
|
json.id = author.id;
|
|
92
92
|
}
|
|
93
|
-
if(author.login){
|
|
93
|
+
if (author.login) {
|
|
94
94
|
json.login = author.login;
|
|
95
95
|
}
|
|
96
96
|
console.log(JSON.stringify(json, null, 2));
|
|
@@ -98,6 +98,6 @@ export async function cmdChangeLogsLookup(options : ParsedOptions) : Promise<num
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/** Default author map path relative to repo root (matches git-change-logs). */
|
|
101
|
-
export function defaultAuthorMapPath(repoRoot
|
|
101
|
+
export function defaultAuthorMapPath(repoRoot: string): string {
|
|
102
102
|
return join(repoRoot, "documentation/maintenance/author-github.json");
|
|
103
103
|
}
|
package/src/cli/cli.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { registerTrustCommand } from "./trust-cmd.js";
|
|
|
15
15
|
import { registerUpdateCommand } from "./update-cmd.js";
|
|
16
16
|
import { registerUploadCommand } from "./upload-cmd.js";
|
|
17
17
|
|
|
18
|
-
function buildNiftyCli(){
|
|
18
|
+
function buildNiftyCli() {
|
|
19
19
|
const localesRoot = join(dirname(fileURLToPath(import.meta.url)), "../../locales");
|
|
20
20
|
const cli = createCli("nifty")
|
|
21
21
|
.locales(localesRoot)
|
|
@@ -37,10 +37,10 @@ function buildNiftyCli(){
|
|
|
37
37
|
return cli;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export async function runCli(argv
|
|
40
|
+
export async function runCli(argv: string[]): Promise < number> {
|
|
41
41
|
try {
|
|
42
42
|
return await buildNiftyCli().parse(argv);
|
|
43
|
-
} catch(error){
|
|
43
|
+
} catch (error) {
|
|
44
44
|
console.error(`error: ${error instanceof Error ? error.message : String(error)}`);
|
|
45
45
|
return 1;
|
|
46
46
|
}
|