@solvro/config 1.9.0 → 1.10.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/cli/index.js CHANGED
@@ -1,46 +1,39 @@
1
1
  // src/cli/index.ts
2
2
  import * as p6 from "@clack/prompts";
3
- import { $ as $4 } from "execa";
4
- import { isPackageListed as isPackageListed2 } from "local-pkg";
5
3
  import c from "picocolors";
6
4
 
7
- // src/utils/get-project-type.ts
8
- import { isPackageExists } from "local-pkg";
9
- var getProjectType = () => {
10
- const isAdonis = isPackageExists("@adonisjs/core");
11
- const isNext = isPackageExists("next");
12
- if (isNext && isAdonis) {
13
- throw new Error(
14
- "You can't use both Adonis and Next.js in the same project"
15
- );
16
- }
17
- if (isAdonis) {
18
- return "adonis";
19
- }
20
- if (isNext) {
21
- return "next";
22
- }
23
- return "node";
24
- };
25
-
26
- // src/utils/git-root.ts
27
- import { execSync } from "node:child_process";
28
- var gitRoot = () => {
29
- const root = execSync("git rev-parse --show-toplevel").toString().trim();
30
- return root;
31
- };
32
-
33
5
  // src/utils/is-git-clean.ts
34
- import { execSync as execSync2 } from "node:child_process";
6
+ import { execSync } from "node:child_process";
35
7
  function isGitClean() {
36
8
  try {
37
- execSync2("git diff-index --quiet HEAD --");
9
+ execSync("git diff-index --quiet HEAD --");
38
10
  return true;
39
11
  } catch {
40
12
  return false;
41
13
  }
42
14
  }
43
15
 
16
+ // src/utils/package-json.ts
17
+ import * as p2 from "@clack/prompts";
18
+ import { $ } from "execa";
19
+ import {
20
+ getPackageInfo,
21
+ isPackageExists,
22
+ isPackageListed,
23
+ loadPackageJSON
24
+ } from "local-pkg";
25
+ import assert from "node:assert";
26
+ import { writeFile } from "node:fs/promises";
27
+ import path from "node:path";
28
+ import semver from "semver";
29
+
30
+ // src/utils/git-root.ts
31
+ import { execSync as execSync2 } from "node:child_process";
32
+ var gitRoot = () => {
33
+ const root2 = execSync2("git rev-parse --show-toplevel").toString().trim();
34
+ return root2;
35
+ };
36
+
44
37
  // src/utils/polish-confirm.ts
45
38
  import * as p from "@clack/prompts";
46
39
  var polishConfirm = async (props) => {
@@ -51,17 +44,141 @@ var polishConfirm = async (props) => {
51
44
  });
52
45
  };
53
46
 
54
- // src/cli/install-eslint.ts
55
- import * as p2 from "@clack/prompts";
56
- import { $ } from "execa";
57
- import { getPackageInfo } from "local-pkg";
58
- import { existsSync } from "node:fs";
59
- import * as fs from "node:fs/promises";
60
- import path from "node:path";
61
- import semver from "semver";
47
+ // src/utils/package-json.ts
62
48
  var $$ = $({
63
49
  cwd: gitRoot()
64
50
  });
51
+ var PackageJson = class {
52
+ json = null;
53
+ async load() {
54
+ const json = await loadPackageJSON(gitRoot());
55
+ if (json === null) {
56
+ p2.cancel(
57
+ "Nie znaleziono package.json. Upewnij si\u0119, \u017Ce jeste\u015B w katalogu projektu."
58
+ );
59
+ process.exit(1);
60
+ }
61
+ this.json = json;
62
+ }
63
+ hasPackage(pkg) {
64
+ return isPackageListed(pkg);
65
+ }
66
+ async doesSatisfies(pkg, version) {
67
+ await this.load();
68
+ assert(this.json !== null);
69
+ if (this.json.dependencies?.[pkg] === void 0) {
70
+ return false;
71
+ }
72
+ return semver.satisfies(this.json.dependencies[pkg], version);
73
+ }
74
+ async ensureESM() {
75
+ await this.load();
76
+ const isConfirmed = await polishConfirm({
77
+ message: `Tw\xF3j projekt nie u\u017Cywa ESM (brak type: "module" w package.json). Czy chcesz to doda\u0107? (Wymagane by kontynuowa\u0107)`
78
+ });
79
+ if (p2.isCancel(isConfirmed) || !isConfirmed) {
80
+ p2.cancel("Zmie\u0144 projekt na ESM i spr\xF3buj ponownie.");
81
+ process.exit(1);
82
+ }
83
+ assert(this.json !== null);
84
+ this.json.type = "module";
85
+ await this.save();
86
+ }
87
+ async getProjectType() {
88
+ const isAdonis = isPackageExists("@adonisjs/core");
89
+ const isNext = isPackageExists("next");
90
+ if (isNext && isAdonis) {
91
+ throw new Error(
92
+ "You can't use both Adonis and Next.js in the same project"
93
+ );
94
+ }
95
+ if (isAdonis) {
96
+ return "adonis";
97
+ }
98
+ if (isNext) {
99
+ return "next";
100
+ }
101
+ return "node";
102
+ }
103
+ async save() {
104
+ await writeFile(
105
+ path.join(gitRoot(), "package.json"),
106
+ JSON.stringify(this.json, null, 2)
107
+ );
108
+ }
109
+ async addScriptIfNotExists(name, script) {
110
+ await this.load();
111
+ assert(this.json !== null);
112
+ if (this.json.scripts?.[name] !== void 0) {
113
+ return;
114
+ }
115
+ this.json.scripts = this.json.scripts ?? {};
116
+ this.json.scripts[name] = script;
117
+ await this.save();
118
+ }
119
+ async install(pkg, options) {
120
+ const info = await getPackageInfo(pkg);
121
+ if (info?.version !== void 0 && options?.minVersion !== void 0) {
122
+ if (!semver.satisfies(info.version, options.minVersion)) {
123
+ const spinner3 = p2.spinner();
124
+ spinner3.start(`Aktualizowanie ${pkg}`);
125
+ await $$`npm i ${options.dev === true ? "-D" : ""}@latest ${pkg}`;
126
+ spinner3.stop(`${pkg} zaktualizowany \u{1F60D}`);
127
+ await this.load();
128
+ return;
129
+ } else {
130
+ return;
131
+ }
132
+ }
133
+ if (info !== void 0) {
134
+ return;
135
+ }
136
+ const spinner2 = p2.spinner();
137
+ spinner2.start(`Instalowanie ${pkg}`);
138
+ await $$`npm i ${options?.dev === true ? "-D" : ""}@latest ${pkg}`;
139
+ spinner2.stop(`${pkg} zainstalowany \u{1F60D}`);
140
+ await this.load();
141
+ }
142
+ };
143
+
144
+ // src/cli/install-commitlint.ts
145
+ import { writeFile as writeFile2 } from "fs/promises";
146
+ import path2 from "path";
147
+
148
+ // src/utils/$$.ts
149
+ import { $ as $2 } from "execa";
150
+ var $$2 = $2({
151
+ cwd: gitRoot()
152
+ });
153
+
154
+ // src/cli/templates/commitlint.ts
155
+ var commitlint = () => `export default {
156
+ extends: ["@solvro/config/commitlint"],
157
+ };
158
+ `;
159
+
160
+ // src/cli/install-commitlint.ts
161
+ var root = gitRoot();
162
+ var packageJson = new PackageJson();
163
+ var installCommitLint = async () => {
164
+ if (!await packageJson.hasPackage("husky")) {
165
+ await packageJson.install("husky", { dev: true });
166
+ await $$2`npx husky init`;
167
+ }
168
+ await packageJson.install("@commitlint/cli", { dev: true });
169
+ await packageJson.install("@commitlint/config-conventional", { dev: true });
170
+ await writeFile2(
171
+ path2.join(root, ".husky/commit-msg"),
172
+ 'npx commitlint --edit "$1"\n'
173
+ );
174
+ await writeFile2(path2.join(root, ".commitlintrc.js"), commitlint());
175
+ };
176
+
177
+ // src/cli/install-eslint.ts
178
+ import * as p3 from "@clack/prompts";
179
+ import { existsSync } from "node:fs";
180
+ import * as fs from "node:fs/promises";
181
+ import path3 from "node:path";
65
182
  var eslintConfigNames = [
66
183
  ".eslintrc.js",
67
184
  ".eslintrc.cjs",
@@ -76,75 +193,70 @@ var eslintConfigNames = [
76
193
  "eslint.config.mts",
77
194
  "eslint.config.cts"
78
195
  ];
196
+ var packageJson2 = new PackageJson();
79
197
  var installEslint = async () => {
80
- const root = gitRoot();
81
- const eslint = await getPackageInfo("eslint");
82
- if (typeof eslint?.version !== "string") {
83
- const isConfirmed = await polishConfirm({
84
- message: `Eslint nie jest zainstalowany. Czy chcesz go zainstalowa\u0107?`
85
- });
86
- if (p2.isCancel(isConfirmed) || !isConfirmed) {
87
- p2.cancel("Zainstaluj Eslint i spr\xF3buj ponownie.");
88
- process.exit(1);
89
- }
90
- const spinner4 = p2.spinner();
91
- spinner4.start("Instalowanie Eslint");
92
- await $$`npm i -D eslint`;
93
- spinner4.stop("Eslint zainstalowany");
94
- } else if (!semver.satisfies(eslint.version, ">=9")) {
95
- const isConfirmed = await polishConfirm({
96
- message: `Eslint jest zainstalowany, ale trzeba go zaktualizowa\u0107. Czy chcesz zaktualizowa\u0107?`
97
- });
98
- if (p2.isCancel(isConfirmed) || !isConfirmed) {
99
- p2.cancel("Zaktualizuj Eslint i spr\xF3buj ponownie.");
198
+ const root2 = gitRoot();
199
+ await packageJson2.load();
200
+ await packageJson2.install("eslint", { dev: true, minVersion: ">=9" });
201
+ const type = await packageJson2.getProjectType();
202
+ if (type === "next") {
203
+ const is15 = await packageJson2.doesSatisfies("next", ">=15");
204
+ if (!is15) {
205
+ p3.cancel(
206
+ "Next.js musi by\u0107 w conajmniej wersji 15. Zaktualizuj Next.js i spr\xF3buj ponownie.\nWi\u0119cej informacji tutaj: https://nextjs.org/docs/app/building-your-application/upgrading/version-15"
207
+ );
100
208
  process.exit(1);
101
209
  }
102
- const spinner4 = p2.spinner();
103
- spinner4.start("Aktualizowanie Eslinta");
104
- await $$`npm i -D eslint@latest`;
105
- spinner4.stop("Eslint zaktualizowany");
210
+ await packageJson2.install("@next/eslint-plugin-next", { dev: true });
106
211
  }
107
212
  const eslintConfig = eslintConfigNames.find(
108
- (configName) => existsSync(path.join(root, configName))
213
+ (configName) => existsSync(path3.join(root2, configName))
109
214
  );
110
215
  if (eslintConfig !== void 0) {
111
216
  const eslintContent = await fs.readFile(
112
- path.join(root, eslintConfig),
217
+ path3.join(root2, eslintConfig),
113
218
  "utf-8"
114
219
  );
115
220
  if (eslintContent.includes("export default solvro(")) {
116
- p2.note("Eslint jest ju\u017C skonfigurowany. Pomijam.");
221
+ p3.note("Eslint jest ju\u017C skonfigurowany. Pomijam.");
117
222
  return;
118
223
  } else {
119
224
  const isConfirmed = await polishConfirm({
120
225
  message: `Znaleziono plik konfiguracyjny Eslint. Czy chcesz go nadpisa\u0107?`
121
226
  });
122
- if (p2.isCancel(isConfirmed) || !isConfirmed) {
123
- p2.cancel("Nadpisz plik konfiguracyjny Eslint i spr\xF3buj ponownie.");
227
+ if (p3.isCancel(isConfirmed) || !isConfirmed) {
228
+ p3.cancel("Nadpisz plik konfiguracyjny Eslint i spr\xF3buj ponownie.");
124
229
  process.exit(1);
125
230
  }
126
- await fs.rm(path.join(root, eslintConfig));
231
+ await fs.rm(path3.join(root2, eslintConfig));
127
232
  }
128
233
  }
129
234
  await fs.writeFile(
130
- path.join(gitRoot(), "eslint.config.js"),
235
+ path3.join(gitRoot(), "eslint.config.js"),
131
236
  `import { solvro } from "@solvro/config/eslint";
132
237
 
133
238
  export default solvro();
134
239
  `
135
240
  );
136
- p2.note("Plik konfiguracyjny Eslint zosta\u0142 utworzony.");
241
+ p3.note("Plik konfiguracyjny Eslint zosta\u0142 utworzony.");
137
242
  };
138
243
 
139
244
  // src/cli/install-ga.ts
140
- import * as p3 from "@clack/prompts";
141
- import { loadPackageJSON } from "local-pkg";
245
+ import * as p4 from "@clack/prompts";
142
246
  import { existsSync as existsSync2 } from "node:fs";
143
247
  import * as fs2 from "node:fs/promises";
144
- import path2 from "node:path";
248
+ import path4 from "node:path";
249
+
250
+ // src/cli/templates/commit-lint-ci.ts
251
+ var commitLintCi = () => ` - name: Run commitlint check
252
+ run: npx commitlint -f \${{ github.event.pull_request.base.sha }}
253
+ `;
145
254
 
146
255
  // src/cli/templates/adonis-ci.ts
147
- var adonisCi = ({ nodeVersion }) => `name: CI
256
+ var adonisCi = ({
257
+ nodeVersion,
258
+ withCommitlint
259
+ }) => `name: CI
148
260
 
149
261
  on:
150
262
  push:
@@ -171,7 +283,7 @@ jobs:
171
283
  run: |
172
284
  cp .env.example .env
173
285
  node ace generate:key
174
-
286
+ ${withCommitlint ? commitLintCi() : ""}
175
287
  - name: Run prettier
176
288
  run: npm run format:check
177
289
  if: always()
@@ -204,7 +316,10 @@ updates:
204
316
  `;
205
317
 
206
318
  // src/cli/templates/next-ci.ts
207
- var nextCi = ({ nodeVersion }) => `name: CI
319
+ var nextCi = ({
320
+ nodeVersion,
321
+ withCommitlint
322
+ }) => `name: CI
208
323
 
209
324
  on:
210
325
  push:
@@ -226,7 +341,7 @@ jobs:
226
341
 
227
342
  - name: Install dependencies
228
343
  run: npm ci
229
-
344
+ ${withCommitlint ? commitLintCi() : ""}
230
345
  - name: Format check
231
346
  run: npm run format:check
232
347
  if: always()
@@ -236,116 +351,72 @@ jobs:
236
351
  if: always()`;
237
352
 
238
353
  // src/cli/install-ga.ts
354
+ var packageJson3 = new PackageJson();
239
355
  var installGithubActions = async () => {
240
- const root = gitRoot();
241
- const ghWorkflowsDir = path2.join(root, ".github/workflows");
356
+ const root2 = gitRoot();
357
+ await packageJson3.load();
358
+ const ghWorkflowsDir = path4.join(root2, ".github/workflows");
242
359
  await fs2.mkdir(ghWorkflowsDir, { recursive: true });
243
- const type = getProjectType();
360
+ const type = await packageJson3.getProjectType();
361
+ const withCommitlint = await packageJson3.hasPackage("@commitlint/cli");
244
362
  if (type === "adonis") {
245
- if (!existsSync2(path2.join(root, ".env.example"))) {
246
- p3.cancel(
363
+ if (!existsSync2(path4.join(root2, ".env.example"))) {
364
+ p4.cancel(
247
365
  "Nie znaleziono pliku .env.example. Upewnij si\u0119, \u017Ce jeste\u015B w katalogu projektu Adonisa."
248
366
  );
249
367
  process.exit(1);
250
368
  }
251
369
  await fs2.writeFile(
252
- path2.join(ghWorkflowsDir, "ci.yml"),
370
+ path4.join(ghWorkflowsDir, "ci.yml"),
253
371
  adonisCi({
254
- nodeVersion: "22"
372
+ nodeVersion: "22",
373
+ withCommitlint
255
374
  })
256
375
  );
257
376
  }
258
377
  if (type === "next") {
259
378
  await fs2.writeFile(
260
- path2.join(ghWorkflowsDir, "ci.yml"),
379
+ path4.join(ghWorkflowsDir, "ci.yml"),
261
380
  nextCi({
262
- nodeVersion: "22"
381
+ nodeVersion: "22",
382
+ withCommitlint
263
383
  })
264
384
  );
265
385
  }
266
- if (!existsSync2(path2.join(root, ".github/dependabot.yml"))) {
267
- await fs2.writeFile(path2.join(root, ".github/dependabot.yml"), dependabot());
386
+ if (!existsSync2(path4.join(root2, ".github/dependabot.yml"))) {
387
+ await fs2.writeFile(path4.join(root2, ".github/dependabot.yml"), dependabot());
268
388
  }
269
- const packageJson = await loadPackageJSON(root);
270
- if (packageJson === null) {
271
- p3.cancel(
272
- "Nie znaleziono package.json. Upewnij si\u0119, \u017Ce jeste\u015B w katalogu projektu."
273
- );
274
- process.exit(1);
275
- }
276
- packageJson.scripts = packageJson.scripts ?? {};
277
- if (!packageJson.scripts["format:check"]) {
278
- packageJson.scripts["format:check"] = "prettier --check .";
279
- }
280
- if (!packageJson.scripts.lint) {
281
- packageJson.scripts.lint = "eslint .";
282
- }
283
- if (!packageJson.scripts.format) {
284
- packageJson.scripts.format = "prettier --write .";
285
- }
286
- if (!packageJson.scripts.typecheck) {
287
- packageJson.scripts.typecheck = "tsc --noEmit";
288
- }
289
- await fs2.writeFile(
290
- path2.join(root, "package.json"),
291
- JSON.stringify(packageJson, null, 2)
292
- );
293
- p3.note("Dodano konfiguracj\u0119 CI i skrypty.");
389
+ await packageJson3.addScriptIfNotExists("format:check", "prettier --check .");
390
+ await packageJson3.addScriptIfNotExists("lint", "eslint . --max-warnings=0");
391
+ await packageJson3.addScriptIfNotExists("format", "prettier --write .");
392
+ await packageJson3.addScriptIfNotExists("typecheck", "tsc --noEmit");
393
+ p4.note("Dodano konfiguracj\u0119 CI i skrypty.");
294
394
  };
295
395
 
296
396
  // src/cli/install-lint-staged.ts
297
- import * as p4 from "@clack/prompts";
298
- import { $ as $2 } from "execa";
299
- import { writeFile as writeFile3 } from "fs/promises";
300
- import { isPackageListed, loadPackageJSON as loadPackageJSON2 } from "local-pkg";
301
- import path3 from "path";
302
- var $$2 = $2({
303
- cwd: gitRoot()
304
- });
397
+ import assert2 from "assert";
398
+ import { writeFile as writeFile5 } from "fs/promises";
399
+ var packageJson4 = new PackageJson();
305
400
  var installLintStaged = async () => {
306
- const lintStaged = await isPackageListed("lint-staged");
307
- const husky = await isPackageListed("husky");
308
- if (!lintStaged) {
309
- const spinner4 = p4.spinner();
310
- spinner4.start("Instalowanie lint-staged");
311
- await $$2`npm i -D lint-staged`;
312
- spinner4.stop("lint-staged zainstalowany");
313
- }
314
- if (!husky) {
315
- const spinner4 = p4.spinner();
316
- spinner4.start("Instalowanie husky");
317
- await $$2`npm i -D husky`;
318
- await $2`npx husky init`;
319
- spinner4.stop("husky zainstalowany");
401
+ await packageJson4.load();
402
+ assert2(packageJson4.json !== null);
403
+ if (!await packageJson4.hasPackage("husky")) {
404
+ await packageJson4.install("husky");
405
+ await $$2`npx husky init`;
320
406
  }
321
- await writeFile3(".husky/pre-commit", "npx lint-staged\n");
322
- const packageJson = await loadPackageJSON2(gitRoot());
323
- if (packageJson === null) {
324
- p4.cancel(
325
- "Nie znaleziono package.json. Upewnij si\u0119, \u017Ce jeste\u015B w katalogu projektu."
326
- );
327
- process.exit(1);
328
- }
329
- packageJson["lint-staged"] = {
407
+ await writeFile5(".husky/pre-commit", "npx lint-staged\n");
408
+ packageJson4.json["lint-staged"] = {
330
409
  "*": "prettier -w --ignore-unknown"
331
410
  };
332
- await writeFile3(
333
- path3.join(gitRoot(), "package.json"),
334
- JSON.stringify(packageJson, null, 2)
335
- );
411
+ await packageJson4.save();
336
412
  };
337
413
 
338
414
  // src/cli/install-prettier.ts
339
415
  import * as p5 from "@clack/prompts";
340
- import { $ as $3 } from "execa";
341
- import { getPackageInfo as getPackageInfo2, loadPackageJSON as loadPackageJSON3 } from "local-pkg";
416
+ import assert3 from "node:assert";
342
417
  import { existsSync as existsSync3 } from "node:fs";
343
418
  import * as fs3 from "node:fs/promises";
344
- import path4 from "node:path";
345
- import semver2 from "semver";
346
- var $$3 = $3({
347
- cwd: gitRoot()
348
- });
419
+ import path5 from "node:path";
349
420
  var prettierConfigNames = [
350
421
  ".prettierrc.js",
351
422
  ".prettierrc.cjs",
@@ -360,46 +431,17 @@ var prettierConfigNames = [
360
431
  "prettier.config.mts",
361
432
  "prettier.config.cts"
362
433
  ];
434
+ var packageJson5 = new PackageJson();
363
435
  var installPrettier = async () => {
364
- const root = gitRoot();
365
- const packageJsonPath = path4.join(root, "package.json");
366
- const prettier = await getPackageInfo2("prettier");
367
- if (typeof prettier?.version !== "string") {
368
- const isConfirmed = await polishConfirm({
369
- message: `Prettier nie jest zainstalowany. Czy chcesz go zainstalowa\u0107?`
370
- });
371
- if (p5.isCancel(isConfirmed) || !isConfirmed) {
372
- p5.cancel("Zainstaluj Prettiera i spr\xF3buj ponownie.");
373
- process.exit(1);
374
- }
375
- const spinner4 = p5.spinner();
376
- spinner4.start("Instalowanie Prettiera");
377
- await $$3`npm i -D prettier`;
378
- spinner4.stop("Prettiera zainstalowany");
379
- } else if (!semver2.satisfies(prettier.version, ">=3")) {
380
- const isConfirmed = await polishConfirm({
381
- message: `Prettier jest zainstalowany, ale trzeba go zaktualizowa\u0107. Czy chcesz zaktualizowa\u0107?`
382
- });
383
- if (p5.isCancel(isConfirmed) || !isConfirmed) {
384
- p5.cancel("Zaktualizuj Prettiera i spr\xF3buj ponownie.");
385
- process.exit(1);
386
- }
387
- const spinner4 = p5.spinner();
388
- spinner4.start("Aktualizowanie Prettiera");
389
- await $$3`npm i -D eslint@latest`;
390
- spinner4.stop("Prettier zaktualizowany");
391
- }
436
+ const root2 = gitRoot();
437
+ await packageJson5.load();
438
+ assert3(packageJson5.json !== null);
392
439
  const prettierConfig = prettierConfigNames.find(
393
- (configName) => existsSync3(path4.join(root, configName))
440
+ (configName) => existsSync3(path5.join(root2, configName))
394
441
  );
395
- const packageJson = await loadPackageJSON3();
396
- if (packageJson === null) {
397
- p5.cancel("Nie znaleziono pliku package.json.");
398
- process.exit(1);
399
- }
400
442
  const solvroPrettierPath = "@solvro/config/prettier";
401
- if (prettierConfig !== void 0 || packageJson.prettier !== void 0) {
402
- if (packageJson.prettier === solvroPrettierPath) {
443
+ if (prettierConfig !== void 0 || packageJson5.json.prettier !== void 0) {
444
+ if (packageJson5.json.prettier === solvroPrettierPath) {
403
445
  p5.note("Konfiguracja Prettiera jest ju\u017C ustawiona. Pomijam.");
404
446
  return;
405
447
  }
@@ -411,22 +453,16 @@ var installPrettier = async () => {
411
453
  process.exit(1);
412
454
  }
413
455
  for (const configName of prettierConfigNames) {
414
- await fs3.rm(path4.join(root, configName)).catch(() => null);
456
+ await fs3.rm(path5.join(root2, configName)).catch(() => null);
415
457
  }
416
458
  }
417
- const newPackageJson = await loadPackageJSON3();
418
- if (newPackageJson === null) {
419
- p5.cancel("Nie znaleziono pliku package.json.");
420
- process.exit(1);
421
- }
422
- newPackageJson.prettier = solvroPrettierPath;
423
- await fs3.writeFile(packageJsonPath, JSON.stringify(newPackageJson, null, 2));
459
+ packageJson5.json.prettier = solvroPrettierPath;
460
+ await packageJson5.save();
424
461
  p5.note("Konfiguracja Prettiera zosta\u0142a dodana.");
425
462
  };
426
463
 
427
464
  // src/cli/index.ts
428
465
  p6.intro(c.bold(c.bgBlue(" @solvro/config ")));
429
- var projectType = getProjectType();
430
466
  if (!isGitClean()) {
431
467
  const isConfirmed = await polishConfirm({
432
468
  message: `Masz niezapisane zmiany w Git. Czy chcesz kontynuowa\u0107?`
@@ -436,6 +472,9 @@ if (!isGitClean()) {
436
472
  process.exit(1);
437
473
  }
438
474
  }
475
+ var packageJson6 = new PackageJson();
476
+ await packageJson6.ensureESM();
477
+ var projectType = await packageJson6.getProjectType();
439
478
  if (projectType === "adonis") {
440
479
  const isConfirmed = await polishConfirm({
441
480
  message: `Wygl\u0105da jakby\u015B u\u017Cywa\u0142 Adonisa. Czy to si\u0119 zgadza?`
@@ -466,7 +505,7 @@ if (projectType === "node") {
466
505
  }
467
506
  var additionalTools = await p6.multiselect({
468
507
  message: `Kt\xF3re rzeczy Ci\u0119 interesuj\u0105? ${c.gray("zaznacz spacj\u0105, potwierd\u017A enterem")}`,
469
- initialValues: ["eslint", "prettier", "gh-action"],
508
+ initialValues: ["eslint", "prettier", "gh-action", "commitlint"],
470
509
  options: [
471
510
  {
472
511
  value: "eslint",
@@ -482,26 +521,20 @@ var additionalTools = await p6.multiselect({
482
521
  value: "gh-action",
483
522
  label: c.bold("GitHub Actions"),
484
523
  hint: "automatyczne testy na Githubie"
524
+ },
525
+ {
526
+ value: "commitlint",
527
+ label: c.bold("Commitlint"),
528
+ hint: "walidacja tre\u015Bci commit\xF3w"
485
529
  }
486
530
  ],
487
531
  required: false
488
532
  });
489
- var $$4 = $4({
490
- cwd: gitRoot()
491
- });
492
- if (p6.isCancel(additionalTools)) {
533
+ if (p6.isCancel(additionalTools) || additionalTools.length === 0) {
493
534
  p6.cancel("Nie wybrano \u017Cadnych narz\u0119dzi.");
494
535
  process.exit(1);
495
536
  }
496
- await p6.tasks([
497
- {
498
- title: "Instalowanie @solvro/config",
499
- enabled: !await isPackageListed2("@solvro/config"),
500
- task: async () => {
501
- await $$4`npm i -D @solvro/config`;
502
- }
503
- }
504
- ]);
537
+ await packageJson6.install("@solvro/config", { dev: true });
505
538
  if (additionalTools.includes("eslint")) {
506
539
  await installEslint();
507
540
  }
@@ -509,6 +542,10 @@ if (additionalTools.includes("prettier")) {
509
542
  await installPrettier();
510
543
  await installLintStaged();
511
544
  }
545
+ if (additionalTools.includes("commitlint")) {
546
+ await installCommitLint();
547
+ }
512
548
  if (additionalTools.includes("gh-action")) {
513
549
  await installGithubActions();
514
550
  }
551
+ //# sourceMappingURL=index.js.map