create-go-cms 0.1.2 → 0.1.3
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/lib/downloader.js +31 -2
- package/lib/scaffolder.js +49 -2
- package/package.json +2 -1
- package/scripts/go-cms-runner.js +51 -0
package/lib/downloader.js
CHANGED
|
@@ -12,13 +12,20 @@ const DEFAULT_VERSION = '0.1.0';
|
|
|
12
12
|
* Checks if a valid go-cms binary is already present locally.
|
|
13
13
|
*/
|
|
14
14
|
function findLocalBinary(binaryName) {
|
|
15
|
-
// 1. Check parent repository bin folder (development mode)
|
|
15
|
+
// 1. Check parent repository bin folder (development mode) and GOPATH bin
|
|
16
|
+
const userHome = process.env.USERPROFILE || process.env.HOME || '';
|
|
17
|
+
const gopath = process.env.GOPATH || (userHome ? path.join(userHome, 'go') : '');
|
|
18
|
+
|
|
16
19
|
const candidateDevPaths = [
|
|
17
20
|
path.resolve(__dirname, '../../../bin', binaryName),
|
|
18
21
|
path.resolve(__dirname, '../../bin', binaryName),
|
|
19
22
|
path.resolve(process.cwd(), 'bin', binaryName),
|
|
20
23
|
];
|
|
21
24
|
|
|
25
|
+
if (gopath) {
|
|
26
|
+
candidateDevPaths.push(path.join(gopath, 'bin', binaryName));
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
for (const c of candidateDevPaths) {
|
|
23
30
|
if (fs.existsSync(c)) {
|
|
24
31
|
try {
|
|
@@ -154,10 +161,32 @@ async function ensureBinary(destDir, platformInfo, version = DEFAULT_VERSION) {
|
|
|
154
161
|
if (fs.existsSync(tempArchive)) fs.unlinkSync(tempArchive);
|
|
155
162
|
if (fs.existsSync(tempChecksums)) fs.unlinkSync(tempChecksums);
|
|
156
163
|
|
|
164
|
+
// Fallback: If Go is installed locally, attempt to build or install it on the fly
|
|
165
|
+
try {
|
|
166
|
+
const whichCmd = platformInfo.isWindows ? 'where go' : 'which go';
|
|
167
|
+
execSync(whichCmd, { stdio: ['ignore', 'ignore', 'ignore'] });
|
|
168
|
+
console.log('⚡ Attempting local build with Go toolchain...');
|
|
169
|
+
|
|
170
|
+
const userHome = process.env.USERPROFILE || process.env.HOME || '';
|
|
171
|
+
const gopath = process.env.GOPATH || (userHome ? path.join(userHome, 'go') : '');
|
|
172
|
+
const goInstalledBin = gopath ? path.join(gopath, 'bin', platformInfo.binaryName) : '';
|
|
173
|
+
|
|
174
|
+
if (goInstalledBin && fs.existsSync(goInstalledBin)) {
|
|
175
|
+
fs.copyFileSync(goInstalledBin, targetBinaryPath);
|
|
176
|
+
return targetBinaryPath;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
execSync(`go install github.com/${REPO_OWNER}/${REPO_NAME}/cmd/go-cms@latest`, { stdio: 'inherit' });
|
|
180
|
+
if (goInstalledBin && fs.existsSync(goInstalledBin)) {
|
|
181
|
+
fs.copyFileSync(goInstalledBin, targetBinaryPath);
|
|
182
|
+
return targetBinaryPath;
|
|
183
|
+
}
|
|
184
|
+
} catch {}
|
|
185
|
+
|
|
157
186
|
throw new Error(
|
|
158
187
|
`Failed to install Go CMS binary: ${err.message}\n` +
|
|
159
188
|
`You can build or install the native binary manually:\n` +
|
|
160
|
-
` go install github.com/
|
|
189
|
+
` go install github.com/${REPO_OWNER}/${REPO_NAME}/cmd/go-cms@latest\n` +
|
|
161
190
|
`or copy go-cms into your project's bin/ folder.`
|
|
162
191
|
);
|
|
163
192
|
}
|
package/lib/scaffolder.js
CHANGED
|
@@ -31,12 +31,59 @@ async function scaffoldProject(options) {
|
|
|
31
31
|
const projectBinDir = path.join(targetDir, 'bin');
|
|
32
32
|
await ensureBinary(projectBinDir, platformInfo);
|
|
33
33
|
|
|
34
|
-
// 2.
|
|
34
|
+
// 2. Ensure go-cms-runner.js is written into scripts/
|
|
35
35
|
const projectScriptsDir = path.join(targetDir, 'scripts');
|
|
36
36
|
fs.mkdirSync(projectScriptsDir, { recursive: true });
|
|
37
|
+
const runnerDest = path.join(projectScriptsDir, 'go-cms-runner.js');
|
|
37
38
|
const runnerSource = path.resolve(__dirname, '../scripts/go-cms-runner.js');
|
|
38
39
|
if (fs.existsSync(runnerSource)) {
|
|
39
|
-
fs.copyFileSync(runnerSource,
|
|
40
|
+
fs.copyFileSync(runnerSource, runnerDest);
|
|
41
|
+
} else {
|
|
42
|
+
const inlineRunner = `#!/usr/bin/env node
|
|
43
|
+
const fs = require('fs');
|
|
44
|
+
const path = require('path');
|
|
45
|
+
const { spawn } = require('child_process');
|
|
46
|
+
|
|
47
|
+
const isWindows = process.platform === 'win32';
|
|
48
|
+
const binName = isWindows ? 'go-cms.exe' : 'go-cms';
|
|
49
|
+
|
|
50
|
+
function resolveBinary() {
|
|
51
|
+
const projectRoot = path.resolve(__dirname, '..');
|
|
52
|
+
const candidates = [
|
|
53
|
+
path.join(projectRoot, 'bin', binName),
|
|
54
|
+
path.join(projectRoot, 'node_modules', '.bin', binName),
|
|
55
|
+
path.join(projectRoot, '..', 'bin', binName)
|
|
56
|
+
];
|
|
57
|
+
for (const c of candidates) {
|
|
58
|
+
if (fs.existsSync(c)) return c;
|
|
59
|
+
}
|
|
60
|
+
return 'go-cms';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const binary = resolveBinary();
|
|
64
|
+
const args = process.argv.slice(2);
|
|
65
|
+
const child = spawn(binary, args, {
|
|
66
|
+
stdio: 'inherit',
|
|
67
|
+
env: process.env,
|
|
68
|
+
shell: binary === 'go-cms' ? isWindows : false
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
child.on('error', (err) => {
|
|
72
|
+
if (err.code === 'ENOENT') {
|
|
73
|
+
console.error('\\n❌ Error: Go CMS executable not found.');
|
|
74
|
+
console.error('Please ensure the go-cms binary exists in bin/ or run:');
|
|
75
|
+
console.error(' go install github.com/vinodkv90/GO-CMS/cmd/go-cms@latest\\n');
|
|
76
|
+
} else {
|
|
77
|
+
console.error('Failed to execute Go CMS:', err.message);
|
|
78
|
+
}
|
|
79
|
+
process.exit(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
child.on('close', (code) => {
|
|
83
|
+
process.exit(code ?? 0);
|
|
84
|
+
});
|
|
85
|
+
`;
|
|
86
|
+
fs.writeFileSync(runnerDest, inlineRunner, { mode: 0o755 });
|
|
40
87
|
}
|
|
41
88
|
|
|
42
89
|
// 3. Create subdirectories
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-go-cms",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Interactive CLI to create Go CMS applications with one command",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
|
11
11
|
"lib",
|
|
12
|
+
"scripts",
|
|
12
13
|
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"engines": {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const isWindows = process.platform === 'win32';
|
|
8
|
+
const binName = isWindows ? 'go-cms.exe' : 'go-cms';
|
|
9
|
+
|
|
10
|
+
function resolveBinary() {
|
|
11
|
+
const projectRoot = path.resolve(__dirname, '..');
|
|
12
|
+
const candidates = [
|
|
13
|
+
path.join(projectRoot, 'bin', binName),
|
|
14
|
+
path.join(projectRoot, 'node_modules', '.bin', binName),
|
|
15
|
+
path.join(projectRoot, '..', 'bin', binName)
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
for (const c of candidates) {
|
|
19
|
+
if (fs.existsSync(c)) {
|
|
20
|
+
return c;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Fallback to global PATH
|
|
25
|
+
return 'go-cms';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const binary = resolveBinary();
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
|
|
31
|
+
const child = spawn(binary, args, {
|
|
32
|
+
stdio: 'inherit',
|
|
33
|
+
env: process.env,
|
|
34
|
+
shell: binary === 'go-cms' ? isWindows : false
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
child.on('error', (err) => {
|
|
38
|
+
if (err.code === 'ENOENT') {
|
|
39
|
+
console.error(`\n❌ Error: Go CMS executable not found.`);
|
|
40
|
+
console.error(`Please install the native CLI binary via:`);
|
|
41
|
+
console.error(` go install github.com/go-cms/cms/cmd/go-cms@latest`);
|
|
42
|
+
console.error(`Or run: npx create-go-cms --doctor\n`);
|
|
43
|
+
} else {
|
|
44
|
+
console.error(`Failed to execute Go CMS:`, err.message);
|
|
45
|
+
}
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
child.on('close', (code) => {
|
|
50
|
+
process.exit(code ?? 0);
|
|
51
|
+
});
|