adamantite 0.13.0 → 0.13.2
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/dist/index.mjs +472 -0
- package/package.json +15 -11
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -16
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import yargs from "yargs";
|
|
2
|
+
import { hideBin } from "yargs/helpers";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import { addDevDependency, detectPackageManager, dlxCommand } from "nypm";
|
|
5
|
+
import { access, mkdir, readFile, writeFile } from "fs/promises";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
import defu from "defu";
|
|
8
|
+
import { parse } from "jsonc-parser";
|
|
9
|
+
import process$1 from "process";
|
|
10
|
+
import { cancel, confirm, intro, isCancel, log, multiselect, outro, spinner } from "@clack/prompts";
|
|
11
|
+
import { readFileSync } from "fs";
|
|
12
|
+
|
|
13
|
+
//#region src/utils.ts
|
|
14
|
+
function defineCommand(input) {
|
|
15
|
+
return input;
|
|
16
|
+
}
|
|
17
|
+
async function getPackageManagerName() {
|
|
18
|
+
const result = await detectPackageManager(process$1.cwd());
|
|
19
|
+
if (!result) throw new Error("No package manager found");
|
|
20
|
+
const { warnings, ...packageManager } = result;
|
|
21
|
+
if (warnings && warnings.length > 0) console.warn(warnings.join("\n"));
|
|
22
|
+
return packageManager.name;
|
|
23
|
+
}
|
|
24
|
+
function handleCommandError(error) {
|
|
25
|
+
const message = error instanceof Error ? error.message : "An unknown error occurred";
|
|
26
|
+
console.error(message);
|
|
27
|
+
cancel("Failed to run Adamantite");
|
|
28
|
+
process$1.exit(1);
|
|
29
|
+
}
|
|
30
|
+
async function checkIfExists(path) {
|
|
31
|
+
try {
|
|
32
|
+
await access(path);
|
|
33
|
+
return true;
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reads and parses package.json with proper typing
|
|
40
|
+
*/
|
|
41
|
+
async function readPackageJson(cwd = process$1.cwd()) {
|
|
42
|
+
const currentPath = join(cwd, "package.json");
|
|
43
|
+
if (!await checkIfExists(currentPath)) throw new Error("package.json not found in the current directory");
|
|
44
|
+
try {
|
|
45
|
+
const content = await readFile(currentPath, "utf-8");
|
|
46
|
+
return JSON.parse(content);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error(`Failed to parse package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Writes package.json with proper formatting
|
|
53
|
+
*/
|
|
54
|
+
async function writePackageJson(packageJson, cwd = process$1.cwd()) {
|
|
55
|
+
const currentPath = join(cwd, "package.json");
|
|
56
|
+
try {
|
|
57
|
+
await writeFile(currentPath, JSON.stringify(packageJson, null, 2));
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error(`Failed to write package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function getTitle() {
|
|
63
|
+
if ((process$1.stdout.columns || 80) >= 120) return `
|
|
64
|
+
█████ █████ ███ █████
|
|
65
|
+
░░███ ░░███ ░░░ ░░███
|
|
66
|
+
██████ ███████ ██████ █████████████ ██████ ████████ ███████ ████ ███████ ██████
|
|
67
|
+
░░░░░███ ███░░███ ░░░░░███ ░░███░░███░░███ ░░░░░███ ░░███░░███ ░░░███░ ░░███ ░░░███░ ███░░███
|
|
68
|
+
███████ ░███ ░███ ███████ ░███ ░███ ░███ ███████ ░███ ░███ ░███ ░███ ░███ ░███████
|
|
69
|
+
███░░███ ░███ ░███ ███░░███ ░███ ░███ ░███ ███░░███ ░███ ░███ ░███ ███ ░███ ░███ ███░███░░░
|
|
70
|
+
░░████████░░████████░░████████ █████░███ █████░░████████ ████ █████ ░░█████ █████ ░░█████ ░░██████
|
|
71
|
+
░░░░░░░░ ░░░░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░
|
|
72
|
+
`;
|
|
73
|
+
return `
|
|
74
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
75
|
+
┃ ADAMANTITE ┃
|
|
76
|
+
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/commands/helpers.ts
|
|
82
|
+
const tsconfig = {
|
|
83
|
+
name: "tsconfig",
|
|
84
|
+
config: { extends: "adamantite/tsconfig" },
|
|
85
|
+
async exists() {
|
|
86
|
+
return await checkIfExists(join(process.cwd(), "tsconfig.json"));
|
|
87
|
+
},
|
|
88
|
+
async create() {
|
|
89
|
+
await writeFile(join(process.cwd(), "tsconfig.json"), JSON.stringify(this.config, null, 2));
|
|
90
|
+
},
|
|
91
|
+
async update() {
|
|
92
|
+
const existingConfig = parse(await readFile(join(process.cwd(), "tsconfig.json"), "utf-8"));
|
|
93
|
+
const newConfig = defu(this.config, existingConfig);
|
|
94
|
+
await writeFile(join(process.cwd(), "tsconfig.json"), JSON.stringify(newConfig, null, 2));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const biome = {
|
|
98
|
+
name: "@biomejs/biome",
|
|
99
|
+
version: "2.3.10",
|
|
100
|
+
config: { $schema: "./node_modules/@biomejs/biome/configuration_schema.json" },
|
|
101
|
+
async exists() {
|
|
102
|
+
return await checkIfExists(join(process.cwd(), "biome.jsonc"));
|
|
103
|
+
},
|
|
104
|
+
async create() {
|
|
105
|
+
await writeFile(join(process.cwd(), "biome.jsonc"), JSON.stringify({
|
|
106
|
+
...this.config,
|
|
107
|
+
extends: ["adamantite"]
|
|
108
|
+
}, null, 2));
|
|
109
|
+
},
|
|
110
|
+
async update() {
|
|
111
|
+
const newConfig = { ...parse(await readFile(await checkIfExists(join(process.cwd(), "biome.jsonc")) ? join(process.cwd(), "biome.jsonc") : join(process.cwd(), "biome.json"), "utf-8")) };
|
|
112
|
+
if (!Array.isArray(newConfig.extends)) newConfig.extends = newConfig.extends ? [newConfig.extends] : [];
|
|
113
|
+
if (!newConfig.extends.includes("adamantite")) newConfig.extends.push("adamantite");
|
|
114
|
+
const mergedConfig = defu(this.config, newConfig);
|
|
115
|
+
await writeFile(join(process.cwd(), "biome.jsonc"), JSON.stringify(mergedConfig, null, 2));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const vscode = {
|
|
119
|
+
name: ".vscode",
|
|
120
|
+
config: {
|
|
121
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
122
|
+
"editor.formatOnSave": true,
|
|
123
|
+
"editor.formatOnPaste": true,
|
|
124
|
+
"editor.codeActionsOnSave": {
|
|
125
|
+
"source.organizeImports.biome": "explicit",
|
|
126
|
+
"source.fixAll.biome": "explicit"
|
|
127
|
+
},
|
|
128
|
+
"[javascript][typescript][javascriptreact][typescriptreact][json][jsonc][css][graphql]": { "editor.defaultFormatter": "biomejs.biome" }
|
|
129
|
+
},
|
|
130
|
+
async exists() {
|
|
131
|
+
return await checkIfExists(join(process.cwd(), ".vscode", "settings.json"));
|
|
132
|
+
},
|
|
133
|
+
async create() {
|
|
134
|
+
const vscodePath = join(process.cwd(), ".vscode");
|
|
135
|
+
await mkdir(vscodePath, { recursive: true });
|
|
136
|
+
await writeFile(join(vscodePath, "settings.json"), JSON.stringify(this.config, null, 2));
|
|
137
|
+
},
|
|
138
|
+
async update() {
|
|
139
|
+
const existingConfig = parse(await readFile(join(process.cwd(), ".vscode", "settings.json"), "utf-8"));
|
|
140
|
+
const newConfig = defu(this.config, existingConfig);
|
|
141
|
+
await writeFile(join(process.cwd(), ".vscode", "settings.json"), JSON.stringify(newConfig, null, 2));
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const sherif = { version: "1.9.0" };
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/commands/check.ts
|
|
148
|
+
var check_default = defineCommand({
|
|
149
|
+
command: "check",
|
|
150
|
+
describe: "Run Biome linter and check files for issues",
|
|
151
|
+
builder: (yargs$1) => yargs$1.positional("files", {
|
|
152
|
+
describe: "Specific files to lint (optional)",
|
|
153
|
+
type: "string"
|
|
154
|
+
}).option("summary", {
|
|
155
|
+
type: "boolean",
|
|
156
|
+
description: "Show summary of lint results"
|
|
157
|
+
}),
|
|
158
|
+
handler: async (argv) => {
|
|
159
|
+
try {
|
|
160
|
+
const packageManager = await getPackageManagerName();
|
|
161
|
+
const args = ["check"];
|
|
162
|
+
if (argv.summary) args.push("--reporter", "summary");
|
|
163
|
+
if (argv.files && argv.files.length > 0) args.push(...argv.files);
|
|
164
|
+
execSync(dlxCommand(packageManager, biome.name, { args }), { stdio: "inherit" });
|
|
165
|
+
} catch (error) {
|
|
166
|
+
handleCommandError(error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/commands/ci.ts
|
|
173
|
+
var ci_default = defineCommand({
|
|
174
|
+
command: "ci",
|
|
175
|
+
describe: "Run Adamantite in a CI environment",
|
|
176
|
+
builder: (yargs$1) => yargs$1.option("monorepo", {
|
|
177
|
+
type: "boolean",
|
|
178
|
+
description: "Run additional monorepo-specific checks"
|
|
179
|
+
}).option("github", {
|
|
180
|
+
type: "boolean",
|
|
181
|
+
description: "Use GitHub reporter"
|
|
182
|
+
}),
|
|
183
|
+
handler: async (argv) => {
|
|
184
|
+
try {
|
|
185
|
+
const packageManager = await getPackageManagerName();
|
|
186
|
+
const tools = [{
|
|
187
|
+
package: "@biomejs/biome",
|
|
188
|
+
args: ["ci", ...argv.github ? ["--reporter", "github"] : []]
|
|
189
|
+
}, ...argv.monorepo ? [{
|
|
190
|
+
package: "sherif",
|
|
191
|
+
args: []
|
|
192
|
+
}] : []];
|
|
193
|
+
for (const tool of tools) execSync(dlxCommand(packageManager, tool.package, { args: tool.args }), { stdio: "inherit" });
|
|
194
|
+
} catch (error) {
|
|
195
|
+
handleCommandError(error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/commands/fix.ts
|
|
202
|
+
var fix_default = defineCommand({
|
|
203
|
+
command: "fix",
|
|
204
|
+
describe: "Run Biome linter and fix issues in files",
|
|
205
|
+
builder: (yargs$1) => yargs$1.positional("files", {
|
|
206
|
+
describe: "Specific files to fix (optional)",
|
|
207
|
+
type: "string"
|
|
208
|
+
}).option("unsafe", {
|
|
209
|
+
type: "boolean",
|
|
210
|
+
description: "Apply unsafe fixes"
|
|
211
|
+
}),
|
|
212
|
+
handler: async (argv) => {
|
|
213
|
+
try {
|
|
214
|
+
const packageManager = await getPackageManagerName();
|
|
215
|
+
const args = ["check", "--write"];
|
|
216
|
+
if (argv.unsafe) args.push("--unsafe");
|
|
217
|
+
if (argv.files && argv.files.length > 0) args.push(...argv.files);
|
|
218
|
+
execSync(dlxCommand(packageManager, biome.name, { args }), { stdio: "inherit" });
|
|
219
|
+
} catch (error) {
|
|
220
|
+
handleCommandError(error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/commands/init.ts
|
|
227
|
+
async function checkIsMonorepo() {
|
|
228
|
+
if (await checkIfExists(join(process$1.cwd(), "pnpm-workspace.yaml"))) return true;
|
|
229
|
+
try {
|
|
230
|
+
return (await readPackageJson()).workspaces !== void 0;
|
|
231
|
+
} catch {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function setupBiomeConfig() {
|
|
236
|
+
const s = spinner();
|
|
237
|
+
if (await biome.exists()) {
|
|
238
|
+
s.start("Biome config found, updating...");
|
|
239
|
+
await biome.update();
|
|
240
|
+
s.stop("Biome config updated with Adamantite preset");
|
|
241
|
+
} else {
|
|
242
|
+
s.start("Biome config not found, creating...");
|
|
243
|
+
await biome.create();
|
|
244
|
+
s.stop("Biome config created with Adamantite preset");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function setupScripts({ check, fix, monorepo }) {
|
|
248
|
+
const s = spinner();
|
|
249
|
+
s.start("Adding scripts to your `package.json`...");
|
|
250
|
+
try {
|
|
251
|
+
const packageJson = await readPackageJson();
|
|
252
|
+
if (!packageJson.scripts) packageJson.scripts = {};
|
|
253
|
+
if (check) packageJson.scripts["check"] = "adamantite check";
|
|
254
|
+
if (fix) packageJson.scripts["fix"] = "adamantite fix";
|
|
255
|
+
if (monorepo) packageJson.scripts["lint:monorepo"] = "adamantite monorepo";
|
|
256
|
+
await writePackageJson(packageJson);
|
|
257
|
+
s.stop("Scripts added to your `package.json`");
|
|
258
|
+
} catch (error) {
|
|
259
|
+
s.stop("Failed to add scripts");
|
|
260
|
+
throw new Error(`Failed to modify package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async function setupTsConfig() {
|
|
264
|
+
const s = spinner();
|
|
265
|
+
if (await tsconfig.exists()) {
|
|
266
|
+
s.start("`tsconfig.json` found, updating...");
|
|
267
|
+
await tsconfig.update();
|
|
268
|
+
s.stop("Updated `tsconfig.json` with preset");
|
|
269
|
+
} else {
|
|
270
|
+
s.start("`tsconfig.json` not found, creating...");
|
|
271
|
+
await tsconfig.create();
|
|
272
|
+
s.stop("Created `tsconfig.json` with preset");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function selectEditorConfig() {
|
|
276
|
+
const selected = await multiselect({
|
|
277
|
+
message: "Which editors do you want to configure (recommended)?",
|
|
278
|
+
options: [{
|
|
279
|
+
label: "VSCode / Cursor / Windsurf",
|
|
280
|
+
value: "vscode"
|
|
281
|
+
}, {
|
|
282
|
+
label: "Zed (coming soon)",
|
|
283
|
+
value: "zed"
|
|
284
|
+
}],
|
|
285
|
+
required: false
|
|
286
|
+
});
|
|
287
|
+
if (isCancel(selected)) throw new Error("Operation cancelled");
|
|
288
|
+
return selected;
|
|
289
|
+
}
|
|
290
|
+
async function setupEditorConfig(selectedEditors) {
|
|
291
|
+
if (!selectedEditors || selectedEditors.length === 0) return;
|
|
292
|
+
const s = spinner();
|
|
293
|
+
if (selectedEditors.includes("vscode")) if (await vscode.exists()) {
|
|
294
|
+
s.start("VSCode settings found, updating...");
|
|
295
|
+
await vscode.update();
|
|
296
|
+
s.stop("VSCode settings updated with Adamantite preset");
|
|
297
|
+
} else {
|
|
298
|
+
s.start("VSCode settings not found, creating...");
|
|
299
|
+
await vscode.create();
|
|
300
|
+
s.stop("VSCode settings created with Adamantite preset");
|
|
301
|
+
}
|
|
302
|
+
if (selectedEditors.includes("zed")) {
|
|
303
|
+
s.start("Zed configuration coming soon...");
|
|
304
|
+
s.stop("Zed configuration coming soon...");
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async function confirmAction(message) {
|
|
308
|
+
const result = await confirm({ message });
|
|
309
|
+
if (isCancel(result)) throw new Error("Operation cancelled");
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
async function installDependencies(options) {
|
|
313
|
+
const s = spinner();
|
|
314
|
+
s.start("Installing dependencies...");
|
|
315
|
+
try {
|
|
316
|
+
await addDevDependency("adamantite");
|
|
317
|
+
const biomeVersion = biome.version;
|
|
318
|
+
await addDevDependency(`@biomejs/biome@${biomeVersion}`);
|
|
319
|
+
if (options?.monorepo) await addDevDependency(`sherif@${sherif.version}`);
|
|
320
|
+
s.stop("Dependencies installed successfully");
|
|
321
|
+
} catch (error) {
|
|
322
|
+
s.stop("Failed to install dependencies");
|
|
323
|
+
throw new Error(`Failed to install dependencies: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
var init_default = defineCommand({
|
|
327
|
+
command: "init",
|
|
328
|
+
describe: "Initialize Adamantite in the current directory",
|
|
329
|
+
builder: (yargs$1) => yargs$1,
|
|
330
|
+
handler: async () => {
|
|
331
|
+
intro(getTitle());
|
|
332
|
+
try {
|
|
333
|
+
const isMonorepo = await checkIsMonorepo();
|
|
334
|
+
const installScripts = await confirmAction("Do you want to add the `check` and `fix` scripts to your `package.json`?");
|
|
335
|
+
const installMonorepoScript = isMonorepo ? await confirmAction("We've detected a monorepo setup in your project. Would you like to install monorepo linting scripts?") : false;
|
|
336
|
+
const installTypeScript = await confirmAction("Adamantite provides a TypeScript preset to enforce strict type-safety. Would you like to install it?");
|
|
337
|
+
const selectedEditors = await selectEditorConfig();
|
|
338
|
+
await installDependencies({ monorepo: installMonorepoScript });
|
|
339
|
+
await setupBiomeConfig();
|
|
340
|
+
if (installScripts || installMonorepoScript) await setupScripts({
|
|
341
|
+
check: installScripts,
|
|
342
|
+
fix: installScripts,
|
|
343
|
+
monorepo: installMonorepoScript
|
|
344
|
+
});
|
|
345
|
+
if (installTypeScript) await setupTsConfig();
|
|
346
|
+
await setupEditorConfig(selectedEditors);
|
|
347
|
+
outro("💠 Adamantite initialized successfully!");
|
|
348
|
+
} catch (error) {
|
|
349
|
+
log.error(`${error instanceof Error ? error.message : "Unknown error"}`);
|
|
350
|
+
cancel("Failed to initialize Adamantite");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region src/commands/monorepo.ts
|
|
357
|
+
var monorepo_default = defineCommand({
|
|
358
|
+
command: "monorepo",
|
|
359
|
+
describe: "Lint and automatically fix monorepo-specific issues using Sherif",
|
|
360
|
+
builder: (yargs$1) => yargs$1,
|
|
361
|
+
handler: async () => {
|
|
362
|
+
try {
|
|
363
|
+
execSync(dlxCommand(await getPackageManagerName(), "sherif", { args: ["--fix"] }), { stdio: "inherit" });
|
|
364
|
+
} catch (error) {
|
|
365
|
+
handleCommandError(error);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/commands/update.ts
|
|
372
|
+
async function detectUpdatesNeeded() {
|
|
373
|
+
const updates = [];
|
|
374
|
+
try {
|
|
375
|
+
const packageJson = await readPackageJson();
|
|
376
|
+
const biomeDep = packageJson.devDependencies?.["@biomejs/biome"];
|
|
377
|
+
if (biomeDep && biomeDep !== biome.version) updates.push({
|
|
378
|
+
name: "@biomejs/biome",
|
|
379
|
+
currentVersion: biomeDep,
|
|
380
|
+
targetVersion: biome.version,
|
|
381
|
+
isDevDependency: true
|
|
382
|
+
});
|
|
383
|
+
const sherifDep = packageJson.devDependencies?.sherif;
|
|
384
|
+
if (sherifDep && sherifDep !== sherif.version) updates.push({
|
|
385
|
+
name: "sherif",
|
|
386
|
+
currentVersion: sherifDep,
|
|
387
|
+
targetVersion: sherif.version,
|
|
388
|
+
isDevDependency: true
|
|
389
|
+
});
|
|
390
|
+
return updates;
|
|
391
|
+
} catch (error) {
|
|
392
|
+
throw new Error(`Failed to read package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async function updateDependencies(updates) {
|
|
396
|
+
const s = spinner();
|
|
397
|
+
s.start("Updating dependencies...");
|
|
398
|
+
try {
|
|
399
|
+
const tasks = updates.map((dep) => addDevDependency(`${dep.name}@${dep.targetVersion}`));
|
|
400
|
+
const results = await Promise.allSettled(tasks);
|
|
401
|
+
const failures = [];
|
|
402
|
+
const successes = [];
|
|
403
|
+
for (const [index, result] of results.entries()) {
|
|
404
|
+
const dep = updates[index];
|
|
405
|
+
if (!dep) continue;
|
|
406
|
+
const depName = dep.name;
|
|
407
|
+
if (result.status === "fulfilled") successes.push(depName);
|
|
408
|
+
else failures.push(`${depName}: ${result.reason?.message || "Unknown error"}`);
|
|
409
|
+
}
|
|
410
|
+
if (failures.length === 0) s.stop("Dependencies updated successfully");
|
|
411
|
+
else if (successes.length === 0) {
|
|
412
|
+
s.stop("Failed to update dependencies");
|
|
413
|
+
throw new Error(`All dependency updates failed:\n${failures.join("\n")}`);
|
|
414
|
+
} else {
|
|
415
|
+
s.stop("Partial update completed");
|
|
416
|
+
log.warn("Some dependencies failed to update:");
|
|
417
|
+
for (const failure of failures) log.warn(` ${failure}`);
|
|
418
|
+
log.success(`Successfully updated: ${successes.join(", ")}`);
|
|
419
|
+
}
|
|
420
|
+
} catch (error) {
|
|
421
|
+
s.stop("Failed to update dependencies");
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async function confirmUpdate(updates) {
|
|
426
|
+
log.message("The following dependencies will be updated:");
|
|
427
|
+
log.message("");
|
|
428
|
+
for (const dep of updates) log.message(` ${dep.name}: ${dep.currentVersion} → ${dep.targetVersion}`);
|
|
429
|
+
log.message("");
|
|
430
|
+
const result = await confirm({ message: "Do you want to proceed with these updates?" });
|
|
431
|
+
if (isCancel(result)) throw new Error("Operation cancelled");
|
|
432
|
+
return result;
|
|
433
|
+
}
|
|
434
|
+
var update_default = defineCommand({
|
|
435
|
+
command: "update",
|
|
436
|
+
describe: "Update adamantite dependencies to latest compatible versions",
|
|
437
|
+
builder: (yargs$1) => yargs$1,
|
|
438
|
+
handler: async () => {
|
|
439
|
+
intro(getTitle());
|
|
440
|
+
try {
|
|
441
|
+
const updates = await detectUpdatesNeeded();
|
|
442
|
+
if (updates.length === 0) {
|
|
443
|
+
log.success("All adamantite dependencies are already up to date!");
|
|
444
|
+
outro("💠 No updates needed");
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (!await confirmUpdate(updates)) {
|
|
448
|
+
outro("💠 Update cancelled");
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
await updateDependencies(updates);
|
|
452
|
+
outro("💠 Dependencies updated successfully!");
|
|
453
|
+
} catch (error) {
|
|
454
|
+
handleCommandError(error);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/version.ts
|
|
461
|
+
function getPackageVersion() {
|
|
462
|
+
return JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf-8")).version;
|
|
463
|
+
}
|
|
464
|
+
const version = getPackageVersion();
|
|
465
|
+
var version_default = version;
|
|
466
|
+
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/index.ts
|
|
469
|
+
yargs(hideBin(process.argv)).scriptName("adamantite").version(version_default).command(check_default).command(ci_default).command(fix_default).command(init_default).command(monorepo_default).command(update_default).demandCommand(1).strict().help().parse();
|
|
470
|
+
|
|
471
|
+
//#endregion
|
|
472
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adamantite",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "An strict and opinionated set of presets for modern TypeScript applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adamantite",
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
"bin": {
|
|
26
26
|
"adamantite": "bin/adamantite"
|
|
27
27
|
},
|
|
28
|
+
"imports": {
|
|
29
|
+
"#*": "./src/*"
|
|
30
|
+
},
|
|
28
31
|
"exports": {
|
|
29
32
|
".": "./src/presets/biome.jsonc",
|
|
30
33
|
"./biome": "./src/presets/biome.jsonc",
|
|
@@ -50,23 +53,24 @@
|
|
|
50
53
|
},
|
|
51
54
|
"dependencies": {
|
|
52
55
|
"@clack/prompts": "0.11.0",
|
|
53
|
-
"citty": "0.1.6",
|
|
54
56
|
"defu": "6.1.4",
|
|
55
57
|
"jsonc-parser": "3.3.1",
|
|
56
|
-
"nypm": "0.6.2"
|
|
58
|
+
"nypm": "0.6.2",
|
|
59
|
+
"yargs": "18.0.0"
|
|
57
60
|
},
|
|
58
61
|
"devDependencies": {
|
|
59
|
-
"@biomejs/biome": "2.3.
|
|
60
|
-
"@changesets/cli": "2.29.
|
|
61
|
-
"@types/bun": "1.3.
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
62
|
+
"@biomejs/biome": "2.3.10",
|
|
63
|
+
"@changesets/cli": "2.29.8",
|
|
64
|
+
"@types/bun": "1.3.5",
|
|
65
|
+
"@types/yargs": "17.0.35",
|
|
66
|
+
"sherif": "1.9.0",
|
|
67
|
+
"tsdown": "0.18.1",
|
|
68
|
+
"type-fest": "5.3.1",
|
|
65
69
|
"typescript": "5.9.3"
|
|
66
70
|
},
|
|
67
71
|
"peerDependencies": {
|
|
68
|
-
"@biomejs/biome": "2.3.
|
|
72
|
+
"@biomejs/biome": "2.3.10",
|
|
69
73
|
"typescript": ">=5.6.0"
|
|
70
74
|
},
|
|
71
|
-
"packageManager": "bun@1.
|
|
75
|
+
"packageManager": "bun@1.3.3"
|
|
72
76
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{defineCommand as e,runMain as t}from"citty";import{execSync as n}from"child_process";import{addDevDependency as r,detectPackageManager as i,dlxCommand as a}from"nypm";import{access as o,mkdir as s,readFile as c,writeFile as l}from"fs/promises";import{join as u}from"path";import d from"process";import{cancel as f,confirm as p,intro as m,isCancel as h,log as g,multiselect as _,outro as v,spinner as y}from"@clack/prompts";import b from"defu";import{parse as x}from"jsonc-parser";import{readFileSync as S}from"fs";async function C(){let e=await i(d.cwd());if(!e)throw Error(`No package manager found`);let{warnings:t,...n}=e;return t&&t.length>0&&console.warn(t.join(`
|
|
2
|
-
`)),n.name}function w(e){let t=e instanceof Error?e.message:`An unknown error occurred`;console.error(t),f(`Failed to run Adamantite`),d.exit(1)}async function T(e){try{return await o(e),!0}catch{return!1}}async function E(e=d.cwd()){let t=u(e,`package.json`);if(!await T(t))throw Error(`package.json not found in the current directory`);try{let e=await c(t,`utf-8`);return JSON.parse(e)}catch(e){throw Error(`Failed to parse package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}async function D(e,t=d.cwd()){let n=u(t,`package.json`);try{await l(n,JSON.stringify(e,null,2))}catch(e){throw Error(`Failed to write package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}function O(){return(d.stdout.columns||80)>=120?`
|
|
3
|
-
█████ █████ ███ █████
|
|
4
|
-
░░███ ░░███ ░░░ ░░███
|
|
5
|
-
██████ ███████ ██████ █████████████ ██████ ████████ ███████ ████ ███████ ██████
|
|
6
|
-
░░░░░███ ███░░███ ░░░░░███ ░░███░░███░░███ ░░░░░███ ░░███░░███ ░░░███░ ░░███ ░░░███░ ███░░███
|
|
7
|
-
███████ ░███ ░███ ███████ ░███ ░███ ░███ ███████ ░███ ░███ ░███ ░███ ░███ ░███████
|
|
8
|
-
███░░███ ░███ ░███ ███░░███ ░███ ░███ ░███ ███░░███ ░███ ░███ ░███ ███ ░███ ░███ ███░███░░░
|
|
9
|
-
░░████████░░████████░░████████ █████░███ █████░░████████ ████ █████ ░░█████ █████ ░░█████ ░░██████
|
|
10
|
-
░░░░░░░░ ░░░░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░
|
|
11
|
-
`:`
|
|
12
|
-
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
13
|
-
┃ ADAMANTITE ┃
|
|
14
|
-
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
15
|
-
`}var k=e({meta:{name:`check`,description:`Run Biome linter and check files for issues`},args:{files:{description:`Specific files to lint (optional)`,type:`positional`,required:!1},summary:{description:`Show summary of lint results`,type:`boolean`}},run:async({args:e})=>{try{let t=await C(),r=[`check`];e.summary&&r.push(`--reporter`,`summary`);let i=e._;i.length>0&&r.push(...i),n(a(t,`@biomejs/biome`,{args:r}),{stdio:`inherit`})}catch(e){w(e)}}}),A=e({meta:{name:`ci`,description:`Run Adamantite in a CI environment`},args:{monorepo:{description:`Run additional monorepo-specific checks`,type:`boolean`},github:{description:`Use GitHub reporter`,type:`boolean`}},run:async({args:e})=>{try{let t=await C(),r=[{package:`@biomejs/biome`,args:[`ci`,...e.github?[`--reporter`,`github`]:[]]},...e.monorepo?[{package:`sherif`,args:[]}]:[]];for(let e of r)n(a(t,e.package,{args:e.args}),{stdio:`inherit`})}catch(e){w(e)}}}),j=e({meta:{name:`fix`,description:`Run Biome linter and fix issues in files`},args:{files:{description:`Specific files to fix (optional)`,type:`positional`,required:!1},unsafe:{description:`Apply unsafe fixes`,type:`boolean`}},run:async({args:e})=>{try{let t=await C(),r=[`check`,`--write`];e.unsafe&&r.push(`--unsafe`);let i=e._;i.length>0&&r.push(...i),n(a(t,`@biomejs/biome`,{args:r}),{stdio:`inherit`})}catch(e){w(e)}}});const M={config:{extends:`adamantite/tsconfig`},async exists(){return await T(u(process.cwd(),`tsconfig.json`))},async create(){await l(u(process.cwd(),`tsconfig.json`),JSON.stringify(this.config,null,2))},async update(){let e=x(await c(u(process.cwd(),`tsconfig.json`),`utf-8`)),t=b(this.config,e);await l(u(process.cwd(),`tsconfig.json`),JSON.stringify(t,null,2))}},N={version:`2.3.2`,config:{$schema:`./node_modules/@biomejs/biome/configuration_schema.json`},async exists(){return await T(u(process.cwd(),`biome.jsonc`))},async create(){await l(u(process.cwd(),`biome.jsonc`),JSON.stringify({...this.config,extends:[`adamantite`]},null,2))},async update(){let e={...x(await c(await T(u(process.cwd(),`biome.jsonc`))?u(process.cwd(),`biome.jsonc`):u(process.cwd(),`biome.json`),`utf-8`))};Array.isArray(e.extends)||(e.extends=e.extends?[e.extends]:[]),e.extends.includes(`adamantite`)||e.extends.push(`adamantite`);let t=b(this.config,e);await l(u(process.cwd(),`biome.jsonc`),JSON.stringify(t,null,2))}},P={config:{"typescript.tsdk":`node_modules/typescript/lib`,"editor.formatOnSave":!0,"editor.formatOnPaste":!0,"editor.codeActionsOnSave":{"source.organizeImports.biome":`explicit`,"source.fixAll.biome":`explicit`},"[javascript][typescript][javascriptreact][typescriptreact][json][jsonc][css][graphql]":{"editor.defaultFormatter":`biomejs.biome`}},async exists(){return await T(u(process.cwd(),`.vscode`,`settings.json`))},async create(){let e=u(process.cwd(),`.vscode`);await s(e,{recursive:!0}),await l(u(e,`settings.json`),JSON.stringify(this.config,null,2))},async update(){let e=x(await c(u(process.cwd(),`.vscode`,`settings.json`),`utf-8`)),t=b(this.config,e);await l(u(process.cwd(),`.vscode`,`settings.json`),JSON.stringify(t,null,2))}},F={version:`1.7.0`};async function I(){if(await T(u(d.cwd(),`pnpm-workspace.yaml`)))return!0;try{return(await E()).workspaces!==void 0}catch{return!1}}async function L(){let e=y();await N.exists()?(e.start(`Biome config found, updating...`),await N.update(),e.stop(`Biome config updated with Adamantite preset`)):(e.start(`Biome config not found, creating...`),await N.create(),e.stop(`Biome config created with Adamantite preset`))}async function R({check:e,fix:t,monorepo:n}){let r=y();r.start("Adding scripts to your `package.json`...");try{let i=await E();i.scripts||={},e&&(i.scripts.check=`adamantite check`),t&&(i.scripts.fix=`adamantite fix`),n&&(i.scripts[`lint:monorepo`]=`adamantite monorepo`),await D(i),r.stop("Scripts added to your `package.json`")}catch(e){throw r.stop(`Failed to add scripts`),Error(`Failed to modify package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}async function z(){let e=y();await M.exists()?(e.start("`tsconfig.json` found, updating..."),await M.update(),e.stop("Updated `tsconfig.json` with preset")):(e.start("`tsconfig.json` not found, creating..."),await M.create(),e.stop("Created `tsconfig.json` with preset"))}async function B(){let e=await _({message:`Which editors do you want to configure (recommended)?`,options:[{label:`VSCode / Cursor / Windsurf`,value:`vscode`},{label:`Zed (coming soon)`,value:`zed`}],required:!1});if(h(e))throw Error(`Operation cancelled`);return e}async function V(e){if(!e||e.length===0)return;let t=y();e.includes(`vscode`)&&(await P.exists()?(t.start(`VSCode settings found, updating...`),await P.update(),t.stop(`VSCode settings updated with Adamantite preset`)):(t.start(`VSCode settings not found, creating...`),await P.create(),t.stop(`VSCode settings created with Adamantite preset`))),e.includes(`zed`)&&(t.start(`Zed configuration coming soon...`),t.stop(`Zed configuration coming soon...`))}async function H(e){let t=await p({message:e});if(h(t))throw Error(`Operation cancelled`);return t}async function U(e){let t=y();t.start(`Installing dependencies...`);try{await r(`adamantite`);let n=N.version;await r(`@biomejs/biome@${n}`),e?.monorepo&&await r(`sherif@${F.version}`),t.stop(`Dependencies installed successfully`)}catch(e){throw t.stop(`Failed to install dependencies`),Error(`Failed to install dependencies: ${e instanceof Error?e.message:`Unknown error`}`)}}var W=e({meta:{name:`init`,description:`Initialize Adamantite in the current directory`},run:async()=>{m(O());try{let e=await I(),t=await H("Do you want to add the `check` and `fix` scripts to your `package.json`?"),n=e?await H(`We've detected a monorepo setup in your project. Would you like to install monorepo linting scripts?`):!1,r=await H(`Adamantite provides a TypeScript preset to enforce strict type-safety. Would you like to install it?`),i=await B();await U({monorepo:n}),await L(),(t||n)&&await R({check:t,fix:t,monorepo:n}),r&&await z(),await V(i),v(`💠 Adamantite initialized successfully!`)}catch(e){g.error(`${e instanceof Error?e.message:`Unknown error`}`),f(`Failed to initialize Adamantite`)}}}),G=e({meta:{name:`monorepo`,description:`Lint and automatically fix monorepo-specific issues using Sherif`},run:async()=>{try{n(a(await C(),`sherif`,{args:[`--fix`]}),{stdio:`inherit`})}catch(e){w(e)}}});async function K(){let e=[];try{let t=await E(),n=t.devDependencies?.[`@biomejs/biome`];n&&n!==N.version&&e.push({name:`@biomejs/biome`,currentVersion:n,targetVersion:N.version,isDevDependency:!0});let r=t.devDependencies?.sherif;return r&&r!==F.version&&e.push({name:`sherif`,currentVersion:r,targetVersion:F.version,isDevDependency:!0}),e}catch(e){throw Error(`Failed to read package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}async function q(e){let t=y();t.start(`Updating dependencies...`);try{let n=e.map(e=>r(`${e.name}@${e.targetVersion}`)),i=await Promise.allSettled(n),a=[],o=[];for(let[t,n]of i.entries()){let r=e[t];if(!r)continue;let i=r.name;n.status===`fulfilled`?o.push(i):a.push(`${i}: ${n.reason?.message||`Unknown error`}`)}if(a.length===0)t.stop(`Dependencies updated successfully`);else if(o.length===0)throw t.stop(`Failed to update dependencies`),Error(`All dependency updates failed:\n${a.join(`
|
|
16
|
-
`)}`);else{t.stop(`Partial update completed`),g.warn(`Some dependencies failed to update:`);for(let e of a)g.warn(` ${e}`);g.success(`Successfully updated: ${o.join(`, `)}`)}}catch(e){throw t.stop(`Failed to update dependencies`),e}}async function J(e){g.message(`The following dependencies will be updated:`),g.message(``);for(let t of e)g.message(` ${t.name}: ${t.currentVersion} → ${t.targetVersion}`);g.message(``);let t=await p({message:`Do you want to proceed with these updates?`});if(h(t))throw Error(`Operation cancelled`);return t}var Y=e({meta:{name:`update`,description:`Update adamantite dependencies to latest compatible versions`},run:async()=>{m(O());try{let e=await K();if(e.length===0){g.success(`All adamantite dependencies are already up to date!`),v(`💠 No updates needed`);return}if(!await J(e)){v(`💠 Update cancelled`);return}await q(e),v(`💠 Dependencies updated successfully!`)}catch(e){w(e)}}});function X(){return JSON.parse(S(u(process.cwd(),`package.json`),`utf-8`)).version}t(e({meta:{name:`adamantite`,description:`An opinionated set of presets for modern TypeScript applications`,version:X()},subCommands:{check:k,ci:A,fix:j,init:W,monorepo:G,update:Y}}));
|