1- var _ = require ( 'lodash' ) ;
2- var exec = require ( 'child_process' ) . execSync ;
3- var fs = require ( 'fs' ) ;
4- var path = require ( 'path' ) ;
5- const rimraf = require ( 'rimraf' ) ;
6-
7- let args = process . argv . length <= 2 ? [ ] : process . argv . slice ( 2 , process . argv . length ) ;
1+ const takeWhile = require ( "lodash/takeWhile" ) ;
2+ const { execSync } = require ( "child_process" ) ;
3+ const fs = require ( "fs" ) ;
4+ const path = require ( "path" ) ;
85
96/*
107This script rebuilds all frameworks from scratch,
@@ -15,66 +12,124 @@ If building a framework fails you can resume building like
1512npm run rebuild-frameworks --restartWith keyed/react
1613*/
1714
15+ const [ , , ...cliArgs ] = process . argv ;
16+
1817// Use npm ci or npm install ?
19- let ci = args . includes ( "--ci" ) ;
18+ const useCi = cliArgs . includes ( "--ci" ) ;
19+
2020// Copy package-lock back for docker build or build locally?
21- let docker = args . includes ( "--docker" ) ;
22- let restartBuildingWith = args . find ( a => ! a . startsWith ( "--" ) ) ;
21+ const useDocker = cliArgs . includes ( "--docker" ) ;
2322
23+ const restartBuildingWith = cliArgs . find ( ( arg ) => ! arg . startsWith ( "--" ) ) ;
24+ const restartWithFramework = restartBuildingWith || "" ;
2425
25- var restartWithFramework = restartBuildingWith || '' ;
26- console . log ( "ARGS" , "ci" , ci , "docker" , docker , "restartWith" , restartWithFramework ) ;
26+ console . log (
27+ "ARGS" ,
28+ "ci" ,
29+ useCi ,
30+ "docker" ,
31+ useDocker ,
32+ "restartWith" ,
33+ restartWithFramework
34+ ) ;
2735
28- var frameworks = [ ] . concat (
29- fs . readdirSync ( './frameworks/keyed' ) . map ( f => [ 'keyed' , f ] ) ,
30- fs . readdirSync ( './frameworks/non-keyed' ) . map ( f => [ 'non-keyed' , f ] ) ) ;
36+ /**
37+ * Returns an array with arrays of types and names of frameworks
38+ * @example getFramewokrs()
39+ * @returns [["keyed", "vue"],["keyed", "qwik"],["non-keyed", "svelte"]]
40+ */
41+ function getFrameworks ( ) {
42+ const keyedFrameworks = fs
43+ . readdirSync ( "./frameworks/keyed" )
44+ . map ( ( framework ) => [ "keyed" , framework ] ) ;
45+ const nonKeyedFrameworks = fs
46+ . readdirSync ( "./frameworks/non-keyed" )
47+ . map ( ( framework ) => [ "non-keyed" , framework ] ) ;
48+ return [ ...keyedFrameworks , ...nonKeyedFrameworks ] ;
49+ }
3150
32- var notRestarter = ( [ dir , name ] ) => {
51+ /**
52+ * @param {[string,string] } tuple
53+ * @returns {boolean }
54+ */
55+ function shouldSkipFramework ( [ dir , name ] ) {
3356 if ( ! restartWithFramework ) return false ;
34- if ( restartWithFramework . indexOf ( "/" ) > - 1 ) {
35- return ! ( dir + "/" + name ) . startsWith ( restartWithFramework ) ;
57+ if ( restartWithFramework . indexOf ( "/" ) > - 1 ) {
58+ return ! ` ${ dir } / ${ name } ` . startsWith ( restartWithFramework ) ;
3659 } else {
3760 return ! name . startsWith ( restartWithFramework ) ;
3861 }
39- } ;
40-
41- let skippable = _ . takeWhile ( frameworks , notRestarter ) ;
42- let buildable = _ . slice ( frameworks , skippable . length ) ;
43-
44- console . log ( "Building " , buildable ) ;
45-
46-
47- for ( f of buildable ) {
48- console . log ( "BUILDING " , f ) ;
49- let [ keyed , name ] = f ;
50- let path = `frameworks/${ keyed } /${ name } ` ;
51- if ( ! fs . existsSync ( path + "/package.json" ) ) {
52- console . log ( "WARN: skipping " , f , " since there's no package.json" ) ;
53- } else {
54- // if (fs.existsSync(path)) {
55- // console.log("deleting folder ",path);
56- // exec(`rm -r ${path}`);
57- // }
58- // rsync(keyed,name);
59- let rm_cmd = `rm -rf ${ ci ? '' : 'package-lock.json' } yarn.lock dist elm-stuff bower_components node_modules output`
60- console . log ( rm_cmd ) ;
61- exec ( rm_cmd , {
62- cwd : path ,
63- stdio : 'inherit'
64- } ) ;
65-
66- let install_cmd = `npm ${ ci ? 'ci' : 'install' } && npm run build-prod` ;
67- console . log ( install_cmd ) ;
68- exec ( install_cmd , {
69- cwd : path ,
70- stdio : 'inherit'
71- } ) ;
72-
73- if ( docker ) {
74- let packageLockPath = path + "/package-lock.json" ;
75- fs . copyFileSync ( packageLockPath , "/src/" + packageLockPath ) ;
76- }
62+ }
63+
64+ /**
65+ * @param {string } frameworkPath
66+ */
67+ function removeFiles ( frameworkPath ) {
68+ const rmCmd = `rm -rf ${
69+ useCi ? "" : "package-lock.json"
70+ } yarn.lock dist elm-stuff bower_components node_modules output`;
71+ console . log ( rmCmd ) ;
72+ execSync ( rmCmd , {
73+ cwd : frameworkPath ,
74+ stdio : "inherit" ,
75+ } ) ;
76+ }
77+
78+ /**
79+ * @param {string } frameworkPath
80+ */
81+ function installAndBuild ( frameworkPath ) {
82+ const installCmd = `npm ${ useCi ? "ci" : "install" } && npm run build-prod` ;
83+ console . log ( installCmd ) ;
84+ execSync ( installCmd , {
85+ cwd : frameworkPath ,
86+ stdio : "inherit" ,
87+ } ) ;
88+ }
89+
90+ /**
91+ * @param {string } frameworkPath
92+ */
93+ function copyPackageLock ( frameworkPath ) {
94+ if ( useDocker ) {
95+ const packageLockPath = path . join ( frameworkPath , "package-lock.json" ) ;
96+ fs . copyFileSync ( packageLockPath , path . join ( "/src" , packageLockPath ) ) ;
97+ }
98+ }
99+
100+ function buildFrameworks ( ) {
101+ const frameworks = getFrameworks ( ) ;
102+ const skippableFrameworks = takeWhile ( frameworks , shouldSkipFramework ) ;
103+ const buildableFrameworks = frameworks . slice ( skippableFrameworks . length ) ;
104+
105+ console . log ( "Building frameworks:" , buildableFrameworks ) ;
106+
107+ for ( const framework of buildableFrameworks ) {
108+ console . log ( "Building framework:" , framework ) ;
109+
110+ const [ keyed , name ] = framework ;
111+ const frameworkPath = path . join ( "frameworks" , keyed , name ) ;
112+
113+ if ( ! fs . existsSync ( `${ frameworkPath } /package.json` ) ) {
114+ console . log (
115+ "WARN: skipping " ,
116+ framework ,
117+ " since there's no package.json"
118+ ) ;
119+ continue ;
77120 }
121+ // if (fs.existsSync(path)) {
122+ // console.log("deleting folder ",path);
123+ // execSync(`rm -r ${path}`);
124+ // }
125+ // rsync(keyed,name);
126+
127+ removeFiles ( frameworkPath ) ;
128+ installAndBuild ( frameworkPath ) ;
129+ copyPackageLock ( frameworkPath ) ;
130+ }
131+
132+ console . log ( "All frameworks were built!" ) ;
78133}
79134
80- console . log ( "All frameworks were built!" ) ;
135+ buildFrameworks ( ) ;
0 commit comments