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