mango-cms 0.1.1 → 0.1.2
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/cli.js +70 -28
- package/default/package.json +8 -0
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -10,6 +10,64 @@ const AdmZip = require('adm-zip');
|
|
|
10
10
|
|
|
11
11
|
const program = new Command();
|
|
12
12
|
|
|
13
|
+
// Helper function to download and extract src.zip
|
|
14
|
+
async function ensureSrcExists(mangoCmsRoot) {
|
|
15
|
+
const srcDir = path.join(mangoCmsRoot, 'src');
|
|
16
|
+
if (!fs.existsSync(srcDir)) {
|
|
17
|
+
console.log('Downloading Mango CMS source files...');
|
|
18
|
+
const response = await axios({
|
|
19
|
+
method: 'get',
|
|
20
|
+
url: 'https://mango-cms.s3.amazonaws.com/src.zip',
|
|
21
|
+
responseType: 'arraybuffer'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const tempZipPath = path.join(mangoCmsRoot, 'src.zip');
|
|
25
|
+
fs.writeFileSync(tempZipPath, response.data);
|
|
26
|
+
|
|
27
|
+
console.log('Extracting source files...');
|
|
28
|
+
const zip = new AdmZip(tempZipPath);
|
|
29
|
+
zip.extractAllTo(mangoCmsRoot, true);
|
|
30
|
+
|
|
31
|
+
// Clean up the zip file
|
|
32
|
+
fs.unlinkSync(tempZipPath);
|
|
33
|
+
console.log('Source files installed successfully.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Helper function to validate and prompt for license if needed
|
|
38
|
+
async function ensureLicenseExists(configPath) {
|
|
39
|
+
let settings = { license: null };
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
if (fs.existsSync(configPath)) {
|
|
43
|
+
settings = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.log('Error reading settings file:', error.message);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!settings.license) {
|
|
50
|
+
const answer = await inquirer.prompt([
|
|
51
|
+
{
|
|
52
|
+
type: 'input',
|
|
53
|
+
name: 'license',
|
|
54
|
+
message: 'Enter your license key:',
|
|
55
|
+
validate: input => {
|
|
56
|
+
if (!input) return 'License key is required';
|
|
57
|
+
if (input !== 'admin') return 'Invalid license key';
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
settings.license = answer.license;
|
|
64
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
65
|
+
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return settings.license;
|
|
69
|
+
}
|
|
70
|
+
|
|
13
71
|
program
|
|
14
72
|
.name('mango')
|
|
15
73
|
.description('Mango CMS CLI');
|
|
@@ -44,28 +102,7 @@ program
|
|
|
44
102
|
]);
|
|
45
103
|
|
|
46
104
|
// First, handle the src.zip download if needed
|
|
47
|
-
|
|
48
|
-
const srcDir = path.join(mangoCmsRoot, 'src');
|
|
49
|
-
|
|
50
|
-
if (!fs.existsSync(srcDir)) {
|
|
51
|
-
console.log('Downloading Mango CMS source files...');
|
|
52
|
-
const response = await axios({
|
|
53
|
-
method: 'get',
|
|
54
|
-
url: 'https://mango-cms.s3.amazonaws.com/src.zip',
|
|
55
|
-
responseType: 'arraybuffer'
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const tempZipPath = path.join(mangoCmsRoot, 'src.zip');
|
|
59
|
-
fs.writeFileSync(tempZipPath, response.data);
|
|
60
|
-
|
|
61
|
-
console.log('Extracting source files...');
|
|
62
|
-
const zip = new AdmZip(tempZipPath);
|
|
63
|
-
zip.extractAllTo(mangoCmsRoot, true);
|
|
64
|
-
|
|
65
|
-
// Clean up the zip file
|
|
66
|
-
fs.unlinkSync(tempZipPath);
|
|
67
|
-
console.log('Source files installed successfully.');
|
|
68
|
-
}
|
|
105
|
+
await ensureSrcExists(__dirname);
|
|
69
106
|
|
|
70
107
|
// Now handle the project creation
|
|
71
108
|
const projectDir = path.join(process.cwd(), answers.projectName);
|
|
@@ -80,7 +117,7 @@ program
|
|
|
80
117
|
const configDir = path.join(projectDir, 'config');
|
|
81
118
|
|
|
82
119
|
// Create or update settings.json
|
|
83
|
-
const settingsPath = path.join(configDir, 'settings.json');
|
|
120
|
+
const settingsPath = path.join(configDir, 'config/settings.json');
|
|
84
121
|
const settings = {
|
|
85
122
|
license: answers.license
|
|
86
123
|
};
|
|
@@ -101,13 +138,20 @@ To get started:
|
|
|
101
138
|
program
|
|
102
139
|
.command('start')
|
|
103
140
|
.description('Start the Mango CMS in watch mode')
|
|
104
|
-
.action(() => {
|
|
141
|
+
.action(async () => {
|
|
105
142
|
try {
|
|
143
|
+
|
|
144
|
+
// Check for license in settings.json
|
|
145
|
+
const settingsPath = path.join(process.cwd(), 'config/config/settings.json');
|
|
146
|
+
await ensureLicenseExists(settingsPath);
|
|
147
|
+
|
|
148
|
+
// Ensure src exists
|
|
149
|
+
await ensureSrcExists(__dirname);
|
|
150
|
+
|
|
106
151
|
// Path to @mango-cms/core inside node_modules
|
|
107
152
|
const cmsPackagePath = path.resolve(__dirname);
|
|
108
153
|
// User's project root (where they run "mango start")
|
|
109
|
-
|
|
110
|
-
const userProjectRoot = '/Users/coltonneifert/Sites/test-2'
|
|
154
|
+
const userProjectRoot = process.cwd();
|
|
111
155
|
|
|
112
156
|
console.log(`Starting Mango CMS...`);
|
|
113
157
|
console.log(`CMS package located at: ${cmsPackagePath}`);
|
|
@@ -122,8 +166,6 @@ program
|
|
|
122
166
|
stdio: 'inherit',
|
|
123
167
|
env: {
|
|
124
168
|
...process.env,
|
|
125
|
-
// NODE_OPTIONS: '--trace-warnings',
|
|
126
|
-
// PROJECT_CONFIG: configDir,
|
|
127
169
|
NODE_PATH: path.resolve(cmsPackagePath, 'node_modules'),
|
|
128
170
|
MANGO_ROOT: cmsPackagePath,
|
|
129
171
|
PROJECT_ROOT: userProjectRoot
|