fwinit 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +39 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -249,6 +249,17 @@ async function askProjectName() {
249
249
  ]);
250
250
  return name.trim();
251
251
  }
252
+ async function askBackendLayout() {
253
+ const { layout } = await inquirer.prompt([
254
+ {
255
+ type: "confirm",
256
+ name: "layout",
257
+ message: "\xBFEmpaquetar el c\xF3digo del template en una carpeta backend/?",
258
+ default: true
259
+ }
260
+ ]);
261
+ return layout;
262
+ }
252
263
 
253
264
  // src/utils.ts
254
265
  import { existsSync } from "fs";
@@ -311,16 +322,17 @@ function resolveCommand(cmd, pm) {
311
322
  return cmd;
312
323
  }
313
324
  }
314
- function printSuccess(projectName, templateName, pm, postInit) {
325
+ function printSuccess(projectName, templateName, pm, postInit, codeDir) {
315
326
  const installCmd = postInit?.install ? resolveCommand(postInit.install, pm) : `${pm} install`;
316
327
  const devCmd = postInit?.dev ? resolveCommand(postInit.dev, pm) : `${pm} run dev`;
328
+ const target = codeDir ? `${projectName}/${codeDir}` : projectName;
317
329
  console.log(`
318
330
  \x1B[32m\u2714\x1B[0m Template descargado
319
- \x1B[32m\u2714\x1B[0m Proyecto creado en ./${projectName}
331
+ \x1B[32m\u2714\x1B[0m Proyecto creado en ./${target}
320
332
 
321
333
  \x1B[1mPr\xF3ximos pasos:\x1B[0m
322
334
 
323
- \x1B[36mcd ${projectName}\x1B[0m
335
+ \x1B[36mcd ${target}\x1B[0m
324
336
  \x1B[36m${installCmd}\x1B[0m
325
337
  \x1B[36m${devCmd}\x1B[0m
326
338
  `);
@@ -424,10 +436,10 @@ program.command("list").description("Mostrar templates disponibles").action(() =
424
436
  });
425
437
  console.log();
426
438
  });
427
- program.argument("[template]", "Template a usar").argument("[project-name]", "Nombre del proyecto").option("-p, --pm <package-manager>", "Package manager a usar: npm, pnpm o bun").action(
439
+ program.argument("[template]", "Template a usar").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)").action(
428
440
  async (templateArg, projectNameArg) => {
429
441
  try {
430
- const { pm: pmArg } = program.opts();
442
+ const { pm: pmArg, backend } = program.opts();
431
443
  if (pmArg && !PACKAGE_MANAGERS.includes(pmArg)) {
432
444
  console.error(
433
445
  chalk.red(
@@ -461,6 +473,7 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
461
473
  if (!projectName) {
462
474
  projectName = await askProjectName();
463
475
  }
476
+ const useBackendLayout = backend === void 0 ? await askBackendLayout() : backend;
464
477
  if (!pm && template.runtime !== "dotnet") {
465
478
  pm = await selectPackageManager();
466
479
  }
@@ -477,22 +490,24 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
477
490
  `Descargando template ${template.name}...`
478
491
  ).start();
479
492
  const { tempDir, templatePath, repoRoot } = await downloadAndExtract(template.folder);
493
+ const projectPath = getProjectPath(projectName);
494
+ const codePath = useBackendLayout ? join2(projectPath, "backend") : projectPath;
480
495
  spinner.text = "Creando proyecto...";
481
496
  await copyTemplate(
482
497
  templatePath,
483
- getProjectPath(projectName)
498
+ codePath
484
499
  );
485
500
  await substituteTemplate(
486
- getProjectPath(projectName),
501
+ codePath,
487
502
  projectName,
488
503
  template.folder
489
504
  );
490
505
  await installOpenCodeFiles(
491
506
  repoRoot,
492
- getProjectPath(projectName)
507
+ projectPath
493
508
  );
494
509
  if (template.runtime === "bun" && pm && pm !== "bun") {
495
- await adaptToNodeRuntime(getProjectPath(projectName));
510
+ await adaptToNodeRuntime(codePath);
496
511
  }
497
512
  await cleanup(tempDir);
498
513
  spinner.succeed("Template descargado");
@@ -502,14 +517,27 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
502
517
  const { join: join3 } = await import("path");
503
518
  const tj = JSON.parse(
504
519
  await readFile2(
505
- join3(getProjectPath(projectName), "template.json"),
520
+ join3(codePath, "template.json"),
506
521
  "utf-8"
507
522
  )
508
523
  );
509
524
  postInit = tj.postInit;
510
525
  } catch {
511
526
  }
512
- printSuccess(projectName, template.name, pm ?? "npm", postInit);
527
+ printSuccess(
528
+ projectName,
529
+ template.name,
530
+ pm ?? "npm",
531
+ postInit,
532
+ useBackendLayout ? "backend" : void 0
533
+ );
534
+ if (useBackendLayout) {
535
+ console.log(
536
+ chalk.dim(
537
+ " Estructura: backend/ (c\xF3digo) \xB7 .opencode/ y specs/ (al mismo nivel)\n"
538
+ )
539
+ );
540
+ }
513
541
  } catch (error) {
514
542
  console.error(
515
543
  chalk.red(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwinit",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "CLI para crear proyectos desde templates",
5
5
  "type": "module",
6
6
  "bin": {