Skip to content

Commit 298f328

Browse files
committed
refactor: rebuild-* files
1 parent 7f454cd commit 298f328

File tree

6 files changed

+155
-118
lines changed

6 files changed

+155
-118
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"adm-zip": "^0.5.10",
4646
"commander": "^11.1.0",
4747
"cross-env": "^7.0.3",
48+
"es-main": "^1.3.0",
4849
"json5": "^2.2.3",
4950
"rimraf": "^5.0.5",
5051
"yargs": "^17.7.2"

rebuild-all.js

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ import path from "node:path";
44
import yargs from "yargs";
55
import { takeWhile } from "./utils/common/index.js";
66
import { getFrameworks } from "./utils/frameworks/index.js";
7-
8-
const args = yargs(process.argv.slice(2))
9-
.usage("$0 [--ci keyed/framework1 ... non-keyed/frameworkN]")
10-
.help()
11-
.boolean("ci")
12-
.default("ci", false)
13-
.default("restartWith", "")
14-
.describe("ci", "Use npm ci or npm install?").argv;
7+
import { hideBin } from "yargs/helpers";
8+
import esMain from "es-main";
159

1610
/*
1711
This script rebuilds all frameworks from scratch,
@@ -22,31 +16,18 @@ If building a framework fails you can resume building like
2216
npm run rebuild-frameworks --restartWith keyed/react
2317
*/
2418

25-
/**
26-
* Use npm ci or npm install?
27-
* @type {boolean}
28-
*/
29-
const useCi = args.ci;
30-
31-
const restartWithFramework = args.restartWith;
32-
33-
console.log("ARGS", args, "ci", useCi, "restartWith", restartWithFramework);
34-
35-
const filesToDelete = ["yarn-lock", "dist", "elm-stuff", "bower_components", "node_modules", "output"].concat(
36-
useCi ? [] : ["package-lock.json"]
37-
);
38-
3919
/**
4020
* @typedef {Object} Framework
4121
* @property {string} name - Name of the framework (e.g., "vue", "qwik", "svelte")
4222
* @property {string} type - Type of the framework (e.g., "keyed" or "non-keyed")
4323
*/
4424

4525
/**
46-
* @param {Framework}
26+
* @param {Framework} framework
27+
* @param {string} restartWithFramework
4728
* @returns {boolean}
4829
*/
49-
function shouldSkipFramework({ type, name }) {
30+
function shouldSkipFramework({ type, name }, restartWithFramework) {
5031
if (!restartWithFramework) return false;
5132
if (restartWithFramework.indexOf("/") > -1) {
5233
return !`${type}/${name}`.startsWith(restartWithFramework);
@@ -81,9 +62,10 @@ function deleteFrameworkFiles(frameworkPath, filesToDelete) {
8162
/**
8263
* Build single framework
8364
* @param {Framework} framework
65+
* @param {boolean} useCi
8466
* @returns
8567
*/
86-
function buildFramework(framework) {
68+
function buildFramework(framework, useCi) {
8769
console.log("Building framework:", framework);
8870

8971
const { type, name } = framework;
@@ -100,6 +82,16 @@ function buildFramework(framework) {
10082
// }
10183
// rsync(keyed,name);
10284

85+
const filesToDelete = [
86+
"yarn-lock",
87+
"dist",
88+
"elm-stuff",
89+
"bower_components",
90+
"node_modules",
91+
"output",
92+
!useCi && "package-lock.json",
93+
].filter(Boolean);
94+
10395
deleteFrameworkFiles(frameworkPath, filesToDelete);
10496

10597
const installCmd = `npm ${useCi ? "ci" : "install"}`;
@@ -109,19 +101,41 @@ function buildFramework(framework) {
109101
runCommand(buildCmd, frameworkPath);
110102
}
111103

112-
function buildFrameworks() {
104+
/**
105+
* @param {string} restartWithFramework
106+
* @param {boolean} useCi
107+
*/
108+
function buildFrameworks(restartWithFramework, useCi) {
113109
const frameworks = getFrameworks();
114110

115-
const skippableFrameworks = takeWhile(frameworks, shouldSkipFramework);
111+
const skippableFrameworks = takeWhile(frameworks, (framework) =>
112+
shouldSkipFramework(framework, restartWithFramework)
113+
);
116114
const buildableFrameworks = frameworks.slice(skippableFrameworks.length);
117115

118116
// console.log("Building frameworks:", buildableFrameworks);
119117

120118
for (const framework of buildableFrameworks) {
121-
buildFramework(framework);
119+
buildFramework(framework, useCi);
122120
}
123121

124122
console.log("All frameworks were built!");
125123
}
126124

127-
buildFrameworks();
125+
if (esMain(import.meta)) {
126+
const args = yargs(hideBin(process.argv))
127+
.usage("$0 [--ci keyed/framework1 ... non-keyed/frameworkN]")
128+
.help()
129+
.boolean("ci")
130+
.default("ci", false)
131+
.default("restartWith", "")
132+
.describe("ci", "Use npm ci or npm install?")
133+
.parseSync();
134+
135+
const useCi = args.ci;
136+
const restartWithFramework = args.restartWith;
137+
138+
console.log("ARGS", args, "ci", useCi, "restartWith", restartWithFramework);
139+
140+
buildFrameworks(restartWithFramework, useCi);
141+
}

rebuild-build-single.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,8 @@ import { execSync } from "node:child_process";
22
import * as fs from "node:fs";
33
import path from "node:path";
44
import yargs from "yargs";
5-
6-
const args = yargs(process.argv.slice(2))
7-
.usage("$0 [--ci keyed/framework1 ... non-keyed/frameworkN]")
8-
.boolean("ci")
9-
.default("ci", false)
10-
.describe("ci", "Use npm ci or npm install ?").argv;
11-
12-
/**
13-
* Use npm ci or npm install?
14-
* @type {boolean}
15-
*/
16-
const useCi = args.ci;
17-
18-
/**
19-
* @type {string}
20-
*/
21-
const frameworks = args._.filter((arg) => !arg.startsWith("--"));
22-
23-
console.log("rebuild-build-single.js started: args", args, "useCi", useCi, "frameworks", frameworks);
24-
25-
const filesToDelete = ["yarn-lock", "dist", "elm-stuff", "bower_components", "node_modules", "output"].concat(
26-
useCi ? [] : ["package-lock.json"]
27-
);
5+
import { hideBin } from "yargs/helpers";
6+
import esMain from "es-main";
287

298
/*
309
rebuild-single.js [--ci] [keyed/framework1 ... non-keyed/frameworkN]
@@ -42,7 +21,7 @@ Pass list of frameworks
4221
/**
4322
* Run a command synchronously in the specified directory and log command
4423
* @param {string} command - The command to run
45-
* @param {string} cwd - The current working directory (optional)
24+
* @param {string|undefined} cwd - The current working directory (optional)
4625
*/
4726
function runCommand(command, cwd = undefined) {
4827
console.log(command);
@@ -69,8 +48,9 @@ function deleteFrameworkFiles(frameworkPath, filesToDelete) {
6948

7049
/**
7150
* @param {string} framework
51+
* @param {boolean} useCi
7252
*/
73-
function rebuildFramework(framework) {
53+
function rebuildFramework(framework, useCi) {
7454
const components = framework.split("/");
7555

7656
if (components.length !== 2) {
@@ -81,6 +61,16 @@ function rebuildFramework(framework) {
8161
const [keyed, name] = components;
8262
const frameworkPath = path.join("frameworks", keyed, name);
8363

64+
const filesToDelete = [
65+
"yarn-lock",
66+
"dist",
67+
"elm-stuff",
68+
"bower_components",
69+
"node_modules",
70+
"output",
71+
!useCi && "package-lock.json",
72+
].filter(Boolean);
73+
8474
deleteFrameworkFiles(frameworkPath, filesToDelete);
8575

8676
const installCmd = `npm ${useCi ? "ci" : "install"}`;
@@ -90,17 +80,37 @@ function rebuildFramework(framework) {
9080
runCommand(buildCmd, frameworkPath);
9181
}
9282

93-
function rebuildFrameworks() {
83+
/**
84+
* @param {string[]} frameworks
85+
* @param {boolean} useCi
86+
*/
87+
export function rebuildFrameworks(frameworks, useCi) {
88+
console.log("rebuild-build-single.js started: useCi", useCi, "frameworks", frameworks);
89+
9490
if (!frameworks.length) {
9591
console.log("ERROR: Missing arguments. Command: rebuild keyed/framework1 non-keyed/framework2 ...");
9692
process.exit(1);
9793
}
9894

9995
for (const framework of frameworks) {
100-
rebuildFramework(framework);
96+
rebuildFramework(framework, useCi);
10197
}
10298

10399
console.log("rebuild-build-single.js finished: Build finsished sucessfully!");
104100
}
105101

106-
rebuildFrameworks();
102+
if (esMain(import.meta)) {
103+
const args = yargs(hideBin(process.argv))
104+
.usage("$0 [--ci keyed/framework1 ... non-keyed/frameworkN]")
105+
.boolean("ci")
106+
.default("ci", false)
107+
.describe("ci", "Use npm ci or npm install ?")
108+
.parseSync();
109+
110+
const useCi = args.ci;
111+
const frameworks = args._.filter((arg) => !arg.startsWith("--"));
112+
113+
console.log("args", args);
114+
115+
rebuildFrameworks(frameworks, useCi);
116+
}

rebuild-check-single.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { execSync } from "node:child_process";
22
import yargs from "yargs";
3-
4-
const args = yargs(process.argv.slice(2)).usage("$0 [keyed/framework1 ... non-keyed/frameworkN]").help().argv;
5-
6-
const frameworks = args._.filter((a) => !a.startsWith("--"));
7-
const frameworkNames = frameworks.join(" ");
8-
9-
console.log("rebuild-check-single.js started: args", args, "frameworks", frameworks);
3+
import { hideBin } from "yargs/helpers";
4+
import esMain from "es-main";
105

116
/*
127
rebuild-check-single.js [keyed/framework1 ... non-keyed/frameworkN]
@@ -23,24 +18,43 @@ Pass list of frameworks
2318
/**
2419
* Run a command synchronously in the specified directory and log command
2520
* @param {string} command - The command to run
26-
* @param {string} cwd - The current working directory (optional)
21+
* @param {string|undefined} cwd - The current working directory (optional)
2722
*/
2823
function runCommand(command, cwd = undefined) {
2924
console.log(command);
3025
execSync(command, { stdio: "inherit", cwd });
3126
}
3227

33-
try {
34-
const benchCmd = `npm run bench -- --headless true --smoketest true ${frameworkNames}`;
35-
runCommand(benchCmd, "webdriver-ts");
28+
/**
29+
* @param {string[]} frameworks
30+
*/
31+
export function rebuildCheckSingle(frameworks) {
32+
console.log("rebuild-check-single.js started: frameworks", frameworks);
33+
34+
const frameworkNames = frameworks.join(" ");
35+
36+
try {
37+
const benchCmd = `npm run bench -- --headless true --smoketest true ${frameworkNames}`;
38+
runCommand(benchCmd, "webdriver-ts");
39+
40+
const keyedCmd = `npm run isKeyed -- --headless true ${frameworkNames}`;
41+
runCommand(keyedCmd, "webdriver-ts");
42+
43+
console.log("rebuild-check-single.js finished");
44+
console.log("All checks are fine!");
45+
console.log(`======> Please rerun the benchmark: npm run bench ${frameworkNames}`);
46+
} catch (e) {
47+
console.log(`rebuild-check-single failed for ${frameworks.join(" ")}`);
48+
process.exit(-1);
49+
}
50+
}
51+
52+
if (esMain(import.meta)) {
53+
const args = yargs(hideBin(process.argv)).usage("$0 [keyed/framework1 ... non-keyed/frameworkN]").help().parseSync();
54+
55+
const frameworks = args._.filter((a) => !a.startsWith("--"));
3656

37-
const keyedCmd = `npm run isKeyed -- --headless true ${frameworkNames}`;
38-
runCommand(keyedCmd, "webdriver-ts");
57+
console.log("args", args);
3958

40-
console.log("rebuild-check-single.js finished");
41-
console.log("All checks are fine!");
42-
console.log(`======> Please rerun the benchmark: npm run bench ${frameworkNames}`);
43-
} catch (e) {
44-
console.log(`rebuild-check-single failed for ${frameworks.join(" ")}`);
45-
process.exit(-1);
59+
rebuildCheckSingle(frameworks);
4660
}

0 commit comments

Comments
 (0)