1
- var _ = require ( 'lodash' ) ;
2
- var exec = require ( 'child_process' ) . execSync ;
3
- var fs = require ( 'fs' ) ;
4
- var path = require ( 'path' ) ;
5
- var yargs = require ( 'yargs' ) ;
6
- const rimraf = require ( 'rimraf' ) ;
1
+ const { execSync } = require ( "child_process" ) ;
2
+ const fs = require ( "fs" ) ;
3
+ const path = require ( "path" ) ;
7
4
8
- let args = process . argv . length <= 2 ? [ ] : process . argv . slice ( 2 , process . argv . length ) ;
5
+ const cliArgs = process . argv . length <= 2 ? [ ] : process . argv . slice ( 2 ) ;
9
6
10
7
// Use npm ci or npm install ?
11
- let ci = args . includes ( "--ci" ) ;
8
+ const useCi = cliArgs . includes ( "--ci" ) ;
9
+
12
10
// Copy package-lock back for docker build or build locally?
13
- let docker = args . includes ( "--docker" ) ;
11
+ const useDocker = cliArgs . includes ( "--docker" ) ;
14
12
15
- let frameworks = args . filter ( a => ! a . startsWith ( "--" ) ) ;
13
+ const frameworks = cliArgs . filter ( ( a ) => ! a . startsWith ( "--" ) ) ;
16
14
17
- console . log ( "rebuild-build-single.js started: args" , args , "ci" , ci , "docker" , docker , "frameworks" , frameworks ) ;
15
+ console . log (
16
+ "rebuild-build-single.js started: args" ,
17
+ cliArgs ,
18
+ "useCi" ,
19
+ useCi ,
20
+ "useDocker" ,
21
+ useDocker ,
22
+ "frameworks" ,
23
+ frameworks
24
+ ) ;
18
25
19
26
/*
20
27
rebuild-single.js [--ci] [--docker] [keyed/framework1 ... non-keyed/frameworkN]
@@ -29,48 +36,72 @@ it calls npm ci and npm run build-prod for the benchmark
29
36
Pass list of frameworks
30
37
*/
31
38
39
+ /**
40
+ * Log command and run it with execSync
41
+ * @param {string } command
42
+ * @param {string|URL|undefined } cwd
43
+ */
44
+ function runCommand ( command , cwd = undefined ) {
45
+ console . log ( command ) ;
46
+ execSync ( command , { stdio : "inherit" , cwd } ) ;
47
+ }
48
+
49
+ /**
50
+ * @param {string } framework
51
+ */
52
+ function rebuildFramework ( framework ) {
53
+ const components = framework . split ( "/" ) ;
32
54
33
- if ( frameworks . length == 0 ) {
34
- console . log ( "ERROR: Missing arguments. Command: docker-rebuild keyed/framework1 non-keyed/framework2 ..." ) ;
55
+ if ( components . length !== 2 ) {
56
+ console . log (
57
+ `ERROR: invalid name ${ framework } . It must contain exactly one /.`
58
+ ) ;
35
59
process . exit ( 1 ) ;
36
- }
60
+ }
37
61
38
- for ( f of frameworks ) {
39
- let components = f . split ( "/" ) ;
40
- if ( components . length != 2 ) {
41
- console . log ( `ERROR: invalid name ${ f } . It must contain exactly one /.` )
42
- process . exit ( 1 ) ;
43
- }
44
- let [ keyed , name ] = components ;
45
- let path = `frameworks/${ keyed } /${ name } `
46
- if ( docker ) {
47
- if ( fs . existsSync ( path ) ) {
48
- console . log ( "deleting folder " , path ) ;
49
- exec ( `rm -r ${ path } ` ) ;
50
- }
51
- let rsync_cmd = `rsync -avC --exclude elm-stuff --exclude dist --exclude output ${ ci ? '' : '--exclude package-lock.json' } --exclude tmp --exclude node_modules --exclude bower_components /src/frameworks/${ keyed } /${ name } /build/frameworks/${ keyed } /` ;
52
- console . log ( rsync_cmd ) ;
53
- exec ( rsync_cmd ,
54
- {
55
- stdio : 'inherit'
56
- } ) ;
57
- }
58
- let rm_cmd = `rm -rf ${ ci ? '' : 'package-lock.json' } yarn.lock dist elm-stuff bower_components node_modules output` ;
59
- console . log ( rm_cmd ) ;
60
- exec ( rm_cmd , {
61
- cwd : path ,
62
- stdio : 'inherit'
63
- } ) ;
64
- let install_cmd = `npm ${ ci ? 'ci' : 'install' } && npm run build-prod` ;
65
- console . log ( install_cmd ) ;
66
- exec ( install_cmd , {
67
- cwd : path ,
68
- stdio : 'inherit'
69
- } ) ;
70
- if ( docker ) {
71
- let packageLockPath = path + "/package-lock.json" ;
72
- fs . copyFileSync ( packageLockPath , "/src/" + packageLockPath )
62
+ const [ keyed , name ] = components ;
63
+ const pathToFramework = path . join ( "frameworks" , keyed , name ) ;
64
+
65
+ if ( useDocker ) {
66
+ if ( fs . existsSync ( pathToFramework ) ) {
67
+ console . log ( "deleting folder " , pathToFramework ) ;
68
+ fs . rmSync ( pathToFramework , { recursive : true } ) ;
73
69
}
70
+
71
+ const rsyncCmd = `rsync -avC --exclude elm-stuff --exclude dist --exclude output ${
72
+ useCi ? "" : "--exclude package-lock.json"
73
+ } --exclude tmp --exclude node_modules --exclude bower_components /src/frameworks/${ keyed } /${ name } /build/frameworks/${ keyed } /`;
74
+ runCommand ( rsyncCmd ) ;
75
+ }
76
+
77
+ const rmCmd = `rm -rf ${
78
+ useCi ? "" : "package-lock.json"
79
+ } yarn.lock dist elm-stuff bower_components node_modules output`;
80
+ runCommand ( rmCmd , pathToFramework ) ;
81
+
82
+ const installCmd = `npm ${ useCi ? "ci" : "install" } && npm run build-prod` ;
83
+ runCommand ( installCmd , pathToFramework ) ;
84
+
85
+ if ( useDocker ) {
86
+ const packageJSONPath = path . join ( pathToFramework , "package-lock.json" ) ;
87
+ const destinationPath = path . join ( "/src" , packageJSONPath ) ;
88
+ fs . copyFileSync ( packageJSONPath , destinationPath ) ;
89
+ }
90
+ }
91
+
92
+ function rebuildFrameworks ( ) {
93
+ if ( ! frameworks . length ) {
94
+ console . log (
95
+ "ERROR: Missing arguments. Command: docker-rebuild keyed/framework1 non-keyed/framework2 ..."
96
+ ) ;
97
+ process . exit ( 1 ) ;
98
+ }
99
+
100
+ for ( const framework of frameworks ) {
101
+ rebuildFramework ( framework ) ;
102
+ }
103
+
104
+ console . log ( "rebuild-build-single.js finished: Build finsished sucessfully!" ) ;
74
105
}
75
106
76
- console . log ( "rebuild-build-single.js finished: Build finsished sucessfully!" ) ;
107
+ rebuildFrameworks ( ) ;
0 commit comments