Skip to content

Commit 3a64434

Browse files
authored
ci: improve publish command (#786)
1 parent 323dc4e commit 3a64434

File tree

10 files changed

+33
-28
lines changed

10 files changed

+33
-28
lines changed

packages/cli/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
},
1818
"publish": {
19-
"command": "node tools/scripts/publish.mjs cli {args.ver} {args.tag}",
19+
"command": "node tools/scripts/publish.mjs --name=cli --ver={args.ver} --tag={args.tag}",
2020
"dependsOn": ["build"]
2121
},
2222
"lint": {

packages/core/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
},
1818
"publish": {
19-
"command": "node tools/scripts/publish.mjs core {args.ver} {args.tag}",
19+
"command": "node tools/scripts/publish.mjs --name=core --ver={args.ver} --tag={args.tag}",
2020
"dependsOn": ["build"]
2121
},
2222
"lint": {

packages/models/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
},
1818
"publish": {
19-
"command": "node tools/scripts/publish.mjs models {args.ver} {args.tag}",
19+
"command": "node tools/scripts/publish.mjs --name=models --ver={args.ver} --tag={args.tag}",
2020
"dependsOn": ["build"]
2121
},
2222
"lint": {

packages/nx-plugin/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
}
3939
},
4040
"publish": {
41-
"command": "node tools/scripts/publish.mjs nx-plugin {args.ver} {args.tag}",
41+
"command": "node tools/scripts/publish.mjs --name=nx-plugin --ver={args.ver} --tag={args.tag}",
4242
"dependsOn": ["build"]
4343
},
4444
"lint": {

packages/plugin-coverage/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
},
4141
"publish": {
42-
"command": "node tools/scripts/publish.mjs plugin-coverage {args.ver} {args.tag}",
42+
"command": "node tools/scripts/publish.mjs --name=plugin-coverage --ver={args.ver} --tag={args.tag}",
4343
"dependsOn": ["build"]
4444
}
4545
},

packages/plugin-eslint/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
},
1919
"publish": {
20-
"command": "node tools/scripts/publish.mjs plugin-eslint {args.ver} {args.tag}",
20+
"command": "node tools/scripts/publish.mjs --name=plugin-eslint --ver={args.ver} --tag={args.tag}",
2121
"dependsOn": ["build"]
2222
},
2323
"lint": {

packages/plugin-js-packages/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
},
4141
"publish": {
42-
"command": "node tools/scripts/publish.mjs plugin-js-packages {args.ver} {args.tag}",
42+
"command": "node tools/scripts/publish.mjs --name=plugin-js-packages --ver={args.ver} --tag={args.tag}",
4343
"dependsOn": ["build"]
4444
}
4545
},

packages/utils/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
},
1818
"publish": {
19-
"command": "node tools/scripts/publish.mjs utils {args.ver} {args.tag}",
19+
"command": "node tools/scripts/publish.mjs --name=utils --ver={args.ver} --tag={args.tag}",
2020
"dependsOn": ["build"]
2121
},
2222
"lint": {

tools/scripts/publish.mjs

+24-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
* You might need to authenticate with NPM before running this script.
88
*/
99
import devkit from '@nx/devkit';
10-
import { execSync } from 'child_process';
11-
import { readFileSync, writeFileSync } from 'fs';
10+
import { execSync } from 'node:child_process';
11+
import { readFileSync, writeFileSync } from 'node:fs';
12+
import yargs from 'yargs';
13+
import { hideBin } from 'yargs/helpers';
1214

1315
const { readCachedProjectGraph } = devkit;
1416

@@ -19,16 +21,28 @@ function invariant(condition, message) {
1921
}
2022
}
2123

22-
// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
23-
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
24-
const [, , name, version, tag = 'next'] = process.argv;
25-
2624
// A simple SemVer validation to validate the version
2725
const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/;
28-
invariant(
29-
version && validVersion.test(version),
30-
`No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${version}.`,
31-
);
26+
27+
// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
28+
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
29+
const {
30+
name,
31+
ver: version,
32+
tag,
33+
} = yargs(hideBin(process.argv))
34+
.options({
35+
name: { type: 'string', demandOption: true },
36+
ver: { type: 'string', demandOption: true },
37+
tag: { type: 'string', default: 'next' },
38+
})
39+
.coerce('ver', ver => {
40+
invariant(
41+
ver && validVersion.test(ver),
42+
`No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${ver}.`,
43+
);
44+
return ver;
45+
}).argv;
3246

3347
const graph = readCachedProjectGraph();
3448
const project = graph.nodes[name];

tools/scripts/start-local-registry.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,7 @@ export default async () => {
2525
// is is also possible to use nx release to publish the packages to the local registry
2626
execFileSync(
2727
'npx',
28-
[
29-
'nx',
30-
'run-many',
31-
'--targets',
32-
'publish',
33-
'--ver',
34-
version,
35-
'--tag',
36-
'e2e',
37-
],
28+
['nx', 'run-many', '--targets=publish', `--ver=${version}`, '--tag=e2e'],
3829
{ env: process.env, stdio: 'inherit', shell: true },
3930
);
4031
};

0 commit comments

Comments
 (0)