@@ -49,6 +49,21 @@ Flags:
4949const EXPECTED_BRANCH = 'v2'
5050// this package will use tags like v1.0.0 while the rest will use the full package name like @pinia/testing@1.0.0
5151const MAIN_PKG_NAME = 'pinia'
52+ // whether the main package is at the root of the mono repo or this is not a mono repo
53+ const IS_MAIN_PKG_ROOT = false
54+ // array of folders of packages to release
55+ const PKG_FOLDERS = [
56+ // comment for multiline format
57+ join ( __dirname , '../packages/pinia' ) ,
58+ join ( __dirname , '../packages/testing' ) ,
59+ join ( __dirname , '../packages/nuxt' ) ,
60+ ]
61+ // files to add and commit after building a new version
62+ const FILES_TO_COMMIT = [
63+ // comment for multiline format
64+ 'packages/*/package.json' ,
65+ 'packages/*/CHANGELOG.md' ,
66+ ]
5267
5368/**
5469 * @type {typeof execa }
@@ -60,7 +75,7 @@ const run = (bin, args, opts = {}) =>
6075 * @param args {string[]}
6176 * @param opts {import('execa').Options}
6277 */
63- const dryRun = ( bin , args , opts = { } ) =>
78+ const dryRun = async ( bin , args , opts = { } ) =>
6479 console . log ( chalk . blue ( `[dry-run] ${ bin } ${ args . join ( ' ' ) } ` ) , opts )
6580const runIfNotDry = isDryRun ? dryRun : run
6681
@@ -112,13 +127,7 @@ async function main() {
112127 }
113128 }
114129
115- const packagesFolders = [
116- join ( __dirname , '../packages/pinia' ) ,
117- join ( __dirname , '../packages/testing' ) ,
118- join ( __dirname , '../packages/nuxt' ) ,
119- ]
120-
121- const changedPackages = await getChangedPackages ( ...packagesFolders )
130+ const changedPackages = await getChangedPackages ( ...PKG_FOLDERS )
122131
123132 if ( ! changedPackages . length ) {
124133 console . log ( chalk . red ( `No packages have changed since last release` ) )
@@ -129,24 +138,29 @@ async function main() {
129138 console . log ( `\n${ chalk . bold . blue ( 'This is a dry run' ) } \n` )
130139 }
131140
132- // allow to select which packages
133- const { pickedPackages } = await prompts ( {
134- type : 'multiselect' ,
135- name : 'pickedPackages' ,
136- message : 'What packages do you want to release?' ,
137- instructions : false ,
138- min : 1 ,
139- choices : changedPackages . map ( ( pkg ) => ( {
140- title : pkg . name ,
141- value : pkg . name ,
142- selected : true ,
143- } ) ) ,
144- } )
141+ let packagesToRelease = changedPackages
142+
143+ // if there are more than one package, ask which ones to release
144+ if ( packagesToRelease . length > 1 ) {
145+ // allow to select which packages
146+ const { pickedPackages } = await prompts ( {
147+ type : 'multiselect' ,
148+ name : 'pickedPackages' ,
149+ message : 'What packages do you want to release?' ,
150+ instructions : false ,
151+ min : 1 ,
152+ choices : changedPackages . map ( ( pkg ) => ( {
153+ title : pkg . name ,
154+ value : pkg . name ,
155+ selected : true ,
156+ } ) ) ,
157+ } )
145158
146- // const packagesToRelease = changedPackages
147- const packagesToRelease = changedPackages . filter ( ( pkg ) =>
148- pickedPackages . includes ( pkg . name )
149- )
159+ // const packagesToRelease = changedPackages
160+ packagesToRelease = changedPackages . filter ( ( pkg ) =>
161+ pickedPackages . includes ( pkg . name )
162+ )
163+ }
150164
151165 step (
152166 `Ready to release ${ packagesToRelease . map ( ( { name } ) => chalk . bold . white ( name ) ) . join ( ', ' ) } `
@@ -271,8 +285,9 @@ async function main() {
271285 changelogExists ? '1' : '0' ,
272286 '--commit-path' ,
273287 '.' ,
274- '--lerna-package' ,
275- pkg . name ,
288+ ...( pkg . name === MAIN_PKG_NAME && IS_MAIN_PKG_ROOT
289+ ? [ ]
290+ : [ '--lerna-package' , pkg . name ] ) ,
276291 ...( pkg . name === MAIN_PKG_NAME
277292 ? [ ]
278293 : [ '--tag-prefix' , `${ pkg . name } @` ] ) ,
@@ -312,11 +327,7 @@ async function main() {
312327 const { stdout } = await run ( 'git' , [ 'diff' ] , { stdio : 'pipe' } )
313328 if ( stdout ) {
314329 step ( '\nCommitting changes...' )
315- await runIfNotDry ( 'git' , [
316- 'add' ,
317- 'packages/*/CHANGELOG.md' ,
318- 'packages/*/package.json' ,
319- ] )
330+ await runIfNotDry ( 'git' , [ 'add' , ...FILES_TO_COMMIT ] )
320331 await runIfNotDry ( 'git' , [
321332 'commit' ,
322333 '-m' ,
0 commit comments