fwinit 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +64 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import ora from "ora";
6
6
  import chalk from "chalk";
7
7
  import { readFileSync } from "fs";
8
8
  import { mkdir as mkdir2, cp as cp2, access, readFile as readFile2 } from "fs/promises";
9
- import { join as join2 } from "path";
9
+ import { join as join2, basename } from "path";
10
10
 
11
11
  // src/templates.ts
12
12
  var TEMPLATES = [
@@ -243,6 +243,17 @@ async function selectTemplateFromLayer(layer) {
243
243
  ]);
244
244
  return template;
245
245
  }
246
+ async function askGitInit() {
247
+ const { initGit } = await inquirer.prompt([
248
+ {
249
+ type: "confirm",
250
+ name: "initGit",
251
+ message: "\xBFInicializar un repositorio git?",
252
+ default: true
253
+ }
254
+ ]);
255
+ return initGit;
256
+ }
246
257
  async function selectPackageManager() {
247
258
  const { pm } = await inquirer.prompt([
248
259
  {
@@ -431,10 +442,9 @@ async function adaptToNodeRuntime(projectPath) {
431
442
  } catch {
432
443
  }
433
444
  }
434
- async function writeRootFiles(info) {
445
+ async function writeRootGitignore(projectPath) {
435
446
  const { writeFile: writeFile2, access: access2 } = await import("fs/promises");
436
447
  const { join: join3 } = await import("path");
437
- const projectPath = resolve(process.cwd(), info.projectName);
438
448
  const gitignorePath = join3(projectPath, ".gitignore");
439
449
  try {
440
450
  await access2(gitignorePath);
@@ -444,6 +454,28 @@ async function writeRootFiles(info) {
444
454
  "# AI dev state\n.atl/\nodd\n.opencode/\n"
445
455
  );
446
456
  }
457
+ }
458
+ async function gitInit(projectPath) {
459
+ const { execFile } = await import("child_process");
460
+ try {
461
+ await new Promise((resolve2, reject) => {
462
+ execFile(
463
+ "git",
464
+ ["init"],
465
+ { cwd: projectPath },
466
+ (err) => err ? reject(err) : resolve2()
467
+ );
468
+ });
469
+ return true;
470
+ } catch {
471
+ return false;
472
+ }
473
+ }
474
+ async function writeRootFiles(info) {
475
+ const { writeFile: writeFile2 } = await import("fs/promises");
476
+ const { join: join3 } = await import("path");
477
+ const projectPath = resolve(process.cwd(), info.projectName);
478
+ await writeRootGitignore(projectPath);
447
479
  const installB = info.backend.postInit?.install ? resolveCommand(info.backend.postInit.install, info.pm) : `${info.pm} install`;
448
480
  const devB = info.backend.postInit?.dev ? resolveCommand(info.backend.postInit.dev, info.pm) : `${info.pm} run dev`;
449
481
  const installF = info.frontend.postInit?.install ? resolveCommand(info.frontend.postInit.install, info.pm) : `${info.pm} install`;
@@ -526,9 +558,9 @@ async function readTemplatePostInit(dir) {
526
558
  return void 0;
527
559
  }
528
560
  }
529
- async function createFullStackProject(projectName, backendTpl, frontendTpl, pm) {
561
+ async function createFullStackProject(projectPath, backendTpl, frontendTpl, pm) {
530
562
  const { tempDir, repoRoot } = await downloadAndExtractRepo();
531
- const projectPath = getProjectPath(projectName);
563
+ const projectName = basename(projectPath);
532
564
  const backendPath = join2(projectPath, "backend");
533
565
  const frontendPath = join2(projectPath, "frontend");
534
566
  await copyTemplate(
@@ -595,10 +627,10 @@ program.command("list").description("Mostrar templates disponibles").action(() =
595
627
  console.log();
596
628
  }
597
629
  });
598
- program.argument("[template]", "Template a usar (o 'fullstack' para backend + frontend)").argument("[project-name]", "Nombre del proyecto").option("-p, --pm <package-manager>", "Package manager a usar: npm, pnpm o bun").option("--backend", "Empaquetar el c\xF3digo en backend/ (saltea la pregunta)").option("--no-backend", "Dejar el c\xF3digo en la ra\xEDz del proyecto (saltea la pregunta)").option("-b, --backend-template <tpl>", "Backend a usar en fullstack (saltea la pregunta)").option("-f, --frontend-template <tpl>", "Frontend a usar en fullstack (saltea la pregunta)").action(
630
+ program.argument("[template]", "Template a usar (o 'fullstack' para backend + frontend)").argument("[project-name]", "Nombre del proyecto").option("-p, --pm <package-manager>", "Package manager a usar: npm, pnpm o bun").option("--backend", "Empaquetar el c\xF3digo en backend/ (saltea la pregunta)").option("--no-backend", "Dejar el c\xF3digo en la ra\xEDz del proyecto (saltea la pregunta)").option("-b, --backend-template <tpl>", "Backend a usar en fullstack (saltea la pregunta)").option("-f, --frontend-template <tpl>", "Frontend a usar en fullstack (saltea la pregunta)").option("--git", "Inicializar un repositorio git (saltea la pregunta)").option("--no-git", "No inicializar git (saltea la pregunta)").action(
599
631
  async (templateArg, projectNameArg) => {
600
632
  try {
601
- const { pm: pmArg, backend, backendTemplate, frontendTemplate } = program.opts();
633
+ const { pm: pmArg, backend, backendTemplate, frontendTemplate, git } = program.opts();
602
634
  if (pmArg && !PACKAGE_MANAGERS.includes(pmArg)) {
603
635
  console.error(
604
636
  chalk.red(
@@ -688,6 +720,7 @@ program.argument("[template]", "Template a usar (o 'fullstack' para backend + fr
688
720
  if (!pm && needsPm) {
689
721
  pm = await selectPackageManager();
690
722
  }
723
+ const wantsGit = git === void 0 ? await askGitInit() : git;
691
724
  if (projectExists(projectName)) {
692
725
  console.error(
693
726
  chalk.red(
@@ -697,21 +730,29 @@ program.argument("[template]", "Template a usar (o 'fullstack' para backend + fr
697
730
  );
698
731
  process.exit(1);
699
732
  }
733
+ const projectPath = getProjectPath(projectName);
700
734
  const spinner = ora(
701
735
  isFullStack ? "Descargando templates..." : `Descargando template ${template.name}...`
702
736
  ).start();
703
737
  if (isFullStack) {
704
738
  spinner.text = "Creando proyecto...";
705
- await createFullStackProject(projectName, backendTpl, frontendTpl, pm ?? "npm");
739
+ await createFullStackProject(
740
+ projectPath,
741
+ backendTpl,
742
+ frontendTpl,
743
+ pm ?? "npm"
744
+ );
706
745
  spinner.succeed("Template descargado");
707
746
  } else {
708
747
  const { tempDir, templatePath, repoRoot } = await downloadAndExtract(template.folder);
709
- const projectPath = getProjectPath(projectName);
710
748
  const codePath = useLayerLayout ? join2(projectPath, layer) : projectPath;
711
749
  spinner.text = "Creando proyecto...";
712
750
  await copyTemplate(templatePath, codePath);
713
751
  await substituteTemplate(codePath, projectName, template.folder);
714
752
  await installOpenCodeFiles(repoRoot, projectPath);
753
+ if (useLayerLayout) {
754
+ await writeRootGitignore(projectPath);
755
+ }
715
756
  if (template.runtime === "bun" && pm && pm !== "bun") {
716
757
  await adaptToNodeRuntime(codePath);
717
758
  }
@@ -733,6 +774,20 @@ program.argument("[template]", "Template a usar (o 'fullstack' para backend + fr
733
774
  );
734
775
  }
735
776
  }
777
+ if (wantsGit) {
778
+ const ok = await gitInit(projectPath);
779
+ if (ok) {
780
+ console.log(
781
+ chalk.dim(" Git: repositorio inicializado\n")
782
+ );
783
+ } else {
784
+ console.log(
785
+ chalk.yellow(
786
+ " \u26A0 No se pudo inicializar git (\xBFest\xE1 instalado?)\n"
787
+ )
788
+ );
789
+ }
790
+ }
736
791
  } catch (error) {
737
792
  console.error(
738
793
  chalk.red(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwinit",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "CLI para crear proyectos desde templates",
5
5
  "type": "module",
6
6
  "bin": {