fwinit 1.0.5 → 1.1.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 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@
4
4
  import { Command } from "commander";
5
5
  import ora from "ora";
6
6
  import chalk from "chalk";
7
+ import { mkdir as mkdir2, cp as cp2, access } from "fs/promises";
8
+ import { join as join2 } from "path";
7
9
 
8
10
  // src/templates.ts
9
11
  var TEMPLATES = [
@@ -82,7 +84,7 @@ async function downloadAndExtract(templateFolder) {
82
84
  `Template "${templateFolder}" not found in repository`
83
85
  );
84
86
  }
85
- return { tempDir, templatePath };
87
+ return { tempDir, templatePath, repoRoot };
86
88
  }
87
89
  async function copyTemplate(source, destination) {
88
90
  await cp(source, destination, { recursive: true });
@@ -332,8 +334,8 @@ function adaptScriptToNode(script) {
332
334
  }
333
335
  async function adaptToNodeRuntime(projectPath) {
334
336
  const { readFile: readFile2, writeFile: writeFile2, readdir: readdir2 } = await import("fs/promises");
335
- const { join: join2 } = await import("path");
336
- const pkgPath = join2(projectPath, "package.json");
337
+ const { join: join3 } = await import("path");
338
+ const pkgPath = join3(projectPath, "package.json");
337
339
  const pkg = JSON.parse(await readFile2(pkgPath, "utf-8"));
338
340
  for (const key of Object.keys(pkg.scripts ?? {})) {
339
341
  pkg.scripts[key] = adaptScriptToNode(pkg.scripts[key]);
@@ -346,7 +348,7 @@ async function adaptToNodeRuntime(projectPath) {
346
348
  async function walk(dir) {
347
349
  const entries = await readdir2(dir, { withFileTypes: true });
348
350
  for (const entry of entries) {
349
- const full = join2(dir, entry.name);
351
+ const full = join3(dir, entry.name);
350
352
  if (entry.isDirectory()) {
351
353
  if (entry.name !== "node_modules") await walk(full);
352
354
  } else if (entry.name.endsWith(".test.ts")) {
@@ -357,12 +359,12 @@ async function adaptToNodeRuntime(projectPath) {
357
359
  }
358
360
  }
359
361
  }
360
- const srcDir = join2(projectPath, "src");
362
+ const srcDir = join3(projectPath, "src");
361
363
  try {
362
364
  await walk(srcDir);
363
365
  } catch {
364
366
  }
365
- const tsconfigPath = join2(projectPath, "tsconfig.json");
367
+ const tsconfigPath = join3(projectPath, "tsconfig.json");
366
368
  try {
367
369
  const tsconfig = JSON.parse(await readFile2(tsconfigPath, "utf-8"));
368
370
  if (tsconfig.compilerOptions?.types?.includes("bun-types")) {
@@ -376,6 +378,30 @@ async function adaptToNodeRuntime(projectPath) {
376
378
  // src/index.ts
377
379
  var program = new Command();
378
380
  var PACKAGE_MANAGERS = ["npm", "pnpm", "bun"];
381
+ async function installOpenCodeFiles(repoRoot, projectPath) {
382
+ const skill = join2(repoRoot, "skills", "create-specs", "SKILL.md");
383
+ const command = join2(repoRoot, "skills", "create-specs", "command.md");
384
+ try {
385
+ await access(skill);
386
+ await access(command);
387
+ } catch {
388
+ return;
389
+ }
390
+ await mkdir2(join2(projectPath, ".opencode", "skills", "create-specs"), {
391
+ recursive: true
392
+ });
393
+ await mkdir2(join2(projectPath, ".opencode", "commands"), {
394
+ recursive: true
395
+ });
396
+ await cp2(
397
+ skill,
398
+ join2(projectPath, ".opencode", "skills", "create-specs", "SKILL.md")
399
+ );
400
+ await cp2(
401
+ command,
402
+ join2(projectPath, ".opencode", "commands", "create-specs.md")
403
+ );
404
+ }
379
405
  program.name("fwinit").description("CLI para crear proyectos desde templates").version("1.0.0");
380
406
  program.command("list").description("Mostrar templates disponibles").action(() => {
381
407
  console.log(
@@ -440,7 +466,7 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
440
466
  const spinner = ora(
441
467
  `Descargando template ${template.name}...`
442
468
  ).start();
443
- const { tempDir, templatePath } = await downloadAndExtract(template.folder);
469
+ const { tempDir, templatePath, repoRoot } = await downloadAndExtract(template.folder);
444
470
  spinner.text = "Creando proyecto...";
445
471
  await copyTemplate(
446
472
  templatePath,
@@ -451,6 +477,10 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
451
477
  projectName,
452
478
  template.folder
453
479
  );
480
+ await installOpenCodeFiles(
481
+ repoRoot,
482
+ getProjectPath(projectName)
483
+ );
454
484
  if (template.runtime === "bun" && pm && pm !== "bun") {
455
485
  await adaptToNodeRuntime(getProjectPath(projectName));
456
486
  }
@@ -459,10 +489,10 @@ program.argument("[template]", "Template a usar").argument("[project-name]", "No
459
489
  let postInit;
460
490
  try {
461
491
  const { readFile: readFile2 } = await import("fs/promises");
462
- const { join: join2 } = await import("path");
492
+ const { join: join3 } = await import("path");
463
493
  const tj = JSON.parse(
464
494
  await readFile2(
465
- join2(getProjectPath(projectName), "template.json"),
495
+ join3(getProjectPath(projectName), "template.json"),
466
496
  "utf-8"
467
497
  )
468
498
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwinit",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "CLI para crear proyectos desde templates",
5
5
  "type": "module",
6
6
  "bin": {