2
2
3
3
const path = require ( 'path' )
4
4
const fs = require ( 'fs' )
5
+ const execa = require ( 'execa' )
5
6
6
7
// Where an example depends on `"ipfs": "^0.51.0"` and we've just released `[email protected] `,
7
8
// go through all of the examples and update the version to `"ipfs": "^0.52.0"` - do
@@ -12,6 +13,22 @@ const EXAMPLES_DIR = path.resolve(__dirname, '../examples')
12
13
const DEP_TYPES = [ 'dependencies' , 'devDependencies' , 'optionalDependencies' , 'peerDependencies' ]
13
14
14
15
async function main ( ) {
16
+ const {
17
+ stdout : branch
18
+ } = await execa ( 'git' , [ 'rev-parse' , '--abbrev-ref' , 'HEAD' ] )
19
+
20
+ if ( branch !== 'master' ) {
21
+ console . info ( `Not running on branch ${ branch } ` )
22
+ return
23
+ }
24
+
25
+ if ( process . env . CI ) {
26
+ console . info ( 'Not running in CI' )
27
+ return
28
+ }
29
+
30
+ console . info ( 'Running on branch' , branch )
31
+
15
32
for ( const dir of fs . readdirSync ( PACKAGES_DIR ) ) {
16
33
const projectPkgPath = path . resolve ( PACKAGES_DIR , dir , 'package.json' )
17
34
@@ -45,9 +62,26 @@ async function main () {
45
62
}
46
63
}
47
64
}
65
+
66
+ await execa ( 'git' , [ 'add' , 'examples' ] )
67
+
68
+ const {
69
+ stdout : updated
70
+ } = await execa ( 'git' , [ 'status' , '--porcelain' ] )
71
+
72
+ console . info ( updated )
73
+
74
+ if ( ! updated . match ( / ^ M \s + e x a m p l e s / g) ) {
75
+ console . info ( 'No examples were updated' )
76
+ return
77
+ }
78
+
79
+ console . info ( 'Pushing updated dependencies' )
80
+ await execa ( 'git' , [ 'commit' , '-m' , '"chore: updated example dependencies"' ] )
81
+ await execa ( 'git' , [ 'push' ] )
48
82
}
49
83
50
84
main ( ) . catch ( err => {
51
85
console . error ( err )
52
86
process . exit ( 1 )
53
- } )
87
+ } )
0 commit comments