7
7
* You might need to authenticate with NPM before running this script.
8
8
*/
9
9
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' ;
12
14
13
15
const { readCachedProjectGraph } = devkit ;
14
16
@@ -19,16 +21,28 @@ function invariant(condition, message) {
19
21
}
20
22
}
21
23
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
-
26
24
// A simple SemVer validation to validate the version
27
25
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 ;
32
46
33
47
const graph = readCachedProjectGraph ( ) ;
34
48
const project = graph . nodes [ name ] ;
0 commit comments