create-next-rkk 1.1.0 → 2.0.1

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.d.ts CHANGED
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export declare function validateProjectName(name: string): {
3
+ valid: boolean;
4
+ reason?: string;
5
+ };
6
+ export declare function cleanupProjectDir(projectPath: string): void;
7
+ export declare function runCli(argv?: string[]): Promise<void>;
package/dist/index.js CHANGED
@@ -37,6 +37,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.validateProjectName = validateProjectName;
41
+ exports.cleanupProjectDir = cleanupProjectDir;
42
+ exports.runCli = runCli;
40
43
  const commander_1 = require("commander");
41
44
  const inquirer_1 = __importDefault(require("inquirer"));
42
45
  const child_process_1 = require("child_process");
@@ -45,10 +48,31 @@ const path = __importStar(require("path"));
45
48
  const chalk_1 = __importDefault(require("chalk"));
46
49
  const ora_1 = __importDefault(require("ora"));
47
50
  const program = new commander_1.Command();
51
+ function validateProjectName(name) {
52
+ const trimmed = name.trim();
53
+ if (!trimmed) {
54
+ return { valid: false, reason: 'Project name cannot be empty.' };
55
+ }
56
+ if (!/^[a-zA-Z0-9._-]+$/.test(trimmed)) {
57
+ return {
58
+ valid: false,
59
+ reason: 'Project name can only contain letters, numbers, dot, underscore, and dash.',
60
+ };
61
+ }
62
+ if (/^(con|prn|aux|nul|com\d|lpt\d)$/i.test(trimmed)) {
63
+ return { valid: false, reason: 'Project name is reserved on Windows.' };
64
+ }
65
+ return { valid: true };
66
+ }
67
+ function cleanupProjectDir(projectPath) {
68
+ if (fs.existsSync(projectPath)) {
69
+ fs.rmSync(projectPath, { recursive: true, force: true });
70
+ }
71
+ }
48
72
  program
49
73
  .name('create-next-rkk')
50
74
  .description('Create a new Next.js app with rkk-next pre-configured')
51
- .version('1.0.0')
75
+ .version('2.0.1')
52
76
  .argument('[project-name]', 'name of your project')
53
77
  .action(async (projectName) => {
54
78
  console.log(chalk_1.default.bold.cyan('\nšŸš€ Create RKK Next.js App\n'));
@@ -84,34 +108,46 @@ program
84
108
  },
85
109
  ]);
86
110
  const targetDir = projectName || answers.projectName;
111
+ const validation = validateProjectName(targetDir);
112
+ if (!validation.valid) {
113
+ console.error(chalk_1.default.red(`\nInvalid project name: ${validation.reason}\n`));
114
+ process.exit(1);
115
+ }
87
116
  const projectPath = path.join(process.cwd(), targetDir);
117
+ let createdProject = false;
118
+ let activeStep = null;
88
119
  // Step 1: Create Next.js app
89
120
  const spinner = (0, ora_1.default)('Creating Next.js application...').start();
90
121
  try {
91
- // Use create-next-app with all options specified to avoid prompts
122
+ // Use create-next-app with all options specified to avoid prompts.
123
+ // --yes tells npx to auto-install create-next-app without asking.
92
124
  const createNextAppCmd = [
93
125
  'npx',
126
+ '--yes',
94
127
  'create-next-app@latest',
95
128
  targetDir,
96
129
  answers.typescript ? '--typescript' : '--js',
97
130
  '--eslint',
98
131
  '--no-tailwind',
99
132
  '--src-dir',
100
- '--app',
133
+ answers.router === 'app' ? '--app' : '--no-app',
101
134
  '--import-alias', '@/*',
102
- '--no-git'
135
+ '--no-git',
103
136
  ].join(' ');
137
+ activeStep = 'create-app';
104
138
  (0, child_process_1.execSync)(createNextAppCmd, {
105
139
  stdio: 'inherit',
106
140
  cwd: process.cwd()
107
141
  });
108
142
  spinner.succeed('Next.js application created!');
143
+ createdProject = true;
109
144
  // Verify directory exists
110
145
  if (!fs.existsSync(projectPath)) {
111
146
  throw new Error(`Project directory ${targetDir} was not created`);
112
147
  }
113
148
  // Step 2: Install rkk-next
114
149
  if (answers.installDeps) {
150
+ activeStep = 'install-rkk';
115
151
  spinner.start('Installing rkk-next...');
116
152
  (0, child_process_1.execSync)('npm install rkk-next', {
117
153
  stdio: 'inherit',
@@ -120,6 +156,7 @@ program
120
156
  spinner.succeed('rkk-next installed!');
121
157
  }
122
158
  // Step 3: Setup template files
159
+ activeStep = 'setup-templates';
123
160
  spinner.start('Setting up rkk-next configuration...');
124
161
  setupTemplateFiles(projectPath, answers.router, answers.typescript);
125
162
  spinner.succeed('Configuration complete!');
@@ -137,7 +174,18 @@ program
137
174
  }
138
175
  catch (error) {
139
176
  spinner.fail('Failed to create application');
177
+ const stepMessage = activeStep ? ` during ${activeStep}` : '';
140
178
  console.error(chalk_1.default.red('\nError:'), error.message);
179
+ if (createdProject) {
180
+ console.log(chalk_1.default.yellow(`\nAttempting rollback${stepMessage}...`));
181
+ try {
182
+ cleanupProjectDir(projectPath);
183
+ console.log(chalk_1.default.green('Rollback successful: cleaned up failed project directory.'));
184
+ }
185
+ catch (cleanupError) {
186
+ console.error(chalk_1.default.red('Rollback failed. Please remove the directory manually:'), projectPath, cleanupError?.message ? `(${cleanupError.message})` : '');
187
+ }
188
+ }
141
189
  process.exit(1);
142
190
  }
143
191
  });
@@ -248,4 +296,12 @@ module.exports = nextConfig;
248
296
  `;
249
297
  fs.writeFileSync(path.join(projectDir, 'next.config.js'), configContent);
250
298
  }
251
- program.parse(process.argv);
299
+ async function runCli(argv = process.argv) {
300
+ await program.parseAsync(argv);
301
+ }
302
+ if (require.main === module) {
303
+ runCli().catch((error) => {
304
+ console.error(chalk_1.default.red('\nUnexpected CLI failure:'), error?.message || error);
305
+ process.exit(1);
306
+ });
307
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-next-rkk",
3
- "version": "1.1.0",
3
+ "version": "2.0.1",
4
4
  "description": "CLI tool to create Next.js apps with rkk-next pre-configured",
5
5
  "author": "Rohit Kumar Kundu",
6
6
  "license": "MIT",
@@ -24,6 +24,8 @@
24
24
  "scripts": {
25
25
  "build": "tsc",
26
26
  "dev": "tsc --watch",
27
+ "test": "jest",
28
+ "test:watch": "jest --watch",
27
29
  "prepublishOnly": "npm run build"
28
30
  },
29
31
  "dependencies": {