nextjs-cms-kit 0.5.38 → 0.5.54
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/dist/index.js +3 -3
- package/dist/lib/program.d.ts.map +1 -1
- package/dist/lib/program.js +130 -29
- package/package.json +5 -7
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import dotenv from 'dotenv';
|
|
3
3
|
import program from './lib/program.js';
|
|
4
|
-
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
5
|
program.parse(process.argv);
|
|
6
|
-
//
|
|
6
|
+
// Load environment file based on parsed dev flag
|
|
7
7
|
if (Boolean(program.opts().dev) === true) {
|
|
8
|
-
|
|
8
|
+
p.note('🔧 Using development environment file');
|
|
9
9
|
dotenv.config({ path: '.env.development' });
|
|
10
10
|
process.env.NODE_ENV = 'development';
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,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+N3C,QAAA,MAAM,OAAO,SAAgB,CAAA;AAoE7B,eAAe,OAAO,CAAA"}
|
package/dist/lib/program.js
CHANGED
|
@@ -1,31 +1,101 @@
|
|
|
1
1
|
import { Command, Option } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import { existsSync,
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { readFileSync, existsSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { join, dirname } from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
import process from 'node:process';
|
|
8
|
+
function findPackageJson(startDir) {
|
|
9
|
+
let dir = startDir ?? process.cwd();
|
|
10
|
+
while (true) {
|
|
11
|
+
const candidate = join(dir, 'package.json');
|
|
12
|
+
if (existsSync(candidate))
|
|
13
|
+
return candidate;
|
|
14
|
+
const parent = dirname(dir);
|
|
15
|
+
if (parent === dir)
|
|
16
|
+
break;
|
|
17
|
+
dir = parent;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
function findConfigFile(startDir) {
|
|
22
|
+
let dir = startDir ?? process.cwd();
|
|
23
|
+
while (true) {
|
|
24
|
+
const candidate = join(dir, 'lz.config.ts');
|
|
25
|
+
if (existsSync(candidate))
|
|
26
|
+
return candidate;
|
|
27
|
+
const parent = dirname(dir);
|
|
28
|
+
if (parent === dir)
|
|
29
|
+
break;
|
|
30
|
+
dir = parent;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
// Get version dynamically from package.json
|
|
35
|
+
const currentFilePath = fileURLToPath(import.meta.url);
|
|
36
|
+
const currentDir = dirname(currentFilePath);
|
|
37
|
+
const packageJsonPath = join(currentDir, '../../package.json');
|
|
38
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
39
|
+
const version = packageJson.version;
|
|
40
|
+
const dependencies = packageJson.dependencies;
|
|
41
|
+
function checkNextjsCmsInstallation() {
|
|
42
|
+
const requireFromCwd = createRequire(join(process.cwd(), 'index.js'));
|
|
7
43
|
// Check for lz.config.ts file
|
|
8
|
-
const configFile =
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
44
|
+
const configFile = findConfigFile();
|
|
45
|
+
if (configFile === undefined) {
|
|
46
|
+
return { error: 'not-nextjs-cms-app' };
|
|
11
47
|
}
|
|
12
48
|
// Check for nextjs-cms dependency in package.json
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
49
|
+
const pkgPath = findPackageJson();
|
|
50
|
+
if (pkgPath === undefined) {
|
|
51
|
+
return { error: 'not-nextjs-cms-app' };
|
|
52
|
+
}
|
|
53
|
+
const packageJson = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
54
|
+
const deps = {
|
|
55
|
+
...(packageJson.dependencies ?? {}),
|
|
56
|
+
};
|
|
57
|
+
const existsInProjectPackageJson = 'nextjs-cms' in deps;
|
|
58
|
+
if (!existsInProjectPackageJson) {
|
|
59
|
+
return { error: 'local-not-found' };
|
|
60
|
+
}
|
|
61
|
+
const versionInProjectPackageJson = deps['nextjs-cms'];
|
|
62
|
+
if (versionInProjectPackageJson === undefined) {
|
|
63
|
+
return { error: 'local-not-found' };
|
|
64
|
+
}
|
|
65
|
+
// Hard check for installed version
|
|
66
|
+
// Resolve whatever the package exports at "." (this IS allowed)
|
|
67
|
+
const entryPath = requireFromCwd.resolve('nextjs-cms');
|
|
68
|
+
// Follow symlinks (helps with pnpm layouts)
|
|
69
|
+
const startPath = realpathSync(entryPath);
|
|
70
|
+
const installedPackageJson = findPackageJson(startPath);
|
|
71
|
+
if (installedPackageJson === undefined) {
|
|
72
|
+
return {
|
|
73
|
+
error: 'local-needs-update',
|
|
74
|
+
installedVersion: 'undefined',
|
|
75
|
+
packageVersion: versionInProjectPackageJson,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const installedPackageJsonParsed = JSON.parse(readFileSync(installedPackageJson, 'utf8'));
|
|
79
|
+
const localInstalledVersion = installedPackageJsonParsed?.version ?? undefined;
|
|
80
|
+
if (localInstalledVersion !== versionInProjectPackageJson) {
|
|
81
|
+
return {
|
|
82
|
+
error: 'local-needs-update',
|
|
83
|
+
installedVersion: localInstalledVersion ?? 'undefined',
|
|
84
|
+
packageVersion: versionInProjectPackageJson,
|
|
23
85
|
};
|
|
24
|
-
return 'nextjs-cms' in allDeps;
|
|
25
86
|
}
|
|
26
|
-
|
|
27
|
-
|
|
87
|
+
const versionInGlobalPackageJson = dependencies['nextjs-cms'];
|
|
88
|
+
if (versionInGlobalPackageJson === undefined) {
|
|
89
|
+
return { error: 'global-not-found' };
|
|
28
90
|
}
|
|
91
|
+
if (versionInProjectPackageJson !== versionInGlobalPackageJson) {
|
|
92
|
+
return {
|
|
93
|
+
error: 'version-mismatch',
|
|
94
|
+
installedVersion: versionInProjectPackageJson,
|
|
95
|
+
globalVersion: versionInGlobalPackageJson,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
29
99
|
}
|
|
30
100
|
function shouldSkipValidation() {
|
|
31
101
|
const args = process.argv.slice(2); // Remove 'node' and script path
|
|
@@ -40,24 +110,55 @@ function validateNextjsCmsApp() {
|
|
|
40
110
|
if (shouldSkipValidation()) {
|
|
41
111
|
return;
|
|
42
112
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
113
|
+
const result = checkNextjsCmsInstallation();
|
|
114
|
+
if (typeof result === 'object' && 'error' in result) {
|
|
115
|
+
switch (result.error) {
|
|
116
|
+
case 'not-nextjs-cms-app':
|
|
117
|
+
console.error(chalk.red('❌ Error: This command must be run in a nextjs-cms application directory.'));
|
|
118
|
+
console.error(chalk.gray('Make sure you have:'));
|
|
119
|
+
console.error(chalk.gray(' - lz.config.ts file'));
|
|
120
|
+
console.error(chalk.gray(' - nextjs-cms as a dependency in package.json'));
|
|
121
|
+
console.error(chalk.gray(' - Did you forget to run `pnpm install`?'));
|
|
122
|
+
console.error('');
|
|
123
|
+
console.error(chalk.gray('To create a new nextjs-cms application, run:'));
|
|
124
|
+
console.error(chalk.gray(' - pnpm create nextjs-cms@latest'));
|
|
125
|
+
break;
|
|
126
|
+
case 'local-not-found':
|
|
127
|
+
console.error(chalk.red('❌ Error: nextjs-cms is not a dependency in package.json'));
|
|
128
|
+
console.error(chalk.gray('Make sure you have:'));
|
|
129
|
+
console.error(chalk.gray(' - nextjs-cms as a dependency in package.json'));
|
|
130
|
+
console.error(chalk.gray(' - Did you forget to run `pnpm install`?'));
|
|
131
|
+
break;
|
|
132
|
+
case 'global-not-found':
|
|
133
|
+
console.error(chalk.red('❌ Error: nextjs-cms is not installed globally'));
|
|
134
|
+
console.error(chalk.gray(' - Please install nextjs-cms-kit globally using `pnpm add -g nextjs-cms-kit`'));
|
|
135
|
+
break;
|
|
136
|
+
case 'version-mismatch':
|
|
137
|
+
console.error(chalk.red('❌ Error: the version of nextjs-cms in the project is different from the version installed globally in nextjs-cms-kit'));
|
|
138
|
+
console.error(chalk.gray(' - Installed version: ' + result.installedVersion));
|
|
139
|
+
console.error(chalk.gray(' - Global version: ' + result.globalVersion));
|
|
140
|
+
console.error(chalk.gray(' - Please run `pnpm remove -g nextjs-cms-kit && pnpm add -g nextjs-cms-kit@' +
|
|
141
|
+
result.installedVersion +
|
|
142
|
+
'`'));
|
|
143
|
+
break;
|
|
144
|
+
case 'local-needs-update':
|
|
145
|
+
console.error(chalk.red('❌ Error: the version of installed nextjs-cms in your cms is different from the version in package.json'));
|
|
146
|
+
console.error(chalk.gray(' - Installed version: ' + result.installedVersion));
|
|
147
|
+
console.error(chalk.gray(' - Package version: ' + result.packageVersion));
|
|
148
|
+
console.error(chalk.green(' - Please run `pnpm install and try again'));
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
50
151
|
process.exit(1);
|
|
51
152
|
}
|
|
52
153
|
}
|
|
53
|
-
// Validate
|
|
154
|
+
// Validate nextjs-cms app and dependencies before proceeding
|
|
54
155
|
validateNextjsCmsApp();
|
|
55
156
|
const program = new Command();
|
|
56
157
|
program
|
|
57
158
|
.name('nextjs-cms-kit')
|
|
58
159
|
.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)
|
|
59
160
|
.description(chalk.green('nextjs-cms CLI toolkit for managing your nextjs-cms application'))
|
|
60
|
-
.version(
|
|
161
|
+
.version(version)
|
|
61
162
|
// Include -v option to show the version number
|
|
62
163
|
.addOption(new Option('-v').hideHelp())
|
|
63
164
|
.enablePositionalOptions();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-cms-kit",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.54",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"nextjs-cms-kit": "./dist/index.js"
|
|
@@ -29,10 +29,8 @@
|
|
|
29
29
|
"commander": "^14.0.2",
|
|
30
30
|
"dotenv": "^17.2.3",
|
|
31
31
|
"drizzle-zod": "^0.7.0",
|
|
32
|
-
"mysql2": "^3.12.0"
|
|
33
|
-
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"nextjs-cms": "0.5.38"
|
|
32
|
+
"mysql2": "^3.12.0",
|
|
33
|
+
"nextjs-cms": "0.5.54"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@types/bcrypt": "^6.0.0",
|
|
@@ -41,9 +39,9 @@
|
|
|
41
39
|
"prettier": "^3.3.3",
|
|
42
40
|
"tsx": "^4.20.6",
|
|
43
41
|
"typescript": "^5.9.2",
|
|
44
|
-
"@lzcms/
|
|
42
|
+
"@lzcms/eslint-config": "0.3.0",
|
|
45
43
|
"@lzcms/tsconfig": "0.1.0",
|
|
46
|
-
"@lzcms/
|
|
44
|
+
"@lzcms/prettier-config": "0.1.0"
|
|
47
45
|
},
|
|
48
46
|
"prettier": "@lzcms/prettier-config",
|
|
49
47
|
"scripts": {
|