forked from krausest/js-framework-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild-all.js
140 lines (117 loc) · 3.61 KB
/
rebuild-all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { execSync } from "node:child_process";
import * as fs from "node:fs";
import path from "node:path";
import yargs from "yargs";
import { takeWhile } from "./utils/common/index.js";
import { getFrameworks } from "./utils/frameworks/index.js";
const args = yargs(process.argv.slice(2))
.usage("$0 [--ci keyed/framework1 ... non-keyed/frameworkN]")
.help()
.boolean("ci")
.default("ci", false)
.default("restartWith", "")
.describe("ci", "Use npm ci or npm install?")
.argv;
/*
This script rebuilds all frameworks from scratch,
it deletes all package.json and package-lock.json files
and invokes npm install and npm run build-prod for all benchmarks
If building a framework fails you can resume building like
npm run rebuild-frameworks --restartWith keyed/react
*/
/**
* Use npm ci or npm install?
* @type {boolean}
*/
const useCi = args.ci;
const restartWithFramework = args.restartWith;
console.log(
"ARGS",
args,
"ci",
useCi,
"restartWith",
restartWithFramework,
);
const filesToDelete = [
"yarn-lock",
"dist",
"elm-stuff",
"bower_components",
"node_modules",
"output",
].concat(useCi ? [] : ["package-lock.json"]);
/**
* @typedef {Object} Framework
* @property {string} name - Name of the framework (e.g., "vue", "qwik", "svelte")
* @property {string} type - Type of the framework (e.g., "keyed" or "non-keyed")
*/
/**
* @param {Framework}
* @returns {boolean}
*/
function shouldSkipFramework({ type, name }) {
if (!restartWithFramework) return false;
if (restartWithFramework.indexOf("/") > -1) {
return !`${type}/${name}`.startsWith(restartWithFramework);
} else {
return !name.startsWith(restartWithFramework);
}
}
/**
* Run a command synchronously in the specified directory and log command
* @param {string} command - The command to run
* @param {string} [cwd] - The current working directory (optional)
*/
function runCommand(command, cwd = undefined) {
console.log(command);
execSync(command, { stdio: "inherit", cwd });
}
/**
* Delete specified files in the framework directory
* @param {string} frameworkPath
* @param {string[]} filesToDelete
*/
function deleteFrameworkFiles(frameworkPath, filesToDelete) {
for (const file of filesToDelete) {
const filePath = path.join(frameworkPath, file);
fs.rmSync(filePath, { recursive: true, force: true });
}
console.log(`Deleted: ${filesToDelete}`);
}
/**
* Build single framework
* @param {Framework} framework
* @returns
*/
function buildFramework(framework) {
console.log("Building framework:", framework);
const { type, name } = framework;
const frameworkPath = path.join("frameworks", type, name);
const packageJSONPath = path.join(frameworkPath, "package.json");
if (!fs.existsSync(packageJSONPath)) {
console.log(`WARN: skipping ${framework} since there's no package.json`);
return;
}
// if (fs.existsSync(path)) {
// console.log("deleting folder ",path);
// execSync(`rm -r ${path}`);
// }
// rsync(keyed,name);
deleteFrameworkFiles(frameworkPath, filesToDelete);
const installCmd = `npm ${useCi ? "ci" : "install"}`;
runCommand(installCmd, frameworkPath);
const buildCmd = "npm run build-prod";
runCommand(buildCmd, frameworkPath);
}
function buildFrameworks() {
const frameworks = getFrameworks();
const skippableFrameworks = takeWhile(frameworks, shouldSkipFramework);
const buildableFrameworks = frameworks.slice(skippableFrameworks.length);
// console.log("Building frameworks:", buildableFrameworks);
for (const framework of buildableFrameworks) {
buildFramework(framework);
}
console.log("All frameworks were built!");
}
buildFrameworks();