@cluerise/tools 5.4.0 → 5.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,270 +2,254 @@ import FileSystem from "node:fs/promises";
2
2
  import * as ActionsCore from "@actions/core";
3
3
  import SemVer from "semver";
4
4
  import { z } from "zod";
5
- const gitProviderOrigins = {
6
- github: "https://github.com"
5
+ //#region src/modules/core/package-json/git-provider.ts
6
+ var gitProviderOrigins = { github: "https://github.com" };
7
+ var GitProvider = class {
8
+ static #origins = gitProviderOrigins;
9
+ static #names = Object.keys(this.#origins);
10
+ /**
11
+ * Check if the provided name is a valid Git provider name.
12
+ *
13
+ * @param name The name to check.
14
+ * @returns True if the name is valid, otherwise false.
15
+ */
16
+ static isValidName(name) {
17
+ return this.#names.includes(name);
18
+ }
19
+ /**
20
+ * Get the origin URL for the given Git provider name.
21
+ *
22
+ * @param name The Git provider name.
23
+ * @returns The origin URL.
24
+ */
25
+ static getOrigin(name) {
26
+ return this.#origins[name];
27
+ }
7
28
  };
8
- class GitProvider {
9
- static #origins = gitProviderOrigins;
10
- static #names = Object.keys(this.#origins);
11
- /**
12
- * Check if the provided name is a valid Git provider name.
13
- *
14
- * @param name The name to check.
15
- * @returns True if the name is valid, otherwise false.
16
- */
17
- static isValidName(name) {
18
- return this.#names.includes(name);
19
- }
20
- /**
21
- * Get the origin URL for the given Git provider name.
22
- *
23
- * @param name The Git provider name.
24
- * @returns The origin URL.
25
- */
26
- static getOrigin(name) {
27
- return this.#origins[name];
28
- }
29
- }
30
- const enginesSchema = z.object({
31
- node: z.string()
29
+ //#endregion
30
+ //#region src/modules/core/package-json/package-json-data.ts
31
+ var enginesSchema = z.object({ node: z.string() });
32
+ var repositoryObjectSchema = z.object({
33
+ type: z.string(),
34
+ url: z.string(),
35
+ directory: z.string().optional()
32
36
  });
33
- const repositoryObjectSchema = z.object({
34
- type: z.string(),
35
- url: z.string(),
36
- directory: z.string().optional()
37
+ var repositorySchema = z.union([z.string(), repositoryObjectSchema]);
38
+ var packageJsonDataSchema = z.object({
39
+ name: z.string(),
40
+ version: z.string().optional(),
41
+ description: z.string().optional(),
42
+ engines: enginesSchema.optional(),
43
+ repository: repositorySchema.optional()
37
44
  });
38
- const repositorySchema = z.union([z.string(), repositoryObjectSchema]);
39
- const packageJsonDataSchema = z.object({
40
- name: z.string(),
41
- version: z.string().optional(),
42
- description: z.string().optional(),
43
- engines: enginesSchema.optional(),
44
- repository: repositorySchema.optional()
45
- });
46
- class PackageJson {
47
- #data;
48
- constructor(data) {
49
- this.#data = data;
50
- }
51
- /**
52
- * Load and parse the `package.json` file, returning a `PackageJson` instance.
53
- *
54
- * Throws an error if the file is invalid or cannot be parsed.
55
- *
56
- * @returns A new `PackageJson` instance with parsed data.
57
- */
58
- static async init() {
59
- const content = await FileSystem.readFile("package.json", { encoding: "utf8" });
60
- const data = JsonUtils.parse(content);
61
- const parseResult = packageJsonDataSchema.safeParse(data);
62
- if (!parseResult.success) {
63
- throw new Error("Invalid package.json", {
64
- cause: parseResult.error
65
- });
66
- }
67
- return new PackageJson(data);
68
- }
69
- /**
70
- * Get the package name from `package.json`.
71
- *
72
- * @returns The package name.
73
- */
74
- get name() {
75
- return this.#data.name;
76
- }
77
- /**
78
- * Get the package version from `package.json`.
79
- *
80
- * @returns The package version.
81
- */
82
- get version() {
83
- return this.#data.version;
84
- }
85
- /**
86
- * Get the engines field from `package.json`, if present.
87
- *
88
- * @returns The engines object or undefined.
89
- */
90
- get engines() {
91
- return this.#data.engines;
92
- }
93
- /**
94
- * Set the engines field in `package.json`.
95
- *
96
- * @param engines The engines object to set.
97
- */
98
- set engines(engines) {
99
- this.#data.engines = engines;
100
- }
101
- /**
102
- * Get the repository field from `package.json`, if present.
103
- *
104
- * @returns The repository object or string, or undefined.
105
- */
106
- get repository() {
107
- return this.#data.repository;
108
- }
109
- #parseGitRepository(urlString) {
110
- if (!urlString) {
111
- return null;
112
- }
113
- const urlValue = urlString.includes(":") ? urlString : `https://${urlString}`;
114
- const url = new URL(urlValue);
115
- const scheme = url.protocol.slice(0, -1);
116
- if (GitProvider.isValidName(scheme)) {
117
- const [owner, repositoryName] = url.pathname.split("/");
118
- if (!owner || !repositoryName) {
119
- throw new Error("Unknown owner or repositoryName");
120
- }
121
- return {
122
- origin: GitProvider.getOrigin(scheme),
123
- owner,
124
- repositoryName
125
- };
126
- }
127
- if (scheme === "https") {
128
- const [, owner, repositoryName] = url.pathname.split("/");
129
- if (!owner || !repositoryName) {
130
- throw new Error("Unknown owner or repositoryName");
131
- }
132
- return {
133
- origin: url.origin,
134
- owner,
135
- repositoryName: repositoryName.endsWith(".git") ? repositoryName.slice(0, -4) : repositoryName
136
- };
137
- }
138
- throw new Error("Unsupported repository URL");
139
- }
140
- /**
141
- * Parse the repository information from `package.json` and return a `GitRepository` object or null.
142
- *
143
- * Returns null if no repository is defined or if parsing fails.
144
- *
145
- * @returns The parsed `GitRepository`, or null if not available.
146
- */
147
- parseGitRepository() {
148
- if (!this.repository) {
149
- return null;
150
- }
151
- if (typeof this.repository === "string") {
152
- return this.#parseGitRepository(this.repository);
153
- }
154
- return this.#parseGitRepository(this.repository.url);
155
- }
156
- /**
157
- * Save the current `package.json` data to disk, formatting it as prettified JSON.
158
- */
159
- async save() {
160
- const content = JsonUtils.prettify(this.#data) + "\n";
161
- await FileSystem.writeFile("package.json", content, { encoding: "utf8" });
162
- }
163
- }
164
- const runMain = (main2) => {
165
- Promise.resolve().then(() => main2(process.argv.slice(2))).then((exitCode) => {
166
- process.exit(exitCode);
167
- }).catch((error) => {
168
- console.error("Error:", error);
169
- process.exit(1);
170
- });
45
+ //#endregion
46
+ //#region src/modules/core/package-json/package-json.ts
47
+ var PackageJson = class PackageJson {
48
+ #data;
49
+ constructor(data) {
50
+ this.#data = data;
51
+ }
52
+ /**
53
+ * Load and parse the `package.json` file, returning a `PackageJson` instance.
54
+ *
55
+ * Throws an error if the file is invalid or cannot be parsed.
56
+ *
57
+ * @returns A new `PackageJson` instance with parsed data.
58
+ */
59
+ static async init() {
60
+ const content = await FileSystem.readFile("package.json", { encoding: "utf8" });
61
+ const data = JsonUtils.parse(content);
62
+ const parseResult = packageJsonDataSchema.safeParse(data);
63
+ if (!parseResult.success) throw new Error("Invalid package.json", { cause: parseResult.error });
64
+ return new PackageJson(data);
65
+ }
66
+ /**
67
+ * Get the package name from `package.json`.
68
+ *
69
+ * @returns The package name.
70
+ */
71
+ get name() {
72
+ return this.#data.name;
73
+ }
74
+ /**
75
+ * Get the package version from `package.json`.
76
+ *
77
+ * @returns The package version.
78
+ */
79
+ get version() {
80
+ return this.#data.version;
81
+ }
82
+ /**
83
+ * Get the engines field from `package.json`, if present.
84
+ *
85
+ * @returns The engines object or undefined.
86
+ */
87
+ get engines() {
88
+ return this.#data.engines;
89
+ }
90
+ /**
91
+ * Set the engines field in `package.json`.
92
+ *
93
+ * @param engines The engines object to set.
94
+ */
95
+ set engines(engines) {
96
+ this.#data.engines = engines;
97
+ }
98
+ /**
99
+ * Get the repository field from `package.json`, if present.
100
+ *
101
+ * @returns The repository object or string, or undefined.
102
+ */
103
+ get repository() {
104
+ return this.#data.repository;
105
+ }
106
+ #parseGitRepository(urlString) {
107
+ if (!urlString) return null;
108
+ const urlValue = urlString.includes(":") ? urlString : `https://${urlString}`;
109
+ const url = new URL(urlValue);
110
+ const scheme = url.protocol.slice(0, -1);
111
+ if (GitProvider.isValidName(scheme)) {
112
+ const [owner, repositoryName] = url.pathname.split("/");
113
+ if (!owner || !repositoryName) throw new Error("Unknown owner or repositoryName");
114
+ return {
115
+ origin: GitProvider.getOrigin(scheme),
116
+ owner,
117
+ repositoryName
118
+ };
119
+ }
120
+ if (scheme === "https") {
121
+ const [, owner, repositoryName] = url.pathname.split("/");
122
+ if (!owner || !repositoryName) throw new Error("Unknown owner or repositoryName");
123
+ return {
124
+ origin: url.origin,
125
+ owner,
126
+ repositoryName: repositoryName.endsWith(".git") ? repositoryName.slice(0, -4) : repositoryName
127
+ };
128
+ }
129
+ throw new Error("Unsupported repository URL");
130
+ }
131
+ /**
132
+ * Parse the repository information from `package.json` and return a `GitRepository` object or null.
133
+ *
134
+ * Returns null if no repository is defined or if parsing fails.
135
+ *
136
+ * @returns The parsed `GitRepository`, or null if not available.
137
+ */
138
+ parseGitRepository() {
139
+ if (!this.repository) return null;
140
+ if (typeof this.repository === "string") return this.#parseGitRepository(this.repository);
141
+ return this.#parseGitRepository(this.repository.url);
142
+ }
143
+ /**
144
+ * Save the current `package.json` data to disk, formatting it as prettified JSON.
145
+ */
146
+ async save() {
147
+ const content = JsonUtils.prettify(this.#data) + "\n";
148
+ await FileSystem.writeFile("package.json", content, { encoding: "utf8" });
149
+ }
150
+ };
151
+ //#endregion
152
+ //#region src/modules/core/run-main.ts
153
+ /**
154
+ * Execute the provided main function and handle any errors that occur.
155
+ *
156
+ * If the main function resolves, the process exits with the returned code.
157
+ * If an error is thrown, it logs the error and exits with code 1.
158
+ *
159
+ * @param main The main function to execute.
160
+ */
161
+ var runMain = (main) => {
162
+ Promise.resolve().then(() => main(process.argv.slice(2))).then((exitCode) => {
163
+ process.exit(exitCode);
164
+ }).catch((error) => {
165
+ console.error("Error:", error);
166
+ process.exit(1);
167
+ });
171
168
  };
172
- class JsonUtils {
173
- static stringify(value) {
174
- return JSON.stringify(value);
175
- }
176
- static prettify(value) {
177
- return JSON.stringify(value, null, 2);
178
- }
179
- static parse(value) {
180
- return JSON.parse(value);
181
- }
182
- }
183
- const nodeJsReleaseSchema = z.object({
184
- version: z.string(),
185
- // 'v20.5.1',
186
- date: z.string(),
187
- // '2023-08-09',
188
- files: z.array(z.string()),
189
- npm: z.string().optional(),
190
- // '9.8.0',
191
- v8: z.string(),
192
- // '11.3.244.8',
193
- uv: z.string().optional(),
194
- // '1.46.0',
195
- zlib: z.string().optional(),
196
- // '1.2.13.1-motley',
197
- openssl: z.string().optional(),
198
- // '3.0.10+quic',
199
- modules: z.string().optional(),
200
- // '115',
201
- lts: z.union([z.boolean(), z.string()]),
202
- // false, 'Argon',
203
- security: z.boolean()
169
+ //#endregion
170
+ //#region src/modules/core/utils/json-utils.ts
171
+ var JsonUtils = class {
172
+ static stringify(value) {
173
+ return JSON.stringify(value);
174
+ }
175
+ static prettify(value) {
176
+ return JSON.stringify(value, null, 2);
177
+ }
178
+ static parse(value) {
179
+ return JSON.parse(value);
180
+ }
181
+ };
182
+ //#endregion
183
+ //#region src/modules/node-js/node-js-release.ts
184
+ var nodeJsReleaseSchema = z.object({
185
+ version: z.string(),
186
+ date: z.string(),
187
+ files: z.array(z.string()),
188
+ npm: z.string().optional(),
189
+ v8: z.string(),
190
+ uv: z.string().optional(),
191
+ zlib: z.string().optional(),
192
+ openssl: z.string().optional(),
193
+ modules: z.string().optional(),
194
+ lts: z.union([z.boolean(), z.string()]),
195
+ security: z.boolean()
204
196
  });
205
- class NodeJs {
206
- static #releasesUrl = "https://nodejs.org/dist/index.json";
207
- /**
208
- * Fetch all Node.js releases.
209
- *
210
- * @returns A promise that resolves to an array of NodeJsRelease objects.
211
- */
212
- static async fetchReleases() {
213
- const response = await fetch(this.#releasesUrl);
214
- const data = await response.json();
215
- return z.array(nodeJsReleaseSchema).parse(data);
216
- }
217
- /**
218
- * Fetch the latest Node.js release.
219
- *
220
- * @returns A promise that resolves to the latest NodeJsRelease object or null if no releases are found.
221
- */
222
- static async fetchLatestRelease() {
223
- const [latestRelease] = await this.fetchReleases();
224
- return latestRelease ?? null;
225
- }
226
- }
227
- const updateNvmrc = (version) => FileSystem.writeFile(".nvmrc", `v${version}
228
- `);
229
- const updatePackageJson = async (version) => {
230
- const packageJson = await PackageJson.init();
231
- if (!packageJson.engines) {
232
- return;
233
- }
234
- const nodeVersion = packageJson.engines.node;
235
- if (!nodeVersion || nodeVersion === version) {
236
- return;
237
- }
238
- const coerceNodeVersion = SemVer.coerce(nodeVersion)?.version;
239
- if (!coerceNodeVersion) {
240
- return;
241
- }
242
- packageJson.engines.node = nodeVersion.replace(coerceNodeVersion, version);
243
- return packageJson.save();
197
+ //#endregion
198
+ //#region src/modules/node-js/node-js.ts
199
+ var NodeJs = class {
200
+ static #releasesUrl = "https://nodejs.org/dist/index.json";
201
+ /**
202
+ * Fetch all Node.js releases.
203
+ *
204
+ * @returns A promise that resolves to an array of NodeJsRelease objects.
205
+ */
206
+ static async fetchReleases() {
207
+ const data = await (await fetch(this.#releasesUrl)).json();
208
+ return z.array(nodeJsReleaseSchema).parse(data);
209
+ }
210
+ /**
211
+ * Fetch the latest Node.js release.
212
+ *
213
+ * @returns A promise that resolves to the latest NodeJsRelease object or null if no releases are found.
214
+ */
215
+ static async fetchLatestRelease() {
216
+ const [latestRelease] = await this.fetchReleases();
217
+ return latestRelease ?? null;
218
+ }
219
+ };
220
+ //#endregion
221
+ //#region src/app/scripts/update-node-versions/main.ts
222
+ var updateNvmrc = (version) => FileSystem.writeFile(".nvmrc", `v${version}\n`);
223
+ var updatePackageJson = async (version) => {
224
+ const packageJson = await PackageJson.init();
225
+ if (!packageJson.engines) return;
226
+ const nodeVersion = packageJson.engines.node;
227
+ if (!nodeVersion || nodeVersion === version) return;
228
+ const coerceNodeVersion = SemVer.coerce(nodeVersion)?.version;
229
+ if (!coerceNodeVersion) return;
230
+ packageJson.engines.node = nodeVersion.replace(coerceNodeVersion, version);
231
+ return packageJson.save();
244
232
  };
245
- const main = async () => {
246
- try {
247
- const nodeRelease = await NodeJs.fetchLatestRelease();
248
- const nodeVersion = nodeRelease?.version;
249
- const versionNumber = nodeVersion?.startsWith("v") ? nodeVersion.slice(1) : nodeVersion;
250
- if (!versionNumber) {
251
- console.error("Error: Unknown latest Node.js version number");
252
- return 1;
253
- }
254
- console.info(`Info: Trying to update Node.js versions to ${versionNumber}`);
255
- await updateNvmrc(versionNumber);
256
- await updatePackageJson(versionNumber);
257
- console.info("Info: Update successful");
258
- if (process.env.GITHUB_ACTIONS === "true") {
259
- ActionsCore.setOutput("version", versionNumber);
260
- }
261
- return 0;
262
- } catch (error) {
263
- if (error instanceof Error) {
264
- console.error("Error:", error.message);
265
- } else {
266
- console.error("Error:", error);
267
- }
268
- return 1;
269
- }
233
+ var main = async () => {
234
+ try {
235
+ const nodeVersion = (await NodeJs.fetchLatestRelease())?.version;
236
+ const versionNumber = nodeVersion?.startsWith("v") ? nodeVersion.slice(1) : nodeVersion;
237
+ if (!versionNumber) {
238
+ console.error("Error: Unknown latest Node.js version number");
239
+ return 1;
240
+ }
241
+ console.info(`Info: Trying to update Node.js versions to ${versionNumber}`);
242
+ await updateNvmrc(versionNumber);
243
+ await updatePackageJson(versionNumber);
244
+ console.info("Info: Update successful");
245
+ if (process.env.GITHUB_ACTIONS === "true") ActionsCore.setOutput("version", versionNumber);
246
+ return 0;
247
+ } catch (error) {
248
+ if (error instanceof Error) console.error("Error:", error.message);
249
+ else console.error("Error:", error);
250
+ return 1;
251
+ }
270
252
  };
271
253
  runMain(main);
254
+ //#endregion
255
+ export {};