Skip to content

Commit 195b689

Browse files
committed
2 parents d29264e + 82525a8 commit 195b689

14 files changed

+190
-315
lines changed

cli/check-obsolete.js

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ const frameworks = getFrameworks();
2020
*/
2121
function findDuplicateFrameworks(frameworks) {
2222
const names = frameworks.map((framework) => framework.name); // Creates an array with framework names only
23-
const duplicateNames = names.filter(
24-
(name, index) => names.indexOf(name) !== index,
25-
); // Filters out repetitive framework names
23+
const duplicateNames = names.filter((name, index) => names.indexOf(name) !== index); // Filters out repetitive framework names
2624

2725
return duplicateNames;
2826
}
@@ -59,11 +57,7 @@ function maybeObsolete(packageName) {
5957
}
6058

6159
const now = new Date();
62-
const obsoleteDate = new Date(
63-
now.getFullYear() - 1,
64-
now.getMonth(),
65-
now.getDay(),
66-
);
60+
const obsoleteDate = new Date(now.getFullYear() - 1, now.getMonth(), now.getDay());
6761

6862
const modifiedDate = new Date(timeData.modified);
6963
const isObsolete = modifiedDate < obsoleteDate;
@@ -72,7 +66,7 @@ function maybeObsolete(packageName) {
7266
return { isObsolete, lastUpdate: formattedDate, packageName };
7367
} catch (error) {
7468
console.error(
75-
`Failed to execute npm view for ${packageName}. Error Code ${error.status} and message: ${error.message}`,
69+
`Failed to execute npm view for ${packageName}. Error Code ${error.status} and message: ${error.message}`
7670
);
7771
return { isObsolete: false, lastUpdate: null, packageName };
7872
}
@@ -95,15 +89,12 @@ function checkObsoleteFrameworks(options) {
9589
const packageJSONPath = path.join(frameworkPath, "package.json");
9690

9791
if (!fs.existsSync(packageJSONPath)) {
98-
missingPackageWarnings.push(
99-
`WARN: skipping ${type}/${name} since there's no package.json`,
100-
);
92+
missingPackageWarnings.push(`WARN: skipping ${type}/${name} since there's no package.json`);
10193
continue;
10294
}
10395

10496
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
105-
const mainPackages =
106-
packageJSON?.["js-framework-benchmark"]?.frameworkVersionFromPackage;
97+
const mainPackages = packageJSON?.["js-framework-benchmark"]?.frameworkVersionFromPackage;
10798

10899
if (!mainPackages) {
109100
manualChecks.push(`${type}/${name} has no frameworkVersionFromPackage`);
@@ -121,35 +112,25 @@ function checkObsoleteFrameworks(options) {
121112
console.log(`Results for ${type}/${name} ${isPackageObsolete}`);
122113
}
123114

124-
const anyPackageObsolete = isPackageObsolete.some(
125-
(packageFramework) => packageFramework.isObsolete,
126-
);
115+
const anyPackageObsolete = isPackageObsolete.some((packageFramework) => packageFramework.isObsolete);
127116

128117
if (anyPackageObsolete) {
129118
const formattedPackages = isPackageObsolete
130119
.map((result) => `${result.packageName}:${result.lastUpdate}`)
131120
.join(", ");
132121

133-
console.log(
134-
`Last npm update for ${type}/${name} - ${mainPackages} is older than a year: ${formattedPackages}`,
135-
);
122+
console.log(`Last npm update for ${type}/${name} - ${mainPackages} is older than a year: ${formattedPackages}`);
136123
continue;
137124
}
138125

139126
if (DEBUG) {
140-
console.log(
141-
`Last npm update for ${type}/${name} ${mainPackages} is newer than a year`,
142-
);
127+
console.log(`Last npm update for ${type}/${name} ${mainPackages} is newer than a year`);
143128
}
144129
}
145130

146-
if (missingPackageWarnings.length > 0)
147-
console.warn("\nWarnings:\n" + missingPackageWarnings.join("\n"));
131+
if (missingPackageWarnings.length > 0) console.warn("\nWarnings:\n" + missingPackageWarnings.join("\n"));
148132
if (manualChecks.length > 0)
149-
console.warn(
150-
"\nThe following frameworks must be checked manually\n" +
151-
manualChecks.join("\n"),
152-
);
133+
console.warn("\nThe following frameworks must be checked manually\n" + manualChecks.join("\n"));
153134
}
154135

155136
export { checkObsoleteFrameworks };

cli/cleanup.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import * as fs from "node:fs";
22
import path from "node:path";
33

4-
const filesToDelete = [
5-
"package-lock.json",
6-
"yarn-lock",
7-
"dist",
8-
"elm-stuff",
9-
"bower_components",
10-
"node_modules",
11-
];
4+
const filesToDelete = ["package-lock.json", "yarn-lock", "dist", "elm-stuff", "bower_components", "node_modules"];
125

136
/**
147
* Delete specified files in the framework directory

cli/configure-styles.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ async function copyAndGenerateSharedStyles(sourceCss, mainCss) {
1212
const sharedStylesContent = `<dom-module id="shared-styles"><template><style>${mainCssContent}</style></template></dom-module>`;
1313

1414
// Write shared-styles.html
15-
await fs.promises.writeFile(
16-
path.join("polymer-v2.0.0-non-keyed", "src", "shared-styles.html"),
17-
sharedStylesContent,
18-
);
15+
await fs.promises.writeFile(path.join("polymer-v2.0.0-non-keyed", "src", "shared-styles.html"), sharedStylesContent);
1916
}
2017

2118
/**
@@ -37,13 +34,10 @@ async function configureStyles(options) {
3734
if (bootstrap) {
3835
await copyAndGenerateSharedStyles(
3936
path.join("css", "useOriginalBootstrap.css"),
40-
path.join("css", "bootstrap", "dist", "css", "bootstrap.min.css"),
37+
path.join("css", "bootstrap", "dist", "css", "bootstrap.min.css")
4138
);
4239
} else {
43-
await copyAndGenerateSharedStyles(
44-
path.join("css", "useMinimalCss.css"),
45-
path.join("css", "useMinimalCss.css"),
46-
);
40+
await copyAndGenerateSharedStyles(path.join("css", "useMinimalCss.css"), path.join("css", "useMinimalCss.css"));
4741
}
4842
} catch (error) {
4943
console.error("An error occurred:", error.message);

cli/copy.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function shouldInclude(name) {
1717
const isTargetWeb = name.includes("/target/web");
1818

1919
console.log(
20-
`File: ${name}\nIs Binding Scala: ${isBindingScala}\nIs Target: ${isTarget}\nIs Target Web: ${isTargetWeb}`,
20+
`File: ${name}\nIs Binding Scala: ${isBindingScala}\nIs Target: ${isTarget}\nIs Target Web: ${isTargetWeb}`
2121
);
2222

2323
if (isTarget) {
@@ -72,15 +72,10 @@ function copyFolderRecursiveSync(sourcePath, destinationPath) {
7272
*/
7373
function processDirectories() {
7474
const directories = fs.readdirSync(".");
75-
const nonHiddenDirectories = directories.filter(
76-
(directory) => !directory.startsWith("."),
77-
);
75+
const nonHiddenDirectories = directories.filter((directory) => !directory.startsWith("."));
7876

7977
for (const directory of nonHiddenDirectories) {
80-
if (
81-
fs.statSync(directory).isDirectory() &&
82-
!rootExclude.includes(directory)
83-
) {
78+
if (fs.statSync(directory).isDirectory() && !rootExclude.includes(directory)) {
8479
const dirPath = path.join("dist", directory);
8580
console.log(dirPath);
8681
fs.mkdirSync(dirPath);
@@ -97,10 +92,7 @@ function copyProjectToDist() {
9792
fs.rmSync("dist", { force: true, recursive: true });
9893
fs.mkdirSync(path.join("dist", "webdriver-ts"), { recursive: true });
9994

100-
fs.copyFileSync(
101-
path.join("webdriver-ts", "table.html"),
102-
path.join("dist", "webdriver-ts", "table.html"),
103-
);
95+
fs.copyFileSync(path.join("webdriver-ts", "table.html"), path.join("dist", "webdriver-ts", "table.html"));
10496
fs.copyFileSync("index.html", path.join("dist", "index.html"));
10597

10698
processDirectories();
Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
11
import { execSync } from "node:child_process";
22
import * as fs from "node:fs";
33
import path from "node:path";
4-
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 ?")
11-
.argv;
12-
13-
/**
14-
* Use npm ci or npm install?
15-
* @type {boolean}
16-
*/
17-
const useCi = args.ci;
18-
19-
/**
20-
* @type {string}
21-
*/
22-
const frameworks = args._.filter((arg) => !arg.startsWith("--"));
23-
24-
console.log(
25-
"rebuild-build-single.js started: args",
26-
args,
27-
"useCi",
28-
useCi,
29-
"frameworks",
30-
frameworks
31-
);
32-
33-
const filesToDelete = [
34-
"yarn-lock",
35-
"dist",
36-
"elm-stuff",
37-
"bower_components",
38-
"node_modules",
39-
"output",
40-
].concat(useCi ? [] : ["package-lock.json"]);
414

425
/*
436
rebuild-single.js [--ci] [keyed/framework1 ... non-keyed/frameworkN]
@@ -55,7 +18,7 @@ Pass list of frameworks
5518
/**
5619
* Run a command synchronously in the specified directory and log command
5720
* @param {string} command - The command to run
58-
* @param {string} cwd - The current working directory (optional)
21+
* @param {string|undefined} cwd - The current working directory (optional)
5922
*/
6023
function runCommand(command, cwd = undefined) {
6124
console.log(command);
@@ -82,43 +45,53 @@ function deleteFrameworkFiles(frameworkPath, filesToDelete) {
8245

8346
/**
8447
* @param {string} framework
48+
* @param {boolean} useCi
8549
*/
86-
function rebuildFramework(framework) {
50+
function rebuildFramework(framework, useCi) {
8751
const components = framework.split("/");
8852

8953
if (components.length !== 2) {
90-
console.log(
91-
`ERROR: invalid name ${framework}. It must contain exactly one /.`
92-
);
54+
console.log(`ERROR: invalid name ${framework}. It must contain exactly one /.`);
9355
process.exit(1);
9456
}
9557

9658
const [keyed, name] = components;
9759
const frameworkPath = path.join("frameworks", keyed, name);
9860

61+
const filesToDelete = [
62+
"yarn-lock",
63+
"dist",
64+
"elm-stuff",
65+
"bower_components",
66+
"node_modules",
67+
"output",
68+
].concat(useCi ? [] : ["package-lock.json"]);
69+
9970
deleteFrameworkFiles(frameworkPath, filesToDelete);
10071

10172
const installCmd = `npm ${useCi ? "ci" : "install"}`;
10273
runCommand(installCmd, frameworkPath);
10374

10475
const buildCmd = "npm run build-prod";
10576
runCommand(buildCmd, frameworkPath);
106-
10777
}
10878

109-
function rebuildFrameworks() {
79+
/**
80+
* @param {string[]} frameworks
81+
* @param {boolean} useCi
82+
*/
83+
export function rebuildFrameworks(frameworks, useCi) {
84+
console.log("rebuild-build-single.js started: useCi", useCi, "frameworks", frameworks);
85+
11086
if (!frameworks.length) {
111-
console.log(
112-
"ERROR: Missing arguments. Command: rebuild keyed/framework1 non-keyed/framework2 ..."
113-
);
87+
console.log("ERROR: Missing arguments. Command: rebuild keyed/framework1 non-keyed/framework2 ...");
11488
process.exit(1);
11589
}
11690

11791
for (const framework of frameworks) {
118-
rebuildFramework(framework);
92+
rebuildFramework(framework, useCi);
11993
}
12094

12195
console.log("rebuild-build-single.js finished: Build finsished sucessfully!");
12296
}
12397

124-
rebuildFrameworks();

cli/rebuild-check-single.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { execSync } from "node:child_process";
2+
3+
/*
4+
rebuild-check-single.js [keyed/framework1 ... non-keyed/frameworkN]
5+
6+
This script is used to run benchmarks and check if the specified frameworks are keyed.
7+
8+
It performs the following steps:
9+
1. Executes benchmarks for the specified frameworks with the necessary options.
10+
2. Checks if the specified frameworks are keyed.
11+
12+
Pass list of frameworks
13+
*/
14+
15+
/**
16+
* Run a command synchronously in the specified directory and log command
17+
* @param {string} command - The command to run
18+
* @param {string|undefined} cwd - The current working directory (optional)
19+
*/
20+
function runCommand(command, cwd = undefined) {
21+
console.log(command);
22+
execSync(command, { stdio: "inherit", cwd });
23+
}
24+
25+
/**
26+
* @param {string[]} frameworks
27+
*/
28+
export function rebuildCheckSingle(frameworks) {
29+
console.log("rebuild-check-single.js started: frameworks", frameworks);
30+
31+
const frameworkNames = frameworks.join(" ");
32+
33+
try {
34+
const benchCmd = `npm run bench -- --headless true --smoketest true ${frameworkNames}`;
35+
runCommand(benchCmd, "webdriver-ts");
36+
37+
const keyedCmd = `npm run isKeyed -- --headless true ${frameworkNames}`;
38+
runCommand(keyedCmd, "webdriver-ts");
39+
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);
46+
}
47+
}

cli/update-lockfiles.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ function getPackageLockJSONVersion(packageLockJSONPath) {
4949
* @param {number} latestLockfileVersion
5050
* @param {string} frameworkDirPath
5151
*/
52-
function updateFrameworkLockfile(
53-
framework,
54-
latestLockfileVersion,
55-
frameworkDirPath,
56-
) {
52+
function updateFrameworkLockfile(framework, latestLockfileVersion, frameworkDirPath) {
5753
const { name, type } = framework;
5854

5955
console.log(`Checking ${type} ${name} lockfile`);
@@ -85,11 +81,7 @@ function updateLockfilesOfAllFrameworks(options) {
8581
const frameworks = getFrameworks(frameworksDirPath, frameworksTypes);
8682

8783
for (const framework of frameworks) {
88-
updateFrameworkLockfile(
89-
framework,
90-
latestLockfileVersion,
91-
frameworksDirPath,
92-
);
84+
updateFrameworkLockfile(framework, latestLockfileVersion, frameworksDirPath);
9385
}
9486
}
9587

0 commit comments

Comments
 (0)