@nextsparkjs/cli 0.1.0-beta.41 → 0.1.0-beta.43

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/cli.js +97 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  // src/cli.ts
13
13
  import { config } from "dotenv";
14
14
  import { Command } from "commander";
15
- import chalk15 from "chalk";
15
+ import chalk16 from "chalk";
16
16
 
17
17
  // src/commands/dev.ts
18
18
  import { spawn } from "child_process";
@@ -3717,6 +3717,96 @@ async function doctorCommand() {
3717
3717
  }
3718
3718
  }
3719
3719
 
3720
+ // src/commands/db.ts
3721
+ import { spawn as spawn5 } from "child_process";
3722
+ import { existsSync as existsSync9, readFileSync as readFileSync8 } from "fs";
3723
+ import { join as join9 } from "path";
3724
+ import chalk15 from "chalk";
3725
+ import ora9 from "ora";
3726
+ function loadProjectEnv4(projectRoot) {
3727
+ const envPath = join9(projectRoot, ".env");
3728
+ const envVars = {};
3729
+ if (existsSync9(envPath)) {
3730
+ const content = readFileSync8(envPath, "utf-8");
3731
+ for (const line of content.split("\n")) {
3732
+ const trimmed = line.trim();
3733
+ if (trimmed && !trimmed.startsWith("#")) {
3734
+ const [key, ...valueParts] = trimmed.split("=");
3735
+ if (key && valueParts.length > 0) {
3736
+ let value = valueParts.join("=");
3737
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
3738
+ value = value.slice(1, -1);
3739
+ }
3740
+ envVars[key] = value;
3741
+ }
3742
+ }
3743
+ }
3744
+ }
3745
+ return envVars;
3746
+ }
3747
+ async function dbMigrateCommand() {
3748
+ const spinner = ora9("Preparing to run migrations...").start();
3749
+ try {
3750
+ const coreDir = getCoreDir();
3751
+ const projectRoot = getProjectRoot();
3752
+ const migrationsScript = join9(coreDir, "scripts", "db", "run-migrations.mjs");
3753
+ if (!existsSync9(migrationsScript)) {
3754
+ spinner.fail("Migrations script not found");
3755
+ console.error(chalk15.red(`Expected script at: ${migrationsScript}`));
3756
+ process.exit(1);
3757
+ }
3758
+ spinner.succeed("Core package found");
3759
+ const projectEnv = loadProjectEnv4(projectRoot);
3760
+ if (!projectEnv.DATABASE_URL) {
3761
+ spinner.fail("DATABASE_URL not found in .env file");
3762
+ console.error(chalk15.red("Please configure DATABASE_URL in your .env file"));
3763
+ process.exit(1);
3764
+ }
3765
+ if (!projectEnv.NEXT_PUBLIC_ACTIVE_THEME) {
3766
+ spinner.fail("NEXT_PUBLIC_ACTIVE_THEME not found in .env file");
3767
+ console.error(chalk15.red("Please configure NEXT_PUBLIC_ACTIVE_THEME in your .env file"));
3768
+ process.exit(1);
3769
+ }
3770
+ spinner.start("Running database migrations...");
3771
+ const migrateProcess = spawn5("node", [migrationsScript], {
3772
+ cwd: projectRoot,
3773
+ stdio: "inherit",
3774
+ env: {
3775
+ ...projectEnv,
3776
+ ...process.env,
3777
+ NEXTSPARK_PROJECT_ROOT: projectRoot,
3778
+ NEXTSPARK_CORE_DIR: coreDir
3779
+ }
3780
+ });
3781
+ migrateProcess.on("error", (err) => {
3782
+ spinner.fail("Migration failed");
3783
+ console.error(chalk15.red(err.message));
3784
+ process.exit(1);
3785
+ });
3786
+ migrateProcess.on("close", (code) => {
3787
+ if (code === 0) {
3788
+ console.log(chalk15.green("\n\u2705 Migrations completed successfully!"));
3789
+ process.exit(0);
3790
+ } else {
3791
+ console.error(chalk15.red(`
3792
+ \u274C Migrations failed with exit code ${code}`));
3793
+ process.exit(code ?? 1);
3794
+ }
3795
+ });
3796
+ } catch (error) {
3797
+ spinner.fail("Migration preparation failed");
3798
+ if (error instanceof Error) {
3799
+ console.error(chalk15.red(error.message));
3800
+ }
3801
+ process.exit(1);
3802
+ }
3803
+ }
3804
+ async function dbSeedCommand() {
3805
+ console.log(chalk15.cyan("\u2139\uFE0F Sample data is included as part of the migration process."));
3806
+ console.log(chalk15.cyan(" Running db:migrate to apply all migrations including sample data...\n"));
3807
+ await dbMigrateCommand();
3808
+ }
3809
+
3720
3810
  // src/cli.ts
3721
3811
  config();
3722
3812
  var program = new Command();
@@ -3733,8 +3823,13 @@ program.command("init").description("Initialize NextSpark project").option("-f,
3733
3823
  program.command("add:plugin <package>").description("Add a plugin to your project").option("-v, --version <version>", "Specific version to install").option("-f, --force", "Overwrite if already exists").option("--skip-postinstall", "Skip postinstall hooks").option("--no-deps", "Skip installing dependencies").option("--dry-run", "Show what would be done without making changes").action(addPluginCommand);
3734
3824
  program.command("add:theme <package>").description("Add a theme to your project").option("-v, --version <version>", "Specific version to install").option("-f, --force", "Overwrite if already exists").option("--skip-postinstall", "Skip postinstall hooks").option("--no-deps", "Skip installing dependencies").option("--dry-run", "Show what would be done without making changes").action(addThemeCommand);
3735
3825
  program.command("doctor").description("Run health check on NextSpark project").action(doctorCommand);
3826
+ var db = program.command("db").description("Database management commands");
3827
+ db.command("migrate").description("Run database migrations").action(dbMigrateCommand);
3828
+ db.command("seed").description("Seed database with sample data").action(dbSeedCommand);
3829
+ program.command("db:migrate").description("Run database migrations (alias)").action(dbMigrateCommand);
3830
+ program.command("db:seed").description("Seed database with sample data (alias)").action(dbSeedCommand);
3736
3831
  program.showHelpAfterError();
3737
3832
  program.configureOutput({
3738
- writeErr: (str) => process.stderr.write(chalk15.red(str))
3833
+ writeErr: (str) => process.stderr.write(chalk16.red(str))
3739
3834
  });
3740
3835
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextsparkjs/cli",
3
- "version": "0.1.0-beta.41",
3
+ "version": "0.1.0-beta.43",
4
4
  "description": "NextSpark CLI - Complete development toolkit",
5
5
  "type": "module",
6
6
  "bin": {