nextjs-cms-kit 0.5.66 → 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.map +1 -1
  9. package/dist/commands/setup.js +12 -16
  10. package/dist/commands/update-sections.d.ts.map +1 -1
  11. package/dist/commands/update-sections.js +11 -16
  12. package/dist/index.js +1 -1
  13. package/dist/lib/{db-config-setup.d.ts → db-config.d.ts} +1 -1
  14. package/dist/lib/db-config.d.ts.map +1 -0
  15. package/dist/lib/{db-config-setup.js → db-config.js} +53 -62
  16. package/dist/lib/db-migrate.d.ts +1 -1
  17. package/dist/lib/db-migrate.js +14 -14
  18. package/dist/lib/fix-master-admin.d.ts +1 -1
  19. package/dist/lib/fix-master-admin.d.ts.map +1 -1
  20. package/dist/lib/fix-master-admin.js +26 -6
  21. package/dist/lib/set-master-admin.d.ts.map +1 -1
  22. package/dist/lib/set-master-admin.js +52 -19
  23. package/dist/lib/update-sections.js +3 -3
  24. package/dist/program/program.d.ts.map +1 -0
  25. package/dist/program/program.js +95 -0
  26. package/dist/utils/add-table-keys.d.ts.map +1 -0
  27. package/dist/utils/check-version.d.ts +3 -0
  28. package/dist/utils/check-version.d.ts.map +1 -0
  29. package/dist/{lib/program.js → utils/check-version.js} +56 -83
  30. package/dist/utils/display-intro.d.ts +6 -0
  31. package/dist/utils/display-intro.d.ts.map +1 -0
  32. package/dist/utils/display-intro.js +9 -0
  33. package/dist/utils/exec-utils.d.ts.map +1 -0
  34. package/dist/utils/get-package-manager.d.ts +4 -0
  35. package/dist/utils/get-package-manager.d.ts.map +1 -0
  36. package/dist/utils/get-package-manager.js +22 -0
  37. package/dist/utils/reload-env.d.ts.map +1 -0
  38. package/dist/utils/render-title.d.ts.map +1 -0
  39. package/dist/utils/schema-generator.d.ts.map +1 -0
  40. package/package.json +4 -4
  41. package/dist/lib/actions.d.ts +0 -7
  42. package/dist/lib/actions.d.ts.map +0 -1
  43. package/dist/lib/actions.js +0 -68
  44. package/dist/lib/add-table-keys.d.ts.map +0 -1
  45. package/dist/lib/db-config-setup.d.ts.map +0 -1
  46. package/dist/lib/exec-utils.d.ts.map +0 -1
  47. package/dist/lib/program.d.ts.map +0 -1
  48. package/dist/lib/reload-env.d.ts.map +0 -1
  49. package/dist/lib/render-title.d.ts.map +0 -1
  50. package/dist/lib/schema-generator.d.ts.map +0 -1
  51. /package/dist/{lib → program}/program.d.ts +0 -0
  52. /package/dist/{lib → utils}/add-table-keys.d.ts +0 -0
  53. /package/dist/{lib → utils}/add-table-keys.js +0 -0
  54. /package/dist/{lib → utils}/exec-utils.d.ts +0 -0
  55. /package/dist/{lib → utils}/exec-utils.js +0 -0
  56. /package/dist/{lib → utils}/reload-env.d.ts +0 -0
  57. /package/dist/{lib → utils}/reload-env.js +0 -0
  58. /package/dist/{lib → utils}/render-title.d.ts +0 -0
  59. /package/dist/{lib → utils}/render-title.js +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 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAIA,wBAAsB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,iBAyCjE"}
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,38 +1,34 @@
1
- import { note, intro, outro } from '@clack/prompts';
1
+ import * as p from '@clack/prompts';
2
2
  import chalk from 'chalk';
3
- import { getTitle } from '../lib/render-title.js';
4
3
  export async function runSetup(dev, skipDbConfig) {
5
- console.log();
6
- console.log(chalk.white.bold(`${getTitle()} > ${chalk.cyan.italic('setup')} ${dev ? chalk.gray('(development)') : chalk.gray('(production)')}`));
7
- console.log();
8
- intro(chalk.inverse(' Setting up nextjs-cms 🚀 '));
4
+ let exitCode = 0;
9
5
  try {
10
6
  if (!skipDbConfig) {
11
- note(chalk.cyan('Configuring database'));
12
- const { dbConfigSetup } = await import('../lib/db-config-setup.js');
7
+ p.log.info(chalk.cyan('Configuring database'));
8
+ const { dbConfigSetup } = await import('../lib/db-config.js');
13
9
  await dbConfigSetup({ dev });
14
10
  }
15
- note(chalk.cyan('Generating database schema'));
16
- const { generateDatabaseSchema } = await import('../lib/db-migrate.js');
17
- await generateDatabaseSchema();
18
- note(chalk.cyan('Setting up master admin'));
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'));
19
15
  const { setMasterAdmin } = await import('../lib/set-master-admin.js');
20
16
  await setMasterAdmin();
21
- outro(chalk.inverse(' ✓ nextjs-cms setup completed successfully '));
17
+ p.outro(chalk.inverse(' ✓ nextjs-cms setup completed successfully '));
22
18
  }
23
19
  catch (error) {
24
20
  console.log('');
25
21
  console.error(chalk.red('✗ Error during setup:'), error);
26
- outro(chalk.red('✗ Setup failed'));
22
+ p.outro(chalk.red('✗ Setup failed'));
27
23
  // Lazy import for cleanup
28
24
  const { dbConnectionClose } = await import('nextjs-cms/db/client');
29
25
  await dbConnectionClose();
30
- process.exit(1);
26
+ exitCode = 1;
31
27
  }
32
28
  finally {
33
29
  // Lazy import for cleanup
34
30
  const { dbConnectionClose } = await import('nextjs-cms/db/client');
35
31
  await dbConnectionClose();
36
- process.exit(0);
37
32
  }
33
+ process.exit(exitCode);
38
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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import dotenv from 'dotenv';
3
- import program from './lib/program.js';
3
+ import program from './program/program.js';
4
4
  program.parse(process.argv);
5
5
  // Load environment file based on parsed dev flag
6
6
  if (Boolean(program.opts().dev) === true) {
@@ -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,5 +1,5 @@
1
1
  import { createConnection } from 'mysql2/promise';
2
- import { log, isCancel, outro, text } 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';
@@ -33,57 +33,48 @@ export async function dbConfigSetup(options) {
33
33
  /**
34
34
  * Step 1: Ask for connection credentials
35
35
  */
36
- log.info('Database Connection');
37
- log.message('Please provide your MySQL/MariaDB server credentials');
38
- const dbHost = await text({
39
- message: 'Database host:',
40
- placeholder: 'localhost',
41
- defaultValue: 'localhost',
42
- validate(value) {
43
- if (value && value.length < 2)
44
- return `Database host must be at least 2 characters`;
45
- },
46
- });
47
- if (isCancel(dbHost)) {
48
- outro(`nextjs-cms init cancelled by user.`);
49
- return;
50
- }
51
- const dbPort = await text({
52
- message: 'Database port:',
53
- placeholder: '3306',
54
- defaultValue: '3306',
55
- validate(value) {
56
- if (value && !isValidPort(value)) {
57
- return `Database port must be a valid number between 1 and 65535`;
58
- }
59
- },
60
- });
61
- if (isCancel(dbPort)) {
62
- outro(`nextjs-cms init cancelled by user.`);
63
- return;
64
- }
65
- const dbUser = await text({
66
- message: 'Database username:',
67
- validate(value) {
68
- if (value.length < 1)
69
- return `Database username is required`;
70
- },
71
- });
72
- if (isCancel(dbUser)) {
73
- outro(`nextjs-cms init cancelled by user.`);
74
- return;
75
- }
76
- const dbPassword = await text({
77
- message: 'Database password:',
78
- validate(value) {
79
- if (value.length < 1)
80
- 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);
81
76
  },
82
77
  });
83
- if (isCancel(dbPassword)) {
84
- outro(`nextjs-cms init cancelled by user.`);
85
- return;
86
- }
87
78
  /**
88
79
  * Step 2: Test the database connection
89
80
  */
@@ -101,11 +92,11 @@ export async function dbConfigSetup(options) {
101
92
  port: parseInt(String(dbPort), 10),
102
93
  });
103
94
  s.stop();
104
- log.success(chalk.green('✓ Connected successfully!'));
95
+ p.log.success(chalk.green('✓ Connected successfully!'));
105
96
  /**
106
97
  * Step 3: Now that connection is successful, ask for database name
107
98
  */
108
- const dbName = await text({
99
+ const dbName = await p.text({
109
100
  message: 'Database name:',
110
101
  placeholder: 'If the database does not exist, it will be created',
111
102
  validate(value) {
@@ -117,9 +108,9 @@ export async function dbConfigSetup(options) {
117
108
  }
118
109
  },
119
110
  });
120
- if (isCancel(dbName)) {
121
- outro(`nextjs-cms init cancelled by user.`);
122
- return;
111
+ if (p.isCancel(dbName)) {
112
+ p.cancel(`Aborted\n`);
113
+ process.exit(1);
123
114
  }
124
115
  /**
125
116
  * Step 4: Create the database
@@ -130,7 +121,7 @@ export async function dbConfigSetup(options) {
130
121
  */
131
122
  await migrationClient.query('CREATE DATABASE IF NOT EXISTS ??', [dbName]);
132
123
  s.stop();
133
- log.success(chalk.green('✓ Database created successfully!'));
124
+ p.log.success(chalk.green('✓ Database created successfully!'));
134
125
  /**
135
126
  * Let's save the database credentials in the .env file
136
127
  */
@@ -177,8 +168,8 @@ DB_PASSWORD='${dbPassword}'
177
168
  DB_USER: String(dbUser),
178
169
  DB_PASSWORD: String(dbPassword),
179
170
  };
180
- const { reloadAndUpdateEnvironmentVariables } = await import('./reload-env.js');
181
- const reloadSuccess = reloadAndUpdateEnvironmentVariables(dbVariables, envFileName);
171
+ const { reloadAndUpdateEnvironmentVariables } = await import('../utils/reload-env.js');
172
+ reloadAndUpdateEnvironmentVariables(dbVariables, envFileName);
182
173
  /**
183
174
  * Get environment variables from env and check if they are correct
184
175
  */
@@ -200,7 +191,7 @@ DB_PASSWORD='${dbPassword}'
200
191
  if (envDbPassword !== String(dbPassword))
201
192
  mismatches.push('DB_PASSWORD');
202
193
  if (mismatches.length > 0) {
203
- log.error(`✗ Couldn't save database credentials to ${envFileName} file}`);
194
+ p.log.error(`✗ Couldn't save database credentials to ${envFileName} file}`);
204
195
  console.error(`Please save these values manually to the ${envFileName} file:`);
205
196
  console.error(`DB_HOST: ${dbHost}`);
206
197
  console.error(`DB_PORT: ${dbPort}`);
@@ -211,11 +202,11 @@ DB_PASSWORD='${dbPassword}'
211
202
  console.error(chalk.cyan(`and then run: ${chalk.green(`pnpm nextjs-cms ${dev ? '-d' : ''} setup --continue`)} to continue your setup`));
212
203
  process.exit(1);
213
204
  }
214
- log.message(chalk.cyan(` - Saved database credentials to ${envFileName} file`));
205
+ p.log.message(chalk.cyan(` - Saved database credentials to ${envFileName} file`));
215
206
  }
216
207
  catch (error) {
217
208
  s.stop();
218
- log.error(chalk.red('✗ Database setup failed!'));
209
+ p.log.error(chalk.red('✗ Database setup failed!'));
219
210
  const errorMessage = error instanceof Error ? error.message : String(error);
220
211
  const errorCode = error && typeof error === 'object' && 'code' in error ? error.code : null;
221
212
  // Provide specific error messages based on error type
@@ -233,7 +224,7 @@ DB_PASSWORD='${dbPassword}'
233
224
  else {
234
225
  console.error('\n❌ Error:', errorMessage);
235
226
  }
236
- outro(`\nSetup failed. Please check the errors above and try again.`);
227
+ p.outro(`\nSetup failed. Please check the errors above and try again.`);
237
228
  process.exit(1);
238
229
  }
239
230
  finally {
@@ -1,2 +1,2 @@
1
- export declare function generateDatabaseSchema(): Promise<void>;
1
+ export declare function generateDatabaseTables(): Promise<void>;
2
2
  //# sourceMappingURL=db-migrate.d.ts.map
@@ -1,10 +1,10 @@
1
- import { log, select } from '@clack/prompts';
2
- import { execWithSpinner } from './exec-utils.js';
1
+ import * as p from '@clack/prompts';
2
+ import { execWithSpinner } from '../utils/exec-utils.js';
3
3
  import chalk from 'chalk';
4
4
  import { MysqlTableChecker } from 'nextjs-cms/core/db';
5
5
  import { db } from 'nextjs-cms/db/client';
6
6
  import { sql } from 'nextjs-cms/db';
7
- export async function generateDatabaseSchema() {
7
+ export async function generateDatabaseTables() {
8
8
  /**
9
9
  * We should first drop all primary keys from the tables
10
10
  */
@@ -26,12 +26,12 @@ export async function generateDatabaseSchema() {
26
26
  });
27
27
  if (_existingTables.length > 0) {
28
28
  const allOrSome = _existingTables.length === tablesToCheck.length ? 'all' : 'some';
29
- log.warn(chalk.yellow(`You already have ${allOrSome === 'some' ? 'a few required tables from' : ''} a previous database schema:`));
29
+ p.log.warn(chalk.yellow(`You already have ${allOrSome === 'some' ? 'a few required tables from' : ''} a previous database schema:`));
30
30
  for (const table of _existingTables) {
31
- log.message(chalk.yellow(` - ${table}`));
31
+ p.log.message(chalk.yellow(` - ${table}`));
32
32
  }
33
- log.message(chalk.cyan('These tables will be dropped and new ones will be created.'));
34
- const answer = await select({
33
+ p.log.message(chalk.cyan('These tables will be dropped and new ones will be created.'));
34
+ const answer = await p.select({
35
35
  message: 'Do you want to continue? (y/n)',
36
36
  options: [
37
37
  { value: 'y', label: 'Yes' },
@@ -39,8 +39,8 @@ export async function generateDatabaseSchema() {
39
39
  ],
40
40
  initialValue: 'n',
41
41
  });
42
- if (answer !== 'y') {
43
- log.error(chalk.red('Aborted'));
42
+ if (p.isCancel(answer) || answer !== 'y') {
43
+ p.log.error(chalk.red('Aborted\n'));
44
44
  process.exit(1);
45
45
  }
46
46
  try {
@@ -59,7 +59,7 @@ export async function generateDatabaseSchema() {
59
59
  // Ignore errors when re-enabling
60
60
  });
61
61
  console.error(chalk.red('✗ Error dropping existing tables:'), error);
62
- log.error(chalk.red('✗ Failed to drop existing tables'));
62
+ p.log.error(chalk.red('✗ Failed to drop existing tables'));
63
63
  throw error;
64
64
  }
65
65
  }
@@ -69,16 +69,16 @@ export async function generateDatabaseSchema() {
69
69
  cwd: process.cwd(),
70
70
  stdout: 'pipe', // Show output
71
71
  stderr: 'inherit', // Show errors
72
- spinnerText: 'Generating database schema...',
72
+ spinnerText: 'Generating database tables...',
73
73
  checkExitCode: true, // Throw on non-zero exit codes
74
74
  checkStderrForErrors: true, // Also check for errors in output even if exit code is 0
75
75
  });
76
76
  spinner?.stop();
77
- log.success(chalk.green('✓ Database schema generated'));
77
+ p.log.success(chalk.green('✓ Database tables generated'));
78
78
  }
79
79
  catch (error) {
80
- console.error(chalk.red('✗ Error generating database schema:'), error);
81
- log.error(chalk.red('✗ Failed to generate database schema'));
80
+ console.error(chalk.red('✗ Error generating database tables:'), error);
81
+ p.log.error(chalk.red('✗ Failed to generate database tables'));
82
82
  process.exit(1);
83
83
  }
84
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"}
@@ -1,7 +1,27 @@
1
- import { intro, outro } from '@clack/prompts';
2
- export async function fixMasterAdmin() {
3
- intro(`Looking up sections...`);
4
- const { fixMasterAdminPrivileges } = await import('./actions.js');
5
- await fixMasterAdminPrivileges();
6
- outro(`Master admin privileges fixed`);
1
+ export async function fixMasterAdminPrivileges() {
2
+ // Lazy import heavy dependencies to avoid eager database connection initialization
3
+ const { SectionFactory } = await import('nextjs-cms/core/factories');
4
+ const { db } = await import('nextjs-cms/db/client');
5
+ const { AdminPrivilegesTable } = await import('nextjs-cms/db/schema');
6
+ // Let's also add privileges for all the sections to the master admin
7
+ // Loop through the sections to get the section ids for the insertion into the admin_privileges table
8
+ const sections = await SectionFactory.getSectionsSilently();
9
+ const rows = sections.map((section) => ({
10
+ adminId: '1',
11
+ sectionName: section.name,
12
+ operations: 'CUD',
13
+ publisher: '1',
14
+ }));
15
+ if (rows.length === 0)
16
+ return;
17
+ await db
18
+ .insert(AdminPrivilegesTable)
19
+ .values(rows)
20
+ .onDuplicateKeyUpdate({
21
+ set: {
22
+ operations: 'CUD',
23
+ publisher: true,
24
+ },
25
+ });
26
+ return;
7
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"set-master-admin.d.ts","sourceRoot":"","sources":["../../src/lib/set-master-admin.ts"],"names":[],"mappings":"AAIA,wBAAsB,cAAc,kBA0DnC"}
1
+ {"version":3,"file":"set-master-admin.d.ts","sourceRoot":"","sources":["../../src/lib/set-master-admin.ts"],"names":[],"mappings":"AAGA,wBAAsB,cAAc,kBA+FnC"}