@@ -12,7 +12,7 @@ If building a framework fails you can resume building like
12
12
npm run rebuild-frameworks --restartWith keyed/react
13
13
*/
14
14
15
- const [ , , ... cliArgs ] = process . argv ;
15
+ const cliArgs = process . argv . slice ( 2 ) ;
16
16
17
17
// Use npm ci or npm install ?
18
18
const useCi = cliArgs . includes ( "--ci" ) ;
@@ -30,70 +30,109 @@ console.log(
30
30
"docker" ,
31
31
useDocker ,
32
32
"restartWith" ,
33
- restartWithFramework
33
+ restartWithFramework ,
34
34
) ;
35
35
36
36
/**
37
- * Returns an array with arrays of types and names of frameworks
37
+ * @typedef {Object } Framework
38
+ * @property {string } type - Type of the framework (e.g., "keyed" or "non-keyed")
39
+ * @property {string } name - Name of the framework (e.g., "vue", "qwik", "svelte")
40
+ */
41
+
42
+ /**
43
+ * Returns an array of frameworks with their type and name
38
44
* @example getFramewokrs()
39
- * @returns [["keyed", "vue"],["keyed", "qwik"],["non-keyed", "svelte"]]
45
+ * @returns { Framework[] }
40
46
*/
41
47
function getFrameworks ( ) {
42
48
const keyedFrameworks = fs
43
49
. readdirSync ( "./frameworks/keyed" )
44
- . map ( ( framework ) => [ "keyed" , framework ] ) ;
50
+ . map ( ( framework ) => ( { type : "keyed" , name : framework } ) ) ;
45
51
const nonKeyedFrameworks = fs
46
52
. readdirSync ( "./frameworks/non-keyed" )
47
- . map ( ( framework ) => [ "non-keyed" , framework ] ) ;
53
+ . map ( ( framework ) => ( { type : "non-keyed" , name : framework } ) ) ;
48
54
return [ ...keyedFrameworks , ...nonKeyedFrameworks ] ;
49
55
}
50
56
51
57
/**
52
- * @param {[string,string] } tuple
58
+ * @param {Framework }
53
59
* @returns {boolean }
54
60
*/
55
- function shouldSkipFramework ( [ dir , name ] ) {
61
+ function shouldSkipFramework ( { type , name } ) {
56
62
if ( ! restartWithFramework ) return false ;
57
63
if ( restartWithFramework . indexOf ( "/" ) > - 1 ) {
58
- return ! `${ dir } /${ name } ` . startsWith ( restartWithFramework ) ;
64
+ return ! `${ type } /${ name } ` . startsWith ( restartWithFramework ) ;
59
65
} else {
60
66
return ! name . startsWith ( restartWithFramework ) ;
61
67
}
62
68
}
63
69
64
70
/**
65
- * @param {string } frameworkPath
71
+ * Run a command synchronously in the specified directory
72
+ * @param {string } command - The command to run
73
+ * @param {string } cwd - The current working directory (optional)
66
74
*/
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
- } ) ;
75
+ function runCommand ( command , cwd = undefined ) {
76
+ console . log ( command ) ;
77
+ execSync ( command , { stdio : "inherit" , cwd } ) ;
76
78
}
77
79
78
80
/**
81
+ * Delete specified files in the framework directory
79
82
* @param {string } frameworkPath
83
+ * @param {string[] } filesToDelete
80
84
*/
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
- } ) ;
85
+ function deleteFrameworkFiles ( frameworkPath , filesToDelete ) {
86
+ for ( const file of filesToDelete ) {
87
+ const filePath = path . join ( frameworkPath , file ) ;
88
+ fs . rmSync ( filePath , { recursive : true , force : true } ) ;
89
+ }
90
+ console . log ( `Deleted: ${ filesToDelete } ` ) ;
88
91
}
89
92
90
93
/**
91
- * @param {string } frameworkPath
94
+ * Build single framework
95
+ * @param {Framework } framework
96
+ * @returns
92
97
*/
93
- function copyPackageLock ( frameworkPath ) {
98
+ function buildFramework ( framework ) {
99
+ console . log ( "Building framework:" , framework ) ;
100
+
101
+ const { type, name } = framework ;
102
+ const frameworkPath = path . join ( "frameworks" , type , name ) ;
103
+ const packageJSONPath = path . join ( frameworkPath , "package.json" ) ;
104
+
105
+ if ( ! fs . existsSync ( packageJSONPath ) ) {
106
+ console . log ( `WARN: skipping ${ framework } since there's no package.json` ) ;
107
+ return ;
108
+ }
109
+ // if (fs.existsSync(path)) {
110
+ // console.log("deleting folder ",path);
111
+ // execSync(`rm -r ${path}`);
112
+ // }
113
+ // rsync(keyed,name);
114
+ const filesToDelete = [
115
+ "yarn-lock" ,
116
+ "dist" ,
117
+ "elm-stuff" ,
118
+ "bower_components" ,
119
+ "node_modules" ,
120
+ "output" ,
121
+ useCi ? "" : "package-lock.json" ,
122
+ ] ;
123
+
124
+ deleteFrameworkFiles ( frameworkPath , filesToDelete ) ;
125
+
126
+ const installCmd = `npm ${ useCi ? "ci" : "install" } ` ;
127
+ runCommand ( installCmd , frameworkPath ) ;
128
+
129
+ const buildCmd = "npm run build-prod" ;
130
+ runCommand ( buildCmd , frameworkPath ) ;
131
+
94
132
if ( useDocker ) {
95
133
const packageLockPath = path . join ( frameworkPath , "package-lock.json" ) ;
96
- fs . copyFileSync ( packageLockPath , path . join ( "/src" , packageLockPath ) ) ;
134
+ const destinationPath = path . join ( "/src" , packageLockPath ) ;
135
+ fs . copyFileSync ( packageLockPath , destinationPath ) ;
97
136
}
98
137
}
99
138
@@ -105,28 +144,7 @@ function buildFrameworks() {
105
144
console . log ( "Building frameworks:" , buildableFrameworks ) ;
106
145
107
146
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 ;
120
- }
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 ) ;
147
+ buildFramework ( framework ) ;
130
148
}
131
149
132
150
console . log ( "All frameworks were built!" ) ;
0 commit comments