fwinit 1.1.1 → 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.
- package/dist/index.js +50 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import ora from "ora";
|
|
6
6
|
import chalk from "chalk";
|
|
7
|
+
import { readFileSync } from "fs";
|
|
7
8
|
import { mkdir as mkdir2, cp as cp2, access } from "fs/promises";
|
|
8
9
|
import { join as join2 } from "path";
|
|
9
10
|
|
|
@@ -248,6 +249,17 @@ async function askProjectName() {
|
|
|
248
249
|
]);
|
|
249
250
|
return name.trim();
|
|
250
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
|
+
}
|
|
251
263
|
|
|
252
264
|
// src/utils.ts
|
|
253
265
|
import { existsSync } from "fs";
|
|
@@ -310,16 +322,17 @@ function resolveCommand(cmd, pm) {
|
|
|
310
322
|
return cmd;
|
|
311
323
|
}
|
|
312
324
|
}
|
|
313
|
-
function printSuccess(projectName, templateName, pm, postInit) {
|
|
325
|
+
function printSuccess(projectName, templateName, pm, postInit, codeDir) {
|
|
314
326
|
const installCmd = postInit?.install ? resolveCommand(postInit.install, pm) : `${pm} install`;
|
|
315
327
|
const devCmd = postInit?.dev ? resolveCommand(postInit.dev, pm) : `${pm} run dev`;
|
|
328
|
+
const target = codeDir ? `${projectName}/${codeDir}` : projectName;
|
|
316
329
|
console.log(`
|
|
317
330
|
\x1B[32m\u2714\x1B[0m Template descargado
|
|
318
|
-
\x1B[32m\u2714\x1B[0m Proyecto creado en ./${
|
|
331
|
+
\x1B[32m\u2714\x1B[0m Proyecto creado en ./${target}
|
|
319
332
|
|
|
320
333
|
\x1B[1mPr\xF3ximos pasos:\x1B[0m
|
|
321
334
|
|
|
322
|
-
\x1B[36mcd ${
|
|
335
|
+
\x1B[36mcd ${target}\x1B[0m
|
|
323
336
|
\x1B[36m${installCmd}\x1B[0m
|
|
324
337
|
\x1B[36m${devCmd}\x1B[0m
|
|
325
338
|
`);
|
|
@@ -378,6 +391,15 @@ async function adaptToNodeRuntime(projectPath) {
|
|
|
378
391
|
// src/index.ts
|
|
379
392
|
var program = new Command();
|
|
380
393
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "bun"];
|
|
394
|
+
function getCliVersion() {
|
|
395
|
+
try {
|
|
396
|
+
const pkgUrl = new URL("../package.json", import.meta.url);
|
|
397
|
+
const pkg = JSON.parse(readFileSync(pkgUrl, "utf-8"));
|
|
398
|
+
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
399
|
+
} catch {
|
|
400
|
+
return "0.0.0";
|
|
401
|
+
}
|
|
402
|
+
}
|
|
381
403
|
async function installOpenCodeFiles(repoRoot, projectPath) {
|
|
382
404
|
const skill = join2(repoRoot, "skills", "create-specs", "SKILL.md");
|
|
383
405
|
const command = join2(repoRoot, "skills", "create-specs", "command.md");
|
|
@@ -402,7 +424,7 @@ async function installOpenCodeFiles(repoRoot, projectPath) {
|
|
|
402
424
|
join2(projectPath, ".opencode", "commands", "create-specs.md")
|
|
403
425
|
);
|
|
404
426
|
}
|
|
405
|
-
program.name("fwinit").description("CLI para crear proyectos desde templates").version(
|
|
427
|
+
program.name("fwinit").description("CLI para crear proyectos desde templates").version(getCliVersion());
|
|
406
428
|
program.command("list").description("Mostrar templates disponibles").action(() => {
|
|
407
429
|
console.log(
|
|
408
430
|
chalk.bold("\nTemplates disponibles:\n")
|
|
@@ -414,10 +436,10 @@ program.command("list").description("Mostrar templates disponibles").action(() =
|
|
|
414
436
|
});
|
|
415
437
|
console.log();
|
|
416
438
|
});
|
|
417
|
-
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(
|
|
418
440
|
async (templateArg, projectNameArg) => {
|
|
419
441
|
try {
|
|
420
|
-
const { pm: pmArg } = program.opts();
|
|
442
|
+
const { pm: pmArg, backend } = program.opts();
|
|
421
443
|
if (pmArg && !PACKAGE_MANAGERS.includes(pmArg)) {
|
|
422
444
|
console.error(
|
|
423
445
|
chalk.red(
|
|
@@ -451,6 +473,7 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
|
|
|
451
473
|
if (!projectName) {
|
|
452
474
|
projectName = await askProjectName();
|
|
453
475
|
}
|
|
476
|
+
const useBackendLayout = backend === void 0 ? await askBackendLayout() : backend;
|
|
454
477
|
if (!pm && template.runtime !== "dotnet") {
|
|
455
478
|
pm = await selectPackageManager();
|
|
456
479
|
}
|
|
@@ -467,22 +490,24 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
|
|
|
467
490
|
`Descargando template ${template.name}...`
|
|
468
491
|
).start();
|
|
469
492
|
const { tempDir, templatePath, repoRoot } = await downloadAndExtract(template.folder);
|
|
493
|
+
const projectPath = getProjectPath(projectName);
|
|
494
|
+
const codePath = useBackendLayout ? join2(projectPath, "backend") : projectPath;
|
|
470
495
|
spinner.text = "Creando proyecto...";
|
|
471
496
|
await copyTemplate(
|
|
472
497
|
templatePath,
|
|
473
|
-
|
|
498
|
+
codePath
|
|
474
499
|
);
|
|
475
500
|
await substituteTemplate(
|
|
476
|
-
|
|
501
|
+
codePath,
|
|
477
502
|
projectName,
|
|
478
503
|
template.folder
|
|
479
504
|
);
|
|
480
505
|
await installOpenCodeFiles(
|
|
481
506
|
repoRoot,
|
|
482
|
-
|
|
507
|
+
projectPath
|
|
483
508
|
);
|
|
484
509
|
if (template.runtime === "bun" && pm && pm !== "bun") {
|
|
485
|
-
await adaptToNodeRuntime(
|
|
510
|
+
await adaptToNodeRuntime(codePath);
|
|
486
511
|
}
|
|
487
512
|
await cleanup(tempDir);
|
|
488
513
|
spinner.succeed("Template descargado");
|
|
@@ -492,14 +517,27 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
|
|
|
492
517
|
const { join: join3 } = await import("path");
|
|
493
518
|
const tj = JSON.parse(
|
|
494
519
|
await readFile2(
|
|
495
|
-
join3(
|
|
520
|
+
join3(codePath, "template.json"),
|
|
496
521
|
"utf-8"
|
|
497
522
|
)
|
|
498
523
|
);
|
|
499
524
|
postInit = tj.postInit;
|
|
500
525
|
} catch {
|
|
501
526
|
}
|
|
502
|
-
printSuccess(
|
|
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
|
+
}
|
|
503
541
|
} catch (error) {
|
|
504
542
|
console.error(
|
|
505
543
|
chalk.red(
|