@@ -3,23 +3,38 @@ const semver = require('semver');
3
3
const cp = require ( 'child_process' ) ;
4
4
const { basename } = require ( 'path' ) ;
5
5
6
- const { read : readConfig } = require ( " @changesets/config" ) ;
7
- const readChangesets = require ( " @changesets/read" ) . default ;
8
- const assembleReleasePlan = require ( " @changesets/assemble-release-plan" ) . default ;
9
- const applyReleasePlan = require ( " @changesets/apply-release-plan" ) . default ;
10
- const { getPackages } = require ( " @manypkg/get-packages" ) ;
6
+ const { read : readConfig } = require ( ' @changesets/config' ) ;
7
+ const readChangesets = require ( ' @changesets/read' ) . default ;
8
+ const assembleReleasePlan = require ( ' @changesets/assemble-release-plan' ) . default ;
9
+ const applyReleasePlan = require ( ' @changesets/apply-release-plan' ) . default ;
10
+ const { getPackages } = require ( ' @manypkg/get-packages' ) ;
11
11
12
12
function getNewVersion ( version , type ) {
13
- const gitHash = cp . spawnSync ( 'git' , [ 'rev-parse' , '--short' , 'HEAD' ] ) . stdout . toString ( ) . trim ( ) ;
14
-
13
+ const gitHash = cp
14
+ . spawnSync ( 'git' , [ 'rev-parse' , '--short' , 'HEAD' ] )
15
+ . stdout . toString ( )
16
+ . trim ( ) ;
17
+
15
18
return semver . inc ( version , `pre${ type } ` , true , 'alpha-' + gitHash ) ;
16
19
}
17
20
18
21
function getRelevantChangesets ( baseBranch ) {
19
- const comparePoint = cp . spawnSync ( 'git' , [ 'merge-base' , `origin/${ baseBranch } ` , 'HEAD' ] ) . stdout . toString ( ) . trim ( ) ;
20
- const listModifiedFiles = cp . spawnSync ( 'git' , [ 'diff' , '--name-only' , comparePoint ] ) . stdout . toString ( ) . trim ( ) . split ( '\n' ) ;
22
+ const comparePoint = cp
23
+ . spawnSync ( 'git' , [ 'merge-base' , `origin/${ baseBranch } ` , 'HEAD' ] )
24
+ . stdout . toString ( )
25
+ . trim ( ) ;
26
+ console . log ( 'compare point' , comparePoint ) ;
27
+ const listModifiedFiles = cp
28
+ . spawnSync ( 'git' , [ 'diff' , '--name-only' , comparePoint ] )
29
+ . stdout . toString ( )
30
+ . trim ( )
31
+ . split ( '\n' ) ;
32
+ console . log ( 'listModifiedFiles' , listModifiedFiles ) ;
33
+
34
+ const items = listModifiedFiles . filter ( f => f . startsWith ( '.changeset' ) ) . map ( f => basename ( f , '.md' ) ) ;
35
+ console . log ( 'items' , items ) ;
21
36
22
- return listModifiedFiles . filter ( f => f . startsWith ( '.changeset' ) ) . map ( f => basename ( f , '.md' ) ) ;
37
+ return items ;
23
38
}
24
39
25
40
async function updateVersions ( ) {
@@ -28,13 +43,13 @@ async function updateVersions() {
28
43
const config = await readConfig ( cwd , packages ) ;
29
44
const modifiedChangesets = getRelevantChangesets ( config . baseBranch ) ;
30
45
const changesets = ( await readChangesets ( cwd ) ) . filter ( change => modifiedChangesets . includes ( change . id ) ) ;
31
-
46
+
32
47
if ( changesets . length === 0 ) {
33
48
console . warn ( `Unable to find any relevant package for canary publishing. Please make sure changesets exists!` ) ;
34
49
process . exit ( 1 ) ;
35
50
} else {
36
51
const releasePlan = assembleReleasePlan ( changesets , packages , config , [ ] , false ) ;
37
-
52
+
38
53
if ( releasePlan . releases . length === 0 ) {
39
54
console . warn ( `Unable to find any relevant package for canary releasing. Please make sure changesets exists!` ) ;
40
55
process . exit ( 1 ) ;
@@ -59,9 +74,11 @@ async function updateVersions() {
59
74
}
60
75
}
61
76
62
- updateVersions ( ) . then ( ( ) => {
63
- console . info ( `Done!` )
64
- } ) . catch ( err => {
65
- console . error ( err ) ;
66
- process . exit ( 1 ) ;
67
- } ) ;
77
+ updateVersions ( )
78
+ . then ( ( ) => {
79
+ console . info ( `Done!` ) ;
80
+ } )
81
+ . catch ( err => {
82
+ console . error ( err ) ;
83
+ process . exit ( 1 ) ;
84
+ } ) ;
0 commit comments