@mayrlabs/setup-project 0.1.3 → 0.1.4

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/index.mjs CHANGED
@@ -16,6 +16,19 @@ var __commonJS = (cb, mod) => function __require() {
16
16
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
17
  };
18
18
 
19
+ // node_modules/tsup/assets/esm_shims.js
20
+ import path from "path";
21
+ import { fileURLToPath } from "url";
22
+ var getFilename, getDirname, __dirname;
23
+ var init_esm_shims = __esm({
24
+ "node_modules/tsup/assets/esm_shims.js"() {
25
+ "use strict";
26
+ getFilename = () => fileURLToPath(import.meta.url);
27
+ getDirname = () => path.dirname(getFilename());
28
+ __dirname = /* @__PURE__ */ getDirname();
29
+ }
30
+ });
31
+
19
32
  // src/utils/pm.ts
20
33
  import { execa } from "execa";
21
34
  async function getPackageManager() {
@@ -48,6 +61,7 @@ async function installPackages(packages, dev = false) {
48
61
  var init_pm = __esm({
49
62
  "src/utils/pm.ts"() {
50
63
  "use strict";
64
+ init_esm_shims();
51
65
  }
52
66
  });
53
67
 
@@ -100,6 +114,7 @@ async function installHusky(config) {
100
114
  var init_husky = __esm({
101
115
  "src/services/husky.ts"() {
102
116
  "use strict";
117
+ init_esm_shims();
103
118
  init_pm();
104
119
  }
105
120
  });
@@ -137,6 +152,7 @@ async function installFormatter(config) {
137
152
  var init_formatter = __esm({
138
153
  "src/services/formatter.ts"() {
139
154
  "use strict";
155
+ init_esm_shims();
140
156
  init_pm();
141
157
  }
142
158
  });
@@ -178,6 +194,7 @@ async function installLinter(config) {
178
194
  var init_linter = __esm({
179
195
  "src/services/linter.ts"() {
180
196
  "use strict";
197
+ init_esm_shims();
181
198
  init_pm();
182
199
  }
183
200
  });
@@ -256,6 +273,7 @@ async function installLintStaged(config) {
256
273
  var init_lint_staged = __esm({
257
274
  "src/services/lint-staged.ts"() {
258
275
  "use strict";
276
+ init_esm_shims();
259
277
  init_pm();
260
278
  init_formatter();
261
279
  init_linter();
@@ -265,7 +283,7 @@ var init_lint_staged = __esm({
265
283
  // src/services/env.ts
266
284
  import { select as select5, confirm, text as text2, multiselect as multiselect2 } from "@clack/prompts";
267
285
  import fs5 from "fs-extra";
268
- import path from "path";
286
+ import path2 from "path";
269
287
  async function promptEnv(config) {
270
288
  const variant = await select5({
271
289
  message: "Which @t3-oss/env variant?",
@@ -341,7 +359,7 @@ import { ${config.envValidator} } from "${config.envValidator}";
341
359
  ${presetImport}`;
342
360
  if (config.envSplit === "split") {
343
361
  await fs5.outputFile(
344
- path.join(targetDir, "env/server.ts"),
362
+ path2.join(targetDir, "env/server.ts"),
345
363
  `${content}
346
364
  // Server env definition
347
365
  export const env = createEnv({
@@ -352,7 +370,7 @@ export const env = createEnv({
352
370
  });`
353
371
  );
354
372
  await fs5.outputFile(
355
- path.join(targetDir, "env/client.ts"),
373
+ path2.join(targetDir, "env/client.ts"),
356
374
  `${content}
357
375
  // Client env definition
358
376
  export const env = createEnv({
@@ -366,7 +384,7 @@ export const env = createEnv({
366
384
  );
367
385
  } else {
368
386
  await fs5.outputFile(
369
- path.join(targetDir, "env.ts"),
387
+ path2.join(targetDir, "env.ts"),
370
388
  `${content}
371
389
  // Joined env definition
372
390
  export const env = createEnv({
@@ -386,10 +404,169 @@ export const env = createEnv({
386
404
  var init_env = __esm({
387
405
  "src/services/env.ts"() {
388
406
  "use strict";
407
+ init_esm_shims();
389
408
  init_pm();
390
409
  }
391
410
  });
392
411
 
412
+ // src/services/test.ts
413
+ import { select as select6 } from "@clack/prompts";
414
+ import fs6 from "fs-extra";
415
+ async function promptTest(config) {
416
+ const runner = await select6({
417
+ message: "Select a test runner:",
418
+ options: [
419
+ { value: "vitest", label: "Vitest" },
420
+ { value: "jest", label: "Jest" }
421
+ ]
422
+ });
423
+ config.testRunner = runner;
424
+ }
425
+ async function installTest(config) {
426
+ if (config.testRunner === "vitest") {
427
+ await installPackages(["vitest"], true);
428
+ const configFile = "vitest.config.ts";
429
+ if (!await fs6.pathExists(configFile)) {
430
+ await fs6.outputFile(
431
+ configFile,
432
+ `import { defineConfig } from 'vitest/config';
433
+
434
+ export default defineConfig({
435
+ test: {
436
+ environment: 'node',
437
+ },
438
+ });
439
+ `
440
+ );
441
+ }
442
+ } else if (config.testRunner === "jest") {
443
+ await installPackages(["jest", "ts-jest", "@types/jest"], true);
444
+ const configFile = "jest.config.js";
445
+ if (!await fs6.pathExists(configFile)) {
446
+ await fs6.outputFile(
447
+ configFile,
448
+ `/** @type {import('ts-jest').JestConfigWithTsJest} */
449
+ module.exports = {
450
+ preset: 'ts-jest',
451
+ testEnvironment: 'node',
452
+ };
453
+ `
454
+ );
455
+ }
456
+ }
457
+ }
458
+ var init_test = __esm({
459
+ "src/services/test.ts"() {
460
+ "use strict";
461
+ init_esm_shims();
462
+ init_pm();
463
+ }
464
+ });
465
+
466
+ // src/services/editor-config.ts
467
+ import { select as select7 } from "@clack/prompts";
468
+ import fs7 from "fs-extra";
469
+ async function promptEditorConfig(config) {
470
+ const preset = await select7({
471
+ message: "Select EditorConfig preset:",
472
+ options: [
473
+ { value: "default", label: "Default (Spaces 2)" },
474
+ { value: "spaces4", label: "Spaces 4" },
475
+ { value: "tabs", label: "Tabs" }
476
+ ]
477
+ });
478
+ config.editorConfigPreset = preset;
479
+ }
480
+ async function installEditorConfig(config) {
481
+ let content = "root = true\n\n[*]\ncharset = utf-8\nend_of_line = lf\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n";
482
+ if (config.editorConfigPreset === "default" || config.editorConfigPreset === "spaces2") {
483
+ content += "indent_style = space\nindent_size = 2\n";
484
+ } else if (config.editorConfigPreset === "spaces4") {
485
+ content += "indent_style = space\nindent_size = 4\n";
486
+ } else if (config.editorConfigPreset === "tabs") {
487
+ content += "indent_style = tab\n";
488
+ }
489
+ await fs7.outputFile(".editorconfig", content);
490
+ }
491
+ var init_editor_config = __esm({
492
+ "src/services/editor-config.ts"() {
493
+ "use strict";
494
+ init_esm_shims();
495
+ }
496
+ });
497
+
498
+ // src/services/license.ts
499
+ import { text as text3, select as select8 } from "@clack/prompts";
500
+ import fs8 from "fs-extra";
501
+ import path3 from "path";
502
+ async function promptLicense(config) {
503
+ const name = await text3({
504
+ message: "License Holder Name:",
505
+ placeholder: "John Doe",
506
+ initialValue: config.authorName || ""
507
+ });
508
+ config.licenseName = name;
509
+ const email = await text3({
510
+ message: "License Holder Email:",
511
+ placeholder: "john@example.com"
512
+ });
513
+ config.licenseEmail = email;
514
+ const website = await text3({
515
+ message: "License Holder Website:",
516
+ placeholder: "https://example.com"
517
+ });
518
+ config.licenseWebsite = website;
519
+ const type = await select8({
520
+ message: "Select License Type:",
521
+ options: [
522
+ { value: "MIT", label: "MIT" },
523
+ { value: "ISC", label: "ISC" },
524
+ { value: "Apache-2.0", label: "Apache 2.0" },
525
+ { value: "UNLICENSED", label: "UNLICENSED" }
526
+ ]
527
+ });
528
+ config.licenseType = type;
529
+ }
530
+ async function installLicense(config) {
531
+ if (config.licenseType !== "UNLICENSED") {
532
+ const year = (/* @__PURE__ */ new Date()).getFullYear().toString();
533
+ const templatePath = path3.join(
534
+ __dirname,
535
+ "licenses",
536
+ `${config.licenseType}.txt`
537
+ );
538
+ if (await fs8.pathExists(templatePath)) {
539
+ let licenseContent = await fs8.readFile(templatePath, "utf-8");
540
+ licenseContent = licenseContent.replace(/{YEAR}/g, year);
541
+ licenseContent = licenseContent.replace(/{HOLDER}/g, config.licenseName);
542
+ licenseContent = licenseContent.replace(/{EMAIL}/g, config.licenseEmail);
543
+ licenseContent = licenseContent.replace(
544
+ /{WEBSITE}/g,
545
+ config.licenseWebsite
546
+ );
547
+ await fs8.outputFile("LICENSE", licenseContent);
548
+ } else {
549
+ const simpleContent = `Copyright (c) ${year} ${config.licenseName}
550
+ Licensed under ${config.licenseType}`;
551
+ await fs8.outputFile("LICENSE", simpleContent);
552
+ }
553
+ }
554
+ if (await fs8.pathExists("package.json")) {
555
+ const pkg = await fs8.readJson("package.json");
556
+ pkg.license = config.licenseType;
557
+ if (config.licenseName) {
558
+ pkg.author = `${config.licenseName} <${config.licenseEmail}> (${config.licenseWebsite})`;
559
+ }
560
+ await fs8.writeJson("package.json", pkg, { spaces: 2 });
561
+ }
562
+ }
563
+ var init_license = __esm({
564
+ "src/services/license.ts"() {
565
+ "use strict";
566
+ init_esm_shims();
567
+ }
568
+ });
569
+
393
570
  // src/utils/git.ts
394
571
  import { execa as execa3 } from "execa";
395
572
  async function isGitRepository() {
@@ -415,6 +592,7 @@ async function commitChanges(message) {
415
592
  var init_git = __esm({
416
593
  "src/utils/git.ts"() {
417
594
  "use strict";
595
+ init_esm_shims();
418
596
  }
419
597
  });
420
598
 
@@ -424,7 +602,7 @@ var init_package = __esm({
424
602
  "package.json"() {
425
603
  package_default = {
426
604
  name: "@mayrlabs/setup-project",
427
- version: "0.1.3",
605
+ version: "0.1.4",
428
606
  description: "Interactive CLI to setup project tools",
429
607
  private: false,
430
608
  publishConfig: {
@@ -457,7 +635,11 @@ var init_package = __esm({
457
635
  directory: "packages/setup-project"
458
636
  },
459
637
  license: "MIT",
460
- author: "Aghogho Meyoron <youngmayor.dev@gmail.com>",
638
+ author: {
639
+ name: "Aghogho Meyoron",
640
+ email: "youngmayor.dev@gmail.com",
641
+ url: "https://mayrlabs.com"
642
+ },
461
643
  type: "commonjs",
462
644
  main: "dist/index.js",
463
645
  scripts: {
@@ -483,6 +665,41 @@ var init_package = __esm({
483
665
  }
484
666
  });
485
667
 
668
+ // src/utils/logger.ts
669
+ import fs9 from "fs-extra";
670
+ import path4 from "path";
671
+ async function logError(error) {
672
+ try {
673
+ await fs9.ensureDir(ERRORS_DIR);
674
+ const gitignorePath = path4.join(LOG_DIR, ".gitignore");
675
+ if (!await fs9.pathExists(gitignorePath)) {
676
+ await fs9.outputFile(gitignorePath, "*\n");
677
+ }
678
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
679
+ const logFile = path4.join(ERRORS_DIR, `log-${timestamp}.txt`);
680
+ const errorMessage = error instanceof Error ? error.stack || error.message : String(error);
681
+ const logContent = `Timestamp: ${(/* @__PURE__ */ new Date()).toISOString()}
682
+
683
+ Error:
684
+ ${errorMessage}
685
+ `;
686
+ await fs9.outputFile(logFile, logContent);
687
+ return logFile;
688
+ } catch (e) {
689
+ console.error("Failed to log error:", e);
690
+ return "";
691
+ }
692
+ }
693
+ var LOG_DIR, ERRORS_DIR;
694
+ var init_logger = __esm({
695
+ "src/utils/logger.ts"() {
696
+ "use strict";
697
+ init_esm_shims();
698
+ LOG_DIR = ".mayrlabs/setup-project";
699
+ ERRORS_DIR = path4.join(LOG_DIR, "errors");
700
+ }
701
+ });
702
+
486
703
  // src/index.ts
487
704
  import {
488
705
  intro,
@@ -498,112 +715,155 @@ import pc from "picocolors";
498
715
  import { program } from "commander";
499
716
  var require_index = __commonJS({
500
717
  "src/index.ts"() {
718
+ init_esm_shims();
501
719
  init_husky();
502
720
  init_formatter();
503
721
  init_linter();
504
722
  init_lint_staged();
505
723
  init_env();
724
+ init_test();
725
+ init_editor_config();
726
+ init_license();
506
727
  init_git();
507
728
  init_package();
729
+ init_logger();
508
730
  async function main() {
509
- intro(pc.bgCyan(pc.black(" @mayrlabs/setup-project ")));
510
- if (await isGitRepository()) {
511
- if (await isGitDirty()) {
512
- const shouldCommit = await confirm2({
513
- message: "Your working directory is dirty. Would you like to commit changes before proceeding?"
514
- });
515
- if (shouldCommit) {
516
- const message = await import("@clack/prompts").then(
517
- (m) => m.text({
518
- message: "Enter commit message:",
519
- placeholder: "wip: pre-setup commit",
520
- validate(value) {
521
- if (value.length === 0) return "Commit message is required";
522
- }
523
- })
524
- );
525
- if (typeof message === "string") {
526
- const s2 = spinner();
527
- s2.start("Committing changes...");
528
- await commitChanges(message);
529
- s2.stop("Changes committed.");
731
+ try {
732
+ intro(pc.bgCyan(pc.black(" @mayrlabs/setup-project ")));
733
+ if (await isGitRepository()) {
734
+ if (await isGitDirty()) {
735
+ const shouldCommit = await confirm2({
736
+ message: "Your working directory is dirty. Would you like to commit changes before proceeding?"
737
+ });
738
+ if (shouldCommit) {
739
+ const message = await import("@clack/prompts").then(
740
+ (m) => m.text({
741
+ message: "Enter commit message:",
742
+ placeholder: "wip: pre-setup commit",
743
+ validate(value) {
744
+ if (value.length === 0) return "Commit message is required";
745
+ }
746
+ })
747
+ );
748
+ if (typeof message === "string") {
749
+ const s2 = spinner();
750
+ s2.start("Committing changes...");
751
+ await commitChanges(message);
752
+ s2.stop("Changes committed.");
753
+ }
530
754
  }
531
755
  }
532
756
  }
533
- }
534
- const tools = await multiselect3({
535
- message: "Select tools to configure:",
536
- options: [
537
- { value: "husky", label: "Husky" },
538
- { value: "formatter", label: "Formatter (Prettier/Oxfmt)" },
539
- { value: "linter", label: "Linter (Eslint/Oxlint)" },
540
- { value: "lint-staged", label: "Lint-staged" },
541
- { value: "env", label: "Env Validation (@t3-oss/env)" }
542
- ],
543
- required: false
544
- });
545
- if (isCancel(tools)) {
546
- cancel("Operation cancelled.");
547
- process.exit(0);
548
- }
549
- const selectedTools = tools;
550
- const config = {
551
- husky: selectedTools.includes("husky"),
552
- formatter: selectedTools.includes("formatter"),
553
- linter: selectedTools.includes("linter"),
554
- lintStaged: selectedTools.includes("lint-staged"),
555
- env: selectedTools.includes("env")
556
- };
557
- if (config.husky) await promptHusky(config);
558
- if (config.formatter) await promptFormatter(config);
559
- if (config.linter) await promptLinter(config);
560
- if (config.lintStaged) await promptLintStaged(config);
561
- if (config.env) await promptEnv(config);
562
- let summary = "The following actions will be performed:\n\n";
563
- if (config.husky) summary += "- Install and configure Husky\n";
564
- if (config.formatter)
565
- summary += `- Install and configure ${config.formatterChoice}
757
+ const tools = await multiselect3({
758
+ message: "Select tools to configure:",
759
+ options: [
760
+ { value: "husky", label: "Husky" },
761
+ { value: "formatter", label: "Formatter (Prettier/Oxfmt)" },
762
+ { value: "linter", label: "Linter (Eslint/Oxlint)" },
763
+ { value: "lint-staged", label: "Lint-staged" },
764
+ { value: "env", label: "Env Validation (@t3-oss/env)" },
765
+ { value: "test", label: "Test Runner (Vitest/Jest)" },
766
+ { value: "editorConfig", label: "EditorConfig" },
767
+ { value: "license", label: "License" }
768
+ ],
769
+ required: false
770
+ });
771
+ if (isCancel(tools)) {
772
+ cancel("Operation cancelled.");
773
+ process.exit(0);
774
+ }
775
+ const selectedTools = tools;
776
+ const config = {
777
+ husky: selectedTools.includes("husky"),
778
+ formatter: selectedTools.includes("formatter"),
779
+ linter: selectedTools.includes("linter"),
780
+ lintStaged: selectedTools.includes("lint-staged"),
781
+ env: selectedTools.includes("env"),
782
+ test: selectedTools.includes("test"),
783
+ editorConfig: selectedTools.includes("editorConfig"),
784
+ license: selectedTools.includes("license")
785
+ };
786
+ if (config.husky) await promptHusky(config);
787
+ if (config.formatter) await promptFormatter(config);
788
+ if (config.linter) await promptLinter(config);
789
+ if (config.lintStaged) await promptLintStaged(config);
790
+ if (config.env) await promptEnv(config);
791
+ if (config.test) await promptTest(config);
792
+ if (config.editorConfig) await promptEditorConfig(config);
793
+ if (config.license) await promptLicense(config);
794
+ let summary = "The following actions will be performed:\n\n";
795
+ if (config.husky) summary += "- Install and configure Husky\n";
796
+ if (config.formatter)
797
+ summary += `- Install and configure ${config.formatterChoice}
566
798
  `;
567
- if (config.linter)
568
- summary += `- Install and configure ${config.linterChoice}
799
+ if (config.linter)
800
+ summary += `- Install and configure ${config.linterChoice}
569
801
  `;
570
- if (config.lintStaged) summary += "- Install and configure Lint-staged\n";
571
- if (config.env) summary += "- Install and configure @t3-oss/env\n";
572
- note(summary, "Configuration Summary");
573
- const proceed = await confirm2({
574
- message: "Do you want to proceed with the installation?"
575
- });
576
- if (!proceed || isCancel(proceed)) {
577
- cancel("Installation cancelled. Configuration saved.");
578
- process.exit(0);
579
- }
580
- const s = spinner();
581
- if (config.husky) {
582
- s.start("Setting up Husky...");
583
- await installHusky(config);
584
- s.stop("Husky setup complete.");
585
- }
586
- if (config.formatter) {
587
- s.start(`Setting up ${config.formatterChoice}...`);
588
- await installFormatter(config);
589
- s.stop(`${config.formatterChoice} setup complete.`);
590
- }
591
- if (config.linter) {
592
- s.start(`Setting up ${config.linterChoice}...`);
593
- await installLinter(config);
594
- s.stop(`${config.linterChoice} setup complete.`);
595
- }
596
- if (config.lintStaged) {
597
- s.start("Setting up Lint-staged...");
598
- await installLintStaged(config);
599
- s.stop("Lint-staged setup complete.");
600
- }
601
- if (config.env) {
602
- s.start("Setting up Env Validation...");
603
- await installEnv(config);
604
- s.stop("Env Validation setup complete.");
802
+ if (config.lintStaged) summary += "- Install and configure Lint-staged\n";
803
+ if (config.env) summary += "- Install and configure @t3-oss/env\n";
804
+ if (config.test)
805
+ summary += `- Install and configure ${config.testRunner}
806
+ `;
807
+ if (config.editorConfig) summary += "- Create .editorconfig\n";
808
+ if (config.license) summary += `- Create LICENSE (${config.licenseType})
809
+ `;
810
+ note(summary, "Configuration Summary");
811
+ const proceed = await confirm2({
812
+ message: "Do you want to proceed with the installation?"
813
+ });
814
+ if (!proceed || isCancel(proceed)) {
815
+ cancel("Installation cancelled. Configuration saved.");
816
+ process.exit(0);
817
+ }
818
+ const s = spinner();
819
+ if (config.husky) {
820
+ s.start("Setting up Husky...");
821
+ await installHusky(config);
822
+ s.stop("Husky setup complete.");
823
+ }
824
+ if (config.formatter) {
825
+ s.start(`Setting up ${config.formatterChoice}...`);
826
+ await installFormatter(config);
827
+ s.stop(`${config.formatterChoice} setup complete.`);
828
+ }
829
+ if (config.linter) {
830
+ s.start(`Setting up ${config.linterChoice}...`);
831
+ await installLinter(config);
832
+ s.stop(`${config.linterChoice} setup complete.`);
833
+ }
834
+ if (config.lintStaged) {
835
+ s.start("Setting up Lint-staged...");
836
+ await installLintStaged(config);
837
+ s.stop("Lint-staged setup complete.");
838
+ }
839
+ if (config.env) {
840
+ s.start("Setting up Env Validation...");
841
+ await installEnv(config);
842
+ s.stop("Env Validation setup complete.");
843
+ }
844
+ if (config.test) {
845
+ s.start(`Setting up ${config.testRunner}...`);
846
+ await installTest(config);
847
+ s.stop(`${config.testRunner} setup complete.`);
848
+ }
849
+ if (config.editorConfig) {
850
+ s.start("Creating .editorconfig...");
851
+ await installEditorConfig(config);
852
+ s.stop(".editorconfig created.");
853
+ }
854
+ if (config.license) {
855
+ s.start("Creating LICENSE...");
856
+ await installLicense(config);
857
+ s.stop("LICENSE created.");
858
+ }
859
+ outro(pc.green("Setup complete!"));
860
+ } catch (error) {
861
+ const logPath = await logError(error);
862
+ outro(pc.red(`
863
+ Something went wrong!
864
+ Error log saved to: ${logPath}`));
865
+ process.exit(1);
605
866
  }
606
- outro(pc.green("Setup complete!"));
607
867
  }
608
868
  program.name("setup-project").description("Interactive setup for common project tools").version(package_default.version).action(main);
609
869
  program.parse();
@@ -616,4 +876,3 @@ export default require_index();
616
876
  * Software should feel intentional.
617
877
  */
618
878
 
619
- //# sourceMappingURL=index.mjs.map