nextjs-cms-kit 0.5.31 → 0.5.33

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.
@@ -1 +1 @@
1
- {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAmE7B,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAA;AA+D3C,QAAA,MAAM,OAAO,SAAgB,CAAA;AAoE7B,eAAe,OAAO,CAAA"}
@@ -1,25 +1,66 @@
1
- import { Command } from 'commander';
1
+ import { Command, Option } from 'commander';
2
2
  import chalk from 'chalk';
3
+ import { existsSync, readFileSync } from 'fs';
4
+ import { join } from 'path';
5
+ function isNextjsCmsApp() {
6
+ const cwd = process.cwd();
7
+ // Check for lz.config.ts file
8
+ const configFile = join(cwd, 'lz.config.ts');
9
+ if (!existsSync(configFile)) {
10
+ return false;
11
+ }
12
+ // Check for nextjs-cms dependency in package.json
13
+ try {
14
+ const packageJsonPath = join(cwd, 'package.json');
15
+ if (!existsSync(packageJsonPath)) {
16
+ return false;
17
+ }
18
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
19
+ const allDeps = {
20
+ ...(packageJson.dependencies ?? {}),
21
+ ...(packageJson.devDependencies ?? {}),
22
+ ...(packageJson.peerDependencies ?? {}),
23
+ };
24
+ return 'nextjs-cms' in allDeps;
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ }
30
+ function shouldSkipValidation() {
31
+ const args = process.argv.slice(2); // Remove 'node' and script path
32
+ return args.includes('-h') || args.includes('--help') || args.includes('-V') || args.includes('--version');
33
+ }
34
+ function validateNextjsCmsApp() {
35
+ // Skip validation for help and version commands
36
+ if (shouldSkipValidation()) {
37
+ return;
38
+ }
39
+ if (!isNextjsCmsApp()) {
40
+ console.error(chalk.red('❌ Error: This command must be run in a nextjs-cms application directory.'));
41
+ console.error(chalk.gray('Make sure you have:'));
42
+ console.error(chalk.gray(' - lz.config.ts file'));
43
+ console.error(chalk.gray(' - nextjs-cms as a dependency in package.json'));
44
+ console.error(chalk.gray('To create a new nextjs-cms application, run:'));
45
+ console.error(chalk.gray(' - pnpm create nextjs-cms@latest'));
46
+ process.exit(1);
47
+ }
48
+ }
49
+ // Validate that we're in a nextjs-cms app before proceeding
50
+ validateNextjsCmsApp();
3
51
  const program = new Command();
4
52
  program
5
53
  .name('nextjs-cms-kit')
54
+ .option('-d, --dev', 'use development environment file, use -d/--dev before any command to use the development environment file (e.g. nextjs-cms-kit -d setup)', false)
6
55
  .description(chalk.green('nextjs-cms CLI toolkit for managing your nextjs-cms application'))
7
56
  .version('0.4.0')
8
- .option('-d, --dev', 'Use development environment file')
9
- .action(() => {
10
- console.log(chalk.hex('#E8DCFF').bold(program.name()));
11
- console.log(program.version());
12
- console.log(program.description());
13
- console.log(chalk.gray('--------------------------'));
14
- console.log(chalk.yellow(`Running in ${process.env.NODE_ENV} mode`));
15
- console.log(chalk.gray('--------------------------'));
16
- });
17
- // Lazy-load commands to avoid eager database connection initialization
18
- // This significantly improves CLI startup time by deferring heavy imports
19
- // until the specific command is actually invoked
57
+ // Include -v option to show the version number
58
+ .addOption(new Option('-v').hideHelp())
59
+ .enablePositionalOptions();
20
60
  program
21
61
  .command('setup')
22
62
  .description('Complete nextjs-cms setup')
63
+ .passThroughOptions()
23
64
  .action(async () => {
24
65
  const { runSetup } = await import('../commands/setup.js');
25
66
  await runSetup(Boolean(program.opts().dev));
@@ -27,6 +68,7 @@ program
27
68
  program
28
69
  .command('db-config')
29
70
  .description('Initialize nextjs-cms database configuration')
71
+ .passThroughOptions()
30
72
  .action(async () => {
31
73
  const { runDbConfig } = await import('../commands/db-config.js');
32
74
  await runDbConfig(Boolean(program.opts().dev));
@@ -34,6 +76,7 @@ program
34
76
  program
35
77
  .command('set-master-admin')
36
78
  .description('Set or update master admin password')
79
+ .passThroughOptions()
37
80
  .action(async () => {
38
81
  const { runSetMasterAdmin } = await import('../commands/set-master-admin.js');
39
82
  await runSetMasterAdmin(Boolean(program.opts().dev));
@@ -41,6 +84,7 @@ program
41
84
  program
42
85
  .command('fix-master-admin')
43
86
  .description('Fix master admin privileges for all sections')
87
+ .passThroughOptions()
44
88
  .action(async () => {
45
89
  const { runFixMasterAdmin } = await import('../commands/fix-master-admin.js');
46
90
  await runFixMasterAdmin();
@@ -48,14 +92,15 @@ program
48
92
  program
49
93
  .command('update-sections')
50
94
  .description('Update database tables based on current sections and update master admin privileges')
95
+ .passThroughOptions()
51
96
  .action(async () => {
52
97
  const { runUpdateSections } = await import('../commands/update-sections.js');
53
98
  await runUpdateSections(Boolean(program.opts().dev));
54
99
  });
55
- // Handle unknown commands
56
- program.on('command:*', (operands) => {
57
- console.error(chalk.red(`Unknown command: ${operands[0]}`));
58
- console.log(chalk.gray('Run nextjs-cms-kit --help to see available commands'));
59
- process.exit(1);
100
+ program.showHelpAfterError('(add --help for additional information)');
101
+ // Show the version number when the -v option is used
102
+ program.on('option:v', () => {
103
+ console.log(program.version());
104
+ process.exit();
60
105
  });
61
106
  export default program;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nextjs-cms-kit",
3
3
  "private": false,
4
- "version": "0.5.31",
4
+ "version": "0.5.33",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "nextjs-cms-kit": "./dist/index.js"
@@ -32,7 +32,7 @@
32
32
  "mysql2": "^3.12.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "nextjs-cms": "0.5.31"
35
+ "nextjs-cms": "0.5.33"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/bcrypt": "^6.0.0",
@@ -49,7 +49,7 @@
49
49
  "scripts": {
50
50
  "build": "tsc",
51
51
  "clean": "git clean -xdf .cache .turbo dist node_modules",
52
- "dev": "tsc",
52
+ "dev": "tsc --watch",
53
53
  "format": "prettier --check . --ignore-path ../../.gitignore",
54
54
  "lint": "eslint",
55
55
  "typecheck": "tsc --noEmit --emitDeclarationOnly false",