adamantite 0.16.0 → 0.17.0
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.js +250 -153
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -153,18 +153,57 @@ var check_default = defineCommand({
|
|
|
153
153
|
})
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
-
// src/commands/
|
|
156
|
+
// src/commands/fix.ts
|
|
157
157
|
import process4 from "node:process";
|
|
158
158
|
import { log as log2 } from "@clack/prompts";
|
|
159
|
-
import { Fault as
|
|
160
|
-
import { ok as
|
|
159
|
+
import { Fault as Fault4 } from "faultier";
|
|
160
|
+
import { ok as ok4, safeTry as safeTry4 } from "neverthrow";
|
|
161
161
|
import { dlxCommand as dlxCommand2 } from "nypm";
|
|
162
|
+
var fix_default = defineCommand({
|
|
163
|
+
command: "fix [files..]",
|
|
164
|
+
describe: "Fix issues in code using Biome",
|
|
165
|
+
builder: (yargs) => yargs.positional("files", {
|
|
166
|
+
describe: "Specific files to fix (optional)",
|
|
167
|
+
type: "string",
|
|
168
|
+
array: true
|
|
169
|
+
}).option("unsafe", {
|
|
170
|
+
type: "boolean",
|
|
171
|
+
description: "Apply unsafe fixes"
|
|
172
|
+
}),
|
|
173
|
+
handler: (argv) => safeTry4(async function* () {
|
|
174
|
+
const packageManager = yield* getPackageManagerName();
|
|
175
|
+
const args = ["check", "--write"];
|
|
176
|
+
if (argv.unsafe) {
|
|
177
|
+
args.push("--unsafe");
|
|
178
|
+
}
|
|
179
|
+
if (argv.files && argv.files.length > 0) {
|
|
180
|
+
args.push(...argv.files);
|
|
181
|
+
}
|
|
182
|
+
const command = dlxCommand2(packageManager, biome.name, { args });
|
|
183
|
+
yield* runCommand(command);
|
|
184
|
+
return ok4();
|
|
185
|
+
}).match(() => {
|
|
186
|
+
process4.exit(0);
|
|
187
|
+
}, (error) => {
|
|
188
|
+
if (Fault4.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
189
|
+
log2.error(error.flatten());
|
|
190
|
+
}
|
|
191
|
+
process4.exit(1);
|
|
192
|
+
})
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// src/commands/format.ts
|
|
196
|
+
import process5 from "node:process";
|
|
197
|
+
import { log as log3 } from "@clack/prompts";
|
|
198
|
+
import { Fault as Fault6 } from "faultier";
|
|
199
|
+
import { ok as ok6, safeTry as safeTry6 } from "neverthrow";
|
|
200
|
+
import { dlxCommand as dlxCommand3 } from "nypm";
|
|
162
201
|
|
|
163
202
|
// src/helpers/packages/oxfmt.ts
|
|
164
203
|
import { readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
|
|
165
204
|
import { join as join3 } from "node:path";
|
|
166
|
-
import { Fault as
|
|
167
|
-
import { err as err3, fromPromise as fromPromise3, ok as
|
|
205
|
+
import { Fault as Fault5 } from "faultier";
|
|
206
|
+
import { err as err3, fromPromise as fromPromise3, ok as ok5, safeTry as safeTry5 } from "neverthrow";
|
|
168
207
|
// presets/oxfmt.json
|
|
169
208
|
var oxfmt_default = {
|
|
170
209
|
arrowParens: "always",
|
|
@@ -221,121 +260,25 @@ var oxfmt = {
|
|
|
221
260
|
}
|
|
222
261
|
return { path: null };
|
|
223
262
|
},
|
|
224
|
-
create: () => fromPromise3(writeFile2(join3(process.cwd(), ".oxfmtrc.jsonc"), JSON.stringify(oxfmt.config, null, 2)), (error) =>
|
|
225
|
-
update: () =>
|
|
263
|
+
create: () => fromPromise3(writeFile2(join3(process.cwd(), ".oxfmtrc.jsonc"), JSON.stringify(oxfmt.config, null, 2)), (error) => Fault5.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write oxfmt configuration", "We're unable to write the oxfmt configuration to the current directory.")),
|
|
264
|
+
update: () => safeTry5(async function* () {
|
|
226
265
|
const exists = await oxfmt.exists();
|
|
227
266
|
if (!exists.path) {
|
|
228
|
-
return err3(
|
|
267
|
+
return err3(Fault5.create("FILE_NOT_FOUND").withDescription("No `.oxfmtrc.jsonc` or `.oxfmtrc.json` found", "We're unable to find an oxfmt configuration in the current directory."));
|
|
229
268
|
}
|
|
230
|
-
const oxfmtFile = yield* fromPromise3(readFile3(exists.path, "utf-8"), (error) =>
|
|
269
|
+
const oxfmtFile = yield* fromPromise3(readFile3(exists.path, "utf-8"), (error) => Fault5.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read oxfmt configuration", "We're unable to read the oxfmt configuration from the current directory."));
|
|
231
270
|
const existingConfig = yield* parseJson(oxfmtFile);
|
|
232
271
|
if (!existingConfig || Object.keys(existingConfig).length === 0) {
|
|
233
|
-
return err3(
|
|
272
|
+
return err3(Fault5.create("INVALID_OXFMT_CONFIG").withDescription("Invalid oxfmt configuration", "The oxfmt configuration file is empty or invalid.").withContext({ path: exists.path }));
|
|
234
273
|
}
|
|
235
274
|
const mergedConfig = yield* mergeConfig(existingConfig, oxfmt.config);
|
|
236
275
|
mergedConfig.$schema = oxfmt.config.$schema;
|
|
237
|
-
yield* fromPromise3(writeFile2(exists.path, JSON.stringify(mergedConfig, null, 2)), (error) =>
|
|
238
|
-
return ok4();
|
|
239
|
-
})
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
// src/helpers/packages/sherif.ts
|
|
243
|
-
var sherif = {
|
|
244
|
-
name: "sherif",
|
|
245
|
-
version: "1.9.0"
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
// src/commands/ci.ts
|
|
249
|
-
var ci_default = defineCommand({
|
|
250
|
-
command: "ci",
|
|
251
|
-
describe: "Run Adamantite in a CI environment",
|
|
252
|
-
builder: (yargs) => yargs.option("monorepo", {
|
|
253
|
-
type: "boolean",
|
|
254
|
-
description: "Run additional monorepo-specific checks"
|
|
255
|
-
}).option("github", {
|
|
256
|
-
type: "boolean",
|
|
257
|
-
description: "Use GitHub reporter"
|
|
258
|
-
}),
|
|
259
|
-
handler: (argv) => safeTry5(async function* () {
|
|
260
|
-
const packageManager = yield* getPackageManagerName();
|
|
261
|
-
const tools = [
|
|
262
|
-
{
|
|
263
|
-
package: biome.name,
|
|
264
|
-
args: ["ci", ...argv.github ? ["--reporter", "github"] : []]
|
|
265
|
-
}
|
|
266
|
-
];
|
|
267
|
-
const oxfmtConfig = await oxfmt.exists();
|
|
268
|
-
if (oxfmtConfig.path) {
|
|
269
|
-
tools.push({
|
|
270
|
-
package: oxfmt.name,
|
|
271
|
-
args: ["--check"]
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
if (argv.monorepo) {
|
|
275
|
-
tools.push({ package: sherif.name, args: [] });
|
|
276
|
-
}
|
|
277
|
-
for (const tool of tools) {
|
|
278
|
-
const command = dlxCommand2(packageManager, tool.package, {
|
|
279
|
-
args: tool.args
|
|
280
|
-
});
|
|
281
|
-
yield* runCommand(command);
|
|
282
|
-
}
|
|
276
|
+
yield* fromPromise3(writeFile2(exists.path, JSON.stringify(mergedConfig, null, 2)), (error) => Fault5.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write oxfmt configuration", "We're unable to write the oxfmt configuration to the current directory.").withContext({ path: exists.path }));
|
|
283
277
|
return ok5();
|
|
284
|
-
}).match(() => {
|
|
285
|
-
process4.exit(0);
|
|
286
|
-
}, (error) => {
|
|
287
|
-
if (Fault5.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
288
|
-
log2.error(error.flatten());
|
|
289
|
-
}
|
|
290
|
-
process4.exit(1);
|
|
291
|
-
})
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// src/commands/fix.ts
|
|
295
|
-
import process5 from "node:process";
|
|
296
|
-
import { log as log3 } from "@clack/prompts";
|
|
297
|
-
import { Fault as Fault6 } from "faultier";
|
|
298
|
-
import { ok as ok6, safeTry as safeTry6 } from "neverthrow";
|
|
299
|
-
import { dlxCommand as dlxCommand3 } from "nypm";
|
|
300
|
-
var fix_default = defineCommand({
|
|
301
|
-
command: "fix [files..]",
|
|
302
|
-
describe: "Fix issues in code using Biome",
|
|
303
|
-
builder: (yargs) => yargs.positional("files", {
|
|
304
|
-
describe: "Specific files to fix (optional)",
|
|
305
|
-
type: "string",
|
|
306
|
-
array: true
|
|
307
|
-
}).option("unsafe", {
|
|
308
|
-
type: "boolean",
|
|
309
|
-
description: "Apply unsafe fixes"
|
|
310
|
-
}),
|
|
311
|
-
handler: (argv) => safeTry6(async function* () {
|
|
312
|
-
const packageManager = yield* getPackageManagerName();
|
|
313
|
-
const args = ["check", "--write"];
|
|
314
|
-
if (argv.unsafe) {
|
|
315
|
-
args.push("--unsafe");
|
|
316
|
-
}
|
|
317
|
-
if (argv.files && argv.files.length > 0) {
|
|
318
|
-
args.push(...argv.files);
|
|
319
|
-
}
|
|
320
|
-
const command = dlxCommand3(packageManager, biome.name, { args });
|
|
321
|
-
yield* runCommand(command);
|
|
322
|
-
return ok6();
|
|
323
|
-
}).match(() => {
|
|
324
|
-
process5.exit(0);
|
|
325
|
-
}, (error) => {
|
|
326
|
-
if (Fault6.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
327
|
-
log3.error(error.flatten());
|
|
328
|
-
}
|
|
329
|
-
process5.exit(1);
|
|
330
278
|
})
|
|
331
|
-
}
|
|
279
|
+
};
|
|
332
280
|
|
|
333
281
|
// src/commands/format.ts
|
|
334
|
-
import process6 from "node:process";
|
|
335
|
-
import { log as log4 } from "@clack/prompts";
|
|
336
|
-
import { Fault as Fault7 } from "faultier";
|
|
337
|
-
import { ok as ok7, safeTry as safeTry7 } from "neverthrow";
|
|
338
|
-
import { dlxCommand as dlxCommand4 } from "nypm";
|
|
339
282
|
var format_default = defineCommand({
|
|
340
283
|
command: "format [files..]",
|
|
341
284
|
describe: "Format files using oxfmt",
|
|
@@ -347,7 +290,7 @@ var format_default = defineCommand({
|
|
|
347
290
|
type: "boolean",
|
|
348
291
|
description: "Check if files are formatted without writing"
|
|
349
292
|
}),
|
|
350
|
-
handler: (argv) =>
|
|
293
|
+
handler: (argv) => safeTry6(async function* () {
|
|
351
294
|
const packageManager = yield* getPackageManagerName();
|
|
352
295
|
const args = [];
|
|
353
296
|
if (argv.check) {
|
|
@@ -356,33 +299,152 @@ var format_default = defineCommand({
|
|
|
356
299
|
if (argv.files && argv.files.length > 0) {
|
|
357
300
|
args.push(...argv.files);
|
|
358
301
|
}
|
|
359
|
-
const command =
|
|
302
|
+
const command = dlxCommand3(packageManager, oxfmt.name, { args });
|
|
360
303
|
const result = yield* runCommand(command);
|
|
361
|
-
return
|
|
304
|
+
return ok6(result);
|
|
362
305
|
}).match(() => {
|
|
363
|
-
|
|
306
|
+
process5.exit(0);
|
|
364
307
|
}, (error) => {
|
|
365
|
-
if (
|
|
366
|
-
|
|
308
|
+
if (Fault6.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
309
|
+
log3.error(error.flatten());
|
|
367
310
|
}
|
|
368
|
-
|
|
311
|
+
process5.exit(1);
|
|
369
312
|
})
|
|
370
313
|
});
|
|
371
314
|
|
|
372
315
|
// src/commands/init.ts
|
|
373
|
-
import { writeFile as
|
|
374
|
-
import { join as
|
|
316
|
+
import { writeFile as writeFile6 } from "node:fs/promises";
|
|
317
|
+
import { join as join7 } from "node:path";
|
|
375
318
|
import process7 from "node:process";
|
|
376
319
|
import * as p from "@clack/prompts";
|
|
377
320
|
import { Fault as Fault10 } from "faultier";
|
|
378
|
-
import { err as err4, fromPromise as
|
|
321
|
+
import { err as err4, fromPromise as fromPromise7, fromSafePromise, ok as ok10, safeTry as safeTry10 } from "neverthrow";
|
|
379
322
|
import { addDevDependency } from "nypm";
|
|
380
323
|
|
|
381
|
-
// src/helpers/
|
|
382
|
-
import { mkdir,
|
|
324
|
+
// src/helpers/ci/github.ts
|
|
325
|
+
import { mkdir, writeFile as writeFile3 } from "node:fs/promises";
|
|
383
326
|
import { join as join4 } from "node:path";
|
|
327
|
+
import process6 from "node:process";
|
|
328
|
+
import { Fault as Fault7 } from "faultier";
|
|
329
|
+
import { fromPromise as fromPromise4, ok as ok7, safeTry as safeTry7 } from "neverthrow";
|
|
330
|
+
import { runScriptCommand } from "nypm";
|
|
331
|
+
var CI_COMPATIBLE_SCRIPTS = ["check", "format", "typecheck", "check:monorepo"];
|
|
332
|
+
var setupSteps = {
|
|
333
|
+
bun: ` - name: Setup Bun
|
|
334
|
+
uses: oven-sh/setup-bun@v2
|
|
335
|
+
|
|
336
|
+
- name: Install dependencies
|
|
337
|
+
run: bun install --frozen-lockfile`,
|
|
338
|
+
pnpm: ` - name: Setup pnpm
|
|
339
|
+
uses: pnpm/action-setup@v4
|
|
340
|
+
|
|
341
|
+
- name: Setup Node.js
|
|
342
|
+
uses: actions/setup-node@v6
|
|
343
|
+
with:
|
|
344
|
+
node-version: "22"
|
|
345
|
+
cache: "pnpm"
|
|
346
|
+
|
|
347
|
+
- name: Install dependencies
|
|
348
|
+
run: pnpm install --frozen-lockfile`,
|
|
349
|
+
yarn: ` - name: Setup Node.js
|
|
350
|
+
uses: actions/setup-node@v6
|
|
351
|
+
with:
|
|
352
|
+
node-version: "22"
|
|
353
|
+
cache: "yarn"
|
|
354
|
+
|
|
355
|
+
- name: Install dependencies
|
|
356
|
+
run: yarn install --frozen-lockfile`,
|
|
357
|
+
npm: ` - name: Setup Node.js
|
|
358
|
+
uses: actions/setup-node@v6
|
|
359
|
+
with:
|
|
360
|
+
node-version: "22"
|
|
361
|
+
cache: "npm"
|
|
362
|
+
|
|
363
|
+
- name: Install dependencies
|
|
364
|
+
run: npm ci`,
|
|
365
|
+
deno: ` - name: Setup Deno
|
|
366
|
+
uses: denoland/setup-deno@v2
|
|
367
|
+
|
|
368
|
+
- name: Install dependencies
|
|
369
|
+
run: deno install --frozen`
|
|
370
|
+
};
|
|
371
|
+
var generateJob = (jobName, stepName, script, packageManager) => `
|
|
372
|
+
${jobName}:
|
|
373
|
+
runs-on: ubuntu-latest
|
|
374
|
+
timeout-minutes: 10
|
|
375
|
+
steps:
|
|
376
|
+
- name: Checkout code
|
|
377
|
+
uses: actions/checkout@v4
|
|
378
|
+
|
|
379
|
+
${setupSteps[packageManager]}
|
|
380
|
+
|
|
381
|
+
- name: ${stepName}
|
|
382
|
+
run: ${runScriptCommand(packageManager, script)}`;
|
|
383
|
+
var generateWorkflow = ({ packageManager, scripts }) => {
|
|
384
|
+
const jobs = [];
|
|
385
|
+
if (scripts.includes("check")) {
|
|
386
|
+
jobs.push(generateJob("lint", "Run linter", "check", packageManager));
|
|
387
|
+
}
|
|
388
|
+
if (scripts.includes("format")) {
|
|
389
|
+
jobs.push(generateJob("format", "Check formatting", "format --check", packageManager));
|
|
390
|
+
}
|
|
391
|
+
if (scripts.includes("typecheck")) {
|
|
392
|
+
jobs.push(generateJob("typecheck", "Run type check", "typecheck", packageManager));
|
|
393
|
+
}
|
|
394
|
+
if (scripts.includes("check:monorepo")) {
|
|
395
|
+
jobs.push(generateJob("monorepo", "Check monorepo", "check:monorepo", packageManager));
|
|
396
|
+
}
|
|
397
|
+
if (jobs.length === 0) {
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
const workflow = `name: CI
|
|
401
|
+
|
|
402
|
+
on:
|
|
403
|
+
push:
|
|
404
|
+
branches:
|
|
405
|
+
- main
|
|
406
|
+
pull_request:
|
|
407
|
+
types: [opened, synchronize, reopened]
|
|
408
|
+
|
|
409
|
+
concurrency:
|
|
410
|
+
group: \${{ github.workflow }}-\${{ github.ref }}
|
|
411
|
+
cancel-in-progress: true
|
|
412
|
+
|
|
413
|
+
jobs:${jobs.join(`
|
|
414
|
+
`)}`;
|
|
415
|
+
return `${workflow}
|
|
416
|
+
`;
|
|
417
|
+
};
|
|
418
|
+
var hasCICompatibleScripts = (scripts) => scripts.some((script) => CI_COMPATIBLE_SCRIPTS.includes(script));
|
|
419
|
+
var github = {
|
|
420
|
+
workflowPath: ".github/workflows/adamantite.yml",
|
|
421
|
+
exists: () => checkIfExists(join4(process6.cwd(), ".github", "workflows", "adamantite.yml")),
|
|
422
|
+
create: (options) => safeTry7(async function* () {
|
|
423
|
+
const workflowDir = join4(process6.cwd(), ".github", "workflows");
|
|
424
|
+
yield* fromPromise4(mkdir(workflowDir, { recursive: true }), (error) => Fault7.wrap(error).withTag("FAILED_TO_CREATE_DIRECTORY").withDescription("Failed to create .github/workflows directory", "We're unable to create the .github/workflows directory in the current directory.").withContext({ path: workflowDir }));
|
|
425
|
+
const workflowContent = generateWorkflow(options);
|
|
426
|
+
if (!workflowContent) {
|
|
427
|
+
return ok7();
|
|
428
|
+
}
|
|
429
|
+
yield* fromPromise4(writeFile3(join4(workflowDir, "adamantite.yml"), workflowContent), (error) => Fault7.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write GitHub Actions workflow", "We're unable to write the GitHub Actions workflow file.").withContext({ path: join4(workflowDir, "adamantite.yml") }));
|
|
430
|
+
return ok7();
|
|
431
|
+
}),
|
|
432
|
+
update: (options) => safeTry7(async function* () {
|
|
433
|
+
const workflowPath = join4(process6.cwd(), ".github", "workflows", "adamantite.yml");
|
|
434
|
+
const workflowContent = generateWorkflow(options);
|
|
435
|
+
if (!workflowContent) {
|
|
436
|
+
return ok7();
|
|
437
|
+
}
|
|
438
|
+
yield* fromPromise4(writeFile3(workflowPath, workflowContent), (error) => Fault7.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write GitHub Actions workflow", "We're unable to update the GitHub Actions workflow file.").withContext({ path: workflowPath }));
|
|
439
|
+
return ok7();
|
|
440
|
+
})
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// src/helpers/editors/vscode.ts
|
|
444
|
+
import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
|
|
445
|
+
import { join as join5 } from "node:path";
|
|
384
446
|
import { Fault as Fault8 } from "faultier";
|
|
385
|
-
import { fromPromise as
|
|
447
|
+
import { fromPromise as fromPromise5, ok as ok8, safeTry as safeTry8 } from "neverthrow";
|
|
386
448
|
var vscode = {
|
|
387
449
|
config: {
|
|
388
450
|
"typescript.tsdk": "node_modules/typescript/lib",
|
|
@@ -395,37 +457,43 @@ var vscode = {
|
|
|
395
457
|
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
396
458
|
}
|
|
397
459
|
},
|
|
398
|
-
exists: () => checkIfExists(
|
|
460
|
+
exists: () => checkIfExists(join5(process.cwd(), ".vscode", "settings.json")),
|
|
399
461
|
create: () => safeTry8(async function* () {
|
|
400
|
-
const vscodePath =
|
|
401
|
-
yield*
|
|
402
|
-
yield*
|
|
462
|
+
const vscodePath = join5(process.cwd(), ".vscode");
|
|
463
|
+
yield* fromPromise5(mkdir2(vscodePath, { recursive: true }), (error) => Fault8.wrap(error).withTag("FAILED_TO_CREATE_DIRECTORY").withDescription("Failed to create .vscode directory", "We're unable to create the .vscode directory in the current directory.").withContext({ path: vscodePath }));
|
|
464
|
+
yield* fromPromise5(writeFile4(join5(vscodePath, "settings.json"), JSON.stringify(vscode.config, null, 2)), (error) => Fault8.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write .vscode/settings.json", "We're unable to write the .vscode/settings.json file in the current directory."));
|
|
403
465
|
return ok8();
|
|
404
466
|
}),
|
|
405
467
|
update: () => safeTry8(async function* () {
|
|
406
|
-
const vscodePath =
|
|
407
|
-
const vscodeFile = yield*
|
|
468
|
+
const vscodePath = join5(process.cwd(), ".vscode", "settings.json");
|
|
469
|
+
const vscodeFile = yield* fromPromise5(readFile4(vscodePath, "utf-8"), (error) => Fault8.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read .vscode/settings.json", "We're unable to read the .vscode/settings.json file in the current directory.").withContext({ path: vscodePath }));
|
|
408
470
|
const existingConfig = yield* parseJson(vscodeFile);
|
|
409
471
|
const newConfig = yield* mergeConfig(vscode.config, existingConfig);
|
|
410
|
-
yield*
|
|
472
|
+
yield* fromPromise5(writeFile4(join5(process.cwd(), ".vscode", "settings.json"), JSON.stringify(newConfig, null, 2)), (error) => Fault8.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write .vscode/settings.json", "We're unable to write the .vscode/settings.json file in the current directory.").withContext({ path: vscodePath }));
|
|
411
473
|
return ok8();
|
|
412
474
|
})
|
|
413
475
|
};
|
|
414
476
|
|
|
477
|
+
// src/helpers/packages/sherif.ts
|
|
478
|
+
var sherif = {
|
|
479
|
+
name: "sherif",
|
|
480
|
+
version: "1.9.0"
|
|
481
|
+
};
|
|
482
|
+
|
|
415
483
|
// src/helpers/tsconfig.ts
|
|
416
|
-
import { readFile as readFile5, writeFile as
|
|
417
|
-
import { join as
|
|
484
|
+
import { readFile as readFile5, writeFile as writeFile5 } from "node:fs/promises";
|
|
485
|
+
import { join as join6 } from "node:path";
|
|
418
486
|
import { Fault as Fault9 } from "faultier";
|
|
419
|
-
import { fromPromise as
|
|
487
|
+
import { fromPromise as fromPromise6, ok as ok9, safeTry as safeTry9 } from "neverthrow";
|
|
420
488
|
var tsconfig = {
|
|
421
489
|
config: { extends: "adamantite/typescript" },
|
|
422
|
-
exists: () => checkIfExists(
|
|
423
|
-
create: () =>
|
|
490
|
+
exists: () => checkIfExists(join6(process.cwd(), "tsconfig.json")),
|
|
491
|
+
create: () => fromPromise6(writeFile5(join6(process.cwd(), "tsconfig.json"), JSON.stringify(tsconfig.config, null, 2)), (error) => Fault9.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write tsconfig.json", "We're unable to write the tsconfig.json file in the current directory.")),
|
|
424
492
|
update: () => safeTry9(async function* () {
|
|
425
|
-
const tsconfigFile = yield*
|
|
493
|
+
const tsconfigFile = yield* fromPromise6(readFile5(join6(process.cwd(), "tsconfig.json"), "utf-8"), (error) => Fault9.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read tsconfig.json", "We're unable to read the tsconfig.json file in the current directory."));
|
|
426
494
|
const existingConfig = yield* parseJson(tsconfigFile);
|
|
427
495
|
const newConfig = yield* mergeConfig(tsconfig.config, existingConfig);
|
|
428
|
-
yield*
|
|
496
|
+
yield* fromPromise6(writeFile5(join6(process.cwd(), "tsconfig.json"), JSON.stringify(newConfig, null, 2)), (error) => Fault9.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write tsconfig.json", "We're unable to write the tsconfig.json file in the current directory."));
|
|
429
497
|
return ok9();
|
|
430
498
|
})
|
|
431
499
|
};
|
|
@@ -436,7 +504,7 @@ var installDependencies = (packages) => safeTry10(async function* () {
|
|
|
436
504
|
s.start("Installing dependencies...");
|
|
437
505
|
const isMonorepo = yield* checkIsMonorepo();
|
|
438
506
|
for (const pkg of packages) {
|
|
439
|
-
yield*
|
|
507
|
+
yield* fromPromise7(addDevDependency(pkg, { silent: true, workspace: isMonorepo }), (error) => Fault10.wrap(error).withTag("FAILED_TO_INSTALL_DEPENDENCY").withMessage(`Failed to install ${pkg}`));
|
|
440
508
|
}
|
|
441
509
|
s.stop("Dependencies installed.");
|
|
442
510
|
return ok10();
|
|
@@ -503,7 +571,7 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
503
571
|
return err4(Fault10.create("UNKNOWN_SCRIPT").withContext({ script }));
|
|
504
572
|
}
|
|
505
573
|
}
|
|
506
|
-
yield*
|
|
574
|
+
yield* fromPromise7(writeFile6(join7(cwd, "package.json"), JSON.stringify(packageJson, null, 2)), (error) => Fault10.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write package.json", "We're unable to update the package.json file.").withContext({ path: join7(cwd, "package.json") }));
|
|
507
575
|
spinner2.stop("Scripts added to your `package.json`");
|
|
508
576
|
return ok10();
|
|
509
577
|
});
|
|
@@ -538,6 +606,20 @@ var setupEditors = (editors) => safeTry10(async function* () {
|
|
|
538
606
|
if (editors.includes("zed")) {}
|
|
539
607
|
return ok10();
|
|
540
608
|
});
|
|
609
|
+
var setupGitHubActions = (packageManager, scripts) => safeTry10(async function* () {
|
|
610
|
+
const spinner2 = p.spinner();
|
|
611
|
+
spinner2.start("Setting up GitHub Actions workflow...");
|
|
612
|
+
if (await github.exists()) {
|
|
613
|
+
spinner2.message("`.github/workflows/adamantite.yml` found, updating...");
|
|
614
|
+
yield* github.update({ packageManager, scripts });
|
|
615
|
+
spinner2.stop("GitHub Actions workflow updated successfully.");
|
|
616
|
+
} else {
|
|
617
|
+
spinner2.message("Creating `.github/workflows/adamantite.yml`...");
|
|
618
|
+
yield* github.create({ packageManager, scripts });
|
|
619
|
+
spinner2.stop("GitHub Actions workflow created successfully.");
|
|
620
|
+
}
|
|
621
|
+
return ok10();
|
|
622
|
+
});
|
|
541
623
|
var init_default = defineCommand({
|
|
542
624
|
command: "init",
|
|
543
625
|
describe: "Initialize Adamantite in the current directory",
|
|
@@ -602,6 +684,18 @@ var init_default = defineCommand({
|
|
|
602
684
|
if (p.isCancel(editors)) {
|
|
603
685
|
return err4(Fault10.create("OPERATION_CANCELLED"));
|
|
604
686
|
}
|
|
687
|
+
const hasCIScripts = hasCICompatibleScripts(scripts);
|
|
688
|
+
let enableGitHubActions = false;
|
|
689
|
+
if (hasCIScripts) {
|
|
690
|
+
const response = yield* fromSafePromise(p.confirm({
|
|
691
|
+
message: "Do you want to add a GitHub Actions workflow to run checks in CI?",
|
|
692
|
+
initialValue: false
|
|
693
|
+
}));
|
|
694
|
+
if (p.isCancel(response)) {
|
|
695
|
+
return err4(Fault10.create("OPERATION_CANCELLED"));
|
|
696
|
+
}
|
|
697
|
+
enableGitHubActions = response;
|
|
698
|
+
}
|
|
605
699
|
const hasBiome = scripts.includes("check") || scripts.includes("fix");
|
|
606
700
|
const hasOxfmt = scripts.includes("format");
|
|
607
701
|
const hasSherif = scripts.includes("check:monorepo") || scripts.includes("fix:monorepo");
|
|
@@ -631,6 +725,9 @@ var init_default = defineCommand({
|
|
|
631
725
|
yield* setupTypescript();
|
|
632
726
|
}
|
|
633
727
|
yield* setupEditors(editors);
|
|
728
|
+
if (enableGitHubActions) {
|
|
729
|
+
yield* setupGitHubActions(packageManager, scripts);
|
|
730
|
+
}
|
|
634
731
|
return ok10();
|
|
635
732
|
}).match(() => {
|
|
636
733
|
p.outro("\uD83D\uDCA0 Adamantite initialized successfully!");
|
|
@@ -653,10 +750,10 @@ var init_default = defineCommand({
|
|
|
653
750
|
|
|
654
751
|
// src/commands/monorepo.ts
|
|
655
752
|
import process8 from "node:process";
|
|
656
|
-
import { log as
|
|
753
|
+
import { log as log5 } from "@clack/prompts";
|
|
657
754
|
import { Fault as Fault11 } from "faultier";
|
|
658
755
|
import { ok as ok11, safeTry as safeTry11 } from "neverthrow";
|
|
659
|
-
import { dlxCommand as
|
|
756
|
+
import { dlxCommand as dlxCommand4 } from "nypm";
|
|
660
757
|
var monorepo_default = defineCommand({
|
|
661
758
|
command: "monorepo",
|
|
662
759
|
describe: "Find and fix monorepo-specific issues using Sherif",
|
|
@@ -670,14 +767,14 @@ var monorepo_default = defineCommand({
|
|
|
670
767
|
if (argv.fix) {
|
|
671
768
|
args.push("--fix");
|
|
672
769
|
}
|
|
673
|
-
const command =
|
|
770
|
+
const command = dlxCommand4(packageManager, sherif.name, { args });
|
|
674
771
|
yield* runCommand(command);
|
|
675
772
|
return ok11(undefined);
|
|
676
773
|
}).match(() => {
|
|
677
774
|
process8.exit(0);
|
|
678
775
|
}, (error) => {
|
|
679
776
|
if (Fault11.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
680
|
-
|
|
777
|
+
log5.error(error.flatten());
|
|
681
778
|
}
|
|
682
779
|
process8.exit(1);
|
|
683
780
|
})
|
|
@@ -685,9 +782,9 @@ var monorepo_default = defineCommand({
|
|
|
685
782
|
|
|
686
783
|
// src/commands/update.ts
|
|
687
784
|
import process9 from "node:process";
|
|
688
|
-
import { cancel as cancel2, confirm, intro as intro2, isCancel as isCancel2, log as
|
|
785
|
+
import { cancel as cancel2, confirm as confirm2, intro as intro2, isCancel as isCancel2, log as log6, outro as outro2, spinner as spinner2 } from "@clack/prompts";
|
|
689
786
|
import { Fault as Fault12 } from "faultier";
|
|
690
|
-
import { err as err5, fromPromise as
|
|
787
|
+
import { err as err5, fromPromise as fromPromise8, fromSafePromise as fromSafePromise2, ok as ok12, safeTry as safeTry12 } from "neverthrow";
|
|
691
788
|
import { addDevDependency as addDevDependency2 } from "nypm";
|
|
692
789
|
var update_default = defineCommand({
|
|
693
790
|
command: "update",
|
|
@@ -710,16 +807,16 @@ var update_default = defineCommand({
|
|
|
710
807
|
}
|
|
711
808
|
}
|
|
712
809
|
if (updates.length === 0) {
|
|
713
|
-
|
|
810
|
+
log6.success("All adamantite dependencies are already up to date!");
|
|
714
811
|
return ok12("no-updates");
|
|
715
812
|
}
|
|
716
|
-
|
|
717
|
-
|
|
813
|
+
log6.message("The following dependencies will be updated:");
|
|
814
|
+
log6.message("");
|
|
718
815
|
for (const dep of updates) {
|
|
719
|
-
|
|
816
|
+
log6.message(` ${dep.name}: ${dep.currentVersion} → ${dep.targetVersion}`);
|
|
720
817
|
}
|
|
721
|
-
|
|
722
|
-
const shouldUpdate = yield* fromSafePromise2(
|
|
818
|
+
log6.message("");
|
|
819
|
+
const shouldUpdate = yield* fromSafePromise2(confirm2({
|
|
723
820
|
message: "Do you want to proceed with these updates?"
|
|
724
821
|
}));
|
|
725
822
|
if (isCancel2(shouldUpdate)) {
|
|
@@ -731,7 +828,7 @@ var update_default = defineCommand({
|
|
|
731
828
|
const s = spinner2();
|
|
732
829
|
s.start("Updating dependencies...");
|
|
733
830
|
for (const dep of updates) {
|
|
734
|
-
yield*
|
|
831
|
+
yield* fromPromise8(addDevDependency2(`${dep.name}@${dep.targetVersion}`), (error) => Fault12.wrap(error).withTag("FAILED_TO_INSTALL_DEPENDENCY").withMessage(`Failed to update ${dep.name}`));
|
|
735
832
|
}
|
|
736
833
|
s.stop("Dependencies updated successfully");
|
|
737
834
|
return ok12("updated");
|
|
@@ -750,9 +847,9 @@ var update_default = defineCommand({
|
|
|
750
847
|
process9.exit(0);
|
|
751
848
|
}
|
|
752
849
|
if (Fault12.isFault(error)) {
|
|
753
|
-
|
|
850
|
+
log6.error(error.flatten());
|
|
754
851
|
} else {
|
|
755
|
-
|
|
852
|
+
log6.error(String(error));
|
|
756
853
|
}
|
|
757
854
|
cancel2("Failed to update dependencies");
|
|
758
855
|
process9.exit(1);
|
|
@@ -760,4 +857,4 @@ var update_default = defineCommand({
|
|
|
760
857
|
});
|
|
761
858
|
|
|
762
859
|
// src/index.ts
|
|
763
|
-
yargs(hideBin(process.argv)).scriptName("adamantite").version("0.
|
|
860
|
+
yargs(hideBin(process.argv)).scriptName("adamantite").version("0.17.0").command(check_default).command(fix_default).command(format_default).command(init_default).command(monorepo_default).command(update_default).demandCommand(1).strict().help().parse();
|