Skip to content

Commit c747026

Browse files
committed
refactor: move getFrameworks to utils dir
1 parent f2a5bb2 commit c747026

File tree

4 files changed

+41
-56
lines changed

4 files changed

+41
-56
lines changed

check-obsolete.js

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from "node:fs";
33
import path from "node:path";
44
import JSON5 from "json5";
55
import yargs from "yargs";
6+
import { getFrameworks } from "./utils/frameworks/index.js";
67

78
const args = yargs(process.argv)
89
.usage("$0 [--debug]")
@@ -21,22 +22,6 @@ const DEBUG = args.debug;
2122
* @property {string} type - Type of the framework (e.g., "keyed" or "non-keyed")
2223
*/
2324

24-
/**
25-
* Returns an array of frameworks with their type and name
26-
* @example getFramewokrs()
27-
* @returns {Framework[]}
28-
*/
29-
function getFrameworks() {
30-
const framewokrsTypes = ["keyed", "non-keyed"];
31-
const framewokrs = framewokrsTypes.flatMap((type) =>
32-
fs
33-
.readdirSync(path.join("framewokrs", type))
34-
.map((framework) => ({ name: framework, type }))
35-
);
36-
37-
return framewokrs;
38-
}
39-
4025
const frameworks = getFrameworks();
4126

4227
/**
@@ -47,7 +32,7 @@ const frameworks = getFrameworks();
4732
function findDuplicateFrameworks(frameworks) {
4833
const names = frameworks.map((framework) => framework.name); // Creates an array with framework names only
4934
const duplicateNames = names.filter(
50-
(name, index) => names.indexOf(name) !== index
35+
(name, index) => names.indexOf(name) !== index,
5136
); // Filters out repetitive framework names
5237

5338
return duplicateNames;
@@ -88,7 +73,7 @@ function maybeObsolete(packageName) {
8873
const obsoleteDate = new Date(
8974
now.getFullYear() - 1,
9075
now.getMonth(),
91-
now.getDay()
76+
now.getDay(),
9277
);
9378

9479
const modifiedDate = new Date(timeData.modified);
@@ -98,7 +83,7 @@ function maybeObsolete(packageName) {
9883
return { isObsolete, packageName, lastUpdate: formattedDate };
9984
} catch (error) {
10085
console.error(
101-
`Failed to execute npm view for ${packageName}. Error Code ${error.status} and message: ${error.message}`
86+
`Failed to execute npm view for ${packageName}. Error Code ${error.status} and message: ${error.message}`,
10287
);
10388
return { isObsolete: false, packageName, lastUpdate: null };
10489
}
@@ -118,7 +103,7 @@ function checkFrameworks() {
118103

119104
if (!fs.existsSync(packageJSONPath)) {
120105
missingPackageWarnings.push(
121-
`WARN: skipping ${type}/${name} since there's no package.json`
106+
`WARN: skipping ${type}/${name} since there's no package.json`,
122107
);
123108
continue;
124109
}
@@ -144,7 +129,7 @@ function checkFrameworks() {
144129
}
145130

146131
const anyPackageObsolete = isPackageObsolete.some(
147-
(packageFramework) => packageFramework.isObsolete
132+
(packageFramework) => packageFramework.isObsolete,
148133
);
149134

150135
if (anyPackageObsolete) {
@@ -153,14 +138,14 @@ function checkFrameworks() {
153138
.join(", ");
154139

155140
console.log(
156-
`Last npm update for ${type}/${name} - ${mainPackages} is older than a year: ${formattedPackages}`
141+
`Last npm update for ${type}/${name} - ${mainPackages} is older than a year: ${formattedPackages}`,
157142
);
158143
continue;
159144
}
160145

161146
if (DEBUG) {
162147
console.log(
163-
`Last npm update for ${type}/${name} ${mainPackages} is newer than a year`
148+
`Last npm update for ${type}/${name} ${mainPackages} is newer than a year`,
164149
);
165150
}
166151
}
@@ -170,7 +155,7 @@ function checkFrameworks() {
170155
if (manualChecks.length > 0)
171156
console.warn(
172157
"\nThe following frameworks must be checked manually\n" +
173-
manualChecks.join("\n")
158+
manualChecks.join("\n"),
174159
);
175160
}
176161

rebuild-all.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from "node:fs";
33
import path from "node:path";
44
import yargs from "yargs";
55
import { takeWhile } from "./utils/common/index.js";
6+
import { getFrameworks } from "./utils/frameworks/index.js";
67

78
const args = yargs(process.argv.slice(2))
89
.usage("$0 [--ci --docker keyed/framework1 ... non-keyed/frameworkN]")
@@ -68,22 +69,6 @@ const filesToDelete = [
6869
* @property {string} type - Type of the framework (e.g., "keyed" or "non-keyed")
6970
*/
7071

71-
/**
72-
* Returns an array of frameworks with their type and name
73-
* @example getFramewokrs()
74-
* @returns {Framework[]}
75-
*/
76-
function getFrameworks() {
77-
const keyedTypes = ["keyed", "non-keyed"];
78-
const framewokrs = keyedTypes.flatMap((type) =>
79-
fs
80-
.readdirSync(path.join("frameworks", type))
81-
.map((framework) => ({ name: framework, type })),
82-
);
83-
84-
return framewokrs;
85-
}
86-
8772
/**
8873
* @param {Framework}
8974
* @returns {boolean}
@@ -159,6 +144,7 @@ function buildFramework(framework) {
159144

160145
function buildFrameworks() {
161146
const frameworks = getFrameworks();
147+
162148
const skippableFrameworks = takeWhile(frameworks, shouldSkipFramework);
163149
const buildableFrameworks = frameworks.slice(skippableFrameworks.length);
164150

update-lockfiles.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { cwd } from "node:process";
33
import * as fs from "node:fs";
44
import path from "node:path";
55
import yargs from "yargs";
6+
import { getFrameworks } from "./utils/frameworks/index.js";
67

78
const args = yargs(process.argv)
89
.usage("$0 [--frameworks-dir]")
@@ -35,21 +36,6 @@ const latestLockfileVersion = args.latestLockfileVersion;
3536
* @property {string} type - Type of the framework (e.g., "keyed" or "non-keyed")
3637
*/
3738

38-
/**
39-
* Returns an array with arrays of types and names of frameworks
40-
* @returns {Framework[]}
41-
*/
42-
function getFrameworks() {
43-
const frameworks = frameworksTypes.flatMap((type) =>
44-
fs.readdirSync(path.join(frameworksDir, type)).map((framework) => ({
45-
name: framework,
46-
type,
47-
})),
48-
);
49-
50-
return frameworks;
51-
}
52-
5339
/**
5440
* @param {string} frameworkPath
5541
*/
@@ -111,7 +97,7 @@ function processFramework(framework) {
11197
* Updates all frameworks lockfiles in the frameworks directory.
11298
*/
11399
function processAllFrameworks() {
114-
const frameworks = getFrameworks();
100+
const frameworks = getFrameworks(frameworksDir, frameworksTypes);
115101

116102
for (const framework of frameworks) {
117103
processFramework(framework);

utils/frameworks/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as fs from "node:fs";
2+
import path from "node:path";
3+
4+
/**
5+
* @typedef {Object} Framework
6+
* @property {string} name - Name of the framework (e.g., "vue", "qwik", "svelte")
7+
* @property {string} type - Type of the framework (e.g., "keyed" or "non-keyed")
8+
*/
9+
10+
/**
11+
* Returns an array with arrays of types and names of frameworks
12+
* @param {string} frameworksDirPath
13+
* @param {Array<string>} frameworksTypes
14+
* @returns {Framework[]}
15+
*/
16+
export function getFrameworks(
17+
frameworksDirPath = "frameworks",
18+
frameworksTypes = ["keyed", "non-keyed"],
19+
) {
20+
const frameworks = frameworksTypes.flatMap((type) =>
21+
fs.readdirSync(path.join(frameworksDirPath, type)).map((framework) => ({
22+
name: framework,
23+
type,
24+
})),
25+
);
26+
27+
return frameworks;
28+
}

0 commit comments

Comments
 (0)