Skip to content

Commit b7d1b68

Browse files
authored
Merge pull request #1354 from nakrovati/update-root-scripts
2 parents 81661fd + 14dff78 commit b7d1b68

22 files changed

+1300
-858
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.git/
44
.gitignore
55
cleanup.js
6-
configureStyles.js
6+
configure-styles.js
77
copy.js
88
favicon.ico
99
frameworks/

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"env": { "node": true, "es2024": true },
3-
"extends": ["eslint:recommended"]
3+
"extends": ["eslint:recommended"],
4+
"parserOptions": { "sourceType": "module" }
45
}

cleanup.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

cli.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { program } from "commander";
2+
3+
import {
4+
checkObsoleteFrameworks,
5+
cleanFrameworkDirectories,
6+
configureStyles,
7+
copyProjectToDist,
8+
createFrameworkZipArchive,
9+
updateLockfilesOfAllFrameworks,
10+
} from "./cli/index.js";
11+
12+
program.command("zip").action(createFrameworkZipArchive);
13+
14+
program.command("copy").action(copyProjectToDist);
15+
16+
program
17+
.command("check-obsolete")
18+
.option("--debug [boolean]", "", false)
19+
.action((options) => {
20+
checkObsoleteFrameworks(options);
21+
});
22+
23+
program
24+
.command("cleanup")
25+
.option("--frameworks-dir-path [string]", "", "frameworks")
26+
.option("--frameworks-types [Array<string>]", "", ["keyed", "non-keyed"])
27+
.action((options) => {
28+
cleanFrameworkDirectories(options);
29+
});
30+
31+
program
32+
.command("update-lockfiles")
33+
.option("--frameworks-dir-path [string]", "", "frameworks")
34+
.option("--frameworks-types [Array<string>]", "", ["keyed", "non-keyed"])
35+
.option("--latest-lockfile-version [number]", "", 3)
36+
.action((options) => {
37+
updateLockfilesOfAllFrameworks(options);
38+
});
39+
40+
program
41+
.command("configure-styles")
42+
.option("--bootstrap [boolean]", "", false)
43+
.option("--minimal [boolean]", "", false)
44+
.action(async (options) => {
45+
await configureStyles(options);
46+
});
47+
48+
program.parse();

checkObsolete.js renamed to cli/check-obsolete.js

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
const { execSync } = require("child_process");
2-
const fs = require("fs");
3-
const JSON5 = require("json5");
4-
const path = require("path");
1+
import JSON5 from "json5";
2+
import { execSync } from "node:child_process";
3+
import * as fs from "node:fs";
4+
import path from "node:path";
55

6-
const DEBUG = false;
6+
import { getFrameworks } from "../utils/frameworks/index.js";
77

88
/**
9-
* Returns an array with arrays of types and names of frameworks
10-
* @example getFramewokrs()
11-
* @returns [{type:"keyed", name:"vue"},{type:"keyed", name:"qwik"},{type:"non-keyed", name:"svelte"}]
9+
* @typedef {Object} Framework
10+
* @property {string} name - Name of the framework (e.g., "vue", "qwik", "svelte")
11+
* @property {string} type - Type of the framework (e.g., "keyed" or "non-keyed")
1212
*/
13-
function getFrameworks() {
14-
const keyedFrameworks = fs
15-
.readdirSync("./frameworks/keyed")
16-
.map((framework) => ({ type: "keyed", name: framework }));
17-
const nonKeyedFrameworks = fs
18-
.readdirSync("./frameworks/non-keyed")
19-
.map((framework) => ({ type: "non-keyed", name: framework }));
20-
return [...keyedFrameworks, ...nonKeyedFrameworks];
21-
}
2213

2314
const frameworks = getFrameworks();
2415

@@ -30,7 +21,7 @@ const frameworks = getFrameworks();
3021
function findDuplicateFrameworks(frameworks) {
3122
const names = frameworks.map((framework) => framework.name); // Creates an array with framework names only
3223
const duplicateNames = names.filter(
33-
(name, index) => names.indexOf(name) !== index
24+
(name, index) => names.indexOf(name) !== index,
3425
); // Filters out repetitive framework names
3526

3627
return duplicateNames;
@@ -71,19 +62,19 @@ function maybeObsolete(packageName) {
7162
const obsoleteDate = new Date(
7263
now.getFullYear() - 1,
7364
now.getMonth(),
74-
now.getDay()
65+
now.getDay(),
7566
);
7667

7768
const modifiedDate = new Date(timeData.modified);
7869
const isObsolete = modifiedDate < obsoleteDate;
7970
const formattedDate = modifiedDate.toISOString().substring(0, 10);
8071

81-
return { isObsolete, packageName, lastUpdate: formattedDate };
72+
return { isObsolete, lastUpdate: formattedDate, packageName };
8273
} catch (error) {
8374
console.error(
84-
`Failed to execute npm view for ${packageName}. Error Code ${error.status} and message: ${error.message}`
75+
`Failed to execute npm view for ${packageName}. Error Code ${error.status} and message: ${error.message}`,
8576
);
86-
return { isObsolete: false, packageName, lastUpdate: null };
77+
return { isObsolete: false, lastUpdate: null, packageName };
8778
}
8879
}
8980

@@ -93,15 +84,19 @@ const manualChecks = [];
9384
/**
9485
* Checks frameworks in frameworks/keyed and frameworks/non-keyed for obsolescence,
9586
* the presence of package.json and the presence of the frameworkVersionFromPackage property
87+
* @param {Object} options
88+
* @param {boolean} options.debug
9689
*/
97-
function checkFrameworks() {
98-
for (const { type, name } of frameworks) {
90+
function checkObsoleteFrameworks(options) {
91+
const DEBUG = options.debug ?? false;
92+
93+
for (const { name, type } of frameworks) {
9994
const frameworkPath = path.join("frameworks", type, name);
10095
const packageJSONPath = path.join(frameworkPath, "package.json");
10196

10297
if (!fs.existsSync(packageJSONPath)) {
10398
missingPackageWarnings.push(
104-
`WARN: skipping ${type}/${name} since there's no package.json`
99+
`WARN: skipping ${type}/${name} since there's no package.json`,
105100
);
106101
continue;
107102
}
@@ -127,7 +122,7 @@ function checkFrameworks() {
127122
}
128123

129124
const anyPackageObsolete = isPackageObsolete.some(
130-
(packageFramework) => packageFramework.isObsolete
125+
(packageFramework) => packageFramework.isObsolete,
131126
);
132127

133128
if (anyPackageObsolete) {
@@ -136,14 +131,14 @@ function checkFrameworks() {
136131
.join(", ");
137132

138133
console.log(
139-
`Last npm update for ${type}/${name} - ${mainPackages} is older than a year: ${formattedPackages}`
134+
`Last npm update for ${type}/${name} - ${mainPackages} is older than a year: ${formattedPackages}`,
140135
);
141136
continue;
142137
}
143138

144139
if (DEBUG) {
145140
console.log(
146-
`Last npm update for ${type}/${name} ${mainPackages} is newer than a year`
141+
`Last npm update for ${type}/${name} ${mainPackages} is newer than a year`,
147142
);
148143
}
149144
}
@@ -153,8 +148,8 @@ function checkFrameworks() {
153148
if (manualChecks.length > 0)
154149
console.warn(
155150
"\nThe following frameworks must be checked manually\n" +
156-
manualChecks.join("\n")
151+
manualChecks.join("\n"),
157152
);
158153
}
159154

160-
checkFrameworks();
155+
export { checkObsoleteFrameworks };

cli/cleanup.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as fs from "node:fs";
2+
import path from "node:path";
3+
4+
const filesToDelete = [
5+
"package-lock.json",
6+
"yarn-lock",
7+
"dist",
8+
"elm-stuff",
9+
"bower_components",
10+
"node_modules",
11+
];
12+
13+
/**
14+
* Delete specified files in the framework directory
15+
* @param {string} frameworkPath
16+
* @param {string[]} filesToDelete
17+
*/
18+
function deleteFrameworkFiles(frameworkPath, filesToDelete) {
19+
for (const file of filesToDelete) {
20+
const filePath = path.join(frameworkPath, file);
21+
fs.rmSync(filePath, { force: true, recursive: true });
22+
}
23+
console.log(`Deleted: ${filesToDelete}`);
24+
}
25+
26+
/**
27+
* Cleans all framework directories of package-lock.json, yarn-lock and the elm-stuff, node-modules, bower-components and dist directories.
28+
* @param {Object} options
29+
* @param {string} options.frameworksDirPath
30+
* @param {Array<string>} options.frameworksTypes
31+
*/
32+
function cleanFrameworkDirectories(options) {
33+
const { frameworksDirPath, frameworksTypes } = options;
34+
35+
for (const frameworkType of frameworksTypes) {
36+
const frameworkDir = path.resolve(frameworksDirPath, frameworkType);
37+
const directories = fs.readdirSync(frameworkDir);
38+
39+
for (const directory of directories) {
40+
const frameworkPath = path.resolve(frameworkDir, directory);
41+
console.log(`cleaning ${frameworkPath}`);
42+
deleteFrameworkFiles(frameworkPath, filesToDelete);
43+
}
44+
}
45+
}
46+
47+
export { cleanFrameworkDirectories };
Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,53 @@
1-
const fs = require("fs-extra");
2-
const yargs = require("yargs");
3-
const path = require("path");
4-
5-
const args = yargs(process.argv)
6-
.usage("$0 [--bootstrap --minimal]")
7-
.help("help")
8-
.boolean("bootstrap")
9-
.default("bootstrap", false)
10-
.boolean("minimal")
11-
.default("minimal", false).argv;
1+
import * as fs from "node:fs";
2+
import path from "node:path";
123

134
// Function to copy CSS and generate shared-styles.html
145
async function copyAndGenerateSharedStyles(sourceCss, mainCss) {
15-
await fs.copy(sourceCss, path.join("css", "currentStyle.css"));
6+
await fs.promises.cp(sourceCss, path.join("css", "currentStyle.css"));
167

178
// Read the main CSS file
18-
const mainCssContent = await fs.readFile(mainCss, "utf8");
9+
const mainCssContent = await fs.promises.readFile(mainCss, "utf8");
1910

2011
// Generate shared-styles.html content
2112
const sharedStylesContent = `<dom-module id="shared-styles"><template><style>${mainCssContent}</style></template></dom-module>`;
2213

2314
// Write shared-styles.html
24-
await fs.writeFile(
15+
await fs.promises.writeFile(
2516
path.join("polymer-v2.0.0-non-keyed", "src", "shared-styles.html"),
26-
sharedStylesContent
17+
sharedStylesContent,
2718
);
2819
}
2920

30-
// Main function
31-
async function configureStyles() {
21+
/**
22+
* @param {Object} options
23+
* @param {boolean} options.bootstrap
24+
* @param {boolean} options.minimal
25+
* @returns
26+
*/
27+
async function configureStyles(options) {
28+
const { bootstrap, minimal } = options;
29+
3230
try {
33-
if (args.bootstrap ^ args.minimal) {
31+
if (bootstrap ^ minimal) {
3432
console.log("ERROR: You must either choose bootstrap or minimal");
3533
return;
3634
}
3735

3836
// Read and copy the appropriate CSS file
39-
if (args.bootstrap) {
37+
if (bootstrap) {
4038
await copyAndGenerateSharedStyles(
4139
path.join("css", "useOriginalBootstrap.css"),
42-
path.join("css", "bootstrap", "dist", "css", "bootstrap.min.css")
40+
path.join("css", "bootstrap", "dist", "css", "bootstrap.min.css"),
4341
);
4442
} else {
4543
await copyAndGenerateSharedStyles(
4644
path.join("css", "useMinimalCss.css"),
47-
path.join("css", "useMinimalCss.css")
45+
path.join("css", "useMinimalCss.css"),
4846
);
4947
}
5048
} catch (error) {
5149
console.error("An error occurred:", error.message);
5250
}
5351
}
5452

55-
configureStyles();
53+
export { configureStyles };

copy.js renamed to cli/copy.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require("fs");
2-
const path = require("path");
1+
import * as fs from "node:fs";
2+
import path from "node:path";
33

44
const internalExclude = ["node_modules", "elm-stuff", "project", ".DS_Store"];
55
const rootExclude = ["dist", "node_modules", "webdriver-ts"];
@@ -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) {
@@ -73,7 +73,7 @@ function copyFolderRecursiveSync(sourcePath, destinationPath) {
7373
function processDirectories() {
7474
const directories = fs.readdirSync(".");
7575
const nonHiddenDirectories = directories.filter(
76-
(directory) => !directory.startsWith(".")
76+
(directory) => !directory.startsWith("."),
7777
);
7878

7979
for (const directory of nonHiddenDirectories) {
@@ -99,13 +99,11 @@ function copyProjectToDist() {
9999

100100
fs.copyFileSync(
101101
path.join("webdriver-ts", "table.html"),
102-
path.join("dist", "webdriver-ts", "table.html")
102+
path.join("dist", "webdriver-ts", "table.html"),
103103
);
104104
fs.copyFileSync("index.html", path.join("dist", "index.html"));
105105

106106
processDirectories();
107107
}
108108

109-
copyProjectToDist();
110-
111-
module.exports = { copyProjectToDist };
109+
export { copyProjectToDist };

0 commit comments

Comments
 (0)