@solvro/config 2.0.4 → 2.0.5

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.
@@ -0,0 +1,997 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // src/cli/index.ts
26
+ var p6 = __toESM(require("@clack/prompts"), 1);
27
+ var import_commander = require("commander");
28
+ var import_detect = require("package-manager-detector/detect");
29
+ var import_picocolors = __toESM(require("picocolors"), 1);
30
+
31
+ // package.json
32
+ var package_default = {
33
+ name: "@solvro/config",
34
+ version: "2.0.4",
35
+ description: "Solvro's engineering style guide",
36
+ keywords: [
37
+ "eslint",
38
+ "prettier",
39
+ "solvro"
40
+ ],
41
+ homepage: "https://github.com/Solvro/lib-web-solvro-config#readme",
42
+ bugs: {
43
+ url: "https://github.com/Solvro/lib-web-solvro-config/issues"
44
+ },
45
+ repository: {
46
+ type: "git",
47
+ url: "git+https://github.com/Solvro/lib-web-solvro-config.git"
48
+ },
49
+ license: "MPL-2.0",
50
+ type: "module",
51
+ exports: {
52
+ "./eslint": {
53
+ types: "./dist/eslint/index.d.ts",
54
+ import: "./dist/eslint/index.js",
55
+ require: "./dist/eslint/index.cjs"
56
+ },
57
+ "./prettier": {
58
+ types: "./dist/prettier/index.d.ts",
59
+ import: "./dist/prettier/index.js",
60
+ require: "./dist/prettier/index.cjs"
61
+ },
62
+ "./commitlint": {
63
+ types: "./dist/commitlint/index.d.ts",
64
+ import: "./dist/commitlint/index.js",
65
+ require: "./dist/commitlint/index.cjs"
66
+ }
67
+ },
68
+ bin: "./bin/index.js",
69
+ files: [
70
+ "dist"
71
+ ],
72
+ scripts: {
73
+ build: "tsup",
74
+ "build:watch": "tsup --watch",
75
+ cli: "tsx ./src/cli/index.ts",
76
+ dev: "npx @eslint/config-inspector",
77
+ format: "prettier --check .",
78
+ knip: "knip",
79
+ lint: "eslint .",
80
+ prepare: "husky || true",
81
+ prepublish: "npm run build",
82
+ release: "semantic-release",
83
+ test: "vitest run",
84
+ "test:ui": "vitest --ui",
85
+ "test:watch": "vitest",
86
+ typecheck: "tsc --noEmit"
87
+ },
88
+ "lint-staged": {
89
+ "*": "prettier -w --ignore-unknown"
90
+ },
91
+ prettier: "./dist/prettier/index.js",
92
+ dependencies: {
93
+ "@adonisjs/eslint-config": "^2.1.0",
94
+ "@clack/prompts": "^0.11.0",
95
+ "@commitlint/config-conventional": "^19.8.1",
96
+ "@darraghor/eslint-plugin-nestjs-typed": "^6.7.0",
97
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
98
+ "@eslint/js": "^9.30.1",
99
+ "@tanstack/eslint-plugin-query": "^5.81.2",
100
+ "@trivago/prettier-plugin-sort-imports": "^5.2.2",
101
+ "@typescript-eslint/eslint-plugin": "^8.35.1",
102
+ commander: "^14.0.0",
103
+ "eslint-config-flat-gitignore": "^2.1.0",
104
+ "eslint-config-prettier": "^10.1.5",
105
+ "eslint-plugin-antfu": "^3.1.1",
106
+ "eslint-plugin-import": "^2.32.0",
107
+ "eslint-plugin-jsdoc": "^51.3.3",
108
+ "eslint-plugin-jsx-a11y": "^6.10.2",
109
+ "eslint-plugin-n": "^17.21.0",
110
+ "eslint-plugin-react": "^7.37.5",
111
+ "eslint-plugin-react-hooks": "^5.2.0",
112
+ "eslint-plugin-react-refresh": "^0.4.16",
113
+ "eslint-plugin-react-you-might-not-need-an-effect": "^0.4.1",
114
+ "eslint-plugin-unicorn": "^59.0.1",
115
+ "eslint-plugin-unused-imports": "^4.1.4",
116
+ execa: "^9.6.0",
117
+ "find-up-simple": "^1.0.1",
118
+ globals: "^16.3.0",
119
+ "is-interactive": "^2.0.0",
120
+ "local-pkg": "^1.1.1",
121
+ "package-manager-detector": "^1.3.0",
122
+ picocolors: "^1.1.1",
123
+ "prettier-plugin-packagejson": "^2.5.18",
124
+ "prettier-plugin-tailwindcss": "^0.6.13",
125
+ semver: "^7.7.2",
126
+ "typescript-eslint": "^8.35.1"
127
+ },
128
+ devDependencies: {
129
+ "@commitlint/cli": "^19.8.1",
130
+ "@eslint/config-inspector": "^1.1.0",
131
+ "@next/eslint-plugin-next": "^15.3.5",
132
+ "@semantic-release/git": "^10.0.1",
133
+ "@types/node": "^24.0.10",
134
+ "@types/semver": "^7.7.0",
135
+ "@vitest/coverage-v8": "^3.2.4",
136
+ "@vitest/ui": "^3.2.4",
137
+ eslint: "^9.30.1",
138
+ husky: "^9.1.7",
139
+ knip: "^5.61.3",
140
+ "lint-staged": "^16.1.2",
141
+ "pkg-pr-new": "^0.0.58",
142
+ prettier: "^3.6.2",
143
+ "semantic-release": "^24.2.6",
144
+ tsup: "^8.5.0",
145
+ tsx: "^4.20.3",
146
+ typescript: "^5.8.3",
147
+ vitest: "^3.2.4"
148
+ },
149
+ peerDependencies: {
150
+ "@next/eslint-plugin-next": ">=12.3.0 <16.0.0-0",
151
+ eslint: ">=9.0.0 <10.0.0"
152
+ },
153
+ packageManager: "npm@11.4.2",
154
+ engines: {
155
+ node: "^20.19.0 || >=22.12.0"
156
+ },
157
+ volta: {
158
+ node: "22.17.0"
159
+ },
160
+ publishConfig: {
161
+ access: "public"
162
+ }
163
+ };
164
+
165
+ // src/utils/is-git-clean.ts
166
+ var import_node_child_process = require("child_process");
167
+ function isGitClean() {
168
+ try {
169
+ (0, import_node_child_process.execSync)("git diff-index --quiet HEAD --");
170
+ return true;
171
+ } catch {
172
+ return false;
173
+ }
174
+ }
175
+
176
+ // src/utils/package-json.ts
177
+ var p = __toESM(require("@clack/prompts"), 1);
178
+ var import_local_pkg = require("local-pkg");
179
+ var import_node_assert = __toESM(require("assert"), 1);
180
+ var import_promises = require("fs/promises");
181
+ var import_node_path2 = __toESM(require("path"), 1);
182
+ var import_semver = __toESM(require("semver"), 1);
183
+
184
+ // src/utils/git-root.ts
185
+ var import_find_up_simple = require("find-up-simple");
186
+ var import_node_child_process2 = require("child_process");
187
+ var import_node_path = __toESM(require("path"), 1);
188
+ var projectRoot = () => {
189
+ const packageJsonPath = (0, import_find_up_simple.findUpSync)("package.json");
190
+ if (packageJsonPath !== void 0) {
191
+ return import_node_path.default.dirname(packageJsonPath);
192
+ }
193
+ return process.cwd();
194
+ };
195
+ var gitRoot = () => {
196
+ try {
197
+ const rootDirectory = (0, import_node_child_process2.execSync)("git rev-parse --show-toplevel", {
198
+ cwd: projectRoot()
199
+ });
200
+ return rootDirectory.toString().trim();
201
+ } catch {
202
+ return projectRoot();
203
+ }
204
+ };
205
+
206
+ // src/utils/$$.ts
207
+ var cachedExeca = null;
208
+ var $$ = async (...arguments_) => {
209
+ if (cachedExeca === null) {
210
+ const { $ } = await import("execa");
211
+ cachedExeca = $({
212
+ cwd: projectRoot()
213
+ });
214
+ }
215
+ return cachedExeca(...arguments_);
216
+ };
217
+
218
+ // src/utils/run-if-interactive.ts
219
+ var import_is_interactive = __toESM(require("is-interactive"), 1);
220
+ var runIfInteractive = (function_) => {
221
+ if ((0, import_is_interactive.default)()) {
222
+ return function_();
223
+ }
224
+ return void 0;
225
+ };
226
+
227
+ // src/utils/package-json.ts
228
+ var PackageJson = class {
229
+ json = null;
230
+ async load() {
231
+ const json = await (0, import_local_pkg.loadPackageJSON)(projectRoot());
232
+ if (json === null) {
233
+ p.cancel(
234
+ "Nie znaleziono package.json. Upewnij si\u0119, \u017Ce jeste\u015B w katalogu projektu."
235
+ );
236
+ process.exit(1);
237
+ }
238
+ this.json = json;
239
+ }
240
+ hasPackage(package_) {
241
+ return (0, import_local_pkg.isPackageListed)(package_);
242
+ }
243
+ async doesSatisfies(package_, version) {
244
+ await this.load();
245
+ import_node_assert.default.ok(this.json !== null);
246
+ const packageInfo = await (0, import_local_pkg.getPackageInfo)(package_);
247
+ if (packageInfo?.version === void 0) {
248
+ return false;
249
+ }
250
+ return import_semver.default.satisfies(packageInfo.version, version);
251
+ }
252
+ async isESM() {
253
+ await this.load();
254
+ import_node_assert.default.ok(this.json !== null);
255
+ return this.json.type === "module";
256
+ }
257
+ async ensureESM() {
258
+ if (await this.isESM()) {
259
+ return;
260
+ }
261
+ import_node_assert.default.ok(this.json !== null);
262
+ this.json.type = "module";
263
+ await this.save();
264
+ }
265
+ async getProjectType() {
266
+ const isAdonis = await (0, import_local_pkg.isPackageListed)("@adonisjs/core");
267
+ const isReact = await (0, import_local_pkg.isPackageListed)("react");
268
+ const isNestJs = await (0, import_local_pkg.isPackageListed)("@nestjs/core");
269
+ if (isReact && isAdonis) {
270
+ throw new Error(
271
+ "You can't use both Adonis and React in the same project"
272
+ );
273
+ }
274
+ if (isNestJs) {
275
+ return "nestjs";
276
+ }
277
+ if (isAdonis) {
278
+ return "adonis";
279
+ }
280
+ if (isReact) {
281
+ return "react";
282
+ }
283
+ return "node";
284
+ }
285
+ async save() {
286
+ await (0, import_promises.writeFile)(
287
+ import_node_path2.default.join(projectRoot(), "package.json"),
288
+ JSON.stringify(this.json, null, 2)
289
+ );
290
+ }
291
+ async addScriptIfNotExists(name, script) {
292
+ await this.load();
293
+ import_node_assert.default.ok(this.json !== null);
294
+ if (this.json.scripts?.[name] !== void 0) {
295
+ return;
296
+ }
297
+ this.json.scripts = this.json.scripts ?? {};
298
+ this.json.scripts[name] = script;
299
+ await this.save();
300
+ }
301
+ async install(package_, options2) {
302
+ const isInstalled = await this.hasPackage(package_);
303
+ if (!isInstalled) {
304
+ const spinner2 = p.spinner();
305
+ runIfInteractive(() => {
306
+ spinner2.start(`Instalowanie ${package_}`);
307
+ });
308
+ await $$`npm i ${options2?.dev === true ? "-D" : ""} ${package_}@latest`;
309
+ runIfInteractive(() => {
310
+ spinner2.stop(`${package_} zainstalowany \u{1F60D}`);
311
+ });
312
+ await this.load();
313
+ return;
314
+ }
315
+ const info = await (0, import_local_pkg.getPackageInfo)(package_);
316
+ if (info?.version !== void 0 && options2?.minVersion !== void 0 && !import_semver.default.satisfies(info.version, options2.minVersion) || options2?.alwaysUpdate === true) {
317
+ const spinner2 = p.spinner();
318
+ runIfInteractive(() => {
319
+ spinner2.start(`Aktualizowanie ${package_}`);
320
+ });
321
+ await $$`npm i ${options2.dev === true ? "-D" : ""} ${package_}@latest`;
322
+ runIfInteractive(() => {
323
+ spinner2.stop(`${package_} zaktualizowany \u{1F60D}`);
324
+ });
325
+ await this.load();
326
+ }
327
+ }
328
+ async clearInstall() {
329
+ await $$`npm ci`;
330
+ }
331
+ };
332
+
333
+ // src/utils/polish-confirm.ts
334
+ var p2 = __toESM(require("@clack/prompts"), 1);
335
+ var import_is_interactive2 = __toESM(require("is-interactive"), 1);
336
+ var polishConfirm = async (props) => {
337
+ if (!(0, import_is_interactive2.default)()) {
338
+ return true;
339
+ }
340
+ return p2.confirm({
341
+ active: "Tak",
342
+ inactive: "Nie",
343
+ ...props
344
+ });
345
+ };
346
+
347
+ // src/cli/install-commitlint.ts
348
+ var import_promises2 = require("fs/promises");
349
+ var import_node_path3 = __toESM(require("path"), 1);
350
+
351
+ // src/cli/install-husky.ts
352
+ var import_node_assert2 = __toESM(require("assert"), 1);
353
+ var packageJson = new PackageJson();
354
+ var installHusky = async () => {
355
+ if (!await packageJson.hasPackage("husky")) {
356
+ await packageJson.install("husky", { dev: true });
357
+ await $$`npx husky init`;
358
+ }
359
+ await packageJson.load();
360
+ import_node_assert2.default.ok(packageJson.json !== null);
361
+ packageJson.json.scripts = packageJson.json.scripts ?? {};
362
+ packageJson.json.scripts.prepare = `husky || true`;
363
+ await packageJson.save();
364
+ };
365
+
366
+ // src/cli/templates/commitlint.ts
367
+ var commitlint = () => `export default {
368
+ extends: ["@solvro/config/commitlint"],
369
+ };
370
+ `;
371
+
372
+ // src/cli/install-commitlint.ts
373
+ var root = projectRoot();
374
+ var packageJson2 = new PackageJson();
375
+ var installCommitLint = async () => {
376
+ await installHusky();
377
+ await packageJson2.install("@commitlint/cli", { dev: true });
378
+ await (0, import_promises2.writeFile)(
379
+ import_node_path3.default.join(root, ".husky/commit-msg"),
380
+ 'npx commitlint --edit "$1"\n'
381
+ );
382
+ await (0, import_promises2.writeFile)(import_node_path3.default.join(root, ".commitlintrc.js"), commitlint());
383
+ };
384
+
385
+ // src/cli/install-eslint.ts
386
+ var p3 = __toESM(require("@clack/prompts"), 1);
387
+ var import_node_fs = require("fs");
388
+ var fs = __toESM(require("fs/promises"), 1);
389
+ var import_node_path4 = __toESM(require("path"), 1);
390
+ var eslintConfigNames = [
391
+ ".eslintrc.js",
392
+ ".eslintrc.cjs",
393
+ ".eslintrc.yaml",
394
+ ".eslintrc.yml",
395
+ ".eslintrc.json",
396
+ ".eslintrc",
397
+ "eslint.config.js",
398
+ "eslint.config.mjs",
399
+ "eslint.config.cjs",
400
+ "eslint.config.ts",
401
+ "eslint.config.mts",
402
+ "eslint.config.cts"
403
+ ];
404
+ var packageJson3 = new PackageJson();
405
+ var installEslint = async (isNonInteractive2 = false) => {
406
+ const root2 = projectRoot();
407
+ await packageJson3.load();
408
+ await packageJson3.install("eslint", { dev: true, minVersion: ">=9" });
409
+ const type = await packageJson3.getProjectType();
410
+ if (type === "react" && await packageJson3.hasPackage("next")) {
411
+ const is15 = await packageJson3.doesSatisfies("next", ">=15");
412
+ if (!is15) {
413
+ p3.cancel(
414
+ "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"
415
+ );
416
+ process.exit(1);
417
+ }
418
+ await packageJson3.install("@next/eslint-plugin-next", { dev: true });
419
+ }
420
+ const eslintConfig = eslintConfigNames.find(
421
+ (configName) => (0, import_node_fs.existsSync)(import_node_path4.default.join(root2, configName))
422
+ );
423
+ if (eslintConfig !== void 0) {
424
+ const eslintContent = await fs.readFile(
425
+ import_node_path4.default.join(root2, eslintConfig),
426
+ "utf8"
427
+ );
428
+ if (eslintContent.includes("export default solvro(")) {
429
+ p3.note("Eslint jest ju\u017C skonfigurowany. Pomijam.");
430
+ return;
431
+ } else {
432
+ if (isNonInteractive2) {
433
+ await fs.rm(import_node_path4.default.join(root2, eslintConfig));
434
+ } else {
435
+ const isConfirmed = await polishConfirm({
436
+ message: `Znaleziono plik konfiguracyjny Eslint. Czy chcesz go nadpisa\u0107?`
437
+ });
438
+ if (p3.isCancel(isConfirmed) || !isConfirmed) {
439
+ p3.cancel("Nadpisz plik konfiguracyjny Eslint i spr\xF3buj ponownie.");
440
+ process.exit(1);
441
+ }
442
+ await fs.rm(import_node_path4.default.join(root2, eslintConfig));
443
+ }
444
+ }
445
+ }
446
+ const isESM = await packageJson3.isESM();
447
+ const eslintFilename = isESM ? "eslint.config.js" : "eslint.config.mjs";
448
+ await fs.writeFile(
449
+ import_node_path4.default.join(root2, eslintFilename),
450
+ `import { solvro } from "@solvro/config/eslint";
451
+
452
+ export default solvro();
453
+ `
454
+ );
455
+ p3.note("Plik konfiguracyjny Eslint zosta\u0142 utworzony.");
456
+ };
457
+
458
+ // src/cli/install-ga.ts
459
+ var p4 = __toESM(require("@clack/prompts"), 1);
460
+ var import_node_fs2 = require("fs");
461
+ var fs2 = __toESM(require("fs/promises"), 1);
462
+ var import_node_path5 = __toESM(require("path"), 1);
463
+
464
+ // src/cli/templates/commit-lint-ci.ts
465
+ var commitLintCi = () => `
466
+ - name: Check commit name
467
+ if: github.event_name == 'pull_request'
468
+ run: npx commitlint --from \${{ github.event.pull_request.base.sha }} --to \${{ github.event.pull_request.head.sha }} --verbose
469
+ `;
470
+
471
+ // src/cli/templates/adonis-ci.ts
472
+ var adonisCi = ({
473
+ nodeVersion,
474
+ withCommitlint
475
+ }) => `name: CI
476
+
477
+ on:
478
+ push:
479
+ branches: ["main"]
480
+ pull_request:
481
+
482
+ jobs:
483
+ lint:
484
+ runs-on: ubuntu-latest
485
+ steps:
486
+ - name: Checkout
487
+ uses: actions/checkout@v4
488
+ with:
489
+ fetch-depth: 0
490
+
491
+ - name: Setup node
492
+ uses: actions/setup-node@v4
493
+ with:
494
+ node-version: ${nodeVersion}
495
+ cache: "npm"
496
+
497
+ - name: Install dependencies
498
+ run: npm ci
499
+
500
+ - name: Set up AdonisJS environment
501
+ run: |
502
+ cp .env.example .env
503
+ node ace generate:key
504
+ ${withCommitlint ? commitLintCi() : ""}
505
+ - name: Run prettier
506
+ run: npm run format:check
507
+ if: always()
508
+
509
+ - name: Run Lint
510
+ run: npm run lint
511
+ if: always()
512
+
513
+ - name: Check types
514
+ run: npm run typecheck
515
+ if: always()
516
+
517
+ - name: Run tests
518
+ run: npm test
519
+ if: always()
520
+
521
+ - name: Build
522
+ run: npm run build
523
+ if: always()`;
524
+
525
+ // src/cli/templates/adonis-ci-migrations.ts
526
+ var adonisMigrationsCi = () => `name: Migration check
527
+
528
+ on:
529
+ pull_request:
530
+ branches: ["*"]
531
+ push:
532
+ branches: ["main"]
533
+
534
+ jobs:
535
+ migration-check:
536
+ runs-on: ubuntu-latest
537
+ env:
538
+ DB_HOST: 127.0.0.1
539
+ DB_PORT: 5432
540
+ DB_USER: postgres
541
+ DB_PASSWORD: postgres
542
+ DB_DATABASE: postgres
543
+
544
+ services:
545
+ postgres:
546
+ image: postgres
547
+ env:
548
+ POSTGRES_PASSWORD: postgres
549
+ options: >-
550
+ --health-cmd pg_isready
551
+ --health-interval 10s
552
+ --health-timeout 5s
553
+ --health-retries 5
554
+ ports:
555
+ - 5432:5432
556
+
557
+ steps:
558
+ - name: Check out repository code
559
+ uses: actions/checkout@v4
560
+
561
+ - name: Install dependencies
562
+ run: npm ci
563
+
564
+ - name: Set up AdonisJS environment
565
+ run: |
566
+ cp .env.example .env
567
+ node ace generate:key
568
+
569
+ - name: Run AdonisJS migrations
570
+ run: node ace migration:run
571
+
572
+ - name: Rollback and rerun AdonisJS migrations
573
+ run: node ace migration:refresh
574
+ `;
575
+
576
+ // src/cli/templates/dependabot.ts
577
+ var dependabot = () => `version: 2
578
+ updates:
579
+ - package-ecosystem: "npm"
580
+ directory: "/"
581
+ schedule:
582
+ interval: "daily"
583
+ allow:
584
+ - dependency-name: "@solvro/config"
585
+ `;
586
+
587
+ // src/cli/templates/nestjs-ci.ts
588
+ var nestjsCi = ({
589
+ nodeVersion,
590
+ withCommitlint
591
+ }) => `name: CI
592
+
593
+ on:
594
+ push:
595
+ branches: ["main"]
596
+ pull_request:
597
+
598
+ jobs:
599
+ lint:
600
+ runs-on: ubuntu-latest
601
+ steps:
602
+ - name: Checkout
603
+ uses: actions/checkout@v4
604
+ with:
605
+ fetch-depth: 0
606
+
607
+ - name: Setup node
608
+ uses: actions/setup-node@v4
609
+ with:
610
+ node-version: ${nodeVersion}
611
+ cache: "npm"
612
+
613
+ - name: Install dependencies
614
+ run: npm ci
615
+ ${withCommitlint ? commitLintCi() : ""}
616
+ - name: Run prettier
617
+ run: npm run format:check
618
+ if: always()
619
+
620
+ - name: Run Lint
621
+ run: npm run lint
622
+ if: always()
623
+
624
+ - name: Check types
625
+ run: npm run typecheck
626
+ if: always()
627
+
628
+ - name: Run tests
629
+ run: npm test
630
+ if: always()
631
+
632
+ - name: Run e2e tests
633
+ run: npm run test:e2e
634
+ if: always()
635
+
636
+ - name: Build
637
+ run: npm run build
638
+ if: always()`;
639
+
640
+ // src/cli/templates/react-ci.ts
641
+ var reactCi = ({
642
+ nodeVersion,
643
+ withCommitlint
644
+ }) => `name: CI
645
+
646
+ on:
647
+ push:
648
+ branches: ["main"]
649
+ pull_request:
650
+
651
+ jobs:
652
+ lint:
653
+ runs-on: ubuntu-latest
654
+ steps:
655
+ - name: Checkout
656
+ uses: actions/checkout@v4
657
+ with:
658
+ fetch-depth: 0
659
+
660
+ - name: Setup node
661
+ uses: actions/setup-node@v4
662
+ with:
663
+ node-version: ${nodeVersion}
664
+ cache: 'npm'
665
+
666
+ - name: Install dependencies
667
+ run: npm ci
668
+ ${withCommitlint ? commitLintCi() : ""}
669
+ - name: Format check
670
+ run: npm run format:check
671
+ if: always()
672
+
673
+ - name: Build
674
+ run: npm run build
675
+ if: always()`;
676
+
677
+ // src/cli/install-ga.ts
678
+ var packageJson4 = new PackageJson();
679
+ var installGithubActions = async () => {
680
+ const gitDirectory = gitRoot();
681
+ const projectDirectory = projectRoot();
682
+ await packageJson4.load();
683
+ const ghWorkflowsDirectory = import_node_path5.default.join(gitDirectory, ".github/workflows");
684
+ await fs2.mkdir(ghWorkflowsDirectory, { recursive: true });
685
+ const type = await packageJson4.getProjectType();
686
+ const withCommitlint = await packageJson4.hasPackage("@commitlint/cli");
687
+ if (type === "adonis") {
688
+ if (!(0, import_node_fs2.existsSync)(import_node_path5.default.join(projectDirectory, ".env.example"))) {
689
+ p4.cancel(
690
+ "Nie znaleziono pliku .env.example. Upewnij si\u0119, \u017Ce jeste\u015B w katalogu projektu Adonisa."
691
+ );
692
+ process.exit(1);
693
+ }
694
+ await fs2.writeFile(
695
+ import_node_path5.default.join(ghWorkflowsDirectory, "ci.yml"),
696
+ adonisCi({
697
+ nodeVersion: "22",
698
+ withCommitlint
699
+ })
700
+ );
701
+ await fs2.writeFile(
702
+ import_node_path5.default.join(ghWorkflowsDirectory, "db.yml"),
703
+ adonisMigrationsCi()
704
+ );
705
+ }
706
+ if (type === "react") {
707
+ await fs2.writeFile(
708
+ import_node_path5.default.join(ghWorkflowsDirectory, "ci.yml"),
709
+ reactCi({
710
+ nodeVersion: "22",
711
+ withCommitlint
712
+ })
713
+ );
714
+ }
715
+ if (type === "nestjs") {
716
+ await fs2.writeFile(
717
+ import_node_path5.default.join(ghWorkflowsDirectory, "ci.yml"),
718
+ nestjsCi({
719
+ nodeVersion: "22",
720
+ withCommitlint
721
+ })
722
+ );
723
+ }
724
+ if (!(0, import_node_fs2.existsSync)(import_node_path5.default.join(gitDirectory, ".github/dependabot.yml"))) {
725
+ await fs2.writeFile(
726
+ import_node_path5.default.join(gitDirectory, ".github/dependabot.yml"),
727
+ dependabot()
728
+ );
729
+ }
730
+ await packageJson4.addScriptIfNotExists("format:check", "prettier --check .");
731
+ await packageJson4.addScriptIfNotExists("lint", "eslint . --max-warnings=0");
732
+ await packageJson4.addScriptIfNotExists("format", "prettier --write .");
733
+ await packageJson4.addScriptIfNotExists("typecheck", "tsc --noEmit");
734
+ p4.note("Dodano konfiguracj\u0119 CI i skrypty.");
735
+ };
736
+
737
+ // src/cli/install-lint-staged.ts
738
+ var import_node_assert3 = __toESM(require("assert"), 1);
739
+ var import_promises3 = require("fs/promises");
740
+ var packageJson5 = new PackageJson();
741
+ var installLintStaged = async () => {
742
+ await packageJson5.load();
743
+ import_node_assert3.default.ok(packageJson5.json !== null);
744
+ await installHusky();
745
+ await packageJson5.install("lint-staged", { dev: true });
746
+ await (0, import_promises3.writeFile)(".husky/pre-commit", "npx lint-staged\n");
747
+ packageJson5.json["lint-staged"] = {
748
+ "*": "prettier -w --ignore-unknown"
749
+ };
750
+ await packageJson5.save();
751
+ };
752
+
753
+ // src/cli/install-prettier.ts
754
+ var p5 = __toESM(require("@clack/prompts"), 1);
755
+ var import_node_assert4 = __toESM(require("assert"), 1);
756
+ var import_node_fs3 = require("fs");
757
+ var fs3 = __toESM(require("fs/promises"), 1);
758
+ var import_node_path6 = __toESM(require("path"), 1);
759
+ var prettierConfigNames = [
760
+ ".prettierrc.js",
761
+ ".prettierrc.cjs",
762
+ ".prettierrc.yaml",
763
+ ".prettierrc.yml",
764
+ ".prettierrc.json",
765
+ ".prettierrc",
766
+ "prettier.config.js",
767
+ "prettier.config.mjs",
768
+ "prettier.config.cjs",
769
+ "prettier.config.ts",
770
+ "prettier.config.mts",
771
+ "prettier.config.cts"
772
+ ];
773
+ var packageJson6 = new PackageJson();
774
+ var installPrettier = async (isNonInteractive2 = false) => {
775
+ const root2 = projectRoot();
776
+ await packageJson6.load();
777
+ import_node_assert4.default.ok(packageJson6.json !== null);
778
+ await packageJson6.install("prettier", { dev: true, minVersion: ">=3" });
779
+ const prettierConfig = prettierConfigNames.find(
780
+ (configName) => (0, import_node_fs3.existsSync)(import_node_path6.default.join(root2, configName))
781
+ );
782
+ const solvroPrettierPath = "@solvro/config/prettier";
783
+ if (prettierConfig !== void 0 || packageJson6.json.prettier !== void 0) {
784
+ if (packageJson6.json.prettier === solvroPrettierPath) {
785
+ p5.note("Konfiguracja Prettiera jest ju\u017C ustawiona. Pomijam.");
786
+ return;
787
+ }
788
+ if (isNonInteractive2) {
789
+ for (const configName of prettierConfigNames) {
790
+ await fs3.rm(import_node_path6.default.join(root2, configName)).catch(() => null);
791
+ }
792
+ } else {
793
+ const isConfirmed = await polishConfirm({
794
+ message: `Znaleziono konfiguracj\u0119 Prettiera. Czy chcesz j\u0105 nadpisa\u0107?`
795
+ });
796
+ if (p5.isCancel(isConfirmed) || !isConfirmed) {
797
+ p5.cancel("Usu\u0144 konfiguracje Prettiera i spr\xF3buj ponownie.");
798
+ process.exit(1);
799
+ }
800
+ for (const configName of prettierConfigNames) {
801
+ await fs3.rm(import_node_path6.default.join(root2, configName)).catch(() => null);
802
+ }
803
+ }
804
+ }
805
+ packageJson6.json.prettier = solvroPrettierPath;
806
+ await packageJson6.save();
807
+ p5.note("Konfiguracja Prettiera zosta\u0142a dodana.");
808
+ };
809
+
810
+ // src/cli/index.ts
811
+ var program = new import_commander.Command();
812
+ program.name("@solvro/config").description("Solvro's engineering style guide setup").version(package_default.version).option("-f, --force", "Skip git clean check", false).option("--eslint", "Install ESLint configuration", false).option("--prettier", "Install Prettier configuration", false).option("--gh-action", "Install GitHub Actions", false).option("--commitlint", "Install Commitlint configuration", false).option("-a, --all", "Install all tools", false);
813
+ program.parse();
814
+ var options = program.opts();
815
+ var isNonInteractive = process.argv.length > 2;
816
+ async function main() {
817
+ if (!isNonInteractive) {
818
+ p6.intro(import_picocolors.default.bold(import_picocolors.default.bgBlue(" @solvro/config ")));
819
+ }
820
+ const userAgent = (0, import_detect.getUserAgent)();
821
+ if (userAgent !== "npm") {
822
+ const packageManager = userAgent ?? "unknown";
823
+ const warningMessage = `
824
+ ${import_picocolors.default.red(import_picocolors.default.bold(`\u26A0\uFE0F OSTRZE\u017BENIE: ${packageManager} nie jest obs\u0142ugiwany \u26A0\uFE0F`))}
825
+
826
+ Pr\xF3bujesz uruchomi\u0107 ten skrypt z ${import_picocolors.default.yellow(packageManager)}'em, ale @solvro/config dzia\u0142a tylko z ${import_picocolors.default.yellow("npm'em")}.
827
+
828
+ Support dla innych mened\u017Cer\xF3w pakiet\xF3w nie jest planowany - chcemy jednolitego stacku technologicznego dla projekt\xF3w w naszym kochanym kole Solvro.
829
+
830
+ U\u017Cyj zamiast tego npm'a:
831
+ ${import_picocolors.default.cyan("npx @solvro/config")}`;
832
+ if (isNonInteractive) {
833
+ console.error(warningMessage);
834
+ } else {
835
+ p6.cancel(warningMessage);
836
+ }
837
+ process.exit(1);
838
+ }
839
+ if (options.force !== true && !isGitClean()) {
840
+ if (isNonInteractive) {
841
+ console.error(
842
+ "Repozytorium Git ma niezatwierdzone zmiany. U\u017Cyj --force, aby pomin\u0105\u0107 to sprawdzenie."
843
+ );
844
+ process.exit(1);
845
+ }
846
+ const isConfirmed = await polishConfirm({
847
+ message: `Masz niezapisane zmiany w Git. Czy chcesz kontynuowa\u0107?`
848
+ });
849
+ if (p6.isCancel(isConfirmed) || !isConfirmed) {
850
+ p6.cancel("Zapisz zmiany w Git i spr\xF3buj ponownie.");
851
+ process.exit(1);
852
+ }
853
+ }
854
+ const packageJson7 = new PackageJson();
855
+ const projectType = await packageJson7.getProjectType();
856
+ if (!isNonInteractive) {
857
+ if (projectType === "adonis") {
858
+ const isConfirmed = await polishConfirm({
859
+ message: `Wygl\u0105da jakby\u015B u\u017Cywa\u0142 Adonisa. Czy to si\u0119 zgadza?`
860
+ });
861
+ if (p6.isCancel(isConfirmed) || !isConfirmed) {
862
+ p6.cancel("Zg\u0142o\u015B b\u0142\u0105d na GitHubie :(, a my spr\xF3bujemy pom\xF3c.");
863
+ process.exit(1);
864
+ }
865
+ }
866
+ if (projectType === "react") {
867
+ const isConfirmed = await polishConfirm({
868
+ message: `Wygl\u0105da jakby\u015B u\u017Cywa\u0142 Reacta. Czy to si\u0119 zgadza?`
869
+ });
870
+ if (p6.isCancel(isConfirmed)) {
871
+ p6.cancel("\u{1F621}");
872
+ process.exit(1);
873
+ }
874
+ if (!isConfirmed) {
875
+ p6.cancel("Zg\u0142o\u015B b\u0142\u0105d na GitHubie :(, a my spr\xF3bujemy pom\xF3c.");
876
+ process.exit(1);
877
+ }
878
+ }
879
+ if (projectType === "nestjs") {
880
+ const isConfirmed = await polishConfirm({
881
+ message: `Wygl\u0105da jakby\u015B u\u017Cywa\u0142 NestJsa. Czy to si\u0119 zgadza?`
882
+ });
883
+ if (p6.isCancel(isConfirmed)) {
884
+ p6.cancel("\u{1F621}");
885
+ process.exit(1);
886
+ }
887
+ }
888
+ if (projectType === "node") {
889
+ p6.cancel(
890
+ "Nie znaleziono ani Adonisa, Reacta, ani NestJsa. Musisz r\u0119cznie konfigurowa\u0107 projekt."
891
+ );
892
+ process.exit(1);
893
+ }
894
+ }
895
+ if (projectType === "adonis" || projectType === "react") {
896
+ if (isNonInteractive) {
897
+ await packageJson7.ensureESM();
898
+ } else {
899
+ if (!await packageJson7.isESM()) {
900
+ const isConfirmed = await polishConfirm({
901
+ message: `Tw\xF3j projekt nie u\u017Cywa ESM (brak type: "module" w package.json). Czy chcesz to doda\u0107? (Wymagane by kontynuowa\u0107)`
902
+ });
903
+ if (p6.isCancel(isConfirmed) || !isConfirmed) {
904
+ p6.cancel("Zmie\u0144 projekt na ESM i spr\xF3buj ponownie.");
905
+ process.exit(1);
906
+ }
907
+ await packageJson7.ensureESM();
908
+ }
909
+ }
910
+ }
911
+ let toolsToInstall = [];
912
+ if (options.all === true) {
913
+ toolsToInstall = ["eslint", "prettier", "gh-action", "commitlint"];
914
+ } else if (isNonInteractive) {
915
+ if (options.eslint === true) {
916
+ toolsToInstall.push("eslint");
917
+ }
918
+ if (options.prettier === true) {
919
+ toolsToInstall.push("prettier");
920
+ }
921
+ if (options.ghAction === true) {
922
+ toolsToInstall.push("gh-action");
923
+ }
924
+ if (options.commitlint === true) {
925
+ toolsToInstall.push("commitlint");
926
+ }
927
+ if (toolsToInstall.length === 0) {
928
+ console.error(
929
+ "Nie wybrano \u017Cadnych narz\u0119dzi. U\u017Cyj --eslint, --prettier, --gh-action, --commitlint, lub --all"
930
+ );
931
+ process.exit(1);
932
+ }
933
+ } else {
934
+ const additionalTools = await p6.multiselect({
935
+ message: `Kt\xF3re rzeczy Ci\u0119 interesuj\u0105? ${import_picocolors.default.gray("zaznacz spacj\u0105, potwierd\u017A enterem")}`,
936
+ initialValues: ["eslint", "prettier", "gh-action", "commitlint"],
937
+ options: [
938
+ {
939
+ value: "eslint",
940
+ label: import_picocolors.default.bold(import_picocolors.default.blueBright("ESLint")),
941
+ hint: "sprawdzanie jako\u015Bci kodu"
942
+ },
943
+ {
944
+ value: "prettier",
945
+ label: import_picocolors.default.bold(import_picocolors.default.yellowBright("Prettier")),
946
+ hint: "formatowanie"
947
+ },
948
+ {
949
+ value: "gh-action",
950
+ label: import_picocolors.default.bold("GitHub Actions"),
951
+ hint: "automatyczne testy na Githubie"
952
+ },
953
+ {
954
+ value: "commitlint",
955
+ label: import_picocolors.default.bold("Commitlint"),
956
+ hint: "walidacja tre\u015Bci commit\xF3w"
957
+ }
958
+ ],
959
+ required: false
960
+ });
961
+ if (p6.isCancel(additionalTools) || additionalTools.length === 0) {
962
+ p6.cancel("Nie wybrano \u017Cadnych narz\u0119dzi.");
963
+ process.exit(1);
964
+ }
965
+ toolsToInstall = additionalTools;
966
+ }
967
+ await packageJson7.install("@solvro/config", {
968
+ dev: true,
969
+ alwaysUpdate: !isNonInteractive
970
+ });
971
+ if (toolsToInstall.includes("eslint")) {
972
+ await installEslint(isNonInteractive);
973
+ }
974
+ if (toolsToInstall.includes("prettier")) {
975
+ await installPrettier(isNonInteractive);
976
+ await installLintStaged();
977
+ }
978
+ if (toolsToInstall.includes("commitlint")) {
979
+ await installCommitLint();
980
+ }
981
+ if (toolsToInstall.includes("gh-action")) {
982
+ await installGithubActions();
983
+ }
984
+ await packageJson7.clearInstall();
985
+ if (isNonInteractive) {
986
+ console.log("\u2705 Konfiguracja zako\u0144czona pomy\u015Blnie!");
987
+ } else {
988
+ p6.outro("\u2705 Konfiguracja zako\u0144czona pomy\u015Blnie!");
989
+ }
990
+ }
991
+ try {
992
+ void main();
993
+ } catch (error) {
994
+ console.error("Wyst\u0105pi\u0142 b\u0142\u0105d:", error);
995
+ process.exit(1);
996
+ }
997
+ //# sourceMappingURL=index.cjs.map