@nextsparkjs/cli 0.1.0-beta.7 → 0.1.0-beta.71

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/bin/nextspark.js CHANGED
@@ -1,3 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // Check Node.js version before importing anything
4
+ const nodeVersion = parseInt(process.versions.node.split('.')[0], 10);
5
+ if (nodeVersion < 18) {
6
+ console.error('\x1b[31m✗ NextSpark requires Node.js 18 or higher\x1b[0m');
7
+ console.error(` Current version: ${process.versions.node}`);
8
+ console.error(' Please upgrade Node.js: https://nodejs.org/');
9
+ process.exit(1);
10
+ }
11
+
3
12
  import '../dist/cli.js';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  addPlugin,
3
3
  addPluginCommand
4
- } from "./chunk-EE6EJYHE.js";
4
+ } from "./chunk-DXL5CEZD.js";
5
5
  export {
6
6
  addPlugin,
7
7
  addPluginCommand
@@ -158,60 +158,21 @@ function validateTheme(packageJson, extractedPath) {
158
158
  }
159
159
 
160
160
  // src/lib/installer.ts
161
- import { existsSync as existsSync5, cpSync, rmSync as rmSync2, mkdirSync } from "fs";
162
- import { join as join5 } from "path";
161
+ import { existsSync as existsSync4, cpSync, rmSync as rmSync2, mkdirSync, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "fs";
162
+ import { join as join4 } from "path";
163
163
  import chalk from "chalk";
164
164
 
165
- // src/lib/package-manager.ts
166
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
167
- import { join as join3 } from "path";
168
- import { execSync as execSync2 } from "child_process";
169
- function detectPackageManager() {
170
- const cwd = process.cwd();
171
- if (existsSync3(join3(cwd, "pnpm-lock.yaml"))) return "pnpm";
172
- if (existsSync3(join3(cwd, "yarn.lock"))) return "yarn";
173
- if (existsSync3(join3(cwd, "package-lock.json"))) return "npm";
174
- const pkgPath = join3(cwd, "package.json");
175
- if (existsSync3(pkgPath)) {
176
- try {
177
- const pkg = JSON.parse(readFileSync3(pkgPath, "utf-8"));
178
- if (pkg.packageManager) {
179
- if (pkg.packageManager.startsWith("pnpm")) return "pnpm";
180
- if (pkg.packageManager.startsWith("yarn")) return "yarn";
181
- }
182
- } catch {
183
- }
184
- }
185
- return "npm";
186
- }
187
- function getInstallCommand(pm, deps) {
188
- const depsStr = deps.join(" ");
189
- switch (pm) {
190
- case "pnpm":
191
- return `pnpm add ${depsStr}`;
192
- case "yarn":
193
- return `yarn add ${depsStr}`;
194
- default:
195
- return `npm install ${depsStr}`;
196
- }
197
- }
198
- async function runInstall(pm, deps) {
199
- if (deps.length === 0) return;
200
- const command = getInstallCommand(pm, deps);
201
- execSync2(command, { stdio: "inherit", cwd: process.cwd() });
202
- }
203
-
204
165
  // src/lib/config-updater.ts
205
- import { existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync } from "fs";
206
- import { join as join4 } from "path";
166
+ import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync } from "fs";
167
+ import { join as join3 } from "path";
207
168
  async function updateTsConfig(name, type) {
208
- const tsconfigPath = join4(process.cwd(), "tsconfig.json");
209
- if (!existsSync4(tsconfigPath)) {
169
+ const tsconfigPath = join3(process.cwd(), "tsconfig.json");
170
+ if (!existsSync3(tsconfigPath)) {
210
171
  console.log(" Warning: tsconfig.json not found, skipping path update");
211
172
  return;
212
173
  }
213
174
  try {
214
- const content = readFileSync4(tsconfigPath, "utf-8");
175
+ const content = readFileSync3(tsconfigPath, "utf-8");
215
176
  const tsconfig = JSON.parse(content);
216
177
  if (!tsconfig.compilerOptions) {
217
178
  tsconfig.compilerOptions = {};
@@ -231,13 +192,13 @@ async function updateTsConfig(name, type) {
231
192
  }
232
193
  }
233
194
  async function registerInPackageJson(npmName, version, type) {
234
- const pkgPath = join4(process.cwd(), "package.json");
235
- if (!existsSync4(pkgPath)) {
195
+ const pkgPath = join3(process.cwd(), "package.json");
196
+ if (!existsSync3(pkgPath)) {
236
197
  console.log(" Warning: package.json not found, skipping registration");
237
198
  return;
238
199
  }
239
200
  try {
240
- const content = readFileSync4(pkgPath, "utf-8");
201
+ const content = readFileSync3(pkgPath, "utf-8");
241
202
  const pkg = JSON.parse(content);
242
203
  if (!pkg.nextspark) {
243
204
  pkg.nextspark = {};
@@ -265,7 +226,7 @@ async function registerInPackageJson(npmName, version, type) {
265
226
  // src/lib/installer.ts
266
227
  async function installPlugin(extractedPath, packageJson, options = {}) {
267
228
  const pluginName = extractPluginName(packageJson.name);
268
- const targetDir = join5(process.cwd(), "contents", "plugins", pluginName);
229
+ const targetDir = join4(process.cwd(), "contents", "plugins", pluginName);
269
230
  if (options.dryRun) {
270
231
  console.log(chalk.cyan("\n [Dry Run] Would perform:"));
271
232
  console.log(` - Copy to: contents/plugins/${pluginName}/`);
@@ -276,7 +237,7 @@ async function installPlugin(extractedPath, packageJson, options = {}) {
276
237
  console.log(` - Register in package.json`);
277
238
  return { success: true, installedPath: targetDir, name: pluginName };
278
239
  }
279
- if (existsSync5(targetDir)) {
240
+ if (existsSync4(targetDir)) {
280
241
  if (!options.force) {
281
242
  throw new Error(
282
243
  `Plugin "${pluginName}" already exists at ${targetDir}.
@@ -286,24 +247,20 @@ Use --force to overwrite.`
286
247
  console.log(chalk.yellow(` Removing existing plugin...`));
287
248
  rmSync2(targetDir, { recursive: true, force: true });
288
249
  }
289
- const pluginsDir = join5(process.cwd(), "contents", "plugins");
290
- if (!existsSync5(pluginsDir)) {
250
+ const pluginsDir = join4(process.cwd(), "contents", "plugins");
251
+ if (!existsSync4(pluginsDir)) {
291
252
  mkdirSync(pluginsDir, { recursive: true });
292
253
  }
293
254
  console.log(` Copying to contents/plugins/${pluginName}/...`);
294
255
  cpSync(extractedPath, targetDir, { recursive: true });
295
- if (!options.skipDeps) {
296
- const deps = packageJson.dependencies || {};
297
- const depNames = Object.keys(deps);
298
- if (depNames.length > 0) {
299
- console.log(` Installing ${depNames.length} dependencies...`);
300
- const pm = detectPackageManager();
301
- const depsWithVersions = Object.entries(deps).map(([name, version]) => `${name}@${version}`);
302
- await runInstall(pm, depsWithVersions);
303
- }
256
+ const deps = packageJson.dependencies || {};
257
+ const depCount = Object.keys(deps).length;
258
+ if (depCount > 0) {
259
+ console.log(` Plugin has ${depCount} dependencies (will be installed via workspace)`);
304
260
  }
305
261
  await updateTsConfig(pluginName, "plugin");
306
262
  await registerInPackageJson(packageJson.name, packageJson.version || "0.0.0", "plugin");
263
+ await registerPluginInThemeConfig(pluginName);
307
264
  return {
308
265
  success: true,
309
266
  installedPath: targetDir,
@@ -312,7 +269,7 @@ Use --force to overwrite.`
312
269
  }
313
270
  async function installTheme(extractedPath, packageJson, options = {}) {
314
271
  const themeName = extractThemeName(packageJson.name);
315
- const targetDir = join5(process.cwd(), "contents", "themes", themeName);
272
+ const targetDir = join4(process.cwd(), "contents", "themes", themeName);
316
273
  if (options.dryRun) {
317
274
  console.log(chalk.cyan("\n [Dry Run] Would perform:"));
318
275
  console.log(` - Copy to: contents/themes/${themeName}/`);
@@ -323,7 +280,7 @@ async function installTheme(extractedPath, packageJson, options = {}) {
323
280
  console.log(` - Register in package.json`);
324
281
  return { success: true, installedPath: targetDir, name: themeName };
325
282
  }
326
- if (existsSync5(targetDir)) {
283
+ if (existsSync4(targetDir)) {
327
284
  if (!options.force) {
328
285
  throw new Error(
329
286
  `Theme "${themeName}" already exists at ${targetDir}.
@@ -333,8 +290,8 @@ Use --force to overwrite.`
333
290
  console.log(chalk.yellow(` Removing existing theme...`));
334
291
  rmSync2(targetDir, { recursive: true, force: true });
335
292
  }
336
- const themesDir = join5(process.cwd(), "contents", "themes");
337
- if (!existsSync5(themesDir)) {
293
+ const themesDir = join4(process.cwd(), "contents", "themes");
294
+ if (!existsSync4(themesDir)) {
338
295
  mkdirSync(themesDir, { recursive: true });
339
296
  }
340
297
  console.log(` Copying to contents/themes/${themeName}/...`);
@@ -353,23 +310,59 @@ function extractPluginName(npmName) {
353
310
  function extractThemeName(npmName) {
354
311
  return npmName.replace(/^@[^/]+\//, "").replace(/^nextspark-theme-/, "").replace(/^theme-/, "");
355
312
  }
313
+ async function registerPluginInThemeConfig(pluginName) {
314
+ const envPath = join4(process.cwd(), ".env");
315
+ let activeTheme = "starter";
316
+ if (existsSync4(envPath)) {
317
+ const envContent = readFileSync4(envPath, "utf-8");
318
+ const match = envContent.match(/NEXT_PUBLIC_ACTIVE_THEME=["']?([^"'\s\n]+)["']?/);
319
+ if (match) {
320
+ activeTheme = match[1];
321
+ }
322
+ }
323
+ const themeConfigPath = join4(process.cwd(), "contents", "themes", activeTheme, "config", "theme.config.ts");
324
+ if (!existsSync4(themeConfigPath)) {
325
+ console.log(chalk.gray(` Theme config not found, skipping plugin registration`));
326
+ return;
327
+ }
328
+ try {
329
+ let content = readFileSync4(themeConfigPath, "utf-8");
330
+ if (content.includes(`'${pluginName}'`) || content.includes(`"${pluginName}"`)) {
331
+ console.log(chalk.gray(` Plugin ${pluginName} already registered in theme config`));
332
+ return;
333
+ }
334
+ const pluginsArrayMatch = content.match(/plugins:\s*\[([^\]]*)\]/s);
335
+ if (pluginsArrayMatch) {
336
+ const existingPlugins = pluginsArrayMatch[1].trim();
337
+ const newPlugins = existingPlugins ? `${existingPlugins}, '${pluginName}'` : `'${pluginName}'`;
338
+ content = content.replace(
339
+ /plugins:\s*\[([^\]]*)\]/s,
340
+ `plugins: [${newPlugins}]`
341
+ );
342
+ writeFileSync2(themeConfigPath, content);
343
+ console.log(` Registered plugin in theme.config.ts`);
344
+ }
345
+ } catch (error) {
346
+ console.log(chalk.yellow(` Could not register plugin in theme config: ${error}`));
347
+ }
348
+ }
356
349
 
357
350
  // src/lib/postinstall/index.ts
358
351
  import chalk6 from "chalk";
359
352
 
360
353
  // src/lib/postinstall/templates.ts
361
- import { existsSync as existsSync6, cpSync as cpSync2, mkdirSync as mkdirSync2 } from "fs";
362
- import { join as join6, dirname } from "path";
354
+ import { existsSync as existsSync5, cpSync as cpSync2, mkdirSync as mkdirSync2 } from "fs";
355
+ import { join as join5, dirname } from "path";
363
356
  import chalk2 from "chalk";
364
357
  async function processTemplates(templates, sourcePath, context) {
365
358
  for (const template of templates) {
366
- const from = join6(sourcePath, template.from);
359
+ const from = join5(sourcePath, template.from);
367
360
  const to = resolveVariables(template.to, context);
368
- if (!existsSync6(from)) {
361
+ if (!existsSync5(from)) {
369
362
  console.log(chalk2.yellow(` Warning: Template source not found: ${template.from}`));
370
363
  continue;
371
364
  }
372
- const targetExists = existsSync6(to);
365
+ const targetExists = existsSync5(to);
373
366
  const condition = template.condition || "!exists";
374
367
  const desc = template.description || template.to;
375
368
  switch (condition) {
@@ -395,7 +388,7 @@ async function processTemplates(templates, sourcePath, context) {
395
388
  break;
396
389
  }
397
390
  const parentDir = dirname(to);
398
- if (!existsSync6(parentDir)) {
391
+ if (!existsSync5(parentDir)) {
399
392
  mkdirSync2(parentDir, { recursive: true });
400
393
  }
401
394
  console.log(chalk2.gray(` Copying ${desc}...`));
@@ -421,21 +414,21 @@ function resolveVariables(path, context) {
421
414
  throw new Error(`Unresolved template variable: ${unresolvedMatch[0]}`);
422
415
  }
423
416
  if (!resolved.startsWith("/")) {
424
- resolved = join6(context.projectRoot, resolved);
417
+ resolved = join5(context.projectRoot, resolved);
425
418
  }
426
419
  return resolved;
427
420
  }
428
421
 
429
422
  // src/lib/postinstall/env-vars.ts
430
- import { existsSync as existsSync7, readFileSync as readFileSync5, writeFileSync as writeFileSync2, appendFileSync } from "fs";
431
- import { join as join7 } from "path";
423
+ import { existsSync as existsSync6, readFileSync as readFileSync5, writeFileSync as writeFileSync3, appendFileSync } from "fs";
424
+ import { join as join6 } from "path";
432
425
  import chalk3 from "chalk";
433
426
  async function processEnvVars(envVars) {
434
- const envExamplePath = join7(process.cwd(), ".env.example");
435
- const envPath = join7(process.cwd(), ".env");
427
+ const envExamplePath = join6(process.cwd(), ".env.example");
428
+ const envPath = join6(process.cwd(), ".env");
436
429
  let added = 0;
437
430
  const existingVars = /* @__PURE__ */ new Set();
438
- if (existsSync7(envExamplePath)) {
431
+ if (existsSync6(envExamplePath)) {
439
432
  const content = readFileSync5(envExamplePath, "utf-8");
440
433
  const matches = content.match(/^[A-Z_][A-Z0-9_]*=/gm);
441
434
  if (matches) {
@@ -456,34 +449,34 @@ async function processEnvVars(envVars) {
456
449
  }
457
450
  if (newLines.length > 0) {
458
451
  const content = "\n" + newLines.join("\n");
459
- if (existsSync7(envExamplePath)) {
452
+ if (existsSync6(envExamplePath)) {
460
453
  appendFileSync(envExamplePath, content);
461
454
  } else {
462
- writeFileSync2(envExamplePath, content.trim() + "\n");
455
+ writeFileSync3(envExamplePath, content.trim() + "\n");
463
456
  }
464
457
  console.log(chalk3.gray(` Added ${added} env vars to .env.example`));
465
458
  }
466
459
  }
467
460
 
468
461
  // src/lib/postinstall/migrations.ts
469
- import { existsSync as existsSync8, mkdirSync as mkdirSync3, cpSync as cpSync3 } from "fs";
470
- import { join as join8, basename } from "path";
462
+ import { existsSync as existsSync7, mkdirSync as mkdirSync3, cpSync as cpSync3 } from "fs";
463
+ import { join as join7, basename } from "path";
471
464
  import chalk4 from "chalk";
472
465
  async function registerMigrations(migrations, installedPath) {
473
- const migrationsDir = join8(process.cwd(), "migrations");
474
- if (!existsSync8(migrationsDir)) {
466
+ const migrationsDir = join7(process.cwd(), "migrations");
467
+ if (!existsSync7(migrationsDir)) {
475
468
  mkdirSync3(migrationsDir, { recursive: true });
476
469
  }
477
470
  let copied = 0;
478
471
  for (const migration of migrations) {
479
- const sourcePath = join8(installedPath, migration);
480
- if (!existsSync8(sourcePath)) {
472
+ const sourcePath = join7(installedPath, migration);
473
+ if (!existsSync7(sourcePath)) {
481
474
  console.log(chalk4.yellow(` Warning: Migration not found: ${migration}`));
482
475
  continue;
483
476
  }
484
477
  const fileName = basename(migration);
485
- const targetPath = join8(migrationsDir, fileName);
486
- if (existsSync8(targetPath)) {
478
+ const targetPath = join7(migrationsDir, fileName);
479
+ if (existsSync7(targetPath)) {
487
480
  console.log(chalk4.gray(` Migration ${fileName} already exists, skipping`));
488
481
  continue;
489
482
  }
@@ -496,12 +489,12 @@ async function registerMigrations(migrations, installedPath) {
496
489
  }
497
490
 
498
491
  // src/lib/postinstall/script-runner.ts
499
- import { existsSync as existsSync9 } from "fs";
500
- import { join as join9 } from "path";
492
+ import { existsSync as existsSync8 } from "fs";
493
+ import { join as join8 } from "path";
501
494
  import chalk5 from "chalk";
502
495
  async function runCustomScript(scriptPath, installedPath, context) {
503
- const fullPath = join9(installedPath, scriptPath);
504
- if (!existsSync9(fullPath)) {
496
+ const fullPath = join8(installedPath, scriptPath);
497
+ if (!existsSync8(fullPath)) {
505
498
  console.log(chalk5.yellow(` Warning: Postinstall script not found: ${scriptPath}`));
506
499
  return;
507
500
  }
@@ -516,8 +509,8 @@ async function runCustomScript(scriptPath, installedPath, context) {
516
509
  }
517
510
 
518
511
  // src/lib/postinstall/index.ts
519
- import { existsSync as existsSync10 } from "fs";
520
- import { join as join10 } from "path";
512
+ import { existsSync as existsSync9 } from "fs";
513
+ import { join as join9 } from "path";
521
514
  async function runPostinstall(packageJson, installedPath, context) {
522
515
  const postinstall = packageJson.nextspark?.postinstall;
523
516
  if (!postinstall) {
@@ -534,7 +527,7 @@ async function runPostinstall(packageJson, installedPath, context) {
534
527
  if (!pluginExists) {
535
528
  console.log(` Installing required plugin: ${plugin}`);
536
529
  context.installingPlugins.add(plugin);
537
- const { addPlugin: addPlugin2 } = await import("./add-plugin-I3UJFL7U.js");
530
+ const { addPlugin: addPlugin2 } = await import("./add-plugin-KIJLCOEQ.js");
538
531
  await addPlugin2(plugin, { installingPlugins: context.installingPlugins });
539
532
  }
540
533
  }
@@ -578,18 +571,18 @@ async function runPostinstall(packageJson, installedPath, context) {
578
571
  }
579
572
  async function checkPluginExists(pluginName) {
580
573
  const name = pluginName.replace(/^@[^/]+\//, "").replace(/^nextspark-plugin-/, "").replace(/^plugin-/, "");
581
- return existsSync10(join10(process.cwd(), "contents", "plugins", name));
574
+ return existsSync9(join9(process.cwd(), "contents", "plugins", name));
582
575
  }
583
576
 
584
577
  // src/lib/theme-detector.ts
585
- import { existsSync as existsSync11, readFileSync as readFileSync6, readdirSync as readdirSync2 } from "fs";
586
- import { join as join11 } from "path";
578
+ import { existsSync as existsSync10, readFileSync as readFileSync6, readdirSync as readdirSync2 } from "fs";
579
+ import { join as join10 } from "path";
587
580
  function detectActiveTheme() {
588
581
  if (process.env.NEXT_PUBLIC_ACTIVE_THEME) {
589
582
  return process.env.NEXT_PUBLIC_ACTIVE_THEME;
590
583
  }
591
- const configPath = join11(process.cwd(), "nextspark.config.ts");
592
- if (existsSync11(configPath)) {
584
+ const configPath = join10(process.cwd(), "nextspark.config.ts");
585
+ if (existsSync10(configPath)) {
593
586
  try {
594
587
  const content = readFileSync6(configPath, "utf-8");
595
588
  const match = content.match(/activeTheme\s*:\s*['"]([^'"]+)['"]/);
@@ -599,8 +592,8 @@ function detectActiveTheme() {
599
592
  } catch {
600
593
  }
601
594
  }
602
- const envPath = join11(process.cwd(), ".env");
603
- if (existsSync11(envPath)) {
595
+ const envPath = join10(process.cwd(), ".env");
596
+ if (existsSync10(envPath)) {
604
597
  try {
605
598
  const content = readFileSync6(envPath, "utf-8");
606
599
  const match = content.match(/NEXT_PUBLIC_ACTIVE_THEME=(.+)/);
@@ -610,8 +603,8 @@ function detectActiveTheme() {
610
603
  } catch {
611
604
  }
612
605
  }
613
- const themesDir = join11(process.cwd(), "contents", "themes");
614
- if (existsSync11(themesDir)) {
606
+ const themesDir = join10(process.cwd(), "contents", "themes");
607
+ if (existsSync10(themesDir)) {
615
608
  try {
616
609
  const themes = readdirSync2(themesDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
617
610
  if (themes.length === 1) {
@@ -624,14 +617,14 @@ function detectActiveTheme() {
624
617
  }
625
618
 
626
619
  // src/commands/add-plugin.ts
627
- import { existsSync as existsSync12, readFileSync as readFileSync7 } from "fs";
628
- import { join as join12 } from "path";
620
+ import { existsSync as existsSync11, readFileSync as readFileSync7 } from "fs";
621
+ import { join as join11 } from "path";
629
622
  async function addPlugin(packageSpec, options = {}) {
630
623
  const spinner = ora(`Adding plugin ${packageSpec}`).start();
631
624
  let cleanup = null;
632
625
  try {
633
- const contentsDir = join12(process.cwd(), "contents");
634
- if (!existsSync12(contentsDir)) {
626
+ const contentsDir = join11(process.cwd(), "contents");
627
+ if (!existsSync11(contentsDir)) {
635
628
  spinner.fail('contents/ directory not found. Run "nextspark init" first.');
636
629
  return;
637
630
  }
@@ -680,8 +673,8 @@ async function addPlugin(packageSpec, options = {}) {
680
673
  }
681
674
  }
682
675
  function getCoreVersion() {
683
- const pkgPath = join12(process.cwd(), "node_modules", "@nextsparkjs", "core", "package.json");
684
- if (existsSync12(pkgPath)) {
676
+ const pkgPath = join11(process.cwd(), "node_modules", "@nextsparkjs", "core", "package.json");
677
+ if (existsSync11(pkgPath)) {
685
678
  try {
686
679
  const pkg = JSON.parse(readFileSync7(pkgPath, "utf-8"));
687
680
  return pkg.version || "0.0.0";