adamantite 0.16.0 → 0.18.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/README.md +76 -74
- package/dist/index.js +431 -238
- package/package.json +10 -11
- package/presets/oxlint/core.json +439 -0
- package/presets/oxlint/node.json +8 -0
- package/presets/oxlint/react.json +7 -0
- package/presets/tsconfig.json +2 -0
- package/presets/biome.jsonc +0 -439
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Fault as Fault3 } from "faultier";
|
|
|
9
9
|
import { ok as ok3, safeTry as safeTry3 } from "neverthrow";
|
|
10
10
|
import { dlxCommand } from "nypm";
|
|
11
11
|
|
|
12
|
-
// src/helpers/packages/
|
|
12
|
+
// src/helpers/packages/oxlint.ts
|
|
13
13
|
import { readFile as readFile2, writeFile } from "node:fs/promises";
|
|
14
14
|
import { join as join2 } from "node:path";
|
|
15
15
|
import { Fault as Fault2 } from "faultier";
|
|
@@ -20,7 +20,7 @@ import { spawnSync } from "node:child_process";
|
|
|
20
20
|
import { access, readFile } from "node:fs/promises";
|
|
21
21
|
import { join } from "node:path";
|
|
22
22
|
import process2 from "node:process";
|
|
23
|
-
import defu from "defu";
|
|
23
|
+
import { defu } from "defu";
|
|
24
24
|
import { Fault } from "faultier";
|
|
25
25
|
import { parse } from "jsonc-parser";
|
|
26
26
|
import { err, fromPromise, fromThrowable, ok, safeTry } from "neverthrow";
|
|
@@ -50,11 +50,12 @@ var parseJson = (content) => {
|
|
|
50
50
|
}
|
|
51
51
|
return ok(parsed);
|
|
52
52
|
};
|
|
53
|
+
var isJsonObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
53
54
|
var WORKSPACE_PREFIX_REGEX = /^workspace:/;
|
|
54
55
|
var RANGE_PREFIX_REGEX = /^[\^~]/;
|
|
55
56
|
var normalizeDependencyVersion = (specifier) => specifier.trim().replace(WORKSPACE_PREFIX_REGEX, "").replace(RANGE_PREFIX_REGEX, "");
|
|
56
57
|
var mergeConfig = fromThrowable(defu, (error) => Fault.wrap(error).withTag("FAILED_TO_MERGE_CONFIG").withDescription("Failed to merge configuration", "We're unable to merge the configuration files."));
|
|
57
|
-
var readPackageJson = (cwd = process2.cwd()) => fromPromise(readFile(join(cwd, "package.json"), "
|
|
58
|
+
var readPackageJson = (cwd = process2.cwd()) => fromPromise(readFile(join(cwd, "package.json"), "utf8"), (error) => Fault.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read package.json", "We're unable to read the package.json file in the current directory.").withContext({ path: join(cwd, "package.json") })).andThen((content) => parseJson(content)).andThen((parsed) => ok(parsed));
|
|
58
59
|
var checkIsMonorepo = () => safeTry(async function* () {
|
|
59
60
|
const pnpmWorkspace = await checkIfExists(join(process2.cwd(), "pnpm-workspace.yaml"));
|
|
60
61
|
if (pnpmWorkspace) {
|
|
@@ -63,84 +64,81 @@ var checkIsMonorepo = () => safeTry(async function* () {
|
|
|
63
64
|
const packageJson = yield* readPackageJson();
|
|
64
65
|
return ok(packageJson?.workspaces !== undefined);
|
|
65
66
|
});
|
|
66
|
-
var TITLE = `
|
|
67
|
-
o ooooooooo o oooo oooo o oooo oooo ooooooooooo ooooo ooooooooooo ooooooooooo
|
|
68
|
-
888 888 88o 888 8888o 888 888 8888o 88 88 888 88 888 88 888 88 888 88
|
|
69
|
-
8 88 888 888 8 88 88 888o8 88 8 88 88 888o88 888 888 888 888ooo8
|
|
70
|
-
8oooo88 888 888 8oooo88 88 888 88 8oooo88 88 8888 888 888 888 888 oo
|
|
71
|
-
o88o o888o o888ooo88 o88o o888o o88o 8 o88o o88o o888o o88o 88 o888o o888o o888o o888ooo8888
|
|
72
|
-
`;
|
|
73
67
|
function printTitle() {
|
|
74
|
-
const
|
|
68
|
+
const title = `
|
|
69
|
+
.o8 . o8o .
|
|
70
|
+
"888 .o8 \`"' .o8
|
|
71
|
+
.oooo. .oooo888 .oooo. ooo. .oo. .oo. .oooo. ooo. .oo. .o888oo oooo .o888oo .ooooo.
|
|
72
|
+
\`P )88b d88' \`888 \`P )88b \`888P"Y88bP"Y88b \`P )88b \`888P"Y88b 888 \`888 888 d88' \`88b
|
|
73
|
+
.oP"888 888 888 .oP"888 888 888 888 .oP"888 888 888 888 888 888 888ooo888
|
|
74
|
+
d8( 888 888 888 d8( 888 888 888 888 d8( 888 888 888 888 . 888 888 . 888 .o
|
|
75
|
+
\`Y888""8o \`Y8bod88P" \`Y888""8o o888o o888o o888o \`Y888""8o o888o o888o "888" o888o "888" \`Y8bod8P'
|
|
76
|
+
`;
|
|
77
|
+
const columns = title.split(`
|
|
75
78
|
`).reduce((max, line) => Math.max(max, line.trim().length), 0);
|
|
76
79
|
if (process2.stdout.columns && process2.stdout.columns >= columns) {
|
|
77
|
-
console.
|
|
80
|
+
console.info(title);
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
// src/helpers/packages/
|
|
82
|
-
var
|
|
83
|
-
name: "
|
|
84
|
-
version: "
|
|
84
|
+
// src/helpers/packages/oxlint.ts
|
|
85
|
+
var oxlint = {
|
|
86
|
+
name: "oxlint",
|
|
87
|
+
version: "1.35.0",
|
|
85
88
|
config: {
|
|
86
|
-
$schema: "./node_modules
|
|
89
|
+
$schema: "./node_modules/oxlint/configuration_schema.json"
|
|
87
90
|
},
|
|
88
91
|
exists: async () => {
|
|
89
|
-
if (await checkIfExists(join2(process.cwd(), "
|
|
90
|
-
return { path: join2(process.cwd(), "
|
|
91
|
-
}
|
|
92
|
-
if (await checkIfExists(join2(process.cwd(), "biome.json"))) {
|
|
93
|
-
return { path: join2(process.cwd(), "biome.json") };
|
|
92
|
+
if (await checkIfExists(join2(process.cwd(), ".oxlintrc.json"))) {
|
|
93
|
+
return { path: join2(process.cwd(), ".oxlintrc.json") };
|
|
94
94
|
}
|
|
95
95
|
return { path: null };
|
|
96
96
|
},
|
|
97
|
-
create: () => fromPromise2(writeFile(join2(process.cwd(), "
|
|
97
|
+
create: () => fromPromise2(writeFile(join2(process.cwd(), ".oxlintrc.json"), JSON.stringify({ ...oxlint.config, extends: ["adamantite/lint"] }, null, 2)), (error) => Fault2.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write oxlint configuration", "We're unable to write the oxlint configuration to the current directory.")),
|
|
98
98
|
update: () => safeTry2(async function* () {
|
|
99
|
-
const exists = await
|
|
99
|
+
const exists = await oxlint.exists();
|
|
100
100
|
if (!exists.path) {
|
|
101
|
-
return err2(Fault2.create("FILE_NOT_FOUND").withDescription("No
|
|
101
|
+
return err2(Fault2.create("FILE_NOT_FOUND").withDescription("No `.oxlintrc.json` found", "We're unable to find an oxlint configuration in the current directory."));
|
|
102
102
|
}
|
|
103
|
-
const
|
|
104
|
-
const existingConfig = yield* parseJson(
|
|
105
|
-
if (!
|
|
106
|
-
return err2(Fault2.create("
|
|
103
|
+
const oxlintFile = yield* fromPromise2(readFile2(exists.path, "utf8"), (error) => Fault2.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read oxlint configuration", "We're unable to read the oxlint configuration from the current directory."));
|
|
104
|
+
const existingConfig = yield* parseJson(oxlintFile);
|
|
105
|
+
if (!isJsonObject(existingConfig)) {
|
|
106
|
+
return err2(Fault2.create("INVALID_CONFIG_FORMAT").withDescription("Invalid oxlint configuration format", "The oxlint configuration must be a JSON object."));
|
|
107
107
|
}
|
|
108
108
|
const newConfig = { ...existingConfig };
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const mergedConfig = yield* mergeConfig(newConfig,
|
|
116
|
-
mergedConfig.$schema =
|
|
117
|
-
yield* fromPromise2(writeFile(exists.path, JSON.stringify(mergedConfig, null, 2)), (error) => Fault2.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write
|
|
109
|
+
const extendsArray = Array.isArray(newConfig.extends) ? newConfig.extends : typeof newConfig.extends === "string" ? [newConfig.extends] : [];
|
|
110
|
+
const hasAdamantite = extendsArray.some((ext) => ext === "adamantite/lint" || ext === "adamantite/lint/core");
|
|
111
|
+
if (!hasAdamantite) {
|
|
112
|
+
extendsArray.push("adamantite/lint");
|
|
113
|
+
}
|
|
114
|
+
newConfig.extends = extendsArray;
|
|
115
|
+
const mergedConfig = yield* mergeConfig(newConfig, oxlint.config);
|
|
116
|
+
mergedConfig.$schema = oxlint.config.$schema;
|
|
117
|
+
yield* fromPromise2(writeFile(exists.path, JSON.stringify(mergedConfig, null, 2)), (error) => Fault2.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write oxlint configuration", "We're unable to write the oxlint configuration to the current directory.").withContext({ path: exists.path }));
|
|
118
118
|
return ok2();
|
|
119
119
|
})
|
|
120
120
|
};
|
|
121
|
+
var tsgolint = {
|
|
122
|
+
name: "oxlint-tsgolint",
|
|
123
|
+
version: "0.10.0"
|
|
124
|
+
};
|
|
121
125
|
|
|
122
126
|
// src/commands/check.ts
|
|
123
127
|
var check_default = defineCommand({
|
|
124
128
|
command: "check [files..]",
|
|
125
|
-
describe: "Find issues in code using
|
|
129
|
+
describe: "Find issues in code using oxlint",
|
|
126
130
|
builder: (yargs) => yargs.positional("files", {
|
|
127
131
|
describe: "Specific files to lint (optional)",
|
|
128
132
|
type: "string",
|
|
129
133
|
array: true
|
|
130
|
-
}).option("summary", {
|
|
131
|
-
type: "boolean",
|
|
132
|
-
description: "Show summary of lint results"
|
|
133
134
|
}),
|
|
134
135
|
handler: (argv) => safeTry3(async function* () {
|
|
135
136
|
const packageManager = yield* getPackageManagerName();
|
|
136
|
-
const args = ["
|
|
137
|
-
if (argv.summary) {
|
|
138
|
-
args.push("--reporter", "summary");
|
|
139
|
-
}
|
|
137
|
+
const args = ["--type-aware"];
|
|
140
138
|
if (argv.files && argv.files.length > 0) {
|
|
141
139
|
args.push(...argv.files);
|
|
142
140
|
}
|
|
143
|
-
const command = dlxCommand(packageManager,
|
|
141
|
+
const command = dlxCommand(packageManager, oxlint.name, { args });
|
|
144
142
|
const result = yield* runCommand(command);
|
|
145
143
|
return ok3(result);
|
|
146
144
|
}).match(() => {
|
|
@@ -153,18 +151,75 @@ var check_default = defineCommand({
|
|
|
153
151
|
})
|
|
154
152
|
});
|
|
155
153
|
|
|
156
|
-
// src/commands/
|
|
154
|
+
// src/commands/fix.ts
|
|
157
155
|
import process4 from "node:process";
|
|
158
156
|
import { log as log2 } from "@clack/prompts";
|
|
159
|
-
import { Fault as
|
|
160
|
-
import { ok as
|
|
157
|
+
import { Fault as Fault4 } from "faultier";
|
|
158
|
+
import { ok as ok4, safeTry as safeTry4 } from "neverthrow";
|
|
161
159
|
import { dlxCommand as dlxCommand2 } from "nypm";
|
|
160
|
+
var fix_default = defineCommand({
|
|
161
|
+
command: "fix [files..]",
|
|
162
|
+
describe: "Fix issues in code using oxlint",
|
|
163
|
+
builder: (yargs) => yargs.positional("files", {
|
|
164
|
+
describe: "Specific files to fix (optional)",
|
|
165
|
+
type: "string",
|
|
166
|
+
array: true
|
|
167
|
+
}).option("suggested", {
|
|
168
|
+
type: "boolean",
|
|
169
|
+
description: "Apply suggested fixes",
|
|
170
|
+
default: false
|
|
171
|
+
}).option("dangerous", {
|
|
172
|
+
type: "boolean",
|
|
173
|
+
description: "Apply dangerous fixes",
|
|
174
|
+
default: false
|
|
175
|
+
}).option("all", {
|
|
176
|
+
type: "boolean",
|
|
177
|
+
description: "Apply all fixes, including suggested and dangerous fixes",
|
|
178
|
+
default: false
|
|
179
|
+
}),
|
|
180
|
+
handler: (argv) => safeTry4(async function* () {
|
|
181
|
+
const packageManager = yield* getPackageManagerName();
|
|
182
|
+
const args = new Set(["--type-aware", "--fix"]);
|
|
183
|
+
if (argv.suggested) {
|
|
184
|
+
args.add("--fix-suggestions");
|
|
185
|
+
}
|
|
186
|
+
if (argv.dangerous) {
|
|
187
|
+
args.add("--fix-dangerously");
|
|
188
|
+
}
|
|
189
|
+
if (argv.all) {
|
|
190
|
+
args.add("--fix-suggestions");
|
|
191
|
+
args.add("--fix-dangerously");
|
|
192
|
+
}
|
|
193
|
+
if (argv.files && argv.files.length > 0) {
|
|
194
|
+
for (const file of argv.files) {
|
|
195
|
+
args.add(file);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const command = dlxCommand2(packageManager, oxlint.name, { args: Array.from(args) });
|
|
199
|
+
yield* runCommand(command);
|
|
200
|
+
return ok4();
|
|
201
|
+
}).match(() => {
|
|
202
|
+
process4.exit(0);
|
|
203
|
+
}, (error) => {
|
|
204
|
+
if (Fault4.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
205
|
+
log2.error(error.flatten());
|
|
206
|
+
}
|
|
207
|
+
process4.exit(1);
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// src/commands/format.ts
|
|
212
|
+
import process5 from "node:process";
|
|
213
|
+
import { log as log3 } from "@clack/prompts";
|
|
214
|
+
import { Fault as Fault6 } from "faultier";
|
|
215
|
+
import { ok as ok6, safeTry as safeTry6 } from "neverthrow";
|
|
216
|
+
import { dlxCommand as dlxCommand3 } from "nypm";
|
|
162
217
|
|
|
163
218
|
// src/helpers/packages/oxfmt.ts
|
|
164
219
|
import { readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
|
|
165
220
|
import { join as join3 } from "node:path";
|
|
166
|
-
import { Fault as
|
|
167
|
-
import { err as err3, fromPromise as fromPromise3, ok as
|
|
221
|
+
import { Fault as Fault5 } from "faultier";
|
|
222
|
+
import { err as err3, fromPromise as fromPromise3, ok as ok5, safeTry as safeTry5 } from "neverthrow";
|
|
168
223
|
// presets/oxfmt.json
|
|
169
224
|
var oxfmt_default = {
|
|
170
225
|
arrowParens: "always",
|
|
@@ -221,121 +276,25 @@ var oxfmt = {
|
|
|
221
276
|
}
|
|
222
277
|
return { path: null };
|
|
223
278
|
},
|
|
224
|
-
create: () => fromPromise3(writeFile2(join3(process.cwd(), ".oxfmtrc.jsonc"), JSON.stringify(oxfmt.config, null, 2)), (error) =>
|
|
225
|
-
update: () =>
|
|
279
|
+
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.")),
|
|
280
|
+
update: () => safeTry5(async function* () {
|
|
226
281
|
const exists = await oxfmt.exists();
|
|
227
282
|
if (!exists.path) {
|
|
228
|
-
return err3(
|
|
283
|
+
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
284
|
}
|
|
230
|
-
const oxfmtFile = yield* fromPromise3(readFile3(exists.path, "
|
|
285
|
+
const oxfmtFile = yield* fromPromise3(readFile3(exists.path, "utf8"), (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
286
|
const existingConfig = yield* parseJson(oxfmtFile);
|
|
232
|
-
if (!
|
|
233
|
-
return err3(
|
|
287
|
+
if (!isJsonObject(existingConfig)) {
|
|
288
|
+
return err3(Fault5.create("INVALID_CONFIG_FORMAT").withDescription("Invalid oxfmt configuration format", "The oxfmt configuration must be a JSON object."));
|
|
234
289
|
}
|
|
235
290
|
const mergedConfig = yield* mergeConfig(existingConfig, oxfmt.config);
|
|
236
291
|
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
|
-
}
|
|
292
|
+
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
293
|
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
294
|
})
|
|
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
|
-
})
|
|
331
|
-
});
|
|
295
|
+
};
|
|
332
296
|
|
|
333
297
|
// 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
298
|
var format_default = defineCommand({
|
|
340
299
|
command: "format [files..]",
|
|
341
300
|
describe: "Format files using oxfmt",
|
|
@@ -347,7 +306,7 @@ var format_default = defineCommand({
|
|
|
347
306
|
type: "boolean",
|
|
348
307
|
description: "Check if files are formatted without writing"
|
|
349
308
|
}),
|
|
350
|
-
handler: (argv) =>
|
|
309
|
+
handler: (argv) => safeTry6(async function* () {
|
|
351
310
|
const packageManager = yield* getPackageManagerName();
|
|
352
311
|
const args = [];
|
|
353
312
|
if (argv.check) {
|
|
@@ -356,76 +315,241 @@ var format_default = defineCommand({
|
|
|
356
315
|
if (argv.files && argv.files.length > 0) {
|
|
357
316
|
args.push(...argv.files);
|
|
358
317
|
}
|
|
359
|
-
const command =
|
|
318
|
+
const command = dlxCommand3(packageManager, oxfmt.name, { args });
|
|
360
319
|
const result = yield* runCommand(command);
|
|
361
|
-
return
|
|
320
|
+
return ok6(result);
|
|
362
321
|
}).match(() => {
|
|
363
|
-
|
|
322
|
+
process5.exit(0);
|
|
364
323
|
}, (error) => {
|
|
365
|
-
if (
|
|
366
|
-
|
|
324
|
+
if (Fault6.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
325
|
+
log3.error(error.flatten());
|
|
367
326
|
}
|
|
368
|
-
|
|
327
|
+
process5.exit(1);
|
|
369
328
|
})
|
|
370
329
|
});
|
|
371
330
|
|
|
372
331
|
// src/commands/init.ts
|
|
373
|
-
import { writeFile as
|
|
374
|
-
import { join as
|
|
332
|
+
import { writeFile as writeFile6 } from "node:fs/promises";
|
|
333
|
+
import { join as join7 } from "node:path";
|
|
375
334
|
import process7 from "node:process";
|
|
376
335
|
import * as p from "@clack/prompts";
|
|
377
336
|
import { Fault as Fault10 } from "faultier";
|
|
378
|
-
import { err as
|
|
337
|
+
import { err as err6, fromPromise as fromPromise7, fromSafePromise, ok as ok10, safeTry as safeTry10 } from "neverthrow";
|
|
379
338
|
import { addDevDependency } from "nypm";
|
|
380
339
|
|
|
381
|
-
// src/helpers/
|
|
382
|
-
import { mkdir,
|
|
340
|
+
// src/helpers/ci/github.ts
|
|
341
|
+
import { mkdir, writeFile as writeFile3 } from "node:fs/promises";
|
|
383
342
|
import { join as join4 } from "node:path";
|
|
343
|
+
import process6 from "node:process";
|
|
344
|
+
import { Fault as Fault7 } from "faultier";
|
|
345
|
+
import { fromPromise as fromPromise4, ok as ok7, safeTry as safeTry7 } from "neverthrow";
|
|
346
|
+
import { runScriptCommand } from "nypm";
|
|
347
|
+
var setupSteps = {
|
|
348
|
+
bun: ` - name: Setup Bun
|
|
349
|
+
uses: oven-sh/setup-bun@v2
|
|
350
|
+
|
|
351
|
+
- name: Cache dependencies
|
|
352
|
+
uses: actions/cache@v4
|
|
353
|
+
with:
|
|
354
|
+
path: |
|
|
355
|
+
~/.bun/install/cache
|
|
356
|
+
node_modules
|
|
357
|
+
key: \${{ runner.os }}-bun-\${{ hashFiles('bun.lock') }}
|
|
358
|
+
restore-keys: |
|
|
359
|
+
\${{ runner.os }}-bun-
|
|
360
|
+
|
|
361
|
+
- name: Install dependencies
|
|
362
|
+
run: bun install --frozen-lockfile`,
|
|
363
|
+
pnpm: ` - name: Setup pnpm
|
|
364
|
+
uses: pnpm/action-setup@v4
|
|
365
|
+
|
|
366
|
+
- name: Setup Node.js
|
|
367
|
+
uses: actions/setup-node@v6
|
|
368
|
+
with:
|
|
369
|
+
node-version: "22"
|
|
370
|
+
cache: "pnpm"
|
|
371
|
+
|
|
372
|
+
- name: Install dependencies
|
|
373
|
+
run: pnpm install --frozen-lockfile`,
|
|
374
|
+
yarn: ` - name: Setup Node.js
|
|
375
|
+
uses: actions/setup-node@v6
|
|
376
|
+
with:
|
|
377
|
+
node-version: "22"
|
|
378
|
+
cache: "yarn"
|
|
379
|
+
|
|
380
|
+
- name: Install dependencies
|
|
381
|
+
run: yarn install --frozen-lockfile`,
|
|
382
|
+
npm: ` - name: Setup Node.js
|
|
383
|
+
uses: actions/setup-node@v6
|
|
384
|
+
with:
|
|
385
|
+
node-version: "22"
|
|
386
|
+
cache: "npm"
|
|
387
|
+
|
|
388
|
+
- name: Install dependencies
|
|
389
|
+
run: npm ci`,
|
|
390
|
+
deno: ` - name: Setup Deno
|
|
391
|
+
uses: denoland/setup-deno@v2
|
|
392
|
+
|
|
393
|
+
- name: Install dependencies
|
|
394
|
+
run: deno install --frozen`
|
|
395
|
+
};
|
|
396
|
+
var buildCommand = (packageManager, script, args) => runScriptCommand(packageManager, script, { args });
|
|
397
|
+
var generateWorkflow = ({ packageManager, scripts }) => {
|
|
398
|
+
const matrixEntries = [];
|
|
399
|
+
if (scripts.includes("check")) {
|
|
400
|
+
matrixEntries.push({
|
|
401
|
+
name: "lint",
|
|
402
|
+
command: buildCommand(packageManager, "check")
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (scripts.includes("format")) {
|
|
406
|
+
matrixEntries.push({
|
|
407
|
+
name: "format",
|
|
408
|
+
command: buildCommand(packageManager, "format", ["--check"])
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if (scripts.includes("typecheck")) {
|
|
412
|
+
matrixEntries.push({
|
|
413
|
+
name: "types",
|
|
414
|
+
command: buildCommand(packageManager, "typecheck")
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
if (scripts.includes("check:monorepo")) {
|
|
418
|
+
matrixEntries.push({
|
|
419
|
+
name: "monorepo",
|
|
420
|
+
command: buildCommand(packageManager, "check:monorepo")
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
if (matrixEntries.length === 0) {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
const matrixInclude = matrixEntries.map((entry) => ` - name: ${entry.name}
|
|
427
|
+
command: ${entry.command}`).join(`
|
|
428
|
+
`);
|
|
429
|
+
const workflow = `name: adamantite
|
|
430
|
+
|
|
431
|
+
on:
|
|
432
|
+
push:
|
|
433
|
+
branches:
|
|
434
|
+
- main
|
|
435
|
+
pull_request:
|
|
436
|
+
types: [opened, synchronize, reopened]
|
|
437
|
+
|
|
438
|
+
permissions:
|
|
439
|
+
contents: read
|
|
440
|
+
|
|
441
|
+
concurrency:
|
|
442
|
+
group: \${{ github.workflow }}-\${{ github.ref }}
|
|
443
|
+
cancel-in-progress: true
|
|
444
|
+
|
|
445
|
+
jobs:
|
|
446
|
+
verify:
|
|
447
|
+
name: \${{ matrix.name }}
|
|
448
|
+
runs-on: ubuntu-latest
|
|
449
|
+
timeout-minutes: 10
|
|
450
|
+
strategy:
|
|
451
|
+
fail-fast: false
|
|
452
|
+
matrix:
|
|
453
|
+
include:
|
|
454
|
+
${matrixInclude}
|
|
455
|
+
|
|
456
|
+
steps:
|
|
457
|
+
- name: Checkout
|
|
458
|
+
uses: actions/checkout@v4
|
|
459
|
+
|
|
460
|
+
${setupSteps[packageManager]}
|
|
461
|
+
|
|
462
|
+
- name: Run \${{ matrix.name }}
|
|
463
|
+
run: \${{ matrix.command }}`;
|
|
464
|
+
return `${workflow}
|
|
465
|
+
`;
|
|
466
|
+
};
|
|
467
|
+
var hasCICompatibleScripts = (scripts) => scripts.some((script) => ["check", "format", "typecheck", "check:monorepo"].includes(script));
|
|
468
|
+
var github = {
|
|
469
|
+
workflowPath: ".github/workflows/adamantite.yml",
|
|
470
|
+
exists: () => checkIfExists(join4(process6.cwd(), ".github", "workflows", "adamantite.yml")),
|
|
471
|
+
create: (options) => safeTry7(async function* () {
|
|
472
|
+
const workflowDir = join4(process6.cwd(), ".github", "workflows");
|
|
473
|
+
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 }));
|
|
474
|
+
const workflowContent = generateWorkflow(options);
|
|
475
|
+
if (!workflowContent) {
|
|
476
|
+
return ok7();
|
|
477
|
+
}
|
|
478
|
+
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") }));
|
|
479
|
+
return ok7();
|
|
480
|
+
}),
|
|
481
|
+
update: (options) => safeTry7(async function* () {
|
|
482
|
+
const workflowPath = join4(process6.cwd(), ".github", "workflows", "adamantite.yml");
|
|
483
|
+
const workflowContent = generateWorkflow(options);
|
|
484
|
+
if (!workflowContent) {
|
|
485
|
+
return ok7();
|
|
486
|
+
}
|
|
487
|
+
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 }));
|
|
488
|
+
return ok7();
|
|
489
|
+
})
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// src/helpers/editors/vscode.ts
|
|
493
|
+
import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
|
|
494
|
+
import { join as join5 } from "node:path";
|
|
384
495
|
import { Fault as Fault8 } from "faultier";
|
|
385
|
-
import { fromPromise as
|
|
496
|
+
import { err as err4, fromPromise as fromPromise5, ok as ok8, safeTry as safeTry8 } from "neverthrow";
|
|
386
497
|
var vscode = {
|
|
387
498
|
config: {
|
|
388
499
|
"typescript.tsdk": "node_modules/typescript/lib",
|
|
389
500
|
"editor.formatOnSave": true,
|
|
390
501
|
"editor.formatOnPaste": true,
|
|
391
502
|
"editor.codeActionsOnSave": {
|
|
392
|
-
"source.fixAll.
|
|
503
|
+
"source.fixAll.oxc": "explicit"
|
|
393
504
|
},
|
|
394
505
|
"[javascript][typescript][javascriptreact][typescriptreact][json][jsonc][css][graphql]": {
|
|
395
506
|
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
396
507
|
}
|
|
397
508
|
},
|
|
398
|
-
exists: () => checkIfExists(
|
|
509
|
+
exists: () => checkIfExists(join5(process.cwd(), ".vscode", "settings.json")),
|
|
399
510
|
create: () => safeTry8(async function* () {
|
|
400
|
-
const vscodePath =
|
|
401
|
-
yield*
|
|
402
|
-
yield*
|
|
511
|
+
const vscodePath = join5(process.cwd(), ".vscode");
|
|
512
|
+
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 }));
|
|
513
|
+
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
514
|
return ok8();
|
|
404
515
|
}),
|
|
405
516
|
update: () => safeTry8(async function* () {
|
|
406
|
-
const vscodePath =
|
|
407
|
-
const vscodeFile = yield*
|
|
517
|
+
const vscodePath = join5(process.cwd(), ".vscode", "settings.json");
|
|
518
|
+
const vscodeFile = yield* fromPromise5(readFile4(vscodePath, "utf8"), (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
519
|
const existingConfig = yield* parseJson(vscodeFile);
|
|
520
|
+
if (!isJsonObject(existingConfig)) {
|
|
521
|
+
return err4(Fault8.create("INVALID_CONFIG_FORMAT").withDescription("Invalid .vscode/settings.json format", "The VS Code settings file must be a JSON object."));
|
|
522
|
+
}
|
|
409
523
|
const newConfig = yield* mergeConfig(vscode.config, existingConfig);
|
|
410
|
-
yield*
|
|
524
|
+
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
525
|
return ok8();
|
|
412
526
|
})
|
|
413
527
|
};
|
|
414
528
|
|
|
415
|
-
// src/helpers/
|
|
416
|
-
|
|
417
|
-
|
|
529
|
+
// src/helpers/packages/sherif.ts
|
|
530
|
+
var sherif = {
|
|
531
|
+
name: "sherif",
|
|
532
|
+
version: "1.9.0"
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
// src/helpers/packages/typescript.ts
|
|
536
|
+
import { readFile as readFile5, writeFile as writeFile5 } from "node:fs/promises";
|
|
537
|
+
import { join as join6 } from "node:path";
|
|
418
538
|
import { Fault as Fault9 } from "faultier";
|
|
419
|
-
import { fromPromise as
|
|
420
|
-
var
|
|
539
|
+
import { err as err5, fromPromise as fromPromise6, ok as ok9, safeTry as safeTry9 } from "neverthrow";
|
|
540
|
+
var typescript = {
|
|
541
|
+
name: "tsc",
|
|
421
542
|
config: { extends: "adamantite/typescript" },
|
|
422
|
-
exists: () => checkIfExists(
|
|
423
|
-
create: () =>
|
|
543
|
+
exists: () => checkIfExists(join6(process.cwd(), "tsconfig.json")),
|
|
544
|
+
create: () => fromPromise6(writeFile5(join6(process.cwd(), "tsconfig.json"), JSON.stringify(typescript.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
545
|
update: () => safeTry9(async function* () {
|
|
425
|
-
const tsconfigFile = yield*
|
|
546
|
+
const tsconfigFile = yield* fromPromise6(readFile5(join6(process.cwd(), "tsconfig.json"), "utf8"), (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
547
|
const existingConfig = yield* parseJson(tsconfigFile);
|
|
427
|
-
|
|
428
|
-
|
|
548
|
+
if (!isJsonObject(existingConfig)) {
|
|
549
|
+
return err5(Fault9.create("INVALID_CONFIG_FORMAT").withDescription("Invalid tsconfig.json format", "The tsconfig.json file must be a JSON object."));
|
|
550
|
+
}
|
|
551
|
+
const newConfig = yield* mergeConfig(typescript.config, existingConfig);
|
|
552
|
+
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
553
|
return ok9();
|
|
430
554
|
})
|
|
431
555
|
};
|
|
@@ -436,23 +560,23 @@ var installDependencies = (packages) => safeTry10(async function* () {
|
|
|
436
560
|
s.start("Installing dependencies...");
|
|
437
561
|
const isMonorepo = yield* checkIsMonorepo();
|
|
438
562
|
for (const pkg of packages) {
|
|
439
|
-
yield*
|
|
563
|
+
yield* fromPromise7(addDevDependency(pkg, { silent: true, workspace: isMonorepo }), (error) => Fault10.wrap(error).withTag("FAILED_TO_INSTALL_DEPENDENCY").withMessage(`Failed to install ${pkg}`));
|
|
440
564
|
}
|
|
441
565
|
s.stop("Dependencies installed.");
|
|
442
566
|
return ok10();
|
|
443
567
|
});
|
|
444
|
-
var
|
|
568
|
+
var setupOxlintConfig = () => safeTry10(async function* () {
|
|
445
569
|
const spinner2 = p.spinner();
|
|
446
|
-
spinner2.start("Setting up
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
449
|
-
spinner2.message(`Found \`${
|
|
450
|
-
yield*
|
|
451
|
-
spinner2.stop("
|
|
570
|
+
spinner2.start("Setting up oxlint config...");
|
|
571
|
+
const oxlintPath = await oxlint.exists();
|
|
572
|
+
if (oxlintPath.path) {
|
|
573
|
+
spinner2.message(`Found \`${oxlintPath.path}\`, updating...`);
|
|
574
|
+
yield* oxlint.update();
|
|
575
|
+
spinner2.stop("oxlint config updated successfully.");
|
|
452
576
|
} else {
|
|
453
|
-
spinner2.message("`.
|
|
454
|
-
yield*
|
|
455
|
-
spinner2.stop("
|
|
577
|
+
spinner2.message("`.oxlintrc.json` not found, creating...");
|
|
578
|
+
yield* oxlint.create();
|
|
579
|
+
spinner2.stop("oxlint config created successfully.");
|
|
456
580
|
}
|
|
457
581
|
return ok10();
|
|
458
582
|
});
|
|
@@ -476,9 +600,7 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
476
600
|
const packageJson = yield* readPackageJson();
|
|
477
601
|
const spinner2 = p.spinner();
|
|
478
602
|
spinner2.start("Adding scripts to your `package.json`...");
|
|
479
|
-
|
|
480
|
-
packageJson.scripts = {};
|
|
481
|
-
}
|
|
603
|
+
packageJson.scripts ??= {};
|
|
482
604
|
for (const script of scripts) {
|
|
483
605
|
switch (script) {
|
|
484
606
|
case "check":
|
|
@@ -491,7 +613,7 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
491
613
|
packageJson.scripts.format = "adamantite format";
|
|
492
614
|
break;
|
|
493
615
|
case "typecheck":
|
|
494
|
-
packageJson.scripts.typecheck = "
|
|
616
|
+
packageJson.scripts.typecheck = "adamantite typecheck";
|
|
495
617
|
break;
|
|
496
618
|
case "check:monorepo":
|
|
497
619
|
packageJson.scripts["check:monorepo"] = "adamantite monorepo";
|
|
@@ -500,23 +622,23 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
500
622
|
packageJson.scripts["fix:monorepo"] = "adamantite monorepo --fix";
|
|
501
623
|
break;
|
|
502
624
|
default:
|
|
503
|
-
return
|
|
625
|
+
return err6(Fault10.create("UNKNOWN_SCRIPT").withContext({ script }));
|
|
504
626
|
}
|
|
505
627
|
}
|
|
506
|
-
yield*
|
|
628
|
+
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
629
|
spinner2.stop("Scripts added to your `package.json`");
|
|
508
630
|
return ok10();
|
|
509
631
|
});
|
|
510
632
|
var setupTypescript = () => safeTry10(async function* () {
|
|
511
633
|
const spinner2 = p.spinner();
|
|
512
634
|
spinner2.start("Setting up TypeScript config...");
|
|
513
|
-
if (await
|
|
635
|
+
if (await typescript.exists()) {
|
|
514
636
|
spinner2.message("`tsconfig.json` found, updating...");
|
|
515
|
-
yield*
|
|
637
|
+
yield* typescript.update();
|
|
516
638
|
spinner2.stop("`tsconfig.json` updated successfully");
|
|
517
639
|
} else {
|
|
518
640
|
spinner2.message("`tsconfig.json` not found, creating...");
|
|
519
|
-
yield*
|
|
641
|
+
yield* typescript.create();
|
|
520
642
|
spinner2.stop("`tsconfig.json` created successfully");
|
|
521
643
|
}
|
|
522
644
|
return ok10();
|
|
@@ -538,6 +660,20 @@ var setupEditors = (editors) => safeTry10(async function* () {
|
|
|
538
660
|
if (editors.includes("zed")) {}
|
|
539
661
|
return ok10();
|
|
540
662
|
});
|
|
663
|
+
var setupGitHubActions = (packageManager, scripts) => safeTry10(async function* () {
|
|
664
|
+
const spinner2 = p.spinner();
|
|
665
|
+
spinner2.start("Setting up GitHub Actions workflow...");
|
|
666
|
+
if (await github.exists()) {
|
|
667
|
+
spinner2.message("`.github/workflows/adamantite.yml` found, updating...");
|
|
668
|
+
yield* github.update({ packageManager, scripts });
|
|
669
|
+
spinner2.stop("GitHub Actions workflow updated successfully.");
|
|
670
|
+
} else {
|
|
671
|
+
spinner2.message("Creating `.github/workflows/adamantite.yml`...");
|
|
672
|
+
yield* github.create({ packageManager, scripts });
|
|
673
|
+
spinner2.stop("GitHub Actions workflow created successfully.");
|
|
674
|
+
}
|
|
675
|
+
return ok10();
|
|
676
|
+
});
|
|
541
677
|
var init_default = defineCommand({
|
|
542
678
|
command: "init",
|
|
543
679
|
describe: "Initialize Adamantite in the current directory",
|
|
@@ -555,12 +691,12 @@ var init_default = defineCommand({
|
|
|
555
691
|
message: "Which scripts do you want to add to your `package.json`?",
|
|
556
692
|
options: [
|
|
557
693
|
{
|
|
558
|
-
label: "check - find issues in code using
|
|
694
|
+
label: "check - find issues in code using oxlint",
|
|
559
695
|
value: "check",
|
|
560
696
|
hint: "recommended"
|
|
561
697
|
},
|
|
562
698
|
{
|
|
563
|
-
label: "fix - fix code issues using
|
|
699
|
+
label: "fix - fix code issues using oxlint",
|
|
564
700
|
value: "fix",
|
|
565
701
|
hint: "recommended"
|
|
566
702
|
},
|
|
@@ -589,7 +725,7 @@ var init_default = defineCommand({
|
|
|
589
725
|
]
|
|
590
726
|
}));
|
|
591
727
|
if (p.isCancel(scripts)) {
|
|
592
|
-
return
|
|
728
|
+
return err6(Fault10.create("OPERATION_CANCELLED"));
|
|
593
729
|
}
|
|
594
730
|
const editors = yield* fromSafePromise(p.multiselect({
|
|
595
731
|
message: "Which editors do you want to configure? (optional)",
|
|
@@ -600,15 +736,28 @@ var init_default = defineCommand({
|
|
|
600
736
|
required: false
|
|
601
737
|
}));
|
|
602
738
|
if (p.isCancel(editors)) {
|
|
603
|
-
return
|
|
739
|
+
return err6(Fault10.create("OPERATION_CANCELLED"));
|
|
740
|
+
}
|
|
741
|
+
const hasCIScripts = hasCICompatibleScripts(scripts);
|
|
742
|
+
let enableGitHubActions = false;
|
|
743
|
+
if (hasCIScripts) {
|
|
744
|
+
const response = yield* fromSafePromise(p.confirm({
|
|
745
|
+
message: "Do you want to add a GitHub Actions workflow to run checks in CI?",
|
|
746
|
+
initialValue: false
|
|
747
|
+
}));
|
|
748
|
+
if (p.isCancel(response)) {
|
|
749
|
+
return err6(Fault10.create("OPERATION_CANCELLED"));
|
|
750
|
+
}
|
|
751
|
+
enableGitHubActions = response;
|
|
604
752
|
}
|
|
605
|
-
const
|
|
753
|
+
const hasOxlint = scripts.includes("check") || scripts.includes("fix");
|
|
606
754
|
const hasOxfmt = scripts.includes("format");
|
|
607
755
|
const hasSherif = scripts.includes("check:monorepo") || scripts.includes("fix:monorepo");
|
|
608
756
|
const hasTypecheck = scripts.includes("typecheck");
|
|
609
757
|
const dependencies = ["adamantite"];
|
|
610
|
-
if (
|
|
611
|
-
dependencies.push(`${
|
|
758
|
+
if (hasOxlint) {
|
|
759
|
+
dependencies.push(`${oxlint.name}@${oxlint.version}`);
|
|
760
|
+
dependencies.push(`${tsgolint.name}@${tsgolint.version}`);
|
|
612
761
|
}
|
|
613
762
|
if (hasOxfmt) {
|
|
614
763
|
dependencies.push(`${oxfmt.name}@${oxfmt.version}`);
|
|
@@ -623,14 +772,17 @@ var init_default = defineCommand({
|
|
|
623
772
|
if (hasOxfmt) {
|
|
624
773
|
yield* setupOxfmtConfig();
|
|
625
774
|
}
|
|
626
|
-
if (
|
|
627
|
-
yield*
|
|
775
|
+
if (hasOxlint) {
|
|
776
|
+
yield* setupOxlintConfig();
|
|
628
777
|
}
|
|
629
778
|
yield* addScripts(scripts);
|
|
630
779
|
if (hasTypecheck) {
|
|
631
780
|
yield* setupTypescript();
|
|
632
781
|
}
|
|
633
782
|
yield* setupEditors(editors);
|
|
783
|
+
if (enableGitHubActions) {
|
|
784
|
+
yield* setupGitHubActions(packageManager, scripts);
|
|
785
|
+
}
|
|
634
786
|
return ok10();
|
|
635
787
|
}).match(() => {
|
|
636
788
|
p.outro("\uD83D\uDCA0 Adamantite initialized successfully!");
|
|
@@ -653,10 +805,10 @@ var init_default = defineCommand({
|
|
|
653
805
|
|
|
654
806
|
// src/commands/monorepo.ts
|
|
655
807
|
import process8 from "node:process";
|
|
656
|
-
import { log as
|
|
808
|
+
import { log as log5 } from "@clack/prompts";
|
|
657
809
|
import { Fault as Fault11 } from "faultier";
|
|
658
810
|
import { ok as ok11, safeTry as safeTry11 } from "neverthrow";
|
|
659
|
-
import { dlxCommand as
|
|
811
|
+
import { dlxCommand as dlxCommand4 } from "nypm";
|
|
660
812
|
var monorepo_default = defineCommand({
|
|
661
813
|
command: "monorepo",
|
|
662
814
|
describe: "Find and fix monorepo-specific issues using Sherif",
|
|
@@ -670,35 +822,75 @@ var monorepo_default = defineCommand({
|
|
|
670
822
|
if (argv.fix) {
|
|
671
823
|
args.push("--fix");
|
|
672
824
|
}
|
|
673
|
-
const command =
|
|
825
|
+
const command = dlxCommand4(packageManager, sherif.name, { args });
|
|
674
826
|
yield* runCommand(command);
|
|
675
|
-
return ok11(
|
|
827
|
+
return ok11();
|
|
676
828
|
}).match(() => {
|
|
677
829
|
process8.exit(0);
|
|
678
830
|
}, (error) => {
|
|
679
831
|
if (Fault11.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
680
|
-
|
|
832
|
+
log5.error(error.flatten());
|
|
681
833
|
}
|
|
682
834
|
process8.exit(1);
|
|
683
835
|
})
|
|
684
836
|
});
|
|
685
837
|
|
|
686
|
-
// src/commands/
|
|
838
|
+
// src/commands/typecheck.ts
|
|
687
839
|
import process9 from "node:process";
|
|
688
|
-
import {
|
|
840
|
+
import { log as log6 } from "@clack/prompts";
|
|
689
841
|
import { Fault as Fault12 } from "faultier";
|
|
690
|
-
import {
|
|
842
|
+
import { ok as ok12, safeTry as safeTry12 } from "neverthrow";
|
|
843
|
+
import { dlxCommand as dlxCommand5 } from "nypm";
|
|
844
|
+
var typecheck_default = defineCommand({
|
|
845
|
+
command: "typecheck",
|
|
846
|
+
describe: "Run TypeScript type checking",
|
|
847
|
+
builder: (yargs) => yargs.option("project", {
|
|
848
|
+
alias: "p",
|
|
849
|
+
type: "string",
|
|
850
|
+
description: "Path to tsconfig.json file"
|
|
851
|
+
}).option("watch", {
|
|
852
|
+
alias: "w",
|
|
853
|
+
type: "boolean",
|
|
854
|
+
description: "Run in watch mode"
|
|
855
|
+
}),
|
|
856
|
+
handler: (argv) => safeTry12(async function* () {
|
|
857
|
+
const packageManager = yield* getPackageManagerName();
|
|
858
|
+
const args = ["--noEmit"];
|
|
859
|
+
if (argv.project) {
|
|
860
|
+
args.push("--project", argv.project);
|
|
861
|
+
}
|
|
862
|
+
if (argv.watch) {
|
|
863
|
+
args.push("--watch");
|
|
864
|
+
}
|
|
865
|
+
const command = dlxCommand5(packageManager, typescript.name, { args });
|
|
866
|
+
const result = yield* runCommand(command);
|
|
867
|
+
return ok12(result);
|
|
868
|
+
}).match(() => {
|
|
869
|
+
process9.exit(0);
|
|
870
|
+
}, (error) => {
|
|
871
|
+
if (Fault12.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
872
|
+
log6.error(error.flatten());
|
|
873
|
+
}
|
|
874
|
+
process9.exit(1);
|
|
875
|
+
})
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
// src/commands/update.ts
|
|
879
|
+
import process10 from "node:process";
|
|
880
|
+
import { cancel as cancel2, confirm as confirm2, intro as intro2, isCancel as isCancel2, log as log7, outro as outro2, spinner as spinner2 } from "@clack/prompts";
|
|
881
|
+
import { Fault as Fault13 } from "faultier";
|
|
882
|
+
import { err as err7, fromPromise as fromPromise8, fromSafePromise as fromSafePromise2, ok as ok13, safeTry as safeTry13 } from "neverthrow";
|
|
691
883
|
import { addDevDependency as addDevDependency2 } from "nypm";
|
|
692
884
|
var update_default = defineCommand({
|
|
693
885
|
command: "update",
|
|
694
886
|
describe: "Update adamantite dependencies to latest compatible versions",
|
|
695
887
|
builder: (yargs) => yargs,
|
|
696
|
-
handler:
|
|
888
|
+
handler: () => safeTry13(async function* () {
|
|
697
889
|
const packageJson = yield* readPackageJson();
|
|
698
890
|
printTitle();
|
|
699
891
|
intro2("\uD83D\uDCA0 adamantite update");
|
|
700
892
|
const updates = [];
|
|
701
|
-
for (const pkg of [
|
|
893
|
+
for (const pkg of [oxlint, oxfmt, sherif]) {
|
|
702
894
|
const dependency = packageJson.devDependencies?.[pkg.name];
|
|
703
895
|
if (dependency && normalizeDependencyVersion(dependency) !== pkg.version) {
|
|
704
896
|
updates.push({
|
|
@@ -711,7 +903,7 @@ var update_default = defineCommand({
|
|
|
711
903
|
}
|
|
712
904
|
if (updates.length === 0) {
|
|
713
905
|
log7.success("All adamantite dependencies are already up to date!");
|
|
714
|
-
return
|
|
906
|
+
return ok13("no-updates");
|
|
715
907
|
}
|
|
716
908
|
log7.message("The following dependencies will be updated:");
|
|
717
909
|
log7.message("");
|
|
@@ -719,22 +911,22 @@ var update_default = defineCommand({
|
|
|
719
911
|
log7.message(` ${dep.name}: ${dep.currentVersion} → ${dep.targetVersion}`);
|
|
720
912
|
}
|
|
721
913
|
log7.message("");
|
|
722
|
-
const shouldUpdate = yield* fromSafePromise2(
|
|
914
|
+
const shouldUpdate = yield* fromSafePromise2(confirm2({
|
|
723
915
|
message: "Do you want to proceed with these updates?"
|
|
724
916
|
}));
|
|
725
917
|
if (isCancel2(shouldUpdate)) {
|
|
726
|
-
return
|
|
918
|
+
return err7(Fault13.create("OPERATION_CANCELLED"));
|
|
727
919
|
}
|
|
728
920
|
if (!shouldUpdate) {
|
|
729
|
-
return
|
|
921
|
+
return ok13("cancelled");
|
|
730
922
|
}
|
|
731
923
|
const s = spinner2();
|
|
732
924
|
s.start("Updating dependencies...");
|
|
733
925
|
for (const dep of updates) {
|
|
734
|
-
yield*
|
|
926
|
+
yield* fromPromise8(addDevDependency2(`${dep.name}@${dep.targetVersion}`), (error) => Fault13.wrap(error).withTag("FAILED_TO_INSTALL_DEPENDENCY").withMessage(`Failed to update ${dep.name}`));
|
|
735
927
|
}
|
|
736
928
|
s.stop("Dependencies updated successfully");
|
|
737
|
-
return
|
|
929
|
+
return ok13("updated");
|
|
738
930
|
}).match((value) => {
|
|
739
931
|
if (value === "no-updates") {
|
|
740
932
|
outro2("✅ No updates needed");
|
|
@@ -743,21 +935,22 @@ var update_default = defineCommand({
|
|
|
743
935
|
} else if (value === "updated") {
|
|
744
936
|
outro2("✅ Dependencies updated successfully!");
|
|
745
937
|
}
|
|
746
|
-
|
|
938
|
+
process10.exit(0);
|
|
747
939
|
}, (error) => {
|
|
748
|
-
if (
|
|
940
|
+
if (Fault13.isFault(error) && error.tag === "OPERATION_CANCELLED") {
|
|
749
941
|
cancel2("You've cancelled the update process.");
|
|
750
|
-
|
|
942
|
+
process10.exit(0);
|
|
751
943
|
}
|
|
752
|
-
if (
|
|
944
|
+
if (Fault13.isFault(error)) {
|
|
753
945
|
log7.error(error.flatten());
|
|
754
946
|
} else {
|
|
755
947
|
log7.error(String(error));
|
|
756
948
|
}
|
|
757
949
|
cancel2("Failed to update dependencies");
|
|
758
|
-
|
|
950
|
+
process10.exit(1);
|
|
759
951
|
})
|
|
760
952
|
});
|
|
761
953
|
|
|
762
954
|
// src/index.ts
|
|
763
|
-
|
|
955
|
+
var version = await "0.18.0";
|
|
956
|
+
yargs(hideBin(process.argv)).scriptName("adamantite").version(version).command(check_default).command(fix_default).command(format_default).command(init_default).command(monorepo_default).command(typecheck_default).command(update_default).demandCommand(1).strict().help().parse();
|