@@ -5,113 +5,120 @@ import { releaseChangelog, releasePublish, releaseVersion } from 'nx/release'
5
5
import { findMatchingProjects } from 'nx/src/utils/find-matching-projects.js'
6
6
import { default as yargs } from 'yargs'
7
7
8
- const options = await yargs ( process . argv )
9
- . version ( false ) // don't use the default meaning of version in yargs
10
- . option ( 'version' , {
11
- description :
12
- 'Explicit version specifier to use, if overriding conventional commits' ,
13
- type : 'string' ,
14
- } )
15
- . option ( 'dryRun' , {
16
- alias : 'd' ,
17
- description :
18
- 'Whether or not to perform a dry-run of the release process, defaults to true' ,
19
- type : 'boolean' ,
20
- default : true ,
21
- } )
22
- . option ( 'verbose' , {
23
- description : 'Whether or not to enable verbose logging, defaults to false' ,
24
- type : 'boolean' ,
25
- default : false ,
26
- } )
27
- . parseAsync ( )
28
-
29
- // get the projects from the nx.json in the parent directory
30
- const nxJsonPath = path . join ( workspaceRoot , 'nx.json' )
31
- const nxJson = await fs . readJSON ( nxJsonPath )
32
- const graph = await createProjectGraphAsync ( )
33
- const projects = findMatchingProjects ( nxJson . release . projects , graph . nodes )
34
- const publishDir = path . join ( workspaceRoot , 'publish' )
35
-
36
- await fs . remove ( publishDir )
8
+ try {
9
+ const options = await yargs ( process . argv )
10
+ . version ( false ) // don't use the default meaning of version in yargs
11
+ . option ( 'version' , {
12
+ description :
13
+ 'Explicit version specifier to use, if overriding conventional commits' ,
14
+ type : 'string' ,
15
+ } )
16
+ . option ( 'dryRun' , {
17
+ alias : 'd' ,
18
+ description :
19
+ 'Whether or not to perform a dry-run of the release process, defaults to true' ,
20
+ type : 'boolean' ,
21
+ default : true ,
22
+ } )
23
+ . option ( 'verbose' , {
24
+ description :
25
+ 'Whether or not to enable verbose logging, defaults to false' ,
26
+ type : 'boolean' ,
27
+ default : false ,
28
+ } )
29
+ . parseAsync ( )
37
30
38
- for ( const project of projects ) {
39
- const projectNode = graph . nodes [ project ]
40
- if ( ! projectNode ) {
41
- throw new Error ( 'ahhhhhhhhhhhhhhhhhh! This should be unpossible!' )
42
- }
31
+ // get the projects from the nx.json in the parent directory
32
+ const nxJsonPath = path . join ( workspaceRoot , 'nx.json' )
33
+ const nxJson = await fs . readJSON ( nxJsonPath )
34
+ const graph = await createProjectGraphAsync ( )
35
+ const projects = findMatchingProjects ( nxJson . release . projects , graph . nodes )
36
+ const publishDir = path . join ( workspaceRoot , 'publish' )
43
37
44
- const srcPath = path . join ( workspaceRoot , projectNode . data . root )
45
- const publishPath = path . join ( publishDir , projectNode . data . root )
38
+ await fs . remove ( publishDir )
46
39
47
- const packageJsonPath = path . join ( srcPath , 'package.json' )
48
- const packageJson = await fs . readJson ( packageJsonPath )
49
- const hasBundleDependencies = packageJson . bundleDependencies ?. length > 0
50
- const filesToCopy = [
51
- ...( packageJson . files ?? [ ] ) ,
52
- 'README.md' ,
53
- 'package.json' ,
54
- hasBundleDependencies ? 'node_modules' : null ,
55
- ] . filter ( Boolean )
40
+ for ( const project of projects ) {
41
+ const projectNode = graph . nodes [ project ]
42
+ if ( ! projectNode ) {
43
+ throw new Error ( 'ahhhhhhhhhhhhhhhhhh! This should be unpossible!' )
44
+ }
56
45
57
- await Promise . all (
58
- filesToCopy . map ( async ( file : string ) => {
59
- const sourcePath = path . join ( srcPath , file )
60
- const destinationPath = path . join ( publishPath , file )
61
- if ( await fs . pathExists ( sourcePath ) ) {
62
- await fs . copy ( sourcePath , destinationPath )
63
- }
64
- } ) ,
65
- )
46
+ const srcPath = path . join ( workspaceRoot , projectNode . data . root )
47
+ const publishPath = path . join ( publishDir , projectNode . data . root )
66
48
67
- if ( hasBundleDependencies ) {
68
- const exclude = [
69
- `${ path . sep } .bin${ path . sep } ` ,
70
- `${ path . sep } .vite${ path . sep } ` ,
71
- `${ path . sep } .cache${ path . sep } ` ,
72
- ]
49
+ const packageJsonPath = path . join ( srcPath , 'package.json' )
50
+ const packageJson = await fs . readJson ( packageJsonPath )
51
+ const hasBundleDependencies = packageJson . bundleDependencies ?. length > 0
52
+ const filesToCopy = [
53
+ ...( packageJson . files ?? [ ] ) ,
54
+ 'README.md' ,
55
+ 'package.json' ,
56
+ hasBundleDependencies ? 'node_modules' : null ,
57
+ ] . filter ( Boolean )
73
58
74
- await fs . copy (
75
- path . join ( workspaceRoot , 'node_modules' ) ,
76
- path . join ( publishPath , 'node_modules' ) ,
77
- {
78
- overwrite : false ,
79
- dereference : false ,
80
- filter : ( srcPath : string ) => ! exclude . some ( ( e ) => srcPath . includes ( e ) ) ,
81
- } ,
59
+ await Promise . all (
60
+ filesToCopy . map ( async ( file : string ) => {
61
+ const sourcePath = path . join ( srcPath , file )
62
+ const destinationPath = path . join ( publishPath , file )
63
+ if ( await fs . pathExists ( sourcePath ) ) {
64
+ await fs . copy ( sourcePath , destinationPath )
65
+ }
66
+ } ) ,
82
67
)
83
- }
84
- }
85
68
86
- const { workspaceVersion, projectsVersionData } = await releaseVersion ( {
87
- gitCommit : false ,
88
- stageChanges : false ,
89
- gitTag : false ,
90
- specifier : options . version ,
91
- dryRun : options . dryRun ,
92
- verbose : options . verbose ,
93
- } )
69
+ if ( hasBundleDependencies ) {
70
+ const exclude = [
71
+ `${ path . sep } .bin${ path . sep } ` ,
72
+ `${ path . sep } .vite${ path . sep } ` ,
73
+ `${ path . sep } .cache${ path . sep } ` ,
74
+ ]
94
75
95
- if ( workspaceVersion === null ) {
96
- console . log ( 'No relevant changes detected, skipping release process.' )
97
- process . exit ( 0 )
98
- } else {
99
- if ( process . env . CI || options . dryRun ) {
100
- await releaseChangelog ( {
101
- gitCommit : false ,
102
- stageChanges : false ,
103
- gitTag : false ,
104
- versionData : projectsVersionData ,
105
- version : workspaceVersion ,
106
- dryRun : options . dryRun ,
107
- verbose : options . verbose ,
108
- } )
76
+ await fs . copy (
77
+ path . join ( workspaceRoot , 'node_modules' ) ,
78
+ path . join ( publishPath , 'node_modules' ) ,
79
+ {
80
+ overwrite : false ,
81
+ dereference : false ,
82
+ filter : ( srcPath : string ) =>
83
+ ! exclude . some ( ( e ) => srcPath . includes ( e ) ) ,
84
+ } ,
85
+ )
86
+ }
109
87
}
110
88
111
- const result = await releasePublish ( {
89
+ const { workspaceVersion, projectsVersionData } = await releaseVersion ( {
90
+ gitCommit : false ,
91
+ stageChanges : false ,
92
+ gitTag : false ,
93
+ specifier : options . version ,
112
94
dryRun : options . dryRun ,
113
95
verbose : options . verbose ,
114
96
} )
115
97
116
- process . exit ( result )
98
+ if ( workspaceVersion === null ) {
99
+ console . log ( 'No relevant changes detected, skipping release process.' )
100
+ process . exit ( 0 )
101
+ } else {
102
+ if ( process . env . CI || options . dryRun ) {
103
+ await releaseChangelog ( {
104
+ gitCommit : false ,
105
+ stageChanges : false ,
106
+ gitTag : false ,
107
+ versionData : projectsVersionData ,
108
+ version : workspaceVersion ,
109
+ dryRun : options . dryRun ,
110
+ verbose : options . verbose ,
111
+ } )
112
+ }
113
+
114
+ const result = await releasePublish ( {
115
+ dryRun : options . dryRun ,
116
+ verbose : options . verbose ,
117
+ } )
118
+
119
+ process . exit ( result )
120
+ }
121
+ } catch ( err ) {
122
+ console . error ( err )
123
+ process . exit ( 1 )
117
124
}
0 commit comments