@haxtheweb/create 9.0.8 → 9.0.9
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/create.js +139 -378
- package/dist/lib/programs/site.js +517 -0
- package/dist/lib/programs/webcomponent.js +184 -0
- package/dist/lib/utils.js +19 -2
- package/package.json +5 -2
package/dist/create.js
CHANGED
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
var fs = _interopRequireWildcard(require("node:fs"));
|
|
6
6
|
var path = _interopRequireWildcard(require("node:path"));
|
|
7
|
-
var _promises = require("node:timers/promises");
|
|
8
|
-
var ejs = _interopRequireWildcard(require("ejs"));
|
|
9
7
|
var p = _interopRequireWildcard(require("@clack/prompts"));
|
|
10
8
|
var _picocolors = _interopRequireDefault(require("picocolors"));
|
|
11
9
|
var _statements = require("./lib/statements.js");
|
|
10
|
+
var _webcomponent = require("./lib/programs/webcomponent.js");
|
|
11
|
+
var _site = require("./lib/programs/site.js");
|
|
12
12
|
var _utils = require("./lib/utils.js");
|
|
13
13
|
var hax = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs"));
|
|
14
|
-
var haxcmsNodejsCli = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs/dist/cli.js"));
|
|
15
14
|
var child_process = _interopRequireWildcard(require("child_process"));
|
|
16
15
|
var util = _interopRequireWildcard(require("node:util"));
|
|
17
16
|
var _commander = require("commander");
|
|
@@ -21,52 +20,80 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
21
20
|
process.env.haxcms_middleware = "node-cli";
|
|
22
21
|
const HAXCMS = hax.HAXCMS;
|
|
23
22
|
const exec = util.promisify(child_process.exec);
|
|
24
|
-
|
|
25
|
-
send: json => console.log(json),
|
|
26
|
-
sendStatus: data => console.log(data)
|
|
27
|
-
};
|
|
28
|
-
var hasGit = true;
|
|
23
|
+
let sysGit = true;
|
|
29
24
|
exec('git --version', error => {
|
|
30
25
|
if (error) {
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
var hasSurge = true;
|
|
35
|
-
exec('surge --version', error => {
|
|
36
|
-
if (error) {
|
|
37
|
-
hasSurge = false;
|
|
26
|
+
sysGit = false;
|
|
38
27
|
}
|
|
39
28
|
});
|
|
40
29
|
async function main() {
|
|
41
|
-
|
|
42
|
-
.option('--skip', 'skip frills like animations')
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.option('--
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.option('--
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
30
|
+
var commandRun = {};
|
|
31
|
+
_commander.program.option('--').option('--v', 'Verbose output for developers').option('--path <char>', 'where to perform operation').option('--npm-client <char>', 'npm client to use (must be installed) npm, yarn, pnpm', 'npm').option('--y', 'yes to all questions').option('--skip', 'skip frills like animations').option('--auto', 'yes to all questions, alias of y')
|
|
32
|
+
|
|
33
|
+
// options for webcomponent
|
|
34
|
+
.option('--org <char>', 'organization for package.json').option('--author <char>', 'author for site / package.json')
|
|
35
|
+
|
|
36
|
+
// options for site
|
|
37
|
+
.option('--node-op <char>', 'node operation to perform').option('--item-id <char>', 'node ID to operate on').option('--name <char>', 'name of the project').option('--domain <char>', 'published domain name').helpCommand(true);
|
|
38
|
+
|
|
39
|
+
// default command which runs interactively
|
|
40
|
+
_commander.program.command('start').description('Interactive program to pick options').action(() => {
|
|
41
|
+
commandRun = {
|
|
42
|
+
command: 'start',
|
|
43
|
+
arguments: {},
|
|
44
|
+
options: {}
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// site operations and actions
|
|
49
|
+
let strActions = '';
|
|
50
|
+
(0, _site.siteActions)().forEach(action => {
|
|
51
|
+
strActions += `${action.value} - ${action.label}` + "\n\r";
|
|
52
|
+
});
|
|
53
|
+
let siteProg = _commander.program.command('site');
|
|
54
|
+
siteProg.argument('[action]', 'Actions to perform on site include:' + "\n\r" + strActions).action(action => {
|
|
55
|
+
commandRun = {
|
|
56
|
+
command: 'site',
|
|
57
|
+
arguments: {},
|
|
58
|
+
options: {}
|
|
59
|
+
};
|
|
60
|
+
if (action) {
|
|
61
|
+
commandRun.arguments.action = action;
|
|
62
|
+
commandRun.options.skip = true;
|
|
63
63
|
}
|
|
64
|
+
}).option('--path <char>', 'path the project should be created in').option('--name <char>', 'name of the site (when creating a new one)').option('--domain <char>', 'published domain name').option('--node-op <char>', 'node operation to perform').version(await HAXCMS.getHAXCMSVersion());
|
|
65
|
+
let siteNodeOps = (0, _site.siteNodeOperations)();
|
|
66
|
+
for (var i in siteNodeOps) {
|
|
67
|
+
_commander.program.option(`--${(0, _utils.camelToDash)(siteNodeOps[i].value)} <char>`, `${siteNodeOps[i].label}`);
|
|
68
|
+
siteProg.option(`--${(0, _utils.camelToDash)(siteNodeOps[i].value)} <char>`, `${siteNodeOps[i].label}`);
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
|
|
71
|
+
// webcomponent program
|
|
72
|
+
_commander.program.command('webcomponent').description('Create Lit based web components, with HAX recommendations').argument('[name]', 'name of the project').action(name => {
|
|
73
|
+
commandRun = {
|
|
74
|
+
command: 'webcomponent',
|
|
75
|
+
arguments: {},
|
|
76
|
+
options: {}
|
|
77
|
+
};
|
|
78
|
+
// if name set, populate
|
|
79
|
+
if (name) {
|
|
80
|
+
commandRun.arguments.name = name;
|
|
81
|
+
commandRun.options.skip = true;
|
|
82
|
+
}
|
|
83
|
+
}).option('--path <char>', 'path the project should be created in').option('--org <char>', 'organization for package.json').option('--author <char>', 'author for site / package.json');
|
|
84
|
+
// process program arguments
|
|
85
|
+
_commander.program.parse();
|
|
86
|
+
commandRun.options = {
|
|
87
|
+
...commandRun.options,
|
|
88
|
+
..._commander.program.opts()
|
|
89
|
+
};
|
|
90
|
+
if (commandRun.options.v) {
|
|
91
|
+
console.log(commandRun);
|
|
67
92
|
}
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
// auto and y assume same thing
|
|
94
|
+
if (commandRun.options.y || commandRun.options.auto) {
|
|
95
|
+
commandRun.options.y = true;
|
|
96
|
+
commandRun.options.auto = true;
|
|
70
97
|
}
|
|
71
98
|
let author = '';
|
|
72
99
|
// should be able to grab if not predefined
|
|
@@ -78,14 +105,14 @@ async function main() {
|
|
|
78
105
|
console.log('git config --global user.name "namehere"');
|
|
79
106
|
console.log('git config --global user.email "email@here');
|
|
80
107
|
}
|
|
81
|
-
if
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
108
|
+
// only set path if not already set
|
|
109
|
+
if (!commandRun.options.path && commandRun.options.skip) {
|
|
110
|
+
commandRun.options.path = process.cwd();
|
|
111
|
+
}
|
|
112
|
+
if (commandRun.options.auto) {
|
|
113
|
+
commandRun.options.org = '';
|
|
114
|
+
commandRun.options.author = author;
|
|
85
115
|
}
|
|
86
|
-
var port = "3000";
|
|
87
|
-
// delay so that we clear and then let them visually react to change
|
|
88
|
-
const siteData = await hax.systemStructureContext();
|
|
89
116
|
let packageData = {};
|
|
90
117
|
let testPackages = [path.join(process.cwd(), 'package.json'), path.join(process.cwd(), '../', 'package.json'), path.join(process.cwd(), '../', '../', 'package.json')];
|
|
91
118
|
// test within reason, for package.json files seeing if anything is available to suggest
|
|
@@ -97,171 +124,44 @@ async function main() {
|
|
|
97
124
|
packageData = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`));
|
|
98
125
|
// assume we are working on a web component / existing if we find this key
|
|
99
126
|
if (packageData.hax && packageData.hax.cli) {
|
|
100
|
-
|
|
127
|
+
commandRun.program = 'webcomponent';
|
|
101
128
|
}
|
|
102
129
|
// leverage these values if they exist downstream
|
|
103
130
|
if (packageData.npmClient) {
|
|
104
|
-
|
|
131
|
+
commandRun.options.npmClient = packageData.npmClient;
|
|
105
132
|
}
|
|
106
133
|
// see if we're in a monorepo
|
|
107
134
|
if (packageData.useWorkspaces && packageData.workspaces && packageData.workspaces.packages && packageData.workspaces.packages[0]) {
|
|
108
135
|
p.intro(`${_picocolors.default.bgBlack(_picocolors.default.white(` Monorepo detected : Setting relative defaults `))}`);
|
|
109
|
-
|
|
110
|
-
|
|
136
|
+
commandRun.options.isMonorepo = true;
|
|
137
|
+
commandRun.options.auto = true;
|
|
111
138
|
// assumed if monorepo
|
|
112
|
-
|
|
113
|
-
|
|
139
|
+
commandRun.command = 'webcomponent';
|
|
140
|
+
commandRun.options.path = path.join(process.cwd(), packageData.workspaces.packages[0].replace('/*', ''));
|
|
114
141
|
if (packageData.orgNpm) {
|
|
115
|
-
|
|
142
|
+
commandRun.options.org = packageData.orgNpm;
|
|
116
143
|
}
|
|
117
|
-
|
|
118
|
-
|
|
144
|
+
commandRun.options.gitRepo = packageData.repository.url;
|
|
145
|
+
commandRun.options.author = packageData.author.name ? packageData.author.name : author;
|
|
119
146
|
}
|
|
120
147
|
} catch (err) {
|
|
121
148
|
console.error(err);
|
|
122
149
|
}
|
|
123
150
|
}
|
|
124
151
|
}
|
|
125
|
-
// delay so that we clear and then let them visually react to change
|
|
126
152
|
// CLI works within context of the site if one is detected, otherwise we can do other thingss
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// defaults if nothing set via CLI
|
|
132
|
-
let operation = {
|
|
133
|
-
action: null,
|
|
134
|
-
title: "New Page",
|
|
135
|
-
domain: `haxcli-${siteData.name}.surge.sh`
|
|
136
|
-
};
|
|
137
|
-
operation = {
|
|
138
|
-
...operation,
|
|
139
|
-
...cliOptions
|
|
140
|
-
};
|
|
141
|
-
// infinite loop until quitting the cli
|
|
142
|
-
while (operation.action !== 'quit') {
|
|
143
|
-
let actions = [{
|
|
144
|
-
value: 'status',
|
|
145
|
-
label: "Site Status"
|
|
146
|
-
}, {
|
|
147
|
-
value: 'localhost',
|
|
148
|
-
label: "Open Site (localhost)"
|
|
149
|
-
}, {
|
|
150
|
-
value: 'sync-git',
|
|
151
|
-
label: "Sync code in git"
|
|
152
|
-
}, {
|
|
153
|
-
value: 'node-add',
|
|
154
|
-
label: "Add New Page"
|
|
155
|
-
}];
|
|
156
|
-
if (hasSurge) {
|
|
157
|
-
actions.push({
|
|
158
|
-
value: 'publish-surge',
|
|
159
|
-
label: "Publish site using Surge.sh"
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
actions.push({
|
|
163
|
-
value: 'quit',
|
|
164
|
-
label: "🚪 Quit"
|
|
165
|
-
});
|
|
166
|
-
if (!operation.action) {
|
|
167
|
-
operation = await p.group({
|
|
168
|
-
action: ({
|
|
169
|
-
results
|
|
170
|
-
}) => p.select({
|
|
171
|
-
message: `Actions you can take`,
|
|
172
|
-
options: actions
|
|
173
|
-
})
|
|
174
|
-
}, {
|
|
175
|
-
onCancel: () => {
|
|
176
|
-
p.cancel('🧙 Merlin: Canceling CLI.. HAX ya later 🪄');
|
|
177
|
-
(0, _statements.communityStatement)();
|
|
178
|
-
process.exit(0);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
switch (operation.action) {
|
|
183
|
-
case "status":
|
|
184
|
-
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Title: ${siteData.manifest.title} `))}`);
|
|
185
|
-
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Description: ${siteData.manifest.description} `))}`);
|
|
186
|
-
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Pages: ${siteData.manifest.items.length} `))}`);
|
|
187
|
-
break;
|
|
188
|
-
case "localhost":
|
|
189
|
-
try {
|
|
190
|
-
await exec(`cd ${siteData.directory} && npx @haxtheweb/haxcms-nodejs`);
|
|
191
|
-
} catch (e) {
|
|
192
|
-
console.log(e.stderr);
|
|
193
|
-
}
|
|
194
|
-
break;
|
|
195
|
-
case "node-add":
|
|
196
|
-
// @todo need to accept arguments
|
|
197
|
-
try {
|
|
198
|
-
haxcmsNodejsCli.cliBridge('createNode', {
|
|
199
|
-
site: siteData,
|
|
200
|
-
node: {
|
|
201
|
-
title: operation.title
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
console.log(`"${operation.title}" added to site`);
|
|
205
|
-
} catch (e) {
|
|
206
|
-
console.log(e.stderr);
|
|
207
|
-
}
|
|
208
|
-
break;
|
|
209
|
-
case "sync-git":
|
|
210
|
-
// @todo git sync might need other arguments / be combined with publishing
|
|
211
|
-
try {
|
|
212
|
-
await exec(`cd ${siteData.directory} && git pull && git push`);
|
|
213
|
-
} catch (e) {
|
|
214
|
-
console.log(e.stderr);
|
|
215
|
-
}
|
|
216
|
-
break;
|
|
217
|
-
case "publish-surge":
|
|
218
|
-
try {
|
|
219
|
-
// @todo should provide an option for setting the domain
|
|
220
|
-
let execOutput = await exec(`cd ${siteData.directory} && surge . ${operation.domain}`);
|
|
221
|
-
console.log(execOutput.stdout.trim());
|
|
222
|
-
} catch (e) {
|
|
223
|
-
console.log(e.stderr);
|
|
224
|
-
}
|
|
225
|
-
break;
|
|
226
|
-
case "quit":
|
|
227
|
-
// quit
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
if (cliOptions.y) {
|
|
231
|
-
process.exit(0);
|
|
232
|
-
}
|
|
233
|
-
operation.action = null;
|
|
234
|
-
}
|
|
153
|
+
if (await hax.systemStructureContext()) {
|
|
154
|
+
commandRun.program = 'site';
|
|
155
|
+
commandRun.options.skip = true;
|
|
156
|
+
await (0, _site.siteCommandDetected)(commandRun);
|
|
235
157
|
} else if (packageData && packageData.hax && packageData.hax.cli && packageData.scripts.start) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
p.note(`${(0, _statements.merlinSays)(`I have summoned a sub-process daemon 👹`)}
|
|
240
|
-
|
|
241
|
-
🚀 Running your ${_picocolors.default.bold('webcomponent')} ${_picocolors.default.bold(packageData.name)}:
|
|
242
|
-
${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
|
|
243
|
-
|
|
244
|
-
🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${process.cwd()}`))))}
|
|
245
|
-
💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${process.cwd()}`)))}
|
|
246
|
-
📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${process.cwd()}`)))}
|
|
247
|
-
📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${process.cwd()}`)))}
|
|
248
|
-
🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${cliOptions.npmClient} start`)))}
|
|
249
|
-
|
|
250
|
-
⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
|
|
251
|
-
`);
|
|
252
|
-
try {
|
|
253
|
-
// ensure it's installed first, unless it's a monorepo
|
|
254
|
-
if (!cliOptions.isMonorepo) {
|
|
255
|
-
let s = p.spinner();
|
|
256
|
-
s.start((0, _statements.merlinSays)(`Installation magic (${cliOptions.npmClient} install)`));
|
|
257
|
-
await exec(`${cliOptions.npmClient} install`);
|
|
258
|
-
s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
|
|
259
|
-
}
|
|
260
|
-
await exec(`${cliOptions.npmClient} start`);
|
|
261
|
-
} catch (e) {
|
|
262
|
-
// don't log bc output is odd
|
|
263
|
-
}
|
|
158
|
+
commandRun.program = 'webcomponent';
|
|
159
|
+
commandRun.options.skip = true;
|
|
160
|
+
await (0, _webcomponent.webcomponentCommandDetected)(commandRun, packageData);
|
|
264
161
|
} else {
|
|
162
|
+
if (commandRun.command === 'start' && !commandRun.options.y && !commandRun.options.auto && !commandRun.options.skip) {
|
|
163
|
+
await (0, _statements.haxIntro)();
|
|
164
|
+
}
|
|
265
165
|
let activeProject = null;
|
|
266
166
|
let project = {
|
|
267
167
|
type: null
|
|
@@ -269,11 +169,15 @@ async function main() {
|
|
|
269
169
|
while (project.type !== 'quit') {
|
|
270
170
|
if (activeProject) {
|
|
271
171
|
p.note(` 🧙🪄 BE GONE ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgGreen(activeProject)))} sub-process daemon! 🪄 + ✨ 👹 = 💀 `);
|
|
272
|
-
|
|
172
|
+
commandRun = {
|
|
173
|
+
command: null,
|
|
174
|
+
arguments: {},
|
|
175
|
+
options: {}
|
|
176
|
+
};
|
|
273
177
|
}
|
|
274
|
-
if (['site', '
|
|
178
|
+
if (['site', 'webcomponent'].includes(commandRun.command)) {
|
|
275
179
|
project = {
|
|
276
|
-
type:
|
|
180
|
+
type: commandRun.command
|
|
277
181
|
};
|
|
278
182
|
} else {
|
|
279
183
|
project = await p.group({
|
|
@@ -285,9 +189,9 @@ async function main() {
|
|
|
285
189
|
required: true,
|
|
286
190
|
options: [{
|
|
287
191
|
value: 'webcomponent',
|
|
288
|
-
label: '🏗️
|
|
192
|
+
label: '🏗️ Create a Web Component'
|
|
289
193
|
}, {
|
|
290
|
-
value: '
|
|
194
|
+
value: 'site',
|
|
291
195
|
label: '🏡 Create a HAXcms site (single)'
|
|
292
196
|
}, {
|
|
293
197
|
value: 'quit',
|
|
@@ -317,9 +221,9 @@ async function main() {
|
|
|
317
221
|
results
|
|
318
222
|
}) => {
|
|
319
223
|
let initialPath = `${process.cwd()}`;
|
|
320
|
-
if (!
|
|
224
|
+
if (!commandRun.options.path && !commandRun.options.auto && !commandRun.options.skip) {
|
|
321
225
|
return p.text({
|
|
322
|
-
message: `What folder will your ${
|
|
226
|
+
message: `What folder will your ${commandRun.command === "webcomponent" || results.type === "webcomponent" ? "project" : "site"} live in?`,
|
|
323
227
|
placeholder: initialPath,
|
|
324
228
|
required: true,
|
|
325
229
|
validate: value => {
|
|
@@ -336,10 +240,10 @@ async function main() {
|
|
|
336
240
|
name: ({
|
|
337
241
|
results
|
|
338
242
|
}) => {
|
|
339
|
-
if (!
|
|
243
|
+
if (!commandRun.arguments.action && !commandRun.arguments.name) {
|
|
340
244
|
let placeholder = "mysite";
|
|
341
245
|
let message = "Site name:";
|
|
342
|
-
if (
|
|
246
|
+
if (commandRun.command === "webcomponent" || results.type === "webcomponent") {
|
|
343
247
|
placeholder = "my-element";
|
|
344
248
|
message = "Element name:";
|
|
345
249
|
}
|
|
@@ -362,8 +266,8 @@ async function main() {
|
|
|
362
266
|
}
|
|
363
267
|
// assumes auto was selected in CLI
|
|
364
268
|
let joint = process.cwd();
|
|
365
|
-
if (
|
|
366
|
-
joint =
|
|
269
|
+
if (commandRun.options.path) {
|
|
270
|
+
joint = commandRun.options.path;
|
|
367
271
|
} else if (results.path) {
|
|
368
272
|
joint = results.path;
|
|
369
273
|
}
|
|
@@ -377,8 +281,7 @@ async function main() {
|
|
|
377
281
|
org: ({
|
|
378
282
|
results
|
|
379
283
|
}) => {
|
|
380
|
-
if (results.type === "webcomponent" && !
|
|
381
|
-
// @todo detect mono repo and automatically add this
|
|
284
|
+
if (results.type === "webcomponent" && !commandRun.options.org && !commandRun.options.auto && !commandRun.options.skip) {
|
|
382
285
|
let initialOrg = '@yourOrganization';
|
|
383
286
|
return p.text({
|
|
384
287
|
message: 'Organization:',
|
|
@@ -395,7 +298,7 @@ async function main() {
|
|
|
395
298
|
author: ({
|
|
396
299
|
results
|
|
397
300
|
}) => {
|
|
398
|
-
if (!
|
|
301
|
+
if (!commandRun.options.author && !commandRun.options.auto && !commandRun.options.skip) {
|
|
399
302
|
return p.text({
|
|
400
303
|
message: 'Author:',
|
|
401
304
|
required: false,
|
|
@@ -406,17 +309,17 @@ async function main() {
|
|
|
406
309
|
extras: ({
|
|
407
310
|
results
|
|
408
311
|
}) => {
|
|
409
|
-
if (!
|
|
312
|
+
if (!commandRun.options.auto) {
|
|
410
313
|
let options = [];
|
|
411
314
|
let initialValues = [];
|
|
412
|
-
if (
|
|
315
|
+
if (commandRun.command === "webcomponent" || results.type === "webcomponent") {
|
|
413
316
|
options = [{
|
|
414
317
|
value: 'launch',
|
|
415
318
|
label: 'Launch project',
|
|
416
319
|
hint: 'recommended'
|
|
417
320
|
}, {
|
|
418
321
|
value: 'install',
|
|
419
|
-
label: `Install dependencies via ${
|
|
322
|
+
label: `Install dependencies via ${commandRun.options.npmClient}`,
|
|
420
323
|
hint: 'recommended'
|
|
421
324
|
}, {
|
|
422
325
|
value: 'git',
|
|
@@ -424,7 +327,7 @@ async function main() {
|
|
|
424
327
|
hint: 'recommended'
|
|
425
328
|
}];
|
|
426
329
|
initialValues = ['launch', 'install', 'git'];
|
|
427
|
-
if (!
|
|
330
|
+
if (!sysGit || commandRun.options.isMonorepo) {
|
|
428
331
|
options.pop();
|
|
429
332
|
initialValues.pop();
|
|
430
333
|
}
|
|
@@ -453,184 +356,42 @@ async function main() {
|
|
|
453
356
|
});
|
|
454
357
|
// merge cli options with project options assume this is NOT a monorepo
|
|
455
358
|
// but spread will overwrite if needed
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
project.extras = extras;
|
|
359
|
+
if (commandRun.command === 'webcomponent' && !commandRun.arguments.name) {
|
|
360
|
+
project = {
|
|
361
|
+
isMonorepo: false,
|
|
362
|
+
...project,
|
|
363
|
+
...commandRun.options
|
|
364
|
+
};
|
|
365
|
+
} else {
|
|
366
|
+
project = {
|
|
367
|
+
isMonorepo: false,
|
|
368
|
+
...project,
|
|
369
|
+
...commandRun.arguments,
|
|
370
|
+
...commandRun.options
|
|
371
|
+
};
|
|
471
372
|
}
|
|
472
|
-
// values not set by user but used in templating
|
|
473
|
-
project.className = (0, _utils.dashToCamel)(project.name);
|
|
474
373
|
project.year = new Date().getFullYear();
|
|
475
374
|
project.version = await HAXCMS.getHAXCMSVersion();
|
|
476
|
-
let s = p.spinner();
|
|
477
375
|
// resolve site vs multi-site
|
|
478
376
|
switch (project.type) {
|
|
479
377
|
case 'site':
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
let siteRequest = {
|
|
483
|
-
"site": {
|
|
484
|
-
"name": project.name,
|
|
485
|
-
"description": "own course",
|
|
486
|
-
"theme": "clean-one"
|
|
487
|
-
},
|
|
488
|
-
"build": {
|
|
489
|
-
"type": "own",
|
|
490
|
-
"structure": "course",
|
|
491
|
-
"items": null,
|
|
492
|
-
"files": null
|
|
493
|
-
},
|
|
494
|
-
"theme": {
|
|
495
|
-
"color": "green",
|
|
496
|
-
"icon": "av:library-add"
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
HAXCMS.cliWritePath = `${project.path}`;
|
|
500
|
-
await hax.RoutesMap.post.createSite({
|
|
501
|
-
body: siteRequest
|
|
502
|
-
}, fakeSend);
|
|
503
|
-
s.stop((0, _statements.merlinSays)(`${project.name} created!`));
|
|
504
|
-
await (0, _promises.setTimeout)(500);
|
|
505
|
-
break;
|
|
506
|
-
case 'webcomponent':
|
|
507
|
-
port = "8000";
|
|
508
|
-
// option to build github repo link for the user
|
|
509
|
-
if (project.extras.includes('git')) {
|
|
510
|
-
// @todo need to support git@ and https methods
|
|
511
|
-
if (cliOptions.auto) {
|
|
512
|
-
project.gitRepo = `https://github.com/${project.author}/${project.name}.git`;
|
|
513
|
-
} else {
|
|
514
|
-
project.gitRepo = await p.text({
|
|
515
|
-
message: 'Git Repo location:',
|
|
516
|
-
placeholder: `https://github.com/${project.author}/${project.name}.git`
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
// if they supplied one and it has github in it, build a link automatically for ejs index
|
|
520
|
-
if (project.gitRepo && project.gitRepo.includes('github.com')) {
|
|
521
|
-
project.githubLink = project.gitRepo.replace('git@github.com:', 'https://github.com/').replace('.git', '');
|
|
522
|
-
} else {
|
|
523
|
-
project.githubLink = null;
|
|
524
|
-
}
|
|
525
|
-
} else {
|
|
526
|
-
project.githubLink = null;
|
|
527
|
-
}
|
|
528
|
-
// if we have an org, add a / at the end so file name is written correctly
|
|
529
|
-
if (project.org) {
|
|
530
|
-
project.org += '/';
|
|
531
|
-
} else {
|
|
532
|
-
project.org = '';
|
|
378
|
+
if (!project.name && commandRun.arguments.action) {
|
|
379
|
+
project.name = commandRun.arguments.action;
|
|
533
380
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
await fs.renameSync(`${project.path}/${project.name}/lib/webcomponent.haxProperties.json`, `${project.path}/${project.name}/lib/${project.name}.haxProperties.json`);
|
|
539
|
-
// loop through and rename all the localization files
|
|
540
|
-
fs.readdir(`${project.path}/${project.name}/locales/`, function (err, files) {
|
|
541
|
-
if (err) {
|
|
542
|
-
console.error("Could not list the directory.", err);
|
|
543
|
-
process.exit(1);
|
|
544
|
-
}
|
|
545
|
-
files.forEach(async function (file, index) {
|
|
546
|
-
await fs.renameSync(`${project.path}/${project.name}/locales/${file}`, `${project.path}/${project.name}/locales/${file.replace('webcomponent', project.name)}`);
|
|
547
|
-
});
|
|
548
|
-
});
|
|
549
|
-
await fs.renameSync(`${project.path}/${project.name}/webcomponent.js`, `${project.path}/${project.name}/${project.name}.js`);
|
|
550
|
-
await fs.renameSync(`${project.path}/${project.name}/test/webcomponent.test.js`, `${project.path}/${project.name}/test/${project.name}.test.js`);
|
|
551
|
-
s.stop((0, _statements.merlinSays)('Files copied'));
|
|
552
|
-
await (0, _promises.setTimeout)(500);
|
|
553
|
-
s.start((0, _statements.merlinSays)('Making files awesome'));
|
|
554
|
-
for (const filePath of (0, _utils.readAllFiles)(`${project.path}/${project.name}`)) {
|
|
555
|
-
try {
|
|
556
|
-
// ensure we don't try to pattern rewrite image files
|
|
557
|
-
if (!filePath.endsWith('.jpg') && !filePath.endsWith('.png')) {
|
|
558
|
-
const ejsString = ejs.fileLoader(filePath, 'utf8');
|
|
559
|
-
let content = ejs.render(ejsString, project);
|
|
560
|
-
// file written successfully
|
|
561
|
-
fs.writeFileSync(filePath, content);
|
|
562
|
-
}
|
|
563
|
-
} catch (err) {
|
|
564
|
-
console.error(filePath);
|
|
565
|
-
console.error(err);
|
|
566
|
-
}
|
|
381
|
+
// only set path if not already set
|
|
382
|
+
if (!commandRun.options.path) {
|
|
383
|
+
commandRun.options.path = process.cwd();
|
|
384
|
+
project.path = commandRun.options.path;
|
|
567
385
|
}
|
|
568
|
-
|
|
386
|
+
await (0, _site.siteProcess)(commandRun, project);
|
|
387
|
+
break;
|
|
388
|
+
case 'webcomponent':
|
|
389
|
+
await (0, _webcomponent.webcomponentProcess)(commandRun, project);
|
|
569
390
|
break;
|
|
570
|
-
}
|
|
571
|
-
if (project.gitRepo && !cliOptions.isMonorepo) {
|
|
572
|
-
try {
|
|
573
|
-
await exec(`cd ${project.path}/${project.name} && git init && git add -A && git commit -m "first commit" && git branch -M main${project.gitRepo ? ` && git remote add origin ${project.gitRepo}` : ''}`);
|
|
574
|
-
} catch (e) {}
|
|
575
|
-
}
|
|
576
|
-
// options for install, git and other extras
|
|
577
|
-
// can't launch if we didn't install first so launch implies installation
|
|
578
|
-
if (project.extras.includes('launch') || project.extras.includes('install')) {
|
|
579
|
-
s.start((0, _statements.merlinSays)(`Installation magic (${cliOptions.npmClient} install)`));
|
|
580
|
-
try {
|
|
581
|
-
// monorepos install from top but then still need to launch from local location
|
|
582
|
-
if (!cliOptions.isMonorepo) {
|
|
583
|
-
await exec(`cd ${project.path}/${project.name} && ${cliOptions.npmClient} install`);
|
|
584
|
-
}
|
|
585
|
-
} catch (e) {
|
|
586
|
-
console.log(e);
|
|
587
|
-
}
|
|
588
|
-
s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
|
|
589
|
-
}
|
|
590
|
-
// autolaunch if default was selected
|
|
591
|
-
if (project.extras.includes('launch')) {
|
|
592
|
-
let optionPath = `${project.path}/${project.name}`;
|
|
593
|
-
let command = `npx @haxtheweb/haxcms-nodejs`;
|
|
594
|
-
if (project.type === "webcomponent") {
|
|
595
|
-
command = `${cliOptions.npmClient} start`;
|
|
596
|
-
}
|
|
597
|
-
p.note(`${(0, _statements.merlinSays)(`I have summoned a sub-process daemon 👹`)}
|
|
598
|
-
|
|
599
|
-
🚀 Running your ${_picocolors.default.bold(project.type)} ${_picocolors.default.bold(project.name)}:
|
|
600
|
-
${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
|
|
601
|
-
|
|
602
|
-
🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${optionPath}`))))}
|
|
603
|
-
💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${optionPath}`)))}
|
|
604
|
-
📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${optionPath}`)))}
|
|
605
|
-
📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${optionPath}`)))}
|
|
606
|
-
🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${command}`)))}
|
|
607
|
-
|
|
608
|
-
⌨️ To resume 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
|
|
609
|
-
`);
|
|
610
|
-
// at least a second to see the message print at all
|
|
611
|
-
await (0, _promises.setTimeout)(1000);
|
|
612
|
-
try {
|
|
613
|
-
await exec(`cd ${optionPath} && ${command}`);
|
|
614
|
-
} catch (e) {
|
|
615
|
-
// don't log bc output is weird
|
|
616
|
-
}
|
|
617
|
-
} else {
|
|
618
|
-
let nextSteps = `cd ${project.path}/${project.name} && `;
|
|
619
|
-
switch (project.type) {
|
|
620
|
-
case 'site':
|
|
621
|
-
case 'haxsite':
|
|
622
|
-
nextSteps += `npx @haxtheweb/haxcms-nodejs`;
|
|
623
|
-
break;
|
|
624
|
-
case 'webcomponent':
|
|
625
|
-
nextSteps += `${project.extras.includes('install') ? '' : `${cliOptions.npmClient} install && `}${cliOptions.npmClient} start`;
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
p.note(`${project.name} is ready to go. Run the following to start development:`);
|
|
629
|
-
p.outro(nextSteps);
|
|
630
391
|
}
|
|
631
392
|
}
|
|
632
393
|
}
|
|
394
|
+
(0, _statements.communityStatement)();
|
|
633
395
|
}
|
|
634
|
-
(0, _statements.communityStatement)();
|
|
635
396
|
}
|
|
636
397
|
main().catch(console.error);
|