This repository was archived by the owner on Jun 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +57
-33
lines changed Expand file tree Collapse file tree 4 files changed +57
-33
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ const questions = [
79
79
'body' ,
80
80
'breaking' ,
81
81
'issues' ,
82
- // 'lerna'
82
+ 'lerna'
83
83
] ;
84
84
85
85
module . exports = {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ const { getAllPackages, getChangedPackages} = require ( '../util/lerna' ) ;
2
+
1
3
exports . createQuestion = ( state ) => {
4
+ const changedPackages = getChangedPackages ( state ) ;
2
5
const question = {
3
- choices : allPackages ,
6
+ choices : getAllPackages ( state ) ,
4
7
default : changedPackages ,
5
8
message : `The packages that this commit has affected (${ changedPackages . length } detected)\n` ,
6
9
name : 'packages' ,
Original file line number Diff line number Diff line change
1
+ const { execSync} = require ( 'child_process' ) ;
2
+ const path = require ( 'path' ) ;
3
+ const fs = require ( 'fs' ) ;
4
+
5
+ const isDir = ( root ) => ( name ) => {
6
+ const filepath = path . join ( root , name ) ;
7
+
8
+ try {
9
+ const stats = fs . statSync ( filepath ) ;
10
+
11
+ return stats . isDirectory ( ) ;
12
+ } catch ( error ) {
13
+ return false ;
14
+ }
15
+ } ;
16
+
17
+ const getAllPackages = ( state ) => {
18
+ try {
19
+ const dir = path . join ( state . root , 'packages' ) ;
20
+
21
+ return fs . readdirSync ( dir ) . map ( isDir ( dir ) ) ;
22
+ } catch ( error ) {
23
+ return [ ] ;
24
+ }
25
+ } ;
26
+
27
+ const getChangedFiles = ( ) =>
28
+ execSync ( 'git diff --cached --name-only 2>/dev/null' )
29
+ . toString ( )
30
+ . trim ( )
31
+ . split ( '\n' ) ;
32
+
33
+ const getChangedPackages = ( ) => {
34
+ const unique = { } ;
35
+ const changedFiles = getChangedFiles ( ) ;
36
+ const regex = / ^ p a c k a g e s \/ ( [ ^ / ] + ) \/ / ;
37
+
38
+ for ( const filename of changedFiles ) {
39
+ const matches = filename . match ( regex ) ;
40
+
41
+ if ( matches ) {
42
+ unique [ matches [ 1 ] ] = 1 ;
43
+ }
44
+ }
45
+
46
+ return Object . keys ( unique ) ;
47
+ } ;
48
+
49
+ module . exports = {
50
+ getAllPackages,
51
+ getChangedPackages
52
+ } ;
You can’t perform that action at this time.
0 commit comments