create-huenei-template 0.2.8 → 0.2.10

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.
@@ -61,6 +61,13 @@ export const TEMPLATE_CATALOG = [
61
61
  description: "Monorepo Angular con Nx para arquitectura escalable de micro-frontends. Ideal para proyectos empresariales.",
62
62
  category: "frontend",
63
63
  path: "frontend/angular-nx",
64
+ },
65
+ {
66
+ id: "cursor-config",
67
+ name: "Cursor Configuration",
68
+ description: "Rules, skills, commands, agents y hooks para desarrollo asistido por IA con Cursor",
69
+ category: "cursor",
70
+ path: "cursor",
64
71
  }
65
72
  ];
66
73
  export function getTemplatesByCategory(category) {
@@ -1,4 +1,5 @@
1
- import { mkdir, cp, rm, access } from "fs/promises";
1
+ import path from "path";
2
+ import { mkdir, cp, rm, access, readdir, stat } from "fs/promises";
2
3
  import { constants } from "fs";
3
4
  export async function ensureDirectory(dirPath) {
4
5
  await mkdir(dirPath, { recursive: true });
@@ -23,3 +24,49 @@ export async function directoryExists(dirPath) {
23
24
  return false;
24
25
  }
25
26
  }
27
+ export async function copyToExistingDir(source, dest) {
28
+ await ensureDirectory(dest);
29
+ await robustCopyDir(source, dest);
30
+ }
31
+ export async function mergeSubdirectories(source, dest, subdirs) {
32
+ for (const subdir of subdirs) {
33
+ const srcPath = path.join(source, subdir);
34
+ const destPath = path.join(dest, subdir);
35
+ if (await directoryExists(srcPath)) {
36
+ await ensureDirectory(destPath);
37
+ await robustCopyDir(srcPath, destPath);
38
+ }
39
+ }
40
+ }
41
+ async function isDirectory(filePath) {
42
+ try {
43
+ const s = await stat(filePath);
44
+ return s.isDirectory();
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ }
50
+ async function robustCopyDir(source, dest) {
51
+ const entries = await readdir(source, { withFileTypes: true });
52
+ for (const entry of entries) {
53
+ const srcEntry = path.join(source, entry.name);
54
+ const destEntry = path.join(dest, entry.name);
55
+ if (await directoryExists(destEntry)) {
56
+ const destIsDir = await isDirectory(destEntry);
57
+ if (entry.isDirectory() && !destIsDir) {
58
+ await rm(destEntry, { force: true });
59
+ }
60
+ else if (!entry.isDirectory() && destIsDir) {
61
+ await rm(destEntry, { recursive: true, force: true });
62
+ }
63
+ }
64
+ if (entry.isDirectory()) {
65
+ await ensureDirectory(destEntry);
66
+ await robustCopyDir(srcEntry, destEntry);
67
+ }
68
+ else {
69
+ await cp(srcEntry, destEntry, { force: true });
70
+ }
71
+ }
72
+ }
@@ -2,113 +2,83 @@ import prompts from "prompts";
2
2
  import { getTemplatesByCategory, getAvailableCategories } from "../config/templates.js";
3
3
  const BACK_OPTION = "<<<BACK>>>";
4
4
  const BACK_LABEL = "← Volver";
5
+ const onCancel = () => {
6
+ throw new Error("USER_CANCELLED");
7
+ };
5
8
  export async function askProjectSetup() {
6
- // Step 1: Project Name (no back option - first step)
7
- const nameResponse = await prompts({
8
- type: "text",
9
- name: "projectName",
10
- message: "Project name",
11
- initial: "my-project",
12
- validate: (value) => {
13
- if (!value || value.trim().length === 0) {
14
- return "Project name is required";
15
- }
16
- if (!/^[a-z0-9-_]+$/i.test(value)) {
17
- return "Project name can only contain letters, numbers, hyphens and underscores";
18
- }
19
- return true;
20
- },
21
- }, {
22
- onCancel: () => {
23
- throw new Error("USER_CANCELLED");
24
- },
25
- });
26
- if (!nameResponse.projectName) {
27
- throw new Error("USER_CANCELLED");
28
- }
29
- const projectName = nameResponse.projectName;
30
- // Step 2 & 3: Category and Template Selection (with back navigation)
31
9
  let category = null;
32
10
  let templateId = "";
33
11
  while (!templateId) {
34
- // Step 2: Category Selection (no back option)
35
12
  if (!category) {
36
- const categories = getAvailableCategories();
37
- const choices = categories.map((cat) => ({
38
- title: cat.charAt(0).toUpperCase() + cat.slice(1),
39
- value: cat,
40
- }));
41
- const categoryResponse = await prompts({
42
- type: "select",
43
- name: "category",
44
- message: "Select project category",
45
- choices,
46
- initial: 0,
47
- }, {
48
- onCancel: () => {
49
- throw new Error("USER_CANCELLED");
50
- },
51
- });
52
- if (!categoryResponse.category) {
53
- throw new Error("USER_CANCELLED");
54
- }
55
- category = categoryResponse.category;
13
+ category = await askCategorySelection();
56
14
  }
57
- // Step 3: Template Selection (with back option to change category)
58
- const templates = getTemplatesByCategory(category);
59
- const choices = [
60
- ...templates.map((template) => ({
61
- title: template.name,
62
- description: template.description,
63
- value: template.id,
64
- })),
65
- {
66
- title: BACK_LABEL,
67
- value: BACK_OPTION,
68
- },
69
- ];
70
- const templateResponse = await prompts({
71
- type: "select",
72
- name: "templateId",
73
- message: "Select template",
74
- choices,
75
- initial: 0, // Start at first template, not at back option
76
- }, {
77
- onCancel: () => {
78
- throw new Error("USER_CANCELLED");
79
- },
80
- });
81
- if (!templateResponse.templateId) {
82
- throw new Error("USER_CANCELLED");
15
+ if (category === "cursor") {
16
+ const installScope = await askCursorInstallScope();
17
+ return { mode: "cursor", installScope };
83
18
  }
84
- if (templateResponse.templateId === BACK_OPTION) {
85
- // Go back to category selection (keep project name)
19
+ const result = await askTemplateSelection(category);
20
+ if (result === BACK_OPTION) {
86
21
  category = null;
87
- continue; // Loop back to category selection
22
+ continue;
88
23
  }
89
- templateId = templateResponse.templateId;
24
+ templateId = result;
90
25
  }
91
- // Step 4: pnpm Check
26
+ const projectName = await askProjectName();
92
27
  const pnpmResponse = await prompts({
93
28
  type: "confirm",
94
29
  name: "checkPnpm",
95
30
  message: "Check / install pnpm?",
96
31
  initial: true,
97
- }, {
98
- onCancel: () => {
99
- throw new Error("USER_CANCELLED");
100
- },
101
- });
32
+ }, { onCancel });
102
33
  const checkPnpm = pnpmResponse.checkPnpm ?? true;
103
34
  return {
35
+ mode: "project",
104
36
  projectName,
105
- category: category, // We know it's not null here
106
37
  templateId,
107
38
  checkPnpm,
108
39
  };
109
40
  }
110
- // Legacy functions for backward compatibility (deprecated)
111
- export async function askProjectName() {
41
+ async function askCategorySelection() {
42
+ const categories = getAvailableCategories();
43
+ const choices = categories.map((cat) => ({
44
+ title: cat.charAt(0).toUpperCase() + cat.slice(1),
45
+ value: cat,
46
+ }));
47
+ const response = await prompts({
48
+ type: "select",
49
+ name: "category",
50
+ message: "Select project category",
51
+ choices,
52
+ initial: 0,
53
+ }, { onCancel });
54
+ if (!response.category) {
55
+ throw new Error("USER_CANCELLED");
56
+ }
57
+ return response.category;
58
+ }
59
+ async function askTemplateSelection(category) {
60
+ const templates = getTemplatesByCategory(category);
61
+ const choices = [
62
+ ...templates.map((template) => ({
63
+ title: template.name,
64
+ description: template.description,
65
+ value: template.id,
66
+ })),
67
+ { title: BACK_LABEL, value: BACK_OPTION },
68
+ ];
69
+ const response = await prompts({
70
+ type: "select",
71
+ name: "templateId",
72
+ message: "Select template",
73
+ choices,
74
+ initial: 0,
75
+ }, { onCancel });
76
+ if (!response.templateId) {
77
+ throw new Error("USER_CANCELLED");
78
+ }
79
+ return response.templateId;
80
+ }
81
+ async function askProjectName() {
112
82
  const response = await prompts({
113
83
  type: "text",
114
84
  name: "projectName",
@@ -123,61 +93,33 @@ export async function askProjectName() {
123
93
  }
124
94
  return true;
125
95
  },
126
- });
96
+ }, { onCancel });
127
97
  if (!response.projectName) {
128
- throw new Error("Project name is required");
98
+ throw new Error("USER_CANCELLED");
129
99
  }
130
100
  return response.projectName;
131
101
  }
132
- export async function askCategory() {
133
- const categories = getAvailableCategories();
134
- const response = await prompts({
135
- type: "select",
136
- name: "category",
137
- message: "Select project category",
138
- choices: categories.map((cat) => ({
139
- title: cat.charAt(0).toUpperCase() + cat.slice(1),
140
- value: cat,
141
- })),
142
- });
143
- if (!response.category) {
144
- throw new Error("Category selection is required");
145
- }
146
- return response.category;
147
- }
148
- export async function askTemplate(category) {
149
- const templates = getTemplatesByCategory(category);
150
- if (templates.length === 0) {
151
- throw new Error(`No templates available for category: ${category}`);
152
- }
102
+ export async function askCursorInstallScope() {
153
103
  const response = await prompts({
154
104
  type: "select",
155
- name: "templateId",
156
- message: "Select template",
157
- choices: templates.map((template) => ({
158
- title: template.name,
159
- description: template.description,
160
- value: template.id,
161
- })),
162
- });
163
- if (!response.templateId) {
164
- throw new Error("Template selection is required");
105
+ name: "scope",
106
+ message: "Where do you want to install Cursor configuration?",
107
+ choices: [
108
+ {
109
+ title: "Current project",
110
+ description: "Copy .cursor/ folder into the current working directory",
111
+ value: "project",
112
+ },
113
+ {
114
+ title: "User level (~/.cursor/)",
115
+ description: "Merge skills/ and commands/ into your user-level Cursor config",
116
+ value: "user",
117
+ },
118
+ ],
119
+ initial: 0,
120
+ }, { onCancel });
121
+ if (!response.scope) {
122
+ throw new Error("USER_CANCELLED");
165
123
  }
166
- return response.templateId;
167
- }
168
- export async function askPnpmCheck() {
169
- const response = await prompts({
170
- type: "confirm",
171
- name: "checkPnpm",
172
- message: "Check / install pnpm?",
173
- initial: true,
174
- });
175
- return response.checkPnpm ?? true;
176
- }
177
- export function setupCancellationHandler(cleanup) {
178
- prompts.override({ onCancel: async () => {
179
- console.log("\n⚠️ Cancelled by user");
180
- await cleanup();
181
- process.exit(1);
182
- } });
124
+ return response.scope;
183
125
  }
package/dist/index.js CHANGED
@@ -1,12 +1,21 @@
1
1
  #!/usr/bin/env node
2
+ import os from "os";
2
3
  import path from "path";
3
4
  import process from "process";
4
5
  import { execSync } from "child_process";
5
- import { askProjectSetup, } from "./core/prompts.js";
6
+ import { fileURLToPath } from "url";
7
+ import { askProjectSetup, askCursorInstallScope, } from "./core/prompts.js";
6
8
  import { ensurePnpm } from "./core/dependency-manager.js";
7
9
  import { resolveTemplatePath } from "./core/template-resolver.js";
8
- import { ensureDirectory, copyTemplate, cleanupOnError, } from "./core/file-operations.js";
10
+ import { ensureDirectory, copyTemplate, cleanupOnError, copyToExistingDir, mergeSubdirectories, directoryExists, } from "./core/file-operations.js";
9
11
  import { formatError } from "./core/errors.js";
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+ const CURSOR_TEMPLATE_SOURCE = path.resolve(__dirname, "../templates/cursor/.cursor");
15
+ const CURSOR_MERGE_SUBDIRS = ["skills", "commands"];
16
+ function hasCursorFlag() {
17
+ return process.argv.includes("--cursor");
18
+ }
10
19
  function initializeGit(projectDir) {
11
20
  try {
12
21
  execSync("git init", {
@@ -42,31 +51,72 @@ function displaySuccessMessage(projectName, pnpmWasJustInstalled) {
42
51
  console.log("\n✨ Thanks for using create-huenei-template");
43
52
  console.log("🚀 Happy coding!\n");
44
53
  }
54
+ function displayCursorSuccessMessage(scope, targetPath) {
55
+ console.log("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
56
+ console.log("🎉 Cursor configuration installed!");
57
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
58
+ if (scope === "project") {
59
+ console.log(` Installed in: ${targetPath}`);
60
+ console.log(" Content: skills, commands");
61
+ }
62
+ else {
63
+ console.log(` Installed in: ${targetPath}`);
64
+ console.log(` Merged: ${CURSOR_MERGE_SUBDIRS.join(", ")}`);
65
+ }
66
+ console.log("\nNext steps:");
67
+ console.log(" 1. Open a new conversation in Cursor");
68
+ console.log(" 2. Run the command /configurar-cursor in Plan mode");
69
+ console.log(" 3. Review the plan, evaluate its viability, and execute it");
70
+ console.log(" 4. Verify the generated files inside .cursor/ at your project root");
71
+ console.log("\n✨ Thanks for using create-huenei-template");
72
+ console.log("🚀 Happy coding!\n");
73
+ }
74
+ async function handleCursorInstall(scope) {
75
+ if (scope === "project") {
76
+ const dest = path.join(process.cwd(), ".cursor");
77
+ if (await directoryExists(dest)) {
78
+ console.log(`\n⚠️ .cursor/ already exists in ${process.cwd()}`);
79
+ console.log(" Existing files with the same name will be overwritten.\n");
80
+ }
81
+ console.log("\n📦 Installing Cursor configuration...");
82
+ await copyToExistingDir(CURSOR_TEMPLATE_SOURCE, dest);
83
+ displayCursorSuccessMessage("project", dest);
84
+ }
85
+ else {
86
+ const userCursorDir = path.join(os.homedir(), ".cursor");
87
+ console.log("\n📦 Merging Cursor configuration...");
88
+ await mergeSubdirectories(CURSOR_TEMPLATE_SOURCE, userCursorDir, CURSOR_MERGE_SUBDIRS);
89
+ displayCursorSuccessMessage("user", userCursorDir);
90
+ }
91
+ }
45
92
  async function main() {
46
93
  let targetDir = "";
47
94
  try {
48
- // Interactive prompts (with back navigation support)
49
- const { projectName, templateId, checkPnpm } = await askProjectSetup();
50
- // Ensure pnpm is available
95
+ if (hasCursorFlag()) {
96
+ const installScope = await askCursorInstallScope();
97
+ await handleCursorInstall(installScope);
98
+ return;
99
+ }
100
+ const setup = await askProjectSetup();
101
+ if (setup.mode === "cursor") {
102
+ await handleCursorInstall(setup.installScope);
103
+ return;
104
+ }
105
+ const { projectName, templateId, checkPnpm } = setup;
51
106
  let pnpmWasJustInstalled = false;
52
107
  if (checkPnpm) {
53
108
  const result = await ensurePnpm();
54
109
  pnpmWasJustInstalled = result.wasJustInstalled;
55
110
  }
56
- // Prepare target directory
57
111
  targetDir = path.resolve(process.cwd(), projectName);
58
112
  await ensureDirectory(targetDir);
59
- // Resolve and copy template
60
113
  const templatePath = resolveTemplatePath(templateId);
61
114
  await copyTemplate(templatePath, targetDir);
62
- // Initialize git repository
63
115
  console.log("\n📦 Setting up project...");
64
116
  initializeGit(targetDir);
65
- // Success!
66
117
  displaySuccessMessage(projectName, pnpmWasJustInstalled);
67
118
  }
68
119
  catch (error) {
69
- // Handle user cancellation gracefully
70
120
  if (error instanceof Error && error.message === "USER_CANCELLED") {
71
121
  console.log("\n⚠️ Cancelled by user");
72
122
  if (targetDir) {
@@ -75,7 +125,6 @@ async function main() {
75
125
  process.exit(1);
76
126
  }
77
127
  console.error(`\n${formatError(error)}`);
78
- // Cleanup on error
79
128
  if (targetDir) {
80
129
  await cleanupOnError(targetDir);
81
130
  }