nextjs-cms-kit 0.5.65 → 0.5.67

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 (61) hide show
  1. package/dist/commands/db-config.d.ts.map +1 -1
  2. package/dist/commands/db-config.js +8 -4
  3. package/dist/commands/fix-master-admin.d.ts.map +1 -1
  4. package/dist/commands/fix-master-admin.js +8 -4
  5. package/dist/commands/set-master-admin.d.ts +1 -1
  6. package/dist/commands/set-master-admin.d.ts.map +1 -1
  7. package/dist/commands/set-master-admin.js +12 -14
  8. package/dist/commands/setup.d.ts +1 -1
  9. package/dist/commands/setup.d.ts.map +1 -1
  10. package/dist/commands/setup.js +21 -49
  11. package/dist/commands/update-sections.d.ts.map +1 -1
  12. package/dist/commands/update-sections.js +11 -16
  13. package/dist/index.js +2 -4
  14. package/dist/lib/{db-config-setup.d.ts → db-config.d.ts} +1 -1
  15. package/dist/lib/db-config.d.ts.map +1 -0
  16. package/dist/lib/{db-config-setup.js → db-config.js} +92 -70
  17. package/dist/lib/db-migrate.d.ts +2 -0
  18. package/dist/lib/db-migrate.d.ts.map +1 -0
  19. package/dist/lib/db-migrate.js +84 -0
  20. package/dist/lib/fix-master-admin.d.ts +1 -1
  21. package/dist/lib/fix-master-admin.d.ts.map +1 -1
  22. package/dist/lib/fix-master-admin.js +26 -6
  23. package/dist/lib/set-master-admin.d.ts.map +1 -1
  24. package/dist/lib/set-master-admin.js +54 -21
  25. package/dist/lib/update-sections.js +19 -19
  26. package/dist/program/program.d.ts.map +1 -0
  27. package/dist/program/program.js +95 -0
  28. package/dist/utils/add-table-keys.d.ts.map +1 -0
  29. package/dist/utils/check-version.d.ts +3 -0
  30. package/dist/utils/check-version.d.ts.map +1 -0
  31. package/dist/{lib/program.js → utils/check-version.js} +58 -81
  32. package/dist/utils/display-intro.d.ts +6 -0
  33. package/dist/utils/display-intro.d.ts.map +1 -0
  34. package/dist/utils/display-intro.js +9 -0
  35. package/dist/utils/exec-utils.d.ts +19 -0
  36. package/dist/utils/exec-utils.d.ts.map +1 -0
  37. package/dist/utils/exec-utils.js +95 -0
  38. package/dist/utils/get-package-manager.d.ts +4 -0
  39. package/dist/utils/get-package-manager.d.ts.map +1 -0
  40. package/dist/utils/get-package-manager.js +22 -0
  41. package/dist/utils/reload-env.d.ts.map +1 -0
  42. package/dist/{lib → utils}/reload-env.js +1 -1
  43. package/dist/utils/render-title.d.ts +2 -0
  44. package/dist/utils/render-title.d.ts.map +1 -0
  45. package/dist/utils/render-title.js +12 -0
  46. package/dist/utils/schema-generator.d.ts.map +1 -0
  47. package/package.json +7 -4
  48. package/dist/lib/actions.d.ts +0 -7
  49. package/dist/lib/actions.d.ts.map +0 -1
  50. package/dist/lib/actions.js +0 -69
  51. package/dist/lib/add-table-keys.d.ts.map +0 -1
  52. package/dist/lib/db-config-setup.d.ts.map +0 -1
  53. package/dist/lib/program.d.ts.map +0 -1
  54. package/dist/lib/reload-env.d.ts.map +0 -1
  55. package/dist/lib/schema-generator.d.ts.map +0 -1
  56. /package/dist/{lib → program}/program.d.ts +0 -0
  57. /package/dist/{lib → utils}/add-table-keys.d.ts +0 -0
  58. /package/dist/{lib → utils}/add-table-keys.js +0 -0
  59. /package/dist/{lib → utils}/reload-env.d.ts +0 -0
  60. /package/dist/{lib → utils}/schema-generator.d.ts +0 -0
  61. /package/dist/{lib → utils}/schema-generator.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"db-config.d.ts","sourceRoot":"","sources":["../../src/commands/db-config.ts"],"names":[],"mappings":"AAEA,wBAAsB,WAAW,CAAC,GAAG,EAAE,OAAO,iBAc7C"}
1
+ {"version":3,"file":"db-config.d.ts","sourceRoot":"","sources":["../../src/commands/db-config.ts"],"names":[],"mappings":"AAGA,wBAAsB,WAAW,CAAC,GAAG,EAAE,OAAO,iBAiB7C"}
@@ -1,18 +1,22 @@
1
1
  import chalk from 'chalk';
2
+ import * as p from '@clack/prompts';
2
3
  export async function runDbConfig(dev) {
4
+ let exitCode = 0;
3
5
  try {
6
+ p.log.info(chalk.cyan('Configuring database'));
4
7
  // Lazy import to avoid eager database connection
5
- const { dbConfigSetup } = await import('../lib/db-config-setup.js');
8
+ const { dbConfigSetup } = await import('../lib/db-config.js');
6
9
  await dbConfigSetup({ dev });
10
+ p.outro(chalk.inverse(' ✓ Database configuration completed '));
7
11
  }
8
12
  catch (error) {
9
- console.error(chalk.red('Error during initialization:'), error);
10
- process.exit(1);
13
+ console.error(chalk.red('Error during database configuration:'), error);
14
+ exitCode = 1;
11
15
  }
12
16
  finally {
13
17
  // Lazy import for cleanup
14
18
  const { dbConnectionClose } = await import('nextjs-cms/db/client');
15
19
  await dbConnectionClose();
16
- process.exit(0);
17
20
  }
21
+ process.exit(exitCode);
18
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fix-master-admin.d.ts","sourceRoot":"","sources":["../../src/commands/fix-master-admin.ts"],"names":[],"mappings":"AAEA,wBAAsB,iBAAiB,kBActC"}
1
+ {"version":3,"file":"fix-master-admin.d.ts","sourceRoot":"","sources":["../../src/commands/fix-master-admin.ts"],"names":[],"mappings":"AAGA,wBAAsB,iBAAiB,kBAiBtC"}
@@ -1,18 +1,22 @@
1
1
  import chalk from 'chalk';
2
+ import * as p from '@clack/prompts';
2
3
  export async function runFixMasterAdmin() {
4
+ let exitCode = 0;
3
5
  try {
6
+ p.log.info(chalk.cyan('Looking up sections'));
4
7
  // Lazy import to avoid eager database connection
5
- const { fixMasterAdmin } = await import('../lib/fix-master-admin.js');
6
- await fixMasterAdmin();
8
+ const { fixMasterAdminPrivileges } = await import('../lib/fix-master-admin.js');
9
+ await fixMasterAdminPrivileges();
10
+ p.outro(chalk.inverse(' ✓ Master admin privileges fixed '));
7
11
  }
8
12
  catch (error) {
9
13
  console.error(chalk.red('Error fixing master admin privileges:'), error);
10
- process.exit(1);
14
+ exitCode = 1;
11
15
  }
12
16
  finally {
13
17
  // Lazy import for cleanup
14
18
  const { dbConnectionClose } = await import('nextjs-cms/db/client');
15
19
  await dbConnectionClose();
16
- process.exit(0);
17
20
  }
21
+ process.exit(exitCode);
18
22
  }
@@ -1,2 +1,2 @@
1
- export declare function runSetMasterAdmin(dev: boolean): Promise<void>;
1
+ export declare function runSetMasterAdmin(): Promise<void>;
2
2
  //# sourceMappingURL=set-master-admin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-master-admin.d.ts","sourceRoot":"","sources":["../../src/commands/set-master-admin.ts"],"names":[],"mappings":"AAEA,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,iBAuBnD"}
1
+ {"version":3,"file":"set-master-admin.d.ts","sourceRoot":"","sources":["../../src/commands/set-master-admin.ts"],"names":[],"mappings":"AAGA,wBAAsB,iBAAiB,kBAoBtC"}
@@ -1,27 +1,25 @@
1
1
  import chalk from 'chalk';
2
- export async function runSetMasterAdmin(dev) {
2
+ import * as p from '@clack/prompts';
3
+ export async function runSetMasterAdmin() {
4
+ p.log.info(chalk.cyan('Setting up master admin'));
5
+ let exitCode = 0;
3
6
  try {
4
- console.log(chalk.hex('#E8DCFF').bold('nextjs-cms-kit'));
5
- console.log(chalk.green('nextjs-cms CLI toolkit for managing your nextjs-cms application'));
6
- console.log(chalk.gray('--------------------------'));
7
- console.log(chalk.hex('#E8DCFF').bold('set-master-admin'));
8
- console.log('Set or update master admin password');
9
- console.log(chalk.gray('--------------------------'));
10
- console.log(chalk.yellow(`Running in ${dev ? 'development' : 'production'} mode`));
11
- console.log(chalk.gray('--------------------------'));
12
- console.log(chalk.gray(`.......................................................`));
13
- // Lazy import to avoid eager database connection
14
7
  const { setMasterAdmin } = await import('../lib/set-master-admin.js');
15
8
  await setMasterAdmin();
9
+ p.outro(chalk.inverse(' ✓ Master admin setup completed successfully '));
16
10
  }
17
11
  catch (error) {
18
- console.error(chalk.red('Error resetting master admin:'), error);
19
- process.exit(1);
12
+ p.log.error(chalk.red('Error resetting master admin:'));
13
+ console.error(error);
14
+ // Lazy import for cleanup
15
+ const { dbConnectionClose } = await import('nextjs-cms/db/client');
16
+ await dbConnectionClose();
17
+ exitCode = 1;
20
18
  }
21
19
  finally {
22
20
  // Lazy import for cleanup
23
21
  const { dbConnectionClose } = await import('nextjs-cms/db/client');
24
22
  await dbConnectionClose();
25
- process.exit(0);
26
23
  }
24
+ process.exit(exitCode);
27
25
  }
@@ -1,2 +1,2 @@
1
- export declare function runSetup(dev: boolean): Promise<void>;
1
+ export declare function runSetup(dev: boolean, skipDbConfig: boolean): Promise<void>;
2
2
  //# sourceMappingURL=setup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAIA,wBAAsB,QAAQ,CAAC,GAAG,EAAE,OAAO,iBA8D1C"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAGA,wBAAsB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,iBAiCjE"}
@@ -1,62 +1,34 @@
1
- import { note, intro, outro, spinner } from '@clack/prompts';
2
- import { spawn } from 'child_process';
1
+ import * as p from '@clack/prompts';
3
2
  import chalk from 'chalk';
4
- export async function runSetup(dev) {
5
- const s = spinner();
6
- console.log(chalk.hex('#E8DCFF').bold('nextjs-cms-kit'));
7
- console.log(chalk.green('nextjs-cms CLI toolkit for managing your nextjs-cms application'));
8
- console.log(chalk.gray('--------------------------'));
9
- console.log(chalk.hex('#E8DCFF').bold('setup'));
10
- console.log('Complete nextjs-cms setup');
11
- console.log(chalk.gray('--------------------------'));
12
- console.log(chalk.yellow(`Running in ${dev ? 'development' : 'production'} mode`));
13
- console.log(chalk.gray('--------------------------'));
14
- console.log(chalk.gray(`.......................................................`));
15
- console.log();
16
- intro('Setting up nextjs-cms... 🚀');
3
+ export async function runSetup(dev, skipDbConfig) {
4
+ let exitCode = 0;
17
5
  try {
18
- note('Configuring database...');
19
- // Lazy import to avoid eager database connection
20
- const { dbConfigSetup } = await import('../lib/db-config-setup.js');
21
- await dbConfigSetup({ dev });
22
- note('Generating database schema...');
23
- // Use spawn to properly handle streams and prevent hanging
24
- await new Promise((resolve, reject) => {
25
- const child = spawn('pnpm drizzle-kit push --force --config=drizzle.config.ts', {
26
- cwd: process.cwd(),
27
- env: { ...process.env },
28
- stdio: 'inherit', // Inherit stdio to prevent hanging and show output directly
29
- shell: true,
30
- });
31
- child.on('close', (code) => {
32
- if (code === 0) {
33
- resolve();
34
- }
35
- else {
36
- reject(new Error(`drizzle-kit push exited with code ${code}`));
37
- }
38
- });
39
- child.on('error', (error) => {
40
- reject(error);
41
- });
42
- });
43
- s.message('Database schema generated');
44
- note('Setting up master admin...');
45
- // Lazy import to avoid eager database connection
6
+ if (!skipDbConfig) {
7
+ p.log.info(chalk.cyan('Configuring database'));
8
+ const { dbConfigSetup } = await import('../lib/db-config.js');
9
+ await dbConfigSetup({ dev });
10
+ }
11
+ p.log.info(chalk.cyan('Generating database tables'));
12
+ const { generateDatabaseTables } = await import('../lib/db-migrate.js');
13
+ await generateDatabaseTables();
14
+ p.log.info(chalk.cyan('Setting up master admin'));
46
15
  const { setMasterAdmin } = await import('../lib/set-master-admin.js');
47
16
  await setMasterAdmin();
48
- note('Master admin configured');
49
- outro('nextjs-cms setup completed successfully! 🎉');
17
+ p.outro(chalk.inverse(' nextjs-cms setup completed successfully '));
50
18
  }
51
19
  catch (error) {
52
- console.error(chalk.red('Error during setup:'), error);
53
- s.stop('Setup failed');
54
- process.exit(1);
20
+ console.log('');
21
+ console.error(chalk.red(' Error during setup:'), error);
22
+ p.outro(chalk.red('✗ Setup failed'));
23
+ // Lazy import for cleanup
24
+ const { dbConnectionClose } = await import('nextjs-cms/db/client');
25
+ await dbConnectionClose();
26
+ exitCode = 1;
55
27
  }
56
28
  finally {
57
29
  // Lazy import for cleanup
58
30
  const { dbConnectionClose } = await import('nextjs-cms/db/client');
59
31
  await dbConnectionClose();
60
- process.exit(0);
61
32
  }
33
+ process.exit(exitCode);
62
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../src/commands/update-sections.ts"],"names":[],"mappings":"AAEA,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,iBA4BnD"}
1
+ {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../src/commands/update-sections.ts"],"names":[],"mappings":"AAGA,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,iBAsBnD"}
@@ -1,32 +1,27 @@
1
1
  import chalk from 'chalk';
2
+ import * as p from '@clack/prompts';
2
3
  export async function runUpdateSections(dev) {
4
+ let exitCode = 0;
3
5
  try {
4
- console.log(chalk.hex('#E8DCFF').bold('nextjs-cms-kit'));
5
- console.log(chalk.green('nextjs-cms CLI toolkit for managing your nextjs-cms application'));
6
- console.log(chalk.gray('--------------------------'));
7
- console.log(chalk.hex('#E8DCFF').bold('update-sections'));
8
- console.log('Update database tables based on current sections and update master admin privileges');
9
- console.log(chalk.gray('--------------------------'));
10
- console.log(chalk.yellow(`Running in ${dev ? 'development' : 'production'} mode`));
11
- console.log(chalk.gray('--------------------------'));
12
- console.log(chalk.gray(`.......................................................`));
13
- // Lazy import to avoid eager database connection
6
+ p.log.info(chalk.cyan('Updating sections'));
14
7
  const { updateSections } = await import('../lib/update-sections.js');
15
8
  await updateSections(dev);
16
- console.log(chalk.blue('Modifying master admin privileges...'));
9
+ p.log.info(chalk.cyan('Modifying master admin privileges'));
17
10
  // Lazy import to avoid eager database connection
18
- const { fixMasterAdminPrivileges } = await import('../lib/actions.js');
11
+ const { fixMasterAdminPrivileges } = await import('../lib/fix-master-admin.js');
19
12
  await fixMasterAdminPrivileges();
20
- console.log(chalk.green('Master admin privileges fixed.'));
13
+ p.log.message(chalk.green(' - ✓ Master admin privileges fixed.'));
14
+ p.outro(chalk.inverse(' ✓ Sections updated '));
21
15
  }
22
16
  catch (error) {
23
- console.error(chalk.red('Error updating sections:'), error);
24
- process.exit(1);
17
+ p.log.error(chalk.red('Error updating sections:'));
18
+ console.error(error);
19
+ exitCode = 1;
25
20
  }
26
21
  finally {
27
22
  // Lazy import for cleanup
28
23
  const { dbConnectionClose } = await import('nextjs-cms/db/client');
29
24
  await dbConnectionClose();
30
- process.exit(0);
31
25
  }
26
+ process.exit(exitCode);
32
27
  }
package/dist/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import dotenv from 'dotenv';
3
- import program from './lib/program.js';
4
- import * as p from '@clack/prompts';
3
+ import program from './program/program.js';
5
4
  program.parse(process.argv);
6
5
  // Load environment file based on parsed dev flag
7
6
  if (Boolean(program.opts().dev) === true) {
8
- p.note('🔧 Using development environment file');
9
- dotenv.config({ path: '.env.development' });
7
+ dotenv.config({ path: '.env.development', quiet: true });
10
8
  process.env.NODE_ENV = 'development';
11
9
  }
12
10
  else {
@@ -1,4 +1,4 @@
1
1
  export declare function dbConfigSetup(options: {
2
2
  dev: boolean;
3
3
  }): Promise<void>;
4
- //# sourceMappingURL=db-config-setup.d.ts.map
4
+ //# sourceMappingURL=db-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-config.d.ts","sourceRoot":"","sources":["../../src/lib/db-config.ts"],"names":[],"mappings":"AAmCA,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,iBAyO5D"}
@@ -1,8 +1,10 @@
1
1
  import { createConnection } from 'mysql2/promise';
2
- import { intro, isCancel, outro, text, spinner, note } from '@clack/prompts';
2
+ import * as p from '@clack/prompts';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
  import { cwd } from 'process';
6
+ import chalk from 'chalk';
7
+ import ora from 'ora';
6
8
  /**
7
9
  * Removes specific environment variables from the .env file content
8
10
  * Removes both the generated comment block and the individual variable lines
@@ -27,67 +29,58 @@ function isValidPort(value) {
27
29
  }
28
30
  export async function dbConfigSetup(options) {
29
31
  const { dev = false } = options;
30
- intro(`Welcome to nextjs-cms! Let's set up the database...`);
32
+ const envFileName = dev ? '.env.development' : '.env.production';
31
33
  /**
32
34
  * Step 1: Ask for connection credentials
33
35
  */
34
- note('Please provide your MySQL/MariaDB server credentials', 'Database Connection');
35
- const dbHost = await text({
36
- message: 'Database host:',
37
- placeholder: 'localhost',
38
- defaultValue: 'localhost',
39
- validate(value) {
40
- if (value && value.length < 2)
41
- return `Database host must be at least 2 characters`;
42
- },
43
- });
44
- if (isCancel(dbHost)) {
45
- outro(`nextjs-cms init cancelled by user.`);
46
- return;
47
- }
48
- const dbPort = await text({
49
- message: 'Database port:',
50
- placeholder: '3306',
51
- defaultValue: '3306',
52
- validate(value) {
53
- if (value && !isValidPort(value)) {
54
- return `Database port must be a valid number between 1 and 65535`;
55
- }
56
- },
57
- });
58
- if (isCancel(dbPort)) {
59
- outro(`nextjs-cms init cancelled by user.`);
60
- return;
61
- }
62
- const dbUser = await text({
63
- message: 'Database username:',
64
- validate(value) {
65
- if (value.length < 1)
66
- return `Database username is required`;
67
- },
68
- });
69
- if (isCancel(dbUser)) {
70
- outro(`nextjs-cms init cancelled by user.`);
71
- return;
72
- }
73
- const dbPassword = await text({
74
- message: 'Database password:',
75
- validate(value) {
76
- if (value.length < 1)
77
- return `Database password is required`;
36
+ p.log.info('Database Connection');
37
+ p.log.message('Please provide your MySQL/MariaDB server credentials');
38
+ const { dbHost, dbPort, dbUser, dbPassword } = await p.group({
39
+ dbHost: () => p.text({
40
+ message: 'Database host:',
41
+ placeholder: 'localhost',
42
+ defaultValue: 'localhost',
43
+ validate(value) {
44
+ if (value && value.length < 2)
45
+ return `Database host must be at least 2 characters`;
46
+ },
47
+ }),
48
+ dbPort: () => p.text({
49
+ message: 'Database port:',
50
+ placeholder: '3306',
51
+ defaultValue: '3306',
52
+ validate(value) {
53
+ if (value && !isValidPort(value)) {
54
+ return `Database port must be a valid number between 1 and 65535`;
55
+ }
56
+ },
57
+ }),
58
+ dbUser: () => p.text({
59
+ message: 'Database username:',
60
+ validate(value) {
61
+ if (value.length < 1)
62
+ return `Database username is required`;
63
+ },
64
+ }),
65
+ dbPassword: () => p.text({
66
+ message: 'Database password:',
67
+ validate(value) {
68
+ if (value.length < 1)
69
+ return `Database password is required`;
70
+ },
71
+ }),
72
+ }, {
73
+ onCancel: () => {
74
+ p.cancel(`Aborted\n`);
75
+ process.exit(1);
78
76
  },
79
77
  });
80
- if (isCancel(dbPassword)) {
81
- outro(`nextjs-cms init cancelled by user.`);
82
- return;
83
- }
84
78
  /**
85
79
  * Step 2: Test the database connection
86
80
  */
87
- const s = spinner();
81
+ const s = ora('Testing database connection...').start();
88
82
  let migrationClient;
89
83
  try {
90
- s.start('Testing database connection...');
91
84
  /**
92
85
  * It's recommended to not use a pool connection for migrations, that's why we're creating a new connection here.
93
86
  */
@@ -98,13 +91,14 @@ export async function dbConfigSetup(options) {
98
91
  database: '',
99
92
  port: parseInt(String(dbPort), 10),
100
93
  });
101
- s.stop('✓ Connected successfully!');
94
+ s.stop();
95
+ p.log.success(chalk.green('✓ Connected successfully!'));
102
96
  /**
103
97
  * Step 3: Now that connection is successful, ask for database name
104
98
  */
105
- note('If the database does not exist, it will be created', 'Database Name');
106
- const dbName = await text({
99
+ const dbName = await p.text({
107
100
  message: 'Database name:',
101
+ placeholder: 'If the database does not exist, it will be created',
108
102
  validate(value) {
109
103
  if (value.length < 2)
110
104
  return `Database name must be at least 2 characters`;
@@ -114,9 +108,9 @@ export async function dbConfigSetup(options) {
114
108
  }
115
109
  },
116
110
  });
117
- if (isCancel(dbName)) {
118
- outro(`nextjs-cms init cancelled by user.`);
119
- return;
111
+ if (p.isCancel(dbName)) {
112
+ p.cancel(`Aborted\n`);
113
+ process.exit(1);
120
114
  }
121
115
  /**
122
116
  * Step 4: Create the database
@@ -126,11 +120,12 @@ export async function dbConfigSetup(options) {
126
120
  * Let's create the database using parameterized query to prevent SQL injection
127
121
  */
128
122
  await migrationClient.query('CREATE DATABASE IF NOT EXISTS ??', [dbName]);
129
- s.stop('✓ Database created successfully!');
123
+ s.stop();
124
+ p.log.success(chalk.green('✓ Database created successfully!'));
130
125
  /**
131
126
  * Let's save the database credentials in the .env file
132
127
  */
133
- const envPath = path.resolve(cwd(), dev ? '.env.development' : '.env.production');
128
+ const envPath = path.resolve(cwd(), envFileName);
134
129
  /**
135
130
  * If the .env file does not exist, we'll create it
136
131
  */
@@ -173,18 +168,45 @@ DB_PASSWORD='${dbPassword}'
173
168
  DB_USER: String(dbUser),
174
169
  DB_PASSWORD: String(dbPassword),
175
170
  };
176
- const { reloadAndUpdateEnvironmentVariables } = await import('./reload-env.js');
177
- const reloadSuccess = reloadAndUpdateEnvironmentVariables(dbVariables, dev ? '.env.development' : '.env.production');
178
- if (reloadSuccess) {
179
- console.log('✓ Environment variables reloaded successfully!');
180
- }
181
- else {
182
- console.warn('⚠️ Environment variables written to file but could not be reloaded in current process');
171
+ const { reloadAndUpdateEnvironmentVariables } = await import('../utils/reload-env.js');
172
+ reloadAndUpdateEnvironmentVariables(dbVariables, envFileName);
173
+ /**
174
+ * Get environment variables from env and check if they are correct
175
+ */
176
+ const envDbHost = process.env.DB_HOST;
177
+ const envDbPort = process.env.DB_PORT;
178
+ const envDbName = process.env.DB_NAME;
179
+ const envDbUser = process.env.DB_USER;
180
+ const envDbPassword = process.env.DB_PASSWORD;
181
+ // Validate that the values match what we just set
182
+ const mismatches = [];
183
+ if (envDbHost !== String(dbHost))
184
+ mismatches.push('DB_HOST');
185
+ if (envDbPort !== String(dbPort))
186
+ mismatches.push('DB_PORT');
187
+ if (envDbName !== String(dbName))
188
+ mismatches.push('DB_NAME');
189
+ if (envDbUser !== String(dbUser))
190
+ mismatches.push('DB_USER');
191
+ if (envDbPassword !== String(dbPassword))
192
+ mismatches.push('DB_PASSWORD');
193
+ if (mismatches.length > 0) {
194
+ p.log.error(`✗ Couldn't save database credentials to ${envFileName} file}`);
195
+ console.error(`Please save these values manually to the ${envFileName} file:`);
196
+ console.error(`DB_HOST: ${dbHost}`);
197
+ console.error(`DB_PORT: ${dbPort}`);
198
+ console.error(`DB_NAME: ${dbName}`);
199
+ console.error(`DB_USER: ${dbUser}`);
200
+ console.error(`DB_PASSWORD: ${dbPassword}`);
201
+ console.error();
202
+ console.error(chalk.cyan(`and then run: ${chalk.green(`pnpm nextjs-cms ${dev ? '-d' : ''} setup --continue`)} to continue your setup`));
203
+ process.exit(1);
183
204
  }
184
- outro(`✓ Database setup completed successfully!`);
205
+ p.log.message(chalk.cyan(` - Saved database credentials to ${envFileName} file`));
185
206
  }
186
207
  catch (error) {
187
- s.stop('✗ Database setup failed!');
208
+ s.stop();
209
+ p.log.error(chalk.red('✗ Database setup failed!'));
188
210
  const errorMessage = error instanceof Error ? error.message : String(error);
189
211
  const errorCode = error && typeof error === 'object' && 'code' in error ? error.code : null;
190
212
  // Provide specific error messages based on error type
@@ -202,7 +224,7 @@ DB_PASSWORD='${dbPassword}'
202
224
  else {
203
225
  console.error('\n❌ Error:', errorMessage);
204
226
  }
205
- outro(`\nSetup failed. Please check the errors above and try again.`);
227
+ p.outro(`\nSetup failed. Please check the errors above and try again.`);
206
228
  process.exit(1);
207
229
  }
208
230
  finally {
@@ -0,0 +1,2 @@
1
+ export declare function generateDatabaseTables(): Promise<void>;
2
+ //# sourceMappingURL=db-migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-migrate.d.ts","sourceRoot":"","sources":["../../src/lib/db-migrate.ts"],"names":[],"mappings":"AAOA,wBAAsB,sBAAsB,kBAqF3C"}
@@ -0,0 +1,84 @@
1
+ import * as p from '@clack/prompts';
2
+ import { execWithSpinner } from '../utils/exec-utils.js';
3
+ import chalk from 'chalk';
4
+ import { MysqlTableChecker } from 'nextjs-cms/core/db';
5
+ import { db } from 'nextjs-cms/db/client';
6
+ import { sql } from 'nextjs-cms/db';
7
+ export async function generateDatabaseTables() {
8
+ /**
9
+ * We should first drop all primary keys from the tables
10
+ */
11
+ const _existingTables = [];
12
+ const tablesToCheck = [
13
+ '__nextjs_cms_tables',
14
+ 'cms_settings',
15
+ 'admins',
16
+ 'admin_privileges',
17
+ 'access_tokens',
18
+ 'editor_photos',
19
+ ];
20
+ try {
21
+ const result = await MysqlTableChecker.getExistingTables();
22
+ result.forEach((table) => {
23
+ if (tablesToCheck.includes(table)) {
24
+ _existingTables.push(table);
25
+ }
26
+ });
27
+ if (_existingTables.length > 0) {
28
+ const allOrSome = _existingTables.length === tablesToCheck.length ? 'all' : 'some';
29
+ p.log.warn(chalk.yellow(`You already have ${allOrSome === 'some' ? 'a few required tables from' : ''} a previous database schema:`));
30
+ for (const table of _existingTables) {
31
+ p.log.message(chalk.yellow(` - ${table}`));
32
+ }
33
+ p.log.message(chalk.cyan('These tables will be dropped and new ones will be created.'));
34
+ const answer = await p.select({
35
+ message: 'Do you want to continue? (y/n)',
36
+ options: [
37
+ { value: 'y', label: 'Yes' },
38
+ { value: 'n', label: 'No' },
39
+ ],
40
+ initialValue: 'n',
41
+ });
42
+ if (p.isCancel(answer) || answer !== 'y') {
43
+ p.log.error(chalk.red('Aborted\n'));
44
+ process.exit(1);
45
+ }
46
+ try {
47
+ // Disable foreign key checks to allow dropping tables with foreign key constraints
48
+ await db.execute(sql `SET FOREIGN_KEY_CHECKS = 0`);
49
+ // Drop all tables at once
50
+ for (const table of _existingTables) {
51
+ await db.execute(sql `DROP TABLE IF EXISTS \`${sql.raw(table)}\``);
52
+ }
53
+ // Re-enable foreign key checks
54
+ await db.execute(sql `SET FOREIGN_KEY_CHECKS = 1`);
55
+ }
56
+ catch (error) {
57
+ // Re-enable foreign key checks even if there's an error
58
+ await db.execute(sql `SET FOREIGN_KEY_CHECKS = 1`).catch(() => {
59
+ // Ignore errors when re-enabling
60
+ });
61
+ console.error(chalk.red('✗ Error dropping existing tables:'), error);
62
+ p.log.error(chalk.red('✗ Failed to drop existing tables'));
63
+ throw error;
64
+ }
65
+ }
66
+ const spinner = await execWithSpinner({
67
+ command: 'pnpm',
68
+ args: ['drizzle-kit', 'push', '--force', '--config=drizzle.config.ts'],
69
+ cwd: process.cwd(),
70
+ stdout: 'pipe', // Show output
71
+ stderr: 'inherit', // Show errors
72
+ spinnerText: 'Generating database tables...',
73
+ checkExitCode: true, // Throw on non-zero exit codes
74
+ checkStderrForErrors: true, // Also check for errors in output even if exit code is 0
75
+ });
76
+ spinner?.stop();
77
+ p.log.success(chalk.green('✓ Database tables generated'));
78
+ }
79
+ catch (error) {
80
+ console.error(chalk.red('✗ Error generating database tables:'), error);
81
+ p.log.error(chalk.red('✗ Failed to generate database tables'));
82
+ process.exit(1);
83
+ }
84
+ }
@@ -1,2 +1,2 @@
1
- export declare function fixMasterAdmin(): Promise<void>;
1
+ export declare function fixMasterAdminPrivileges(): Promise<void>;
2
2
  //# sourceMappingURL=fix-master-admin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fix-master-admin.d.ts","sourceRoot":"","sources":["../../src/lib/fix-master-admin.ts"],"names":[],"mappings":"AAEA,wBAAsB,cAAc,kBAKnC"}
1
+ {"version":3,"file":"fix-master-admin.d.ts","sourceRoot":"","sources":["../../src/lib/fix-master-admin.ts"],"names":[],"mappings":"AAAA,wBAAsB,wBAAwB,kBA6B7C"}