@chanom/cli 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. package/dist/index.js +37 -86
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -118,34 +118,17 @@ function isPackageInstalled(pkg, name) {
118
118
  }
119
119
  //#endregion
120
120
  //#region src/commands/add-commitlint/index.ts
121
- function getPackages$7(pkg) {
121
+ function getPackages$5(pkg) {
122
122
  const missing = [];
123
123
  if (!isPackageInstalled(pkg, "@commitlint/cli")) missing.push("@commitlint/cli");
124
124
  if (!isPackageInstalled(pkg, "@commitlint/config-conventional")) missing.push("@commitlint/config-conventional");
125
125
  return missing;
126
126
  }
127
- function apply$7(cwd) {
127
+ function apply$5(cwd) {
128
128
  writeFileSync(join(cwd, ".commitlintrc.json"), JSON.stringify({ extends: ["@commitlint/config-conventional"] }, null, 2) + "\n");
129
129
  if (existsSync(join(cwd, ".husky"))) writeFileSync(join(cwd, ".husky", "commit-msg"), "npx --no -- commitlint --edit $1\n");
130
130
  }
131
131
  //#endregion
132
- //#region src/commands/add-eslint/index.ts
133
- function getPackages$6(pkg) {
134
- return isPackageInstalled(pkg, "eslint") ? [] : ["eslint"];
135
- }
136
- function apply$6(cwd, esm) {
137
- writeFileSync(join(cwd, `eslint.config.${esm ? "ts" : "mts"}`), `export { default } from '@chanom/dev-config/eslint/config';\n`);
138
- const { pkg, pkgPath } = readPkg(cwd);
139
- pkg.scripts ??= {};
140
- const missing = {};
141
- if (!pkg.scripts["lint"]) missing["lint"] = "eslint .";
142
- if (!pkg.scripts["lint:fix"]) missing["lint:fix"] = "eslint . --fix";
143
- for (const [key, value] of Object.entries(missing)) pkg.scripts[key] = value;
144
- const skipped = ["lint", "lint:fix"].filter((k) => !(k in missing));
145
- for (const key of skipped) log.warn(`\`${key}\` script already exists in package.json - skipping`);
146
- if (Object.keys(missing).length > 0) writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
147
- }
148
- //#endregion
149
132
  //#region src/commands/add-husky/index.ts
150
133
  const PM_EXEC = {
151
134
  pnpm: ["pnpm", "exec"],
@@ -153,10 +136,10 @@ const PM_EXEC = {
153
136
  yarn: ["yarn"],
154
137
  bun: ["bunx"]
155
138
  };
156
- function getPackages$5(pkg) {
139
+ function getPackages$4(pkg) {
157
140
  return isPackageInstalled(pkg, "husky") ? [] : ["husky"];
158
141
  }
159
- function apply$5(cwd, pm) {
142
+ function apply$4(cwd, pm) {
160
143
  const [cmd, ...args] = PM_EXEC[pm];
161
144
  spawnSync(cmd, [
162
145
  ...args,
@@ -168,44 +151,43 @@ function apply$5(cwd, pm) {
168
151
  });
169
152
  }
170
153
  //#endregion
154
+ //#region src/commands/add-knip/logic.ts
155
+ function getMissingScripts$2(scripts) {
156
+ const missing = {};
157
+ if (!scripts["knip"]) missing["knip"] = "knip";
158
+ return missing;
159
+ }
160
+ //#endregion
171
161
  //#region src/commands/add-knip/index.ts
172
- function getPackages$4(pkg) {
173
- return isPackageInstalled(pkg, "knip") ? [] : ["knip"];
162
+ function getPackages$3(pkg) {
163
+ return isPackageInstalled(pkg, "knip") ? [] : [`knip@6.23.0`, "@chanom/dev-config"];
174
164
  }
175
- function apply$4(cwd) {
176
- writeFileSync(join(cwd, "knip.json"), JSON.stringify({ entry: ["src/index.ts"] }, null, 2) + "\n");
165
+ function apply$3(cwd, esm) {
166
+ writeFileSync(join(cwd, `knip.config.${esm ? "ts" : "mts"}`), `export { default } from '@chanom/dev-config/knip/config';\n`);
177
167
  const { pkg, pkgPath } = readPkg(cwd);
178
168
  pkg.scripts ??= {};
179
- if (pkg.scripts["knip"]) log.warn("`knip` script already exists in package.json - skipping");
180
- else {
181
- pkg.scripts["knip"] = "knip";
182
- writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
183
- }
169
+ const missing = getMissingScripts$2(pkg.scripts);
170
+ for (const [key, value] of Object.entries(missing)) pkg.scripts[key] = value;
171
+ const skipped = ["knip"].filter((k) => !(k in missing));
172
+ for (const key of skipped) log.warn(`\`${key}\` script already exists in package.json - skipping`);
173
+ if (Object.keys(missing).length > 0) writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
184
174
  }
185
175
  //#endregion
186
176
  //#region src/commands/add-lint-staged/index.ts
187
- function getPackages$3(pkg) {
177
+ function getPackages$2(pkg) {
188
178
  return isPackageInstalled(pkg, "lint-staged") ? [] : ["lint-staged"];
189
179
  }
190
- function apply$3(cwd, linters = [], formatters = []) {
180
+ function apply$2(cwd, linters = [], formatters = []) {
191
181
  const config = {};
192
182
  const jsGlob = "**/*.{js,jsx,ts,tsx,mjs,cjs,mts,cts}";
193
183
  if (linters.includes("oxlint")) {
194
184
  config[jsGlob] ??= [];
195
185
  config[jsGlob].push("oxlint --fix");
196
186
  }
197
- if (linters.includes("eslint")) {
198
- config[jsGlob] ??= [];
199
- config[jsGlob].push("eslint --fix");
200
- }
201
187
  if (formatters.includes("oxfmt")) {
202
188
  config["*"] ??= [];
203
189
  config["*"].push("oxfmt");
204
190
  }
205
- if (formatters.includes("prettier")) {
206
- config["*"] ??= [];
207
- config["*"].push("prettier --ignore-unknown --write");
208
- }
209
191
  writeFileSync(join(cwd, ".lintstagedrc.json"), JSON.stringify(config, null, 2) + "\n");
210
192
  if (existsSync(join(cwd, ".husky"))) writeFileSync(join(cwd, ".husky", "pre-commit"), "lint-staged\n");
211
193
  }
@@ -219,10 +201,10 @@ function getMissingScripts$1(scripts) {
219
201
  }
220
202
  //#endregion
221
203
  //#region src/commands/add-oxfmt/index.ts
222
- function getPackages$2(pkg) {
204
+ function getPackages$1(pkg) {
223
205
  return isPackageInstalled(pkg, "oxfmt") ? [] : [`oxfmt@0.56.0`, "@chanom/dev-config"];
224
206
  }
225
- function apply$2(cwd, esm) {
207
+ function apply$1(cwd, esm) {
226
208
  writeFileSync(join(cwd, `oxfmt.config.${esm ? "ts" : "mts"}`), `export { default } from '@chanom/dev-config/oxfmt/config';\n`);
227
209
  const { pkg, pkgPath } = readPkg(cwd);
228
210
  pkg.scripts ??= {};
@@ -242,10 +224,10 @@ function getMissingScripts(scripts) {
242
224
  }
243
225
  //#endregion
244
226
  //#region src/commands/add-oxlint/index.ts
245
- function getPackages$1(pkg) {
227
+ function getPackages(pkg) {
246
228
  return isPackageInstalled(pkg, "oxlint") ? [] : [`oxlint@1.71.0`, "@chanom/dev-config"];
247
229
  }
248
- function apply$1(cwd, esm) {
230
+ function apply(cwd, esm) {
249
231
  writeFileSync(join(cwd, `oxlint.config.${esm ? "ts" : "mts"}`), `export { default } from '@chanom/dev-config/oxlint/config';\n`);
250
232
  const { pkg, pkgPath } = readPkg(cwd);
251
233
  pkg.scripts ??= {};
@@ -256,23 +238,6 @@ function apply$1(cwd, esm) {
256
238
  if (Object.keys(missing).length > 0) writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
257
239
  }
258
240
  //#endregion
259
- //#region src/commands/add-prettier/index.ts
260
- function getPackages(pkg) {
261
- return isPackageInstalled(pkg, "prettier") ? [] : ["prettier"];
262
- }
263
- function apply(cwd) {
264
- writeFileSync(join(cwd, ".prettierrc"), JSON.stringify({}, null, 2) + "\n");
265
- const { pkg, pkgPath } = readPkg(cwd);
266
- pkg.scripts ??= {};
267
- const missing = {};
268
- if (!pkg.scripts["format"]) missing["format"] = "prettier --write .";
269
- if (!pkg.scripts["format:check"]) missing["format:check"] = "prettier --check .";
270
- for (const [key, value] of Object.entries(missing)) pkg.scripts[key] = value;
271
- const skipped = ["format", "format:check"].filter((k) => !(k in missing));
272
- for (const key of skipped) log.warn(`\`${key}\` script already exists in package.json - skipping`);
273
- if (Object.keys(missing).length > 0) writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
274
- }
275
- //#endregion
276
241
  //#region src/commands/brew/index.ts
277
242
  async function brew(cwd = process.cwd()) {
278
243
  intro(pc.magenta("🧋 Chanom - Let's brew your project!"));
@@ -297,20 +262,10 @@ async function brew(cwd = process.cwd()) {
297
262
  label: "oxfmt",
298
263
  hint: "fast Rust-based formatter"
299
264
  },
300
- {
301
- value: "eslint",
302
- label: "eslint",
303
- hint: "stub config"
304
- },
305
- {
306
- value: "prettier",
307
- label: "prettier",
308
- hint: "stub config"
309
- },
310
265
  {
311
266
  value: "knip",
312
267
  label: "knip",
313
- hint: "stub config"
268
+ hint: "dead code remover"
314
269
  }
315
270
  ],
316
271
  required: false
@@ -332,12 +287,10 @@ async function brew(cwd = process.cwd()) {
332
287
  const { pkg } = readPkg(cwd);
333
288
  const esm = isEsm(pkg);
334
289
  const packages = [];
335
- if (toppings.includes("oxlint")) packages.push(...getPackages$1(pkg));
336
- if (toppings.includes("oxfmt")) packages.push(...getPackages$2(pkg));
337
- if (toppings.includes("eslint")) packages.push(...getPackages$6(pkg));
338
- if (toppings.includes("prettier")) packages.push(...getPackages(pkg));
339
- if (toppings.includes("knip")) packages.push(...getPackages$4(pkg));
340
- if (sweetness === "medium") packages.push(...getPackages$5(pkg), ...getPackages$3(pkg), ...getPackages$7(pkg));
290
+ if (toppings.includes("oxlint")) packages.push(...getPackages(pkg));
291
+ if (toppings.includes("oxfmt")) packages.push(...getPackages$1(pkg));
292
+ if (toppings.includes("knip")) packages.push(...getPackages$3(pkg));
293
+ if (sweetness === "medium") packages.push(...getPackages$4(pkg), ...getPackages$2(pkg), ...getPackages$5(pkg));
341
294
  if (packages.length > 0) {
342
295
  const s = spinner();
343
296
  const uniquePackages = Array.from(new Set(packages));
@@ -345,15 +298,13 @@ async function brew(cwd = process.cwd()) {
345
298
  installDev(pm, cwd, ...uniquePackages);
346
299
  s.stop("Packages installed");
347
300
  }
348
- if (toppings.includes("oxlint")) apply$1(cwd, esm);
349
- if (toppings.includes("oxfmt")) apply$2(cwd, esm);
350
- if (toppings.includes("eslint")) apply$6(cwd, esm);
351
- if (toppings.includes("prettier")) apply(cwd);
352
- if (toppings.includes("knip")) apply$4(cwd);
301
+ if (toppings.includes("oxlint")) apply(cwd, esm);
302
+ if (toppings.includes("oxfmt")) apply$1(cwd, esm);
303
+ if (toppings.includes("knip")) apply$3(cwd, esm);
353
304
  if (sweetness === "medium") {
354
- apply$5(cwd, pm);
355
- apply$3(cwd, toppings.filter((t) => ["oxlint", "eslint"].includes(t)), toppings.filter((t) => ["oxfmt", "prettier"].includes(t)));
356
- apply$7(cwd);
305
+ apply$4(cwd, pm);
306
+ apply$2(cwd, toppings.filter((t) => ["oxlint"].includes(t)), toppings.filter((t) => ["oxfmt"].includes(t)));
307
+ apply$5(cwd);
357
308
  }
358
309
  const s2 = spinner();
359
310
  s2.start("Committing changes...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chanom/cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "@types/node": "26.0.1",
21
21
  "tsdown": "0.22.3",
22
22
  "typescript": "6.0.3",
23
- "@chanom/dev-config": "0.0.2"
23
+ "@chanom/dev-config": "0.0.3"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "tsdown",