@cluerise/tools 5.1.6 → 5.2.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.
package/README.md
CHANGED
|
@@ -297,10 +297,22 @@ export default defineConfig([
|
|
|
297
297
|
// Enable all hidden directories
|
|
298
298
|
'!.*/',
|
|
299
299
|
|
|
300
|
+
// Apollo
|
|
301
|
+
'**/apollo-ios-cli',
|
|
302
|
+
|
|
303
|
+
// Apple files and directories
|
|
304
|
+
'**/*.xcdatamodeld/',
|
|
305
|
+
'**/*.xcodeproj/',
|
|
306
|
+
'**/*.entitlements',
|
|
307
|
+
'**/*.plist',
|
|
308
|
+
'**/*.storekit',
|
|
309
|
+
'**/*.xcassets',
|
|
310
|
+
'**/*.xcstrings',
|
|
311
|
+
|
|
300
312
|
// Archives
|
|
301
|
-
'
|
|
302
|
-
'
|
|
303
|
-
'
|
|
313
|
+
'**/*.zip',
|
|
314
|
+
'**/*.gz',
|
|
315
|
+
'**/*.tgz',
|
|
304
316
|
|
|
305
317
|
// Build
|
|
306
318
|
'**/build/',
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import * as FileSystem from "node:fs/promises";
|
|
2
|
+
import FileSystem__default from "node:fs/promises";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
const gitProviderOrigins = {
|
|
5
|
+
github: "https://github.com"
|
|
6
|
+
};
|
|
7
|
+
class GitProvider {
|
|
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
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const enginesSchema = z.object({
|
|
30
|
+
node: z.string()
|
|
31
|
+
});
|
|
32
|
+
const repositoryObjectSchema = z.object({
|
|
33
|
+
type: z.string(),
|
|
34
|
+
url: z.string(),
|
|
35
|
+
directory: z.string().optional()
|
|
36
|
+
});
|
|
37
|
+
const repositorySchema = z.union([z.string(), repositoryObjectSchema]);
|
|
38
|
+
const 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()
|
|
44
|
+
});
|
|
45
|
+
class PackageJson {
|
|
46
|
+
#data;
|
|
47
|
+
constructor(data) {
|
|
48
|
+
this.#data = data;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Load and parse the `package.json` file, returning a `PackageJson` instance.
|
|
52
|
+
*
|
|
53
|
+
* Throws an error if the file is invalid or cannot be parsed.
|
|
54
|
+
*
|
|
55
|
+
* @returns A new `PackageJson` instance with parsed data.
|
|
56
|
+
*/
|
|
57
|
+
static async init() {
|
|
58
|
+
const content = await FileSystem__default.readFile("package.json", { encoding: "utf8" });
|
|
59
|
+
const data = JsonUtils.parse(content);
|
|
60
|
+
const parseResult = packageJsonDataSchema.safeParse(data);
|
|
61
|
+
if (!parseResult.success) {
|
|
62
|
+
throw new Error("Invalid package.json", {
|
|
63
|
+
cause: parseResult.error
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return new PackageJson(data);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the package name from `package.json`.
|
|
70
|
+
*
|
|
71
|
+
* @returns The package name.
|
|
72
|
+
*/
|
|
73
|
+
get name() {
|
|
74
|
+
return this.#data.name;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the package version from `package.json`.
|
|
78
|
+
*
|
|
79
|
+
* @returns The package version.
|
|
80
|
+
*/
|
|
81
|
+
get version() {
|
|
82
|
+
return this.#data.version;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the engines field from `package.json`, if present.
|
|
86
|
+
*
|
|
87
|
+
* @returns The engines object or undefined.
|
|
88
|
+
*/
|
|
89
|
+
get engines() {
|
|
90
|
+
return this.#data.engines;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Set the engines field in `package.json`.
|
|
94
|
+
*
|
|
95
|
+
* @param engines The engines object to set.
|
|
96
|
+
*/
|
|
97
|
+
set engines(engines) {
|
|
98
|
+
this.#data.engines = engines;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the repository field from `package.json`, if present.
|
|
102
|
+
*
|
|
103
|
+
* @returns The repository object or string, or undefined.
|
|
104
|
+
*/
|
|
105
|
+
get repository() {
|
|
106
|
+
return this.#data.repository;
|
|
107
|
+
}
|
|
108
|
+
#parseGitRepository(urlString) {
|
|
109
|
+
if (!urlString) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const urlValue = urlString.includes(":") ? urlString : `https://${urlString}`;
|
|
113
|
+
const url = new URL(urlValue);
|
|
114
|
+
const scheme = url.protocol.slice(0, -1);
|
|
115
|
+
if (GitProvider.isValidName(scheme)) {
|
|
116
|
+
const [owner, repositoryName] = url.pathname.split("/");
|
|
117
|
+
if (!owner || !repositoryName) {
|
|
118
|
+
throw new Error("Unknown owner or repositoryName");
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
origin: GitProvider.getOrigin(scheme),
|
|
122
|
+
owner,
|
|
123
|
+
repositoryName
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (scheme === "https") {
|
|
127
|
+
const [, owner, repositoryName] = url.pathname.split("/");
|
|
128
|
+
if (!owner || !repositoryName) {
|
|
129
|
+
throw new Error("Unknown owner or repositoryName");
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
origin: url.origin,
|
|
133
|
+
owner,
|
|
134
|
+
repositoryName: repositoryName.endsWith(".git") ? repositoryName.slice(0, -4) : repositoryName
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
throw new Error("Unsupported repository URL");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Parse the repository information from `package.json` and return a `GitRepository` object or null.
|
|
141
|
+
*
|
|
142
|
+
* Returns null if no repository is defined or if parsing fails.
|
|
143
|
+
*
|
|
144
|
+
* @returns The parsed `GitRepository`, or null if not available.
|
|
145
|
+
*/
|
|
146
|
+
parseGitRepository() {
|
|
147
|
+
if (!this.repository) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
if (typeof this.repository === "string") {
|
|
151
|
+
return this.#parseGitRepository(this.repository);
|
|
152
|
+
}
|
|
153
|
+
return this.#parseGitRepository(this.repository.url);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Save the current `package.json` data to disk, formatting it as prettified JSON.
|
|
157
|
+
*/
|
|
158
|
+
async save() {
|
|
159
|
+
const content = JsonUtils.prettify(this.#data) + "\n";
|
|
160
|
+
await FileSystem__default.writeFile("package.json", content, { encoding: "utf8" });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const runMain = (main2) => {
|
|
164
|
+
Promise.resolve().then(() => main2(process.argv.slice(2))).then((exitCode) => {
|
|
165
|
+
process.exit(exitCode);
|
|
166
|
+
}).catch((error) => {
|
|
167
|
+
console.error("Error:", error);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
class JsonUtils {
|
|
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
|
+
const parseUpdateXcodeVersionArgs = ([pathArg, ...appArgs]) => {
|
|
183
|
+
const path = z.string().parse(pathArg);
|
|
184
|
+
const apps = z.array(z.string()).parse(appArgs);
|
|
185
|
+
return {
|
|
186
|
+
path,
|
|
187
|
+
apps
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
const main = async (args) => {
|
|
191
|
+
const { path, apps: appNames } = parseUpdateXcodeVersionArgs(args);
|
|
192
|
+
const packageJson = await PackageJson.init();
|
|
193
|
+
const content = await FileSystem.readFile(path, "utf8");
|
|
194
|
+
const lines = content.split("\n");
|
|
195
|
+
let appBlock = false;
|
|
196
|
+
const nextLines = lines.map((line) => {
|
|
197
|
+
const appLine = appNames.some((appName) => line.includes(`INFOPLIST_KEY_CFBundleDisplayName = "${appName}";`));
|
|
198
|
+
if (appLine) {
|
|
199
|
+
appBlock = true;
|
|
200
|
+
}
|
|
201
|
+
if (appBlock && line.includes("MARKETING_VERSION = ")) {
|
|
202
|
+
appBlock = false;
|
|
203
|
+
const [variableName] = line.split("=");
|
|
204
|
+
return `${variableName}= ${packageJson.version};`;
|
|
205
|
+
}
|
|
206
|
+
return line;
|
|
207
|
+
});
|
|
208
|
+
const nextContent = nextLines.join("\n");
|
|
209
|
+
await FileSystem.writeFile(path, nextContent);
|
|
210
|
+
return 0;
|
|
211
|
+
};
|
|
212
|
+
runMain(main);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cluerise/tools",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Tools for maintaining TypeScript projects.",
|
|
5
5
|
"author": "Branislav Holý <brano@holy.am>",
|
|
6
6
|
"repository": "github:cluerise/tools",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"@commitlint/load": "19.8.1",
|
|
24
24
|
"@commitlint/types": "19.8.1",
|
|
25
25
|
"@eslint/js": "9.31.0",
|
|
26
|
-
"@eslint/json": "0.13.
|
|
27
|
-
"@eslint/markdown": "7.
|
|
26
|
+
"@eslint/json": "0.13.1",
|
|
27
|
+
"@eslint/markdown": "7.1.0",
|
|
28
28
|
"@html-eslint/eslint-plugin": "0.43.0",
|
|
29
29
|
"@html-eslint/parser": "0.43.0",
|
|
30
|
-
"@typescript-eslint/parser": "8.
|
|
30
|
+
"@typescript-eslint/parser": "8.38.0",
|
|
31
31
|
"conventional-changelog-conventionalcommits": "9.1.0",
|
|
32
32
|
"eslint": "9.31.0",
|
|
33
33
|
"eslint-config-prettier": "10.1.8",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"semantic-release": "24.2.7",
|
|
46
46
|
"semver": "7.7.2",
|
|
47
47
|
"smol-toml": "1.4.1",
|
|
48
|
-
"typescript-eslint": "8.
|
|
48
|
+
"typescript-eslint": "8.38.0",
|
|
49
49
|
"zod": "4.0.5"
|
|
50
50
|
}
|
|
51
51
|
}
|