create-go-cms 0.0.0-stage → 0.1.0
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/README.md +52 -2
- package/bin/index.js +127 -0
- package/lib/downloader.js +172 -0
- package/lib/index.js +10 -0
- package/lib/platform.js +49 -0
- package/lib/scaffolder.js +263 -0
- package/package.json +34 -4
package/README.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-go-cms
|
|
2
|
+
|
|
3
|
+
The official command-line tool to create and scaffold **Go CMS** projects.
|
|
4
|
+
|
|
5
|
+
Go CMS is an open-source, high-performance content management system inspired by Strapi and WordPress Gutenberg, powered by Go and React.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
Create a new project using `npx`:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx create-go-cms@latest my-project
|
|
13
|
+
cd my-project
|
|
14
|
+
npm run dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or using `yarn`:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn create go-cms my-project
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or using `pnpm`:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm create go-cms my-project
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
npx create-go-cms [project-name] [options]
|
|
33
|
+
|
|
34
|
+
Options:
|
|
35
|
+
--mode <type> CMS mode: 'templated' (default) or 'headless'
|
|
36
|
+
--template <type> Starter template: 'blog' (default) or 'blank'
|
|
37
|
+
--quickstart, -y Skip prompts and scaffold with defaults
|
|
38
|
+
-h, --help Show CLI help
|
|
39
|
+
-v, --version Show version
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Available Scripts in Scaffolded Projects
|
|
43
|
+
|
|
44
|
+
* `npm run dev`: Starts the development server with auto-migrations.
|
|
45
|
+
* `npm run build`: Validates configuration, schemas, and templates for production.
|
|
46
|
+
* `npm run start`: Runs the hardened server in production mode.
|
|
47
|
+
* `npm run migrate`: Applies pending database migrations.
|
|
48
|
+
* `npm run doctor`: Runs health checks on your database and system environment.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT © [Go CMS Contributors](https://github.com/go-cms/cms)
|
|
2
53
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const readline = require('readline');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { scaffoldProject } = require('../lib/scaffolder');
|
|
6
|
+
const pkg = require('../package.json');
|
|
7
|
+
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
|
|
10
|
+
function printHelp() {
|
|
11
|
+
console.log(`
|
|
12
|
+
create-go-cms v${pkg.version}
|
|
13
|
+
The high-performance, open-source content management system.
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
npx create-go-cms [project-name] [options]
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
--mode <type> CMS mode: 'templated' (default) or 'headless'
|
|
20
|
+
--template <type> Starter template: 'blog' (default) or 'blank'
|
|
21
|
+
--quickstart, -y Use default options non-interactively
|
|
22
|
+
-h, --help Display this help message
|
|
23
|
+
-v, --version Display version
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
npx create-go-cms my-project
|
|
27
|
+
npx create-go-cms my-headless-api --mode=headless
|
|
28
|
+
npx create-go-cms my-blog --quickstart
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function prompt(rl, question, defaultValue) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
const promptText = defaultValue ? `${question} (${defaultValue}): ` : `${question}: `;
|
|
35
|
+
rl.question(promptText, (answer) => {
|
|
36
|
+
resolve(answer.trim() || defaultValue);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function main() {
|
|
42
|
+
let projectName = '';
|
|
43
|
+
let mode = '';
|
|
44
|
+
let template = '';
|
|
45
|
+
let isQuickstart = false;
|
|
46
|
+
|
|
47
|
+
for (let i = 0; i < args.length; i++) {
|
|
48
|
+
const arg = args[i];
|
|
49
|
+
if (arg === '-h' || arg === '--help') {
|
|
50
|
+
printHelp();
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
if (arg === '-v' || arg === '--version') {
|
|
54
|
+
console.log(`create-go-cms v${pkg.version}`);
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
if (arg === '-y' || arg === '--quickstart') {
|
|
58
|
+
isQuickstart = true;
|
|
59
|
+
} else if (arg.startsWith('--mode=')) {
|
|
60
|
+
mode = arg.split('=')[1];
|
|
61
|
+
} else if (arg === '--mode' && i + 1 < args.length) {
|
|
62
|
+
mode = args[++i];
|
|
63
|
+
} else if (arg.startsWith('--template=')) {
|
|
64
|
+
template = arg.split('=')[1];
|
|
65
|
+
} else if (arg === '--template' && i + 1 < args.length) {
|
|
66
|
+
template = args[++i];
|
|
67
|
+
} else if (!arg.startsWith('-') && !projectName) {
|
|
68
|
+
projectName = arg;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const rl = readline.createInterface({
|
|
73
|
+
input: process.stdin,
|
|
74
|
+
output: process.stdout
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
if (!projectName) {
|
|
79
|
+
if (isQuickstart) {
|
|
80
|
+
projectName = 'my-go-cms';
|
|
81
|
+
} else {
|
|
82
|
+
projectName = await prompt(rl, '? What is your project named?', 'my-go-cms');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
projectName = projectName.trim().replace(/\s+/g, '-');
|
|
87
|
+
|
|
88
|
+
if (!mode) {
|
|
89
|
+
if (isQuickstart) {
|
|
90
|
+
mode = 'templated';
|
|
91
|
+
} else {
|
|
92
|
+
console.log('\n? Which CMS mode would you like to use?');
|
|
93
|
+
console.log(' 1) Templated CMS — Go HTML templates, themes, visual page builder (Recommended)');
|
|
94
|
+
console.log(' 2) Headless CMS — Pure JSON REST APIs, content management, media');
|
|
95
|
+
const choice = await prompt(rl, 'Select [1-2]', '1');
|
|
96
|
+
mode = choice === '2' ? 'headless' : 'templated';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!template) {
|
|
101
|
+
if (isQuickstart) {
|
|
102
|
+
template = 'blog';
|
|
103
|
+
} else {
|
|
104
|
+
console.log('\n? Choose a starter template:');
|
|
105
|
+
console.log(' 1) Blog starter — Complete with blog posts, articles, and home page (Recommended)');
|
|
106
|
+
console.log(' 2) Blank — Clean minimal project');
|
|
107
|
+
const choice = await prompt(rl, 'Select [1-2]', '1');
|
|
108
|
+
template = choice === '2' ? 'blank' : 'blog';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
rl.close();
|
|
113
|
+
|
|
114
|
+
await scaffoldProject({
|
|
115
|
+
projectName,
|
|
116
|
+
mode,
|
|
117
|
+
template
|
|
118
|
+
});
|
|
119
|
+
} catch (err) {
|
|
120
|
+
rl.close();
|
|
121
|
+
console.error('\n❌ Project creation failed:', err.message);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
main();
|
|
127
|
+
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const crypto = require('crypto');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const REPO_OWNER = 'go-cms';
|
|
8
|
+
const REPO_NAME = 'cms';
|
|
9
|
+
const DEFAULT_VERSION = '0.1.0';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a valid go-cms binary is already present locally.
|
|
13
|
+
*/
|
|
14
|
+
function findLocalBinary(binaryName) {
|
|
15
|
+
// 1. Check parent repository bin folder (development mode)
|
|
16
|
+
const candidateDevPaths = [
|
|
17
|
+
path.resolve(__dirname, '../../../bin', binaryName),
|
|
18
|
+
path.resolve(__dirname, '../../bin', binaryName),
|
|
19
|
+
path.resolve(process.cwd(), 'bin', binaryName),
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
for (const c of candidateDevPaths) {
|
|
23
|
+
if (fs.existsSync(c)) {
|
|
24
|
+
try {
|
|
25
|
+
fs.accessSync(c, fs.constants.X_OK || fs.constants.R_OK);
|
|
26
|
+
return c;
|
|
27
|
+
} catch {}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 2. Check if go-cms is in system PATH
|
|
32
|
+
try {
|
|
33
|
+
const whichCmd = process.platform === 'win32' ? 'where' : 'which';
|
|
34
|
+
const found = execSync(`${whichCmd} go-cms`, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim().split('\n')[0].trim();
|
|
35
|
+
if (found && fs.existsSync(found)) {
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
} catch {}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Downloads a file from a URL using native https with redirect following.
|
|
45
|
+
*/
|
|
46
|
+
function downloadFile(url, destPath) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const request = https.get(url, (response) => {
|
|
49
|
+
// Follow HTTP 301/302 redirects
|
|
50
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
51
|
+
return resolve(downloadFile(response.headers.location, destPath));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (response.statusCode !== 200) {
|
|
55
|
+
return reject(new Error(`Download failed with HTTP ${response.statusCode} from ${url}`));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const fileStream = fs.createWriteStream(destPath);
|
|
59
|
+
response.pipe(fileStream);
|
|
60
|
+
|
|
61
|
+
fileStream.on('finish', () => {
|
|
62
|
+
fileStream.close(resolve);
|
|
63
|
+
});
|
|
64
|
+
fileStream.on('error', (err) => {
|
|
65
|
+
fs.unlink(destPath, () => {});
|
|
66
|
+
reject(err);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
request.on('error', (err) => {
|
|
71
|
+
fs.unlink(destPath, () => {});
|
|
72
|
+
reject(err);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Verifies SHA-256 hash of a file against expected checksum.
|
|
79
|
+
*/
|
|
80
|
+
function verifyChecksum(filePath, expectedSha256) {
|
|
81
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
82
|
+
const hashSum = crypto.createHash('sha256').update(fileBuffer).digest('hex');
|
|
83
|
+
return hashSum.toLowerCase() === expectedSha256.toLowerCase();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Ensures the go-cms binary is available in destDir.
|
|
88
|
+
*/
|
|
89
|
+
async function ensureBinary(destDir, platformInfo, version = DEFAULT_VERSION) {
|
|
90
|
+
const targetBinaryPath = path.join(destDir, platformInfo.binaryName);
|
|
91
|
+
const localBinary = findLocalBinary(platformInfo.binaryName);
|
|
92
|
+
|
|
93
|
+
if (localBinary) {
|
|
94
|
+
// Copy local binary to project bin/
|
|
95
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
96
|
+
fs.copyFileSync(localBinary, targetBinaryPath);
|
|
97
|
+
if (!platformInfo.isWindows) {
|
|
98
|
+
fs.chmodSync(targetBinaryPath, 0o755);
|
|
99
|
+
}
|
|
100
|
+
return targetBinaryPath;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Download from GitHub release
|
|
104
|
+
const releaseBaseUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/v${version}`;
|
|
105
|
+
const archiveName = `go-cms_${version}_${platformInfo.platform}_${platformInfo.arch}.${platformInfo.archiveExt}`;
|
|
106
|
+
const archiveUrl = `${releaseBaseUrl}/${archiveName}`;
|
|
107
|
+
const checksumUrl = `${releaseBaseUrl}/checksums.txt`;
|
|
108
|
+
|
|
109
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
110
|
+
const tempArchive = path.join(destDir, archiveName);
|
|
111
|
+
const tempChecksums = path.join(destDir, 'checksums.txt');
|
|
112
|
+
|
|
113
|
+
console.log(`⬇️ Downloading Go CMS ${version} binary for ${platformInfo.platform}/${platformInfo.arch}...`);
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
await Promise.all([
|
|
117
|
+
downloadFile(archiveUrl, tempArchive),
|
|
118
|
+
downloadFile(checksumUrl, tempChecksums)
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
// Parse checksums.txt
|
|
122
|
+
const checksumContent = fs.readFileSync(tempChecksums, 'utf8');
|
|
123
|
+
let expectedSha256 = '';
|
|
124
|
+
for (const line of checksumContent.split('\n')) {
|
|
125
|
+
const parts = line.trim().split(/\s+/);
|
|
126
|
+
if (parts.length >= 2 && parts[1].includes(archiveName)) {
|
|
127
|
+
expectedSha256 = parts[0];
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (expectedSha256) {
|
|
133
|
+
const valid = verifyChecksum(tempArchive, expectedSha256);
|
|
134
|
+
if (!valid) {
|
|
135
|
+
throw new Error(`SECURITY ALERT: Checksum verification failed for ${archiveName}. Binary may be corrupted or tampered with.`);
|
|
136
|
+
}
|
|
137
|
+
console.log('🔒 Checksum verified successfully.');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Extract archive
|
|
141
|
+
if (platformInfo.isWindows) {
|
|
142
|
+
execSync(`tar -xf "${tempArchive}" -C "${destDir}"`);
|
|
143
|
+
} else {
|
|
144
|
+
execSync(`tar -xzf "${tempArchive}" -C "${destDir}"`);
|
|
145
|
+
fs.chmodSync(targetBinaryPath, 0o755);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Clean up archive files
|
|
149
|
+
fs.unlinkSync(tempArchive);
|
|
150
|
+
fs.unlinkSync(tempChecksums);
|
|
151
|
+
|
|
152
|
+
return targetBinaryPath;
|
|
153
|
+
} catch (err) {
|
|
154
|
+
if (fs.existsSync(tempArchive)) fs.unlinkSync(tempArchive);
|
|
155
|
+
if (fs.existsSync(tempChecksums)) fs.unlinkSync(tempChecksums);
|
|
156
|
+
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Failed to install Go CMS binary: ${err.message}\n` +
|
|
159
|
+
`You can build or install the native binary manually:\n` +
|
|
160
|
+
` go install github.com/go-cms/cms/cmd/go-cms@latest\n` +
|
|
161
|
+
`or copy go-cms into your project's bin/ folder.`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = {
|
|
167
|
+
findLocalBinary,
|
|
168
|
+
downloadFile,
|
|
169
|
+
verifyChecksum,
|
|
170
|
+
ensureBinary
|
|
171
|
+
};
|
|
172
|
+
|
package/lib/index.js
ADDED
package/lib/platform.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const os = require('os');
|
|
2
|
+
|
|
3
|
+
function getPlatformInfo() {
|
|
4
|
+
const rawPlatform = os.platform();
|
|
5
|
+
const rawArch = os.arch();
|
|
6
|
+
|
|
7
|
+
let platform = '';
|
|
8
|
+
switch (rawPlatform) {
|
|
9
|
+
case 'win32':
|
|
10
|
+
platform = 'windows';
|
|
11
|
+
break;
|
|
12
|
+
case 'darwin':
|
|
13
|
+
platform = 'darwin';
|
|
14
|
+
break;
|
|
15
|
+
case 'linux':
|
|
16
|
+
platform = 'linux';
|
|
17
|
+
break;
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unsupported operating system: ${rawPlatform}. Go CMS supports Windows, macOS, and Linux.`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let arch = '';
|
|
23
|
+
switch (rawArch) {
|
|
24
|
+
case 'x64':
|
|
25
|
+
arch = 'amd64';
|
|
26
|
+
break;
|
|
27
|
+
case 'arm64':
|
|
28
|
+
arch = 'arm64';
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
throw new Error(`Unsupported CPU architecture: ${rawArch}. Go CMS supports x64 (amd64) and arm64.`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isWindows = platform === 'windows';
|
|
35
|
+
const binaryName = isWindows ? 'go-cms.exe' : 'go-cms';
|
|
36
|
+
const archiveExt = isWindows ? 'zip' : 'tar.gz';
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
platform,
|
|
40
|
+
arch,
|
|
41
|
+
isWindows,
|
|
42
|
+
binaryName,
|
|
43
|
+
archiveExt,
|
|
44
|
+
targetAsset: `go-cms_${platform}_${arch}.${archiveExt}`
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { getPlatformInfo };
|
|
49
|
+
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const { getPlatformInfo } = require('./platform');
|
|
5
|
+
const { ensureBinary } = require('./downloader');
|
|
6
|
+
|
|
7
|
+
function randomHex(length = 32) {
|
|
8
|
+
return crypto.randomBytes(length).toString('hex');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function scaffoldProject(options) {
|
|
12
|
+
const {
|
|
13
|
+
projectName,
|
|
14
|
+
targetDir = path.resolve(process.cwd(), projectName),
|
|
15
|
+
mode = 'templated',
|
|
16
|
+
template = 'blog',
|
|
17
|
+
dbHost = 'localhost',
|
|
18
|
+
dbPort = 5432,
|
|
19
|
+
dbUser = 'postgres',
|
|
20
|
+
dbPass = '',
|
|
21
|
+
dbName = `${projectName.replace(/[^a-zA-Z0-9]/g, '_')}_db`,
|
|
22
|
+
serverPort = 8080
|
|
23
|
+
} = options;
|
|
24
|
+
|
|
25
|
+
console.log(`\n⏳ Scaffolding Go CMS project in ${targetDir}...`);
|
|
26
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
27
|
+
|
|
28
|
+
const platformInfo = getPlatformInfo();
|
|
29
|
+
|
|
30
|
+
// 1. Ensure binary is present in project bin/
|
|
31
|
+
const projectBinDir = path.join(targetDir, 'bin');
|
|
32
|
+
await ensureBinary(projectBinDir, platformInfo);
|
|
33
|
+
|
|
34
|
+
// 2. Copy go-cms-runner.js into scripts/
|
|
35
|
+
const projectScriptsDir = path.join(targetDir, 'scripts');
|
|
36
|
+
fs.mkdirSync(projectScriptsDir, { recursive: true });
|
|
37
|
+
const runnerSource = path.resolve(__dirname, '../scripts/go-cms-runner.js');
|
|
38
|
+
if (fs.existsSync(runnerSource)) {
|
|
39
|
+
fs.copyFileSync(runnerSource, path.join(projectScriptsDir, 'go-cms-runner.js'));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 3. Create subdirectories
|
|
43
|
+
const subdirs = ['uploads', 'plugins', 'schemas'];
|
|
44
|
+
if (mode === 'templated') subdirs.push('themes');
|
|
45
|
+
for (const d of subdirs) {
|
|
46
|
+
const dirPath = path.join(targetDir, d);
|
|
47
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
48
|
+
fs.writeFileSync(path.join(dirPath, '.gitkeep'), '');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 4. Generate secrets
|
|
52
|
+
const jwtSecret = randomHex(32);
|
|
53
|
+
const sessionSecret = randomHex(32);
|
|
54
|
+
const mediaSecret = randomHex(32);
|
|
55
|
+
|
|
56
|
+
// 5. Write config.yaml
|
|
57
|
+
const configContent = `# Go CMS Configuration
|
|
58
|
+
# Documentation: https://github.com/go-cms/cms
|
|
59
|
+
|
|
60
|
+
server:
|
|
61
|
+
host: "0.0.0.0"
|
|
62
|
+
port: ${serverPort}
|
|
63
|
+
env: "development"
|
|
64
|
+
read_timeout: 15s
|
|
65
|
+
write_timeout: 30s
|
|
66
|
+
idle_timeout: 60s
|
|
67
|
+
shutdown_timeout: 10s
|
|
68
|
+
cors_allowed_origins:
|
|
69
|
+
- "*"
|
|
70
|
+
trusted_proxies:
|
|
71
|
+
- "127.0.0.1/32"
|
|
72
|
+
- "::1/128"
|
|
73
|
+
|
|
74
|
+
database:
|
|
75
|
+
driver: "postgres"
|
|
76
|
+
host: "${dbHost}"
|
|
77
|
+
port: ${dbPort}
|
|
78
|
+
user: "${dbUser}"
|
|
79
|
+
password: "${dbPass}"
|
|
80
|
+
database: "${dbName}"
|
|
81
|
+
ssl_mode: "disable"
|
|
82
|
+
max_open_conns: 25
|
|
83
|
+
max_idle_conns: 10
|
|
84
|
+
conn_max_lifetime: 30m
|
|
85
|
+
conn_max_idle_time: 5m
|
|
86
|
+
|
|
87
|
+
logging:
|
|
88
|
+
level: "info"
|
|
89
|
+
format: "text"
|
|
90
|
+
|
|
91
|
+
auth:
|
|
92
|
+
jwt_secret: "\${CMS_AUTH_JWT_SECRET:-${jwtSecret}}"
|
|
93
|
+
session_secret: "\${CMS_AUTH_SESSION_SECRET:-${sessionSecret}}"
|
|
94
|
+
token_expiration: 24h
|
|
95
|
+
|
|
96
|
+
media:
|
|
97
|
+
provider: "local"
|
|
98
|
+
upload_dir: "./uploads"
|
|
99
|
+
signed_urls:
|
|
100
|
+
enabled: true
|
|
101
|
+
algorithm: "HMAC-SHA256"
|
|
102
|
+
expiration: 1h
|
|
103
|
+
secret_key: "\${CMS_MEDIA_SIGNED_URLS_SECRET_KEY:-${mediaSecret}}"
|
|
104
|
+
|
|
105
|
+
themes:
|
|
106
|
+
active_theme: "default"
|
|
107
|
+
themes_dir: "./themes"
|
|
108
|
+
cache: false
|
|
109
|
+
|
|
110
|
+
plugins:
|
|
111
|
+
plugins_dir: "./plugins"
|
|
112
|
+
`;
|
|
113
|
+
fs.writeFileSync(path.join(targetDir, 'config.yaml'), configContent);
|
|
114
|
+
|
|
115
|
+
// 6. Write .env
|
|
116
|
+
const envContent = `# Go CMS Environment Variables
|
|
117
|
+
CMS_SERVER_HOST=0.0.0.0
|
|
118
|
+
CMS_SERVER_PORT=${serverPort}
|
|
119
|
+
CMS_SERVER_ENV=development
|
|
120
|
+
|
|
121
|
+
CMS_DB_DRIVER=postgres
|
|
122
|
+
CMS_DB_HOST=${dbHost}
|
|
123
|
+
CMS_DB_PORT=${dbPort}
|
|
124
|
+
CMS_DB_USER=${dbUser}
|
|
125
|
+
CMS_DB_PASSWORD=${dbPass}
|
|
126
|
+
CMS_DB_NAME=${dbName}
|
|
127
|
+
CMS_DB_SSLMODE=disable
|
|
128
|
+
|
|
129
|
+
CMS_AUTH_JWT_SECRET=${jwtSecret}
|
|
130
|
+
CMS_AUTH_SESSION_SECRET=${sessionSecret}
|
|
131
|
+
CMS_MEDIA_SIGNED_URLS_SECRET_KEY=${mediaSecret}
|
|
132
|
+
`;
|
|
133
|
+
fs.writeFileSync(path.join(targetDir, '.env'), envContent);
|
|
134
|
+
|
|
135
|
+
// 7. Write package.json with working npm scripts
|
|
136
|
+
const packageJSON = {
|
|
137
|
+
name: projectName,
|
|
138
|
+
version: '0.1.0',
|
|
139
|
+
private: true,
|
|
140
|
+
description: `Go CMS ${mode} application`,
|
|
141
|
+
scripts: {
|
|
142
|
+
dev: 'node scripts/go-cms-runner.js develop',
|
|
143
|
+
develop: 'node scripts/go-cms-runner.js develop',
|
|
144
|
+
start: 'node scripts/go-cms-runner.js start',
|
|
145
|
+
build: 'node scripts/go-cms-runner.js build',
|
|
146
|
+
migrate: 'node scripts/go-cms-runner.js migrate up',
|
|
147
|
+
doctor: 'node scripts/go-cms-runner.js doctor'
|
|
148
|
+
},
|
|
149
|
+
keywords: ['go-cms', 'cms', 'strapi', 'nextjs', 'gutenberg']
|
|
150
|
+
};
|
|
151
|
+
fs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageJSON, null, 2) + '\n');
|
|
152
|
+
|
|
153
|
+
// 8. Write .gitignore
|
|
154
|
+
const gitignore = `# Dependencies and binaries
|
|
155
|
+
node_modules/
|
|
156
|
+
bin/
|
|
157
|
+
*.exe
|
|
158
|
+
|
|
159
|
+
# CMS Data & uploads
|
|
160
|
+
uploads/
|
|
161
|
+
data/
|
|
162
|
+
*.db
|
|
163
|
+
*.sqlite
|
|
164
|
+
|
|
165
|
+
# Environment secrets
|
|
166
|
+
.env
|
|
167
|
+
.env.local
|
|
168
|
+
|
|
169
|
+
# Logs
|
|
170
|
+
*.log
|
|
171
|
+
`;
|
|
172
|
+
fs.writeFileSync(path.join(targetDir, '.gitignore'), gitignore);
|
|
173
|
+
|
|
174
|
+
// 9. Write README.md
|
|
175
|
+
const readme = `# ${projectName}
|
|
176
|
+
|
|
177
|
+
Welcome to your new **Go CMS** project!
|
|
178
|
+
|
|
179
|
+
Go CMS is a high-performance open-source content management system inspired by Strapi and WordPress Gutenberg, built with Go and React.
|
|
180
|
+
|
|
181
|
+
## Quickstart
|
|
182
|
+
|
|
183
|
+
Run the development server:
|
|
184
|
+
|
|
185
|
+
\`\`\`bash
|
|
186
|
+
npm run dev
|
|
187
|
+
\`\`\`
|
|
188
|
+
|
|
189
|
+
Once running, access your application:
|
|
190
|
+
|
|
191
|
+
* **Admin Dashboard:** [http://localhost:${serverPort}/admin/](http://localhost:${serverPort}/admin/)
|
|
192
|
+
* **Public Website:** [http://localhost:${serverPort}/](http://localhost:${serverPort}/)
|
|
193
|
+
* **REST APIs:** [http://localhost:${serverPort}/api/v1](http://localhost:${serverPort}/api/v1)
|
|
194
|
+
* **System Health:** [http://localhost:${serverPort}/healthz](http://localhost:${serverPort}/healthz)
|
|
195
|
+
|
|
196
|
+
Default Administrator:
|
|
197
|
+
* **Username:** \`admin\`
|
|
198
|
+
* **Password:** \`Admin@CMS2026!\`
|
|
199
|
+
|
|
200
|
+
## Available Scripts
|
|
201
|
+
|
|
202
|
+
* \`npm run dev\`: Starts the server in development mode with auto-migrations.
|
|
203
|
+
* \`npm run build\`: Validates themes, schemas, and configuration for production.
|
|
204
|
+
* \`npm run start\`: Runs the server in hardened production mode.
|
|
205
|
+
* \`npm run migrate\`: Runs pending database migrations.
|
|
206
|
+
* \`npm run doctor\`: Runs diagnostics on your environment and database.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
MIT Licensed • Powered by [Go CMS](https://github.com/go-cms/cms)
|
|
210
|
+
`;
|
|
211
|
+
fs.writeFileSync(path.join(targetDir, 'README.md'), readme);
|
|
212
|
+
|
|
213
|
+
// 10. If templated mode, copy theme assets if available in monorepo
|
|
214
|
+
if (mode === 'templated') {
|
|
215
|
+
const localThemesDir = path.resolve(__dirname, '../../../themes/default');
|
|
216
|
+
if (fs.existsSync(localThemesDir)) {
|
|
217
|
+
copyRecursive(localThemesDir, path.join(targetDir, 'themes', 'default'));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Success Banner
|
|
222
|
+
console.log(`
|
|
223
|
+
✨ Success! Created ${projectName} at ${targetDir}
|
|
224
|
+
Inside that directory, you can run several commands:
|
|
225
|
+
|
|
226
|
+
npm run dev
|
|
227
|
+
Starts the development server with auto-migrations.
|
|
228
|
+
|
|
229
|
+
npm run build
|
|
230
|
+
Validates themes, schemas, and configuration for production.
|
|
231
|
+
|
|
232
|
+
npm run start
|
|
233
|
+
Runs the hardened server in production mode.
|
|
234
|
+
|
|
235
|
+
npm run migrate
|
|
236
|
+
Applies pending database migrations.
|
|
237
|
+
|
|
238
|
+
npm run doctor
|
|
239
|
+
Runs system diagnostics on your database and configuration.
|
|
240
|
+
|
|
241
|
+
We suggest that you begin by typing:
|
|
242
|
+
|
|
243
|
+
cd ${projectName}
|
|
244
|
+
npm run dev
|
|
245
|
+
|
|
246
|
+
Happy hacking with Go CMS! 🚀
|
|
247
|
+
`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function copyRecursive(src, dest) {
|
|
251
|
+
if (fs.statSync(src).isDirectory()) {
|
|
252
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
253
|
+
for (const file of fs.readdirSync(src)) {
|
|
254
|
+
copyRecursive(path.join(src, file), path.join(dest, file));
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
258
|
+
fs.copyFileSync(src, dest);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = { scaffoldProject };
|
|
263
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-go-cms",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Interactive CLI to create Go CMS applications with one command",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-go-cms": "bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"lib",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=16.0.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "node bin/index.js --help"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/go-cms/cms.git",
|
|
23
|
+
"directory": "packages/create-go-cms"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"go-cms",
|
|
27
|
+
"cms",
|
|
28
|
+
"strapi",
|
|
29
|
+
"nextjs",
|
|
30
|
+
"gutenberg",
|
|
31
|
+
"golang",
|
|
32
|
+
"headless-cms"
|
|
33
|
+
],
|
|
34
|
+
"author": "Go CMS Contributors",
|
|
35
|
+
"license": "MIT"
|
|
36
|
+
}
|