@solvro/config 2.0.4 → 2.0.6

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,1014 @@
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.5",
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.2",
94
+ "@clack/prompts": "^0.11.0",
95
+ "@commitlint/config-conventional": "^19.8.1",
96
+ "@darraghor/eslint-plugin-nestjs-typed": "^6.7.1",
97
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
98
+ "@eslint/js": "^9.34.0",
99
+ "@tanstack/eslint-plugin-query": "^5.83.1",
100
+ "@trivago/prettier-plugin-sort-imports": "^5.2.2",
101
+ "@typescript-eslint/eslint-plugin": "^8.41.0",
102
+ commander: "^14.0.0",
103
+ "eslint-config-flat-gitignore": "^2.1.0",
104
+ "eslint-config-prettier": "^10.1.8",
105
+ "eslint-plugin-antfu": "^3.1.1",
106
+ "eslint-plugin-import": "^2.32.0",
107
+ "eslint-plugin-jsdoc": "^54.1.1",
108
+ "eslint-plugin-jsx-a11y": "^6.10.2",
109
+ "eslint-plugin-n": "^17.21.3",
110
+ "eslint-plugin-react": "^7.37.5",
111
+ "eslint-plugin-react-hooks": "^5.2.0",
112
+ "eslint-plugin-react-refresh": "^0.4.20",
113
+ "eslint-plugin-react-you-might-not-need-an-effect": "^0.4.4",
114
+ "eslint-plugin-unicorn": "^60.0.0",
115
+ "eslint-plugin-unused-imports": "^4.2.0",
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.2",
121
+ "package-manager-detector": "^1.3.0",
122
+ picocolors: "^1.1.1",
123
+ "prettier-plugin-packagejson": "^2.5.19",
124
+ "prettier-plugin-tailwindcss": "^0.6.14",
125
+ semver: "^7.7.2",
126
+ "typescript-eslint": "^8.41.0"
127
+ },
128
+ devDependencies: {
129
+ "@commitlint/cli": "^19.8.1",
130
+ "@eslint/config-inspector": "^1.2.0",
131
+ "@next/eslint-plugin-next": "^15.5.2",
132
+ "@semantic-release/git": "^10.0.1",
133
+ "@types/node": "^24.3.0",
134
+ "@types/semver": "^7.7.0",
135
+ "@vitest/coverage-v8": "^3.2.4",
136
+ "@vitest/ui": "^3.2.4",
137
+ eslint: "^9.34.0",
138
+ husky: "^9.1.7",
139
+ knip: "^5.63.0",
140
+ "lint-staged": "^16.1.5",
141
+ "pkg-pr-new": "^0.0.58",
142
+ prettier: "^3.6.2",
143
+ "semantic-release": "^24.2.7",
144
+ tsup: "^8.5.0",
145
+ tsx: "^4.20.5",
146
+ typescript: "^5.9.2",
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.5.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 isNextJs() {
244
+ return this.hasPackage("next");
245
+ }
246
+ async doesSatisfies(package_, version) {
247
+ await this.load();
248
+ import_node_assert.default.ok(this.json !== null);
249
+ const packageInfo = await (0, import_local_pkg.getPackageInfo)(package_);
250
+ if (packageInfo?.version === void 0) {
251
+ return false;
252
+ }
253
+ return import_semver.default.satisfies(packageInfo.version, version);
254
+ }
255
+ async isESM() {
256
+ await this.load();
257
+ import_node_assert.default.ok(this.json !== null);
258
+ return this.json.type === "module";
259
+ }
260
+ async ensureESM() {
261
+ if (await this.isESM()) {
262
+ return;
263
+ }
264
+ import_node_assert.default.ok(this.json !== null);
265
+ this.json.type = "module";
266
+ await this.save();
267
+ }
268
+ async getProjectType() {
269
+ const isAdonis = await (0, import_local_pkg.isPackageListed)("@adonisjs/core");
270
+ const isReact = await (0, import_local_pkg.isPackageListed)("react");
271
+ const isNestJs = await (0, import_local_pkg.isPackageListed)("@nestjs/core");
272
+ if (isReact && isAdonis) {
273
+ throw new Error(
274
+ "You can't use both Adonis and React in the same project"
275
+ );
276
+ }
277
+ if (isNestJs) {
278
+ return "nestjs";
279
+ }
280
+ if (isAdonis) {
281
+ return "adonis";
282
+ }
283
+ if (isReact) {
284
+ return "react";
285
+ }
286
+ return "node";
287
+ }
288
+ async save() {
289
+ await (0, import_promises.writeFile)(
290
+ import_node_path2.default.join(projectRoot(), "package.json"),
291
+ JSON.stringify(this.json, null, 2)
292
+ );
293
+ }
294
+ async addScriptIfNotExists(name, script) {
295
+ await this.load();
296
+ import_node_assert.default.ok(this.json !== null);
297
+ if (this.json.scripts?.[name] !== void 0) {
298
+ return;
299
+ }
300
+ this.json.scripts = this.json.scripts ?? {};
301
+ this.json.scripts[name] = script;
302
+ await this.save();
303
+ }
304
+ async install(package_, options2) {
305
+ const isInstalled = await this.hasPackage(package_);
306
+ if (!isInstalled) {
307
+ const spinner2 = p.spinner();
308
+ runIfInteractive(() => {
309
+ spinner2.start(`Instalowanie ${package_}`);
310
+ });
311
+ await $$`npm i ${options2?.dev === true ? "-D" : ""} ${package_}@latest`;
312
+ runIfInteractive(() => {
313
+ spinner2.stop(`${package_} zainstalowany \u{1F60D}`);
314
+ });
315
+ await this.load();
316
+ return;
317
+ }
318
+ const info = await (0, import_local_pkg.getPackageInfo)(package_);
319
+ if (info?.version !== void 0 && options2?.minVersion !== void 0 && !import_semver.default.satisfies(info.version, options2.minVersion) || options2?.alwaysUpdate === true) {
320
+ const spinner2 = p.spinner();
321
+ runIfInteractive(() => {
322
+ spinner2.start(`Aktualizowanie ${package_}`);
323
+ });
324
+ await $$`npm i ${options2.dev === true ? "-D" : ""} ${package_}@latest`;
325
+ runIfInteractive(() => {
326
+ spinner2.stop(`${package_} zaktualizowany \u{1F60D}`);
327
+ });
328
+ await this.load();
329
+ }
330
+ }
331
+ async clearInstall() {
332
+ await $$`npm ci`;
333
+ }
334
+ };
335
+
336
+ // src/utils/polish-confirm.ts
337
+ var p2 = __toESM(require("@clack/prompts"), 1);
338
+ var import_is_interactive2 = __toESM(require("is-interactive"), 1);
339
+ var polishConfirm = async (props) => {
340
+ if (!(0, import_is_interactive2.default)()) {
341
+ return true;
342
+ }
343
+ return p2.confirm({
344
+ active: "Tak",
345
+ inactive: "Nie",
346
+ ...props
347
+ });
348
+ };
349
+
350
+ // src/cli/install-commitlint.ts
351
+ var import_promises2 = require("fs/promises");
352
+ var import_node_path3 = __toESM(require("path"), 1);
353
+
354
+ // src/cli/install-husky.ts
355
+ var import_node_assert2 = __toESM(require("assert"), 1);
356
+ var packageJson = new PackageJson();
357
+ var installHusky = async () => {
358
+ if (!await packageJson.hasPackage("husky")) {
359
+ await packageJson.install("husky", { dev: true });
360
+ await $$`npx husky init`;
361
+ }
362
+ await packageJson.load();
363
+ import_node_assert2.default.ok(packageJson.json !== null);
364
+ packageJson.json.scripts = packageJson.json.scripts ?? {};
365
+ packageJson.json.scripts.prepare = `husky || true`;
366
+ await packageJson.save();
367
+ };
368
+
369
+ // src/cli/templates/commitlint.ts
370
+ var commitlint = () => `export default {
371
+ extends: ["@solvro/config/commitlint"],
372
+ };
373
+ `;
374
+
375
+ // src/cli/install-commitlint.ts
376
+ var root = projectRoot();
377
+ var packageJson2 = new PackageJson();
378
+ var installCommitLint = async () => {
379
+ await installHusky();
380
+ await packageJson2.install("@commitlint/cli", { dev: true });
381
+ await (0, import_promises2.writeFile)(
382
+ import_node_path3.default.join(root, ".husky/commit-msg"),
383
+ 'npx commitlint --edit "$1"\n'
384
+ );
385
+ await (0, import_promises2.writeFile)(import_node_path3.default.join(root, ".commitlintrc.js"), commitlint());
386
+ };
387
+
388
+ // src/cli/install-eslint.ts
389
+ var p3 = __toESM(require("@clack/prompts"), 1);
390
+ var import_node_fs = require("fs");
391
+ var fs = __toESM(require("fs/promises"), 1);
392
+ var import_node_path4 = __toESM(require("path"), 1);
393
+ var eslintConfigNames = [
394
+ ".eslintrc.js",
395
+ ".eslintrc.cjs",
396
+ ".eslintrc.yaml",
397
+ ".eslintrc.yml",
398
+ ".eslintrc.json",
399
+ ".eslintrc",
400
+ "eslint.config.js",
401
+ "eslint.config.mjs",
402
+ "eslint.config.cjs",
403
+ "eslint.config.ts",
404
+ "eslint.config.mts",
405
+ "eslint.config.cts"
406
+ ];
407
+ var packageJson3 = new PackageJson();
408
+ var installEslint = async (isNonInteractive2 = false) => {
409
+ const root2 = projectRoot();
410
+ await packageJson3.load();
411
+ await packageJson3.install("eslint", { dev: true, minVersion: ">=9" });
412
+ const type = await packageJson3.getProjectType();
413
+ if (type === "react" && await packageJson3.isNextJs()) {
414
+ const is15 = await packageJson3.doesSatisfies("next", ">=15");
415
+ if (!is15) {
416
+ p3.cancel(
417
+ "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"
418
+ );
419
+ process.exit(1);
420
+ }
421
+ await packageJson3.install("@next/eslint-plugin-next", { dev: true });
422
+ }
423
+ const eslintConfig = eslintConfigNames.find(
424
+ (configName) => (0, import_node_fs.existsSync)(import_node_path4.default.join(root2, configName))
425
+ );
426
+ if (eslintConfig !== void 0) {
427
+ const eslintContent = await fs.readFile(
428
+ import_node_path4.default.join(root2, eslintConfig),
429
+ "utf8"
430
+ );
431
+ if (eslintContent.includes("export default solvro(")) {
432
+ p3.note("Eslint jest ju\u017C skonfigurowany. Pomijam.");
433
+ return;
434
+ } else {
435
+ if (isNonInteractive2) {
436
+ await fs.rm(import_node_path4.default.join(root2, eslintConfig));
437
+ } else {
438
+ const isConfirmed = await polishConfirm({
439
+ message: `Znaleziono plik konfiguracyjny Eslint. Czy chcesz go nadpisa\u0107?`
440
+ });
441
+ if (p3.isCancel(isConfirmed) || !isConfirmed) {
442
+ p3.cancel("Nadpisz plik konfiguracyjny Eslint i spr\xF3buj ponownie.");
443
+ process.exit(1);
444
+ }
445
+ await fs.rm(import_node_path4.default.join(root2, eslintConfig));
446
+ }
447
+ }
448
+ }
449
+ const isESM = await packageJson3.isESM();
450
+ const eslintFilename = isESM ? "eslint.config.js" : "eslint.config.mjs";
451
+ await fs.writeFile(
452
+ import_node_path4.default.join(root2, eslintFilename),
453
+ `import { solvro } from "@solvro/config/eslint";
454
+
455
+ export default solvro();
456
+ `
457
+ );
458
+ p3.note("Plik konfiguracyjny Eslint zosta\u0142 utworzony.");
459
+ };
460
+
461
+ // src/cli/install-ga.ts
462
+ var p4 = __toESM(require("@clack/prompts"), 1);
463
+ var import_node_fs2 = require("fs");
464
+ var fs2 = __toESM(require("fs/promises"), 1);
465
+ var import_node_path5 = __toESM(require("path"), 1);
466
+
467
+ // src/cli/templates/commit-lint-ci.ts
468
+ var commitLintCi = () => `
469
+ - name: Check commit name
470
+ if: github.event_name == 'pull_request'
471
+ run: npx commitlint --from \${{ github.event.pull_request.base.sha }} --to \${{ github.event.pull_request.head.sha }} --verbose
472
+ `;
473
+
474
+ // src/cli/templates/adonis-ci.ts
475
+ var adonisCi = ({
476
+ nodeVersion,
477
+ withCommitlint
478
+ }) => `name: CI
479
+
480
+ on:
481
+ push:
482
+ branches: ["main"]
483
+ pull_request:
484
+
485
+ jobs:
486
+ lint:
487
+ runs-on: ubuntu-latest
488
+ steps:
489
+ - name: Checkout
490
+ uses: actions/checkout@v4
491
+ with:
492
+ fetch-depth: 0
493
+
494
+ - name: Setup node
495
+ uses: actions/setup-node@v4
496
+ with:
497
+ node-version: ${nodeVersion}
498
+ cache: "npm"
499
+
500
+ - name: Install dependencies
501
+ run: npm ci
502
+
503
+ - name: Set up AdonisJS environment
504
+ run: |
505
+ cp .env.example .env
506
+ node ace generate:key
507
+ ${withCommitlint ? commitLintCi() : ""}
508
+ - name: Run prettier
509
+ run: npm run format:check
510
+ if: always()
511
+
512
+ - name: Run Lint
513
+ run: npm run lint
514
+ if: always()
515
+
516
+ - name: Check types
517
+ run: npm run typecheck
518
+ if: always()
519
+
520
+ - name: Run tests
521
+ run: npm test
522
+ if: always()
523
+
524
+ - name: Build
525
+ run: npm run build
526
+ if: always()`;
527
+
528
+ // src/cli/templates/adonis-ci-migrations.ts
529
+ var adonisMigrationsCi = () => `name: Migration check
530
+
531
+ on:
532
+ pull_request:
533
+ branches: ["*"]
534
+ push:
535
+ branches: ["main"]
536
+
537
+ jobs:
538
+ migration-check:
539
+ runs-on: ubuntu-latest
540
+ env:
541
+ DB_HOST: 127.0.0.1
542
+ DB_PORT: 5432
543
+ DB_USER: postgres
544
+ DB_PASSWORD: postgres
545
+ DB_DATABASE: postgres
546
+
547
+ services:
548
+ postgres:
549
+ image: postgres
550
+ env:
551
+ POSTGRES_PASSWORD: postgres
552
+ options: >-
553
+ --health-cmd pg_isready
554
+ --health-interval 10s
555
+ --health-timeout 5s
556
+ --health-retries 5
557
+ ports:
558
+ - 5432:5432
559
+
560
+ steps:
561
+ - name: Check out repository code
562
+ uses: actions/checkout@v4
563
+
564
+ - name: Install dependencies
565
+ run: npm ci
566
+
567
+ - name: Set up AdonisJS environment
568
+ run: |
569
+ cp .env.example .env
570
+ node ace generate:key
571
+
572
+ - name: Run AdonisJS migrations
573
+ run: node ace migration:run
574
+
575
+ - name: Rollback and rerun AdonisJS migrations
576
+ run: node ace migration:refresh
577
+ `;
578
+
579
+ // src/cli/templates/dependabot.ts
580
+ var dependabot = () => `version: 2
581
+ updates:
582
+ - package-ecosystem: "npm"
583
+ directory: "/"
584
+ schedule:
585
+ interval: "daily"
586
+ allow:
587
+ - dependency-name: "@solvro/config"
588
+ `;
589
+
590
+ // src/cli/templates/nestjs-ci.ts
591
+ var nestjsCi = ({
592
+ nodeVersion,
593
+ withCommitlint
594
+ }) => `name: CI
595
+
596
+ on:
597
+ push:
598
+ branches: ["main"]
599
+ pull_request:
600
+
601
+ jobs:
602
+ lint:
603
+ runs-on: ubuntu-latest
604
+ steps:
605
+ - name: Checkout
606
+ uses: actions/checkout@v4
607
+ with:
608
+ fetch-depth: 0
609
+
610
+ - name: Setup node
611
+ uses: actions/setup-node@v4
612
+ with:
613
+ node-version: ${nodeVersion}
614
+ cache: "npm"
615
+
616
+ - name: Install dependencies
617
+ run: npm ci
618
+ ${withCommitlint ? commitLintCi() : ""}
619
+ - name: Run prettier
620
+ run: npm run format:check
621
+ if: always()
622
+
623
+ - name: Run Lint
624
+ run: npm run lint
625
+ if: always()
626
+
627
+ - name: Check types
628
+ run: npm run typecheck
629
+ if: always()
630
+
631
+ - name: Run tests
632
+ run: npm test
633
+ if: always()
634
+
635
+ - name: Run e2e tests
636
+ run: npm run test:e2e
637
+ if: always()
638
+
639
+ - name: Build
640
+ run: npm run build
641
+ if: always()`;
642
+
643
+ // src/cli/templates/nextjs-ci.ts
644
+ var nextJsCi = () => `
645
+ - name: Setup build cache
646
+ uses: actions/cache@v4
647
+ with:
648
+ path: \${{ github.workspace }}/.next/cache
649
+ key: \${{ runner.os }}-nextjs-\${{ hashFiles('**/package-lock.json') }}-\${{ hashFiles('**/*.ts', '**/*.tsx') }}
650
+ restore-keys: |
651
+ \${{ runner.os }}-nextjs-\${{ hashFiles('**/package-lock.json') }}-
652
+ `;
653
+
654
+ // src/cli/templates/react-ci.ts
655
+ var reactCi = ({
656
+ nodeVersion,
657
+ withCommitlint,
658
+ usingNextJs
659
+ }) => `name: CI
660
+
661
+ on:
662
+ push:
663
+ branches: ["main"]
664
+ pull_request:
665
+
666
+ jobs:
667
+ lint:
668
+ runs-on: ubuntu-latest
669
+ steps:
670
+ - name: Checkout
671
+ uses: actions/checkout@v4
672
+ with:
673
+ fetch-depth: 0
674
+
675
+ - name: Setup node
676
+ uses: actions/setup-node@v4
677
+ with:
678
+ node-version: ${nodeVersion}
679
+ cache: 'npm'
680
+ ${usingNextJs ? nextJsCi() : ""}
681
+ - name: Install dependencies
682
+ run: npm ci
683
+ ${withCommitlint ? commitLintCi() : ""}
684
+ - name: Format check
685
+ run: npm run format:check
686
+ if: always()
687
+
688
+ - name: Build
689
+ run: npm run build
690
+ if: always()`;
691
+
692
+ // src/cli/install-ga.ts
693
+ var packageJson4 = new PackageJson();
694
+ var installGithubActions = async () => {
695
+ const gitDirectory = gitRoot();
696
+ const projectDirectory = projectRoot();
697
+ await packageJson4.load();
698
+ const ghWorkflowsDirectory = import_node_path5.default.join(gitDirectory, ".github/workflows");
699
+ await fs2.mkdir(ghWorkflowsDirectory, { recursive: true });
700
+ const type = await packageJson4.getProjectType();
701
+ const withCommitlint = await packageJson4.hasPackage("@commitlint/cli");
702
+ if (type === "adonis") {
703
+ if (!(0, import_node_fs2.existsSync)(import_node_path5.default.join(projectDirectory, ".env.example"))) {
704
+ p4.cancel(
705
+ "Nie znaleziono pliku .env.example. Upewnij si\u0119, \u017Ce jeste\u015B w katalogu projektu Adonisa."
706
+ );
707
+ process.exit(1);
708
+ }
709
+ await fs2.writeFile(
710
+ import_node_path5.default.join(ghWorkflowsDirectory, "ci.yml"),
711
+ adonisCi({
712
+ nodeVersion: "22",
713
+ withCommitlint
714
+ })
715
+ );
716
+ await fs2.writeFile(
717
+ import_node_path5.default.join(ghWorkflowsDirectory, "db.yml"),
718
+ adonisMigrationsCi()
719
+ );
720
+ }
721
+ if (type === "react") {
722
+ const usingNextJs = await packageJson4.isNextJs();
723
+ await fs2.writeFile(
724
+ import_node_path5.default.join(ghWorkflowsDirectory, "ci.yml"),
725
+ reactCi({
726
+ nodeVersion: "22",
727
+ withCommitlint,
728
+ usingNextJs
729
+ })
730
+ );
731
+ }
732
+ if (type === "nestjs") {
733
+ await fs2.writeFile(
734
+ import_node_path5.default.join(ghWorkflowsDirectory, "ci.yml"),
735
+ nestjsCi({
736
+ nodeVersion: "22",
737
+ withCommitlint
738
+ })
739
+ );
740
+ }
741
+ if (!(0, import_node_fs2.existsSync)(import_node_path5.default.join(gitDirectory, ".github/dependabot.yml"))) {
742
+ await fs2.writeFile(
743
+ import_node_path5.default.join(gitDirectory, ".github/dependabot.yml"),
744
+ dependabot()
745
+ );
746
+ }
747
+ await packageJson4.addScriptIfNotExists("format:check", "prettier --check .");
748
+ await packageJson4.addScriptIfNotExists("lint", "eslint . --max-warnings=0");
749
+ await packageJson4.addScriptIfNotExists("format", "prettier --write .");
750
+ await packageJson4.addScriptIfNotExists("typecheck", "tsc --noEmit");
751
+ p4.note("Dodano konfiguracj\u0119 CI i skrypty.");
752
+ };
753
+
754
+ // src/cli/install-lint-staged.ts
755
+ var import_node_assert3 = __toESM(require("assert"), 1);
756
+ var import_promises3 = require("fs/promises");
757
+ var packageJson5 = new PackageJson();
758
+ var installLintStaged = async () => {
759
+ await packageJson5.load();
760
+ import_node_assert3.default.ok(packageJson5.json !== null);
761
+ await installHusky();
762
+ await packageJson5.install("lint-staged", { dev: true });
763
+ await (0, import_promises3.writeFile)(".husky/pre-commit", "npx lint-staged\n");
764
+ packageJson5.json["lint-staged"] = {
765
+ "*": "prettier -w --ignore-unknown"
766
+ };
767
+ await packageJson5.save();
768
+ };
769
+
770
+ // src/cli/install-prettier.ts
771
+ var p5 = __toESM(require("@clack/prompts"), 1);
772
+ var import_node_assert4 = __toESM(require("assert"), 1);
773
+ var import_node_fs3 = require("fs");
774
+ var fs3 = __toESM(require("fs/promises"), 1);
775
+ var import_node_path6 = __toESM(require("path"), 1);
776
+ var prettierConfigNames = [
777
+ ".prettierrc.js",
778
+ ".prettierrc.cjs",
779
+ ".prettierrc.yaml",
780
+ ".prettierrc.yml",
781
+ ".prettierrc.json",
782
+ ".prettierrc",
783
+ "prettier.config.js",
784
+ "prettier.config.mjs",
785
+ "prettier.config.cjs",
786
+ "prettier.config.ts",
787
+ "prettier.config.mts",
788
+ "prettier.config.cts"
789
+ ];
790
+ var packageJson6 = new PackageJson();
791
+ var installPrettier = async (isNonInteractive2 = false) => {
792
+ const root2 = projectRoot();
793
+ await packageJson6.load();
794
+ import_node_assert4.default.ok(packageJson6.json !== null);
795
+ await packageJson6.install("prettier", { dev: true, minVersion: ">=3" });
796
+ const prettierConfig = prettierConfigNames.find(
797
+ (configName) => (0, import_node_fs3.existsSync)(import_node_path6.default.join(root2, configName))
798
+ );
799
+ const solvroPrettierPath = "@solvro/config/prettier";
800
+ if (prettierConfig !== void 0 || packageJson6.json.prettier !== void 0) {
801
+ if (packageJson6.json.prettier === solvroPrettierPath) {
802
+ p5.note("Konfiguracja Prettiera jest ju\u017C ustawiona. Pomijam.");
803
+ return;
804
+ }
805
+ if (isNonInteractive2) {
806
+ for (const configName of prettierConfigNames) {
807
+ await fs3.rm(import_node_path6.default.join(root2, configName)).catch(() => null);
808
+ }
809
+ } else {
810
+ const isConfirmed = await polishConfirm({
811
+ message: `Znaleziono konfiguracj\u0119 Prettiera. Czy chcesz j\u0105 nadpisa\u0107?`
812
+ });
813
+ if (p5.isCancel(isConfirmed) || !isConfirmed) {
814
+ p5.cancel("Usu\u0144 konfiguracje Prettiera i spr\xF3buj ponownie.");
815
+ process.exit(1);
816
+ }
817
+ for (const configName of prettierConfigNames) {
818
+ await fs3.rm(import_node_path6.default.join(root2, configName)).catch(() => null);
819
+ }
820
+ }
821
+ }
822
+ packageJson6.json.prettier = solvroPrettierPath;
823
+ await packageJson6.save();
824
+ p5.note("Konfiguracja Prettiera zosta\u0142a dodana.");
825
+ };
826
+
827
+ // src/cli/index.ts
828
+ var program = new import_commander.Command();
829
+ 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);
830
+ program.parse();
831
+ var options = program.opts();
832
+ var isNonInteractive = process.argv.length > 2;
833
+ async function main() {
834
+ if (!isNonInteractive) {
835
+ p6.intro(import_picocolors.default.bold(import_picocolors.default.bgBlue(" @solvro/config ")));
836
+ }
837
+ const userAgent = (0, import_detect.getUserAgent)();
838
+ if (userAgent !== "npm") {
839
+ const packageManager = userAgent ?? "unknown";
840
+ const warningMessage = `
841
+ ${import_picocolors.default.red(import_picocolors.default.bold(`\u26A0\uFE0F OSTRZE\u017BENIE: ${packageManager} nie jest obs\u0142ugiwany \u26A0\uFE0F`))}
842
+
843
+ 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")}.
844
+
845
+ Support dla innych mened\u017Cer\xF3w pakiet\xF3w nie jest planowany - chcemy jednolitego stacku technologicznego dla projekt\xF3w w naszym kochanym kole Solvro.
846
+
847
+ U\u017Cyj zamiast tego npm'a:
848
+ ${import_picocolors.default.cyan("npx @solvro/config")}`;
849
+ if (isNonInteractive) {
850
+ console.error(warningMessage);
851
+ } else {
852
+ p6.cancel(warningMessage);
853
+ }
854
+ process.exit(1);
855
+ }
856
+ if (options.force !== true && !isGitClean()) {
857
+ if (isNonInteractive) {
858
+ console.error(
859
+ "Repozytorium Git ma niezatwierdzone zmiany. U\u017Cyj --force, aby pomin\u0105\u0107 to sprawdzenie."
860
+ );
861
+ process.exit(1);
862
+ }
863
+ const isConfirmed = await polishConfirm({
864
+ message: `Masz niezapisane zmiany w Git. Czy chcesz kontynuowa\u0107?`
865
+ });
866
+ if (p6.isCancel(isConfirmed) || !isConfirmed) {
867
+ p6.cancel("Zapisz zmiany w Git i spr\xF3buj ponownie.");
868
+ process.exit(1);
869
+ }
870
+ }
871
+ const packageJson7 = new PackageJson();
872
+ const projectType = await packageJson7.getProjectType();
873
+ if (!isNonInteractive) {
874
+ if (projectType === "adonis") {
875
+ const isConfirmed = await polishConfirm({
876
+ message: `Wygl\u0105da jakby\u015B u\u017Cywa\u0142 Adonisa. Czy to si\u0119 zgadza?`
877
+ });
878
+ if (p6.isCancel(isConfirmed) || !isConfirmed) {
879
+ p6.cancel("Zg\u0142o\u015B b\u0142\u0105d na GitHubie :(, a my spr\xF3bujemy pom\xF3c.");
880
+ process.exit(1);
881
+ }
882
+ }
883
+ if (projectType === "react") {
884
+ const isConfirmed = await polishConfirm({
885
+ message: `Wygl\u0105da jakby\u015B u\u017Cywa\u0142 Reacta. Czy to si\u0119 zgadza?`
886
+ });
887
+ if (p6.isCancel(isConfirmed)) {
888
+ p6.cancel("\u{1F621}");
889
+ process.exit(1);
890
+ }
891
+ if (!isConfirmed) {
892
+ p6.cancel("Zg\u0142o\u015B b\u0142\u0105d na GitHubie :(, a my spr\xF3bujemy pom\xF3c.");
893
+ process.exit(1);
894
+ }
895
+ }
896
+ if (projectType === "nestjs") {
897
+ const isConfirmed = await polishConfirm({
898
+ message: `Wygl\u0105da jakby\u015B u\u017Cywa\u0142 NestJsa. Czy to si\u0119 zgadza?`
899
+ });
900
+ if (p6.isCancel(isConfirmed)) {
901
+ p6.cancel("\u{1F621}");
902
+ process.exit(1);
903
+ }
904
+ }
905
+ if (projectType === "node") {
906
+ p6.cancel(
907
+ "Nie znaleziono ani Adonisa, Reacta, ani NestJsa. Musisz r\u0119cznie konfigurowa\u0107 projekt."
908
+ );
909
+ process.exit(1);
910
+ }
911
+ }
912
+ if (projectType === "adonis" || projectType === "react") {
913
+ if (isNonInteractive) {
914
+ await packageJson7.ensureESM();
915
+ } else {
916
+ if (!await packageJson7.isESM()) {
917
+ const isConfirmed = await polishConfirm({
918
+ message: `Tw\xF3j projekt nie u\u017Cywa ESM (brak type: "module" w package.json). Czy chcesz to doda\u0107? (Wymagane by kontynuowa\u0107)`
919
+ });
920
+ if (p6.isCancel(isConfirmed) || !isConfirmed) {
921
+ p6.cancel("Zmie\u0144 projekt na ESM i spr\xF3buj ponownie.");
922
+ process.exit(1);
923
+ }
924
+ await packageJson7.ensureESM();
925
+ }
926
+ }
927
+ }
928
+ let toolsToInstall = [];
929
+ if (options.all === true) {
930
+ toolsToInstall = ["eslint", "prettier", "gh-action", "commitlint"];
931
+ } else if (isNonInteractive) {
932
+ if (options.eslint === true) {
933
+ toolsToInstall.push("eslint");
934
+ }
935
+ if (options.prettier === true) {
936
+ toolsToInstall.push("prettier");
937
+ }
938
+ if (options.ghAction === true) {
939
+ toolsToInstall.push("gh-action");
940
+ }
941
+ if (options.commitlint === true) {
942
+ toolsToInstall.push("commitlint");
943
+ }
944
+ if (toolsToInstall.length === 0) {
945
+ console.error(
946
+ "Nie wybrano \u017Cadnych narz\u0119dzi. U\u017Cyj --eslint, --prettier, --gh-action, --commitlint, lub --all"
947
+ );
948
+ process.exit(1);
949
+ }
950
+ } else {
951
+ const additionalTools = await p6.multiselect({
952
+ message: `Kt\xF3re rzeczy Ci\u0119 interesuj\u0105? ${import_picocolors.default.gray("zaznacz spacj\u0105, potwierd\u017A enterem")}`,
953
+ initialValues: ["eslint", "prettier", "gh-action", "commitlint"],
954
+ options: [
955
+ {
956
+ value: "eslint",
957
+ label: import_picocolors.default.bold(import_picocolors.default.blueBright("ESLint")),
958
+ hint: "sprawdzanie jako\u015Bci kodu"
959
+ },
960
+ {
961
+ value: "prettier",
962
+ label: import_picocolors.default.bold(import_picocolors.default.yellowBright("Prettier")),
963
+ hint: "formatowanie"
964
+ },
965
+ {
966
+ value: "gh-action",
967
+ label: import_picocolors.default.bold("GitHub Actions"),
968
+ hint: "automatyczne testy na Githubie"
969
+ },
970
+ {
971
+ value: "commitlint",
972
+ label: import_picocolors.default.bold("Commitlint"),
973
+ hint: "walidacja tre\u015Bci commit\xF3w"
974
+ }
975
+ ],
976
+ required: false
977
+ });
978
+ if (p6.isCancel(additionalTools) || additionalTools.length === 0) {
979
+ p6.cancel("Nie wybrano \u017Cadnych narz\u0119dzi.");
980
+ process.exit(1);
981
+ }
982
+ toolsToInstall = additionalTools;
983
+ }
984
+ await packageJson7.install("@solvro/config", {
985
+ dev: true,
986
+ alwaysUpdate: !isNonInteractive
987
+ });
988
+ if (toolsToInstall.includes("eslint")) {
989
+ await installEslint(isNonInteractive);
990
+ }
991
+ if (toolsToInstall.includes("prettier")) {
992
+ await installPrettier(isNonInteractive);
993
+ await installLintStaged();
994
+ }
995
+ if (toolsToInstall.includes("commitlint")) {
996
+ await installCommitLint();
997
+ }
998
+ if (toolsToInstall.includes("gh-action")) {
999
+ await installGithubActions();
1000
+ }
1001
+ await packageJson7.clearInstall();
1002
+ if (isNonInteractive) {
1003
+ console.log("\u2705 Konfiguracja zako\u0144czona pomy\u015Blnie!");
1004
+ } else {
1005
+ p6.outro("\u2705 Konfiguracja zako\u0144czona pomy\u015Blnie!");
1006
+ }
1007
+ }
1008
+ try {
1009
+ void main();
1010
+ } catch (error) {
1011
+ console.error("Wyst\u0105pi\u0142 b\u0142\u0105d:", error);
1012
+ process.exit(1);
1013
+ }
1014
+ //# sourceMappingURL=index.cjs.map