@haxtheweb/create 10.0.4 → 10.0.6

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.
@@ -348,7 +348,7 @@ async function siteCommandDetected(commandRun) {
348
348
  }
349
349
  recipe.log(siteLoggingName, (0, _logging.commandString)(commandRun));
350
350
  } else if (!commandRun.options.quiet) {
351
- (0, _logging.log)('Must specify --item-import as path to valid item export file or URL', 'error');
351
+ (0, _logging.log)('Must specify --items-import as path to valid item export file or URL', 'error');
352
352
  }
353
353
  break;
354
354
  case "start":
@@ -588,7 +588,7 @@ async function siteCommandDetected(commandRun) {
588
588
  // these have fixed possible values
589
589
  else if (['parent', 'theme'].includes(nodeProp)) {
590
590
  let l = nodeProp === 'parent' ? "-- no parent --" : "-- no theme --";
591
- let list = nodeProp === 'parent' ? await siteItemsOptionsList(activeHaxsite, page.id) : await siteThemeList();
591
+ let list = nodeProp === 'parent' ? await siteItemsOptionsList(activeHaxsite, page.id) : await siteThemeList(true);
592
592
  propValue = await p.select({
593
593
  message: `${nodeProp}:`,
594
594
  defaultValue: val,
@@ -744,8 +744,8 @@ async function siteCommandDetected(commandRun) {
744
744
  case "site:theme":
745
745
  try {
746
746
  //theme
747
- let list = await siteThemeList();
748
747
  activeHaxsite = await hax.systemStructureContext();
748
+ let list = await siteThemeList(true, activeHaxsite.directory);
749
749
  let val = activeHaxsite.manifest.metadata.theme.element;
750
750
  if (!commandRun.options.theme) {
751
751
  commandRun.options.theme = await p.select({
@@ -755,11 +755,71 @@ async function siteCommandDetected(commandRun) {
755
755
  options: list
756
756
  });
757
757
  }
758
+ if (commandRun.options.theme === "custom-theme") {
759
+ if (!commandRun.options.customThemeName) {
760
+ commandRun.options.customThemeName = await p.text({
761
+ message: 'Theme Name:',
762
+ placeholder: `custom-${activeHaxsite.name}-theme`,
763
+ required: false,
764
+ validate: value => {
765
+ if (!value) {
766
+ return "Theme name is required (tab writes default)";
767
+ }
768
+ if (list.some(theme => theme.value === value)) {
769
+ return "Theme name is already in use";
770
+ }
771
+ if (/^\d/.test(value)) {
772
+ return "Theme name cannot start with a number";
773
+ }
774
+ if (/[A-Z]/.test(value)) {
775
+ return "No uppercase letters allowed in theme name";
776
+ }
777
+ if (value.indexOf(' ') !== -1) {
778
+ return "No spaces allowed in theme name";
779
+ }
780
+ }
781
+ });
782
+ }
783
+ if (!commandRun.options.customThemeTemplate) {
784
+ const options = [{
785
+ value: 'base',
786
+ label: 'Vanilla Theme with Hearty Documentation'
787
+ }, {
788
+ value: 'polaris-flex',
789
+ label: 'Minimalist Theme with Horizontal Nav'
790
+ }, {
791
+ value: 'polaris-sidebar',
792
+ label: 'Content-Focused Theme with Flexible Sidebar'
793
+ }];
794
+ commandRun.options.customThemeTemplate = await p.select({
795
+ message: 'Template:',
796
+ required: false,
797
+ options: options,
798
+ initialValue: options[0]
799
+ });
800
+ }
801
+ }
758
802
  let themes = await HAXCMS.getThemes();
759
- if (themes && commandRun.options.theme && themes[commandRun.options.theme]) {
760
- activeHaxsite.manifest.metadata.theme = themes[commandRun.options.theme];
761
- activeHaxsite.manifest.save(false);
762
- recipe.log(siteLoggingName, (0, _logging.commandString)(commandRun));
803
+ if (themes && commandRun.options.theme) {
804
+ if (themes[commandRun.options.theme]) {
805
+ activeHaxsite.manifest.metadata.theme = themes[commandRun.options.theme];
806
+ activeHaxsite.manifest.save(false);
807
+ recipe.log(siteLoggingName, (0, _logging.commandString)(commandRun));
808
+ } else if (commandRun.options.theme === "custom-theme") {
809
+ commandRun.options.name = activeHaxsite.name;
810
+ commandRun.options.directory = activeHaxsite.directory;
811
+ // temporary for proof of concept
812
+ commandRun.options.npmClient = 'npm';
813
+ await customSiteTheme(commandRun, {});
814
+ } else if (!themes[commandRun.options.theme]) {
815
+ let themeObj = {
816
+ element: commandRun.options.theme,
817
+ path: "./custom/build/custom.es6.js",
818
+ name: (0, _utils.dashToCamel)(commandRun.options.theme)
819
+ };
820
+ activeHaxsite.manifest.metadata.theme = themeObj;
821
+ activeHaxsite.manifest.save(false);
822
+ }
763
823
  }
764
824
  } catch (e) {
765
825
  (0, _logging.log)(e.stderr);
@@ -1107,7 +1167,7 @@ async function siteProcess(commandRun, project, port = '3000') {
1107
1167
  if (commandRun.options.importStructure === 'drupal7-book-print-html') {
1108
1168
  let siteContent = await fetch(commandRun.options.importSite).then(d => d.ok ? d.text() : '');
1109
1169
  if (siteContent) {
1110
- // @todo refactor to support 9 levels of heirarchy as this is technically what Drupal supports
1170
+ // @todo refactor to support 9 levels of hierarchy as this is technically what Drupal supports
1111
1171
  let dom = (0, _nodeHtmlParser.parse)(siteContent);
1112
1172
  // pull all of level 1 of hierarchy
1113
1173
  let depth;
@@ -1197,6 +1257,9 @@ async function siteProcess(commandRun, project, port = '3000') {
1197
1257
  });
1198
1258
  // matching the common object elsewhere tho different reference in this command since it creates from nothing
1199
1259
  // capture this if use input on the fly
1260
+ if (!commandRun.arguments.action) {
1261
+ commandRun.arguments.action = project.name;
1262
+ }
1200
1263
  commandRun.options.theme = project.theme;
1201
1264
  recipe.log(siteLoggingName, (0, _logging.commandString)(commandRun));
1202
1265
  if (commandRun.options.v) {
@@ -1269,14 +1332,53 @@ async function siteItemsOptionsList(activeHaxsite, skipId = null) {
1269
1332
  }
1270
1333
  return optionItems;
1271
1334
  }
1272
- async function siteThemeList() {
1273
- let themes = await HAXCMS.getThemes();
1335
+ async function siteThemeList(coreOnly = true, directory = null) {
1274
1336
  let items = [];
1275
- for (var i in themes) {
1276
- items.push({
1277
- value: i,
1278
- label: themes[i].name
1279
- });
1337
+ if (coreOnly) {
1338
+ items = [{
1339
+ value: 'clean-one',
1340
+ label: 'Clean One'
1341
+ }, {
1342
+ value: 'clean-two',
1343
+ label: 'Clean Two'
1344
+ }, {
1345
+ value: 'clean-portfolio-theme',
1346
+ label: 'Clean Portfolio'
1347
+ }, {
1348
+ value: 'haxor-slevin',
1349
+ label: 'Haxor Blog'
1350
+ }, {
1351
+ value: 'polaris-flex-theme',
1352
+ label: 'Polaris - Flex'
1353
+ }, {
1354
+ value: 'polaris-flex-sidebar',
1355
+ label: 'Polaris - Flex Sidebar'
1356
+ }, {
1357
+ value: 'polaris-invent-theme',
1358
+ label: 'Polaris - Invent'
1359
+ }, {
1360
+ value: 'custom-theme',
1361
+ label: 'Create Custom Theme'
1362
+ }];
1363
+ if (fs.existsSync(`${directory}/custom/custom-elements.json`)) {
1364
+ let customThemeArray = JSON.parse(fs.readFileSync(`${directory}/custom/custom-elements.json`, 'utf8')).modules;
1365
+ for (var i in customThemeArray) {
1366
+ if (customThemeArray[i].declarations[0].superclass.name === "PolarisFlexTheme" || customThemeArray[i].declarations[0].superclass.name === "HAXCMSLitElementTheme") {
1367
+ items.push({
1368
+ value: customThemeArray[i].declarations[0].tagName,
1369
+ label: customThemeArray[i].declarations[0].name
1370
+ });
1371
+ }
1372
+ }
1373
+ }
1374
+ } else {
1375
+ let themes = await HAXCMS.getThemes();
1376
+ for (var i in themes) {
1377
+ items.push({
1378
+ value: i,
1379
+ label: themes[i].name
1380
+ });
1381
+ }
1280
1382
  }
1281
1383
  return items;
1282
1384
  }
@@ -1287,7 +1389,7 @@ async function customSiteTheme(commandRun, project) {
1287
1389
  // validate start and end tags for theme name
1288
1390
  if (/^custom/.test(project.customThemeName) && !/^custom-/.test(project.customThemeName)) {
1289
1391
  project.customThemeName = project.customThemeName.replace(/^custom/, "custom-");
1290
- } else if (!/^custom-/.test(project.className)) {
1392
+ } else if (!/^custom-/.test(project.customThemeName)) {
1291
1393
  project.customThemeName = `custom-${project.customThemeName}`;
1292
1394
  }
1293
1395
  if (/theme$/.test(project.customThemeName) && !/-theme$/.test(project.customThemeName)) {
@@ -1300,10 +1402,30 @@ async function customSiteTheme(commandRun, project) {
1300
1402
  project.className = (0, _utils.dashToCamel)(project.customThemeName);
1301
1403
 
1302
1404
  // path to hax site
1303
- var sitePath = `${project.path}/${commandRun.options.name ? commandRun.options.name : project.name}`;
1405
+ var sitePath;
1406
+ if (!commandRun.options.directory) {
1407
+ sitePath = `${commandRun.options.path ? commandRun.options.path : project.path}/${commandRun.options.name ? commandRun.options.name : project.name}`;
1408
+ } else {
1409
+ // existing sites
1410
+ sitePath = commandRun.options.directory;
1411
+ }
1304
1412
 
1305
1413
  // path to new theme file
1306
1414
  const filePath = `${sitePath}/custom/src/${project.customThemeName}.js`;
1415
+ if (!project.year) {
1416
+ project.year = new Date().getFullYear();
1417
+ }
1418
+ if (!project.author) {
1419
+ try {
1420
+ let value = await exec(`git config user.name`);
1421
+ project.author = value.stdout.trim();
1422
+ } catch (e) {
1423
+ (0, _logging.log)(`
1424
+ git user name not configured. Run the following to do this:\n
1425
+ git config --global user.name "namehere"\n
1426
+ git config --global user.email "email@here`, 'debug');
1427
+ }
1428
+ }
1307
1429
 
1308
1430
  // theme template to use
1309
1431
  const themeTemplate = commandRun.options.customThemeTemplate ? commandRun.options.customThemeTemplate : project.customThemeTemplate;
@@ -1338,14 +1460,14 @@ async function customSiteTheme(commandRun, project) {
1338
1460
  // add theme to site.json
1339
1461
  let themeObj = {
1340
1462
  element: project.customThemeName,
1341
- path: filePath,
1463
+ path: "./custom/build/custom.es6.js",
1342
1464
  name: project.className
1343
1465
  };
1344
1466
  activeHaxsite.manifest.metadata.theme = themeObj;
1345
1467
  activeHaxsite.manifest.save(false);
1346
1468
 
1347
1469
  // install and build theme dependencies
1348
- await exec(`cd ${sitePath}/custom/ && ${commandRun.options.npmClient} install && ${commandRun.options.npmClient} run build && cd ${sitePath}`);
1470
+ await exec(`cd ${sitePath}/custom/ && ${commandRun.options.npmClient} install && ${commandRun.options.npmClient} run build && ${commandRun.options.npmClient} run analyze && cd ${sitePath}`);
1349
1471
  }
1350
1472
 
1351
1473
  // @fork of the hax core util for this so that we avoid api difference between real dom and parse nodejs dom
@@ -4,10 +4,12 @@
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.webcomponentActions = webcomponentActions;
7
8
  exports.webcomponentCommandDetected = webcomponentCommandDetected;
8
9
  exports.webcomponentGenerateHAXSchema = webcomponentGenerateHAXSchema;
9
10
  exports.webcomponentProcess = webcomponentProcess;
10
11
  var fs = _interopRequireWildcard(require("node:fs"));
12
+ var path = _interopRequireWildcard(require("node:path"));
11
13
  var _promises = require("node:timers/promises");
12
14
  var ejs = _interopRequireWildcard(require("ejs"));
13
15
  var p = _interopRequireWildcard(require("@clack/prompts"));
@@ -159,7 +161,8 @@ async function webcomponentProcess(commandRun, project, port = "8000") {
159
161
  } else {
160
162
  project.gitRepo = await p.text({
161
163
  message: 'Git Repo location:',
162
- placeholder: `https://github.com/${project.author}/${project.name}.git`
164
+ placeholder: `https://github.com/${project.author}/${project.name}.git`,
165
+ initialValue: `https://github.com/${project.author}/${project.name}.git`
163
166
  });
164
167
  }
165
168
  // if they supplied one and it has github in it, build a link automatically for ejs index
@@ -184,6 +187,7 @@ async function webcomponentProcess(commandRun, project, port = "8000") {
184
187
  // rename gitignore to improve copy cross platform compat
185
188
  await fs.renameSync(`${project.path}/${project.name}/_github`, `${project.path}/${project.name}/.github`);
186
189
  await fs.renameSync(`${project.path}/${project.name}/_vscode`, `${project.path}/${project.name}/.vscode`);
190
+ await fs.renameSync(`${project.path}/${project.name}/_dddignore`, `${project.path}/${project.name}/.dddignore`);
187
191
  await fs.renameSync(`${project.path}/${project.name}/_editorconfig`, `${project.path}/${project.name}/.editorconfig`);
188
192
  await fs.renameSync(`${project.path}/${project.name}/_gitignore`, `${project.path}/${project.name}/.gitignore`);
189
193
  await fs.renameSync(`${project.path}/${project.name}/_nojekyll`, `${project.path}/${project.name}/.nojekyll`);
@@ -261,7 +265,7 @@ ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${por
261
265
  // at least a second to see the message print at all
262
266
  await (0, _promises.setTimeout)(1000);
263
267
  try {
264
- await exec(`cd ${optionPath} && ${command}`);
268
+ await exec(`cd ${optionPath} && ${command} && ${commandRun.options.npmClient} run analyze`);
265
269
  } catch (e) {
266
270
  // don't log bc output is weird
267
271
  }
@@ -271,6 +275,21 @@ ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${por
271
275
  p.outro(nextSteps);
272
276
  }
273
277
  }
278
+ function webcomponentActions() {
279
+ return [{
280
+ value: 'start',
281
+ label: "Launch project"
282
+ }, {
283
+ value: 'wc:stats',
284
+ label: "Check status of web component"
285
+ }, {
286
+ value: 'wc:element',
287
+ label: "Add a new Lit module to an existing project"
288
+ }, {
289
+ value: 'wc:haxproperties',
290
+ label: "Write haxProperties schema"
291
+ }];
292
+ }
274
293
 
275
294
  // autodetect webcomponent
276
295
  async function webcomponentCommandDetected(commandRun, packageData = {}, port = "8000") {
@@ -278,42 +297,243 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
278
297
  p.intro(`${_picocolors.default.bgBlack(_picocolors.default.white(` HAXTheWeb : Webcomponent detected `))}`);
279
298
  p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Web component name: ${packageData.name} `))}`);
280
299
  }
281
- // if we support customElement analyzer (hax wcs do) then generate if asked
282
- if (commandRun.options.writeHaxProperties && packageData.customElements) {
283
- webcomponentGenerateHAXSchema(commandRun, packageData);
284
- } else {
285
- if (!commandRun.options.quiet) {
286
- p.note(`${(0, _statements.merlinSays)(`I have summoned a sub-process daemon 👹`)}
287
-
288
- 🚀 Running your ${_picocolors.default.bold('webcomponent')} ${_picocolors.default.bold(packageData.name)}:
289
- ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
290
-
291
- 🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${process.cwd()}`))))}
292
- 💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${process.cwd()}`)))}
293
- 📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${process.cwd()}`)))}
294
- 📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${process.cwd()}`)))}
295
- 🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${commandRun.options.npmClient} start`)))}
296
-
297
- ⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
298
- `);
300
+ let actions = webcomponentActions();
301
+ let actionAssigned = false;
302
+ // default to status unless already set so we don't issue a create in a create
303
+ if (!commandRun.arguments.action) {
304
+ actionAssigned = true;
305
+ commandRun.arguments.action = 'wc:status';
306
+ }
307
+ commandRun.command = "webcomponent";
308
+ let operation = {
309
+ ...commandRun.arguments,
310
+ ...commandRun.options
311
+ };
312
+ actions.push({
313
+ value: 'quit',
314
+ label: "🚪 Quit"
315
+ });
316
+ while (operation.action !== 'quit') {
317
+ if (!operation.action) {
318
+ commandRun = {
319
+ command: null,
320
+ arguments: {},
321
+ options: {
322
+ npmClient: `${operation.npmClient}`
323
+ }
324
+ };
325
+ operation = await p.group({
326
+ action: ({
327
+ results
328
+ }) => p.select({
329
+ message: `Actions you can take:`,
330
+ defaultValue: actions[0],
331
+ initialValue: actions[0],
332
+ options: actions
333
+ })
334
+ }, {
335
+ onCancel: () => {
336
+ if (!commandRun.options.quiet) {
337
+ p.cancel('🧙 Merlin: Canceling CLI.. HAX ya later 🪄');
338
+ }
339
+ process.exit(0);
340
+ }
341
+ });
299
342
  }
300
- try {
301
- // ensure it's installed first, unless it's a monorepo. basic check for node_modules
302
- // folder as far as if already installed so we don't double install needlessly
303
- if (!commandRun.options.isMonorepo && !fs.existsSync("./node_modules")) {
343
+ if (operation.action) {
344
+ p.intro(`hax wc ${_picocolors.default.bold(operation.action)}`);
345
+ }
346
+ switch (operation.action) {
347
+ case "start":
304
348
  if (!commandRun.options.quiet) {
305
- let s = p.spinner();
306
- s.start((0, _statements.merlinSays)(`Installation magic (${commandRun.options.npmClient} install)`));
307
- await exec(`${commandRun.options.npmClient} install`);
308
- s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
309
- } else {
310
- await exec(`${commandRun.options.npmClient} install`);
349
+ // Multi-line clack spacing
350
+ p.note(`${(0, _statements.merlinSays)(`I have summoned a sub-process daemon 👹`)}
351
+
352
+ 🚀 Running your ${_picocolors.default.bold('webcomponent')} ${_picocolors.default.bold(packageData.name)}:
353
+ ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
354
+
355
+ 🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${process.cwd()}`))))}
356
+ 💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${process.cwd()}`)))}
357
+ 📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${process.cwd()}`)))}
358
+ 📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${process.cwd()}`)))}
359
+ 🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${commandRun.options.npmClient} start`)))}
360
+
361
+ ⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
362
+ `);
311
363
  }
312
- }
313
- await exec(`${commandRun.options.npmClient} start`);
314
- } catch (e) {
315
- // don't log bc output is odd
364
+ try {
365
+ // ensure it's installed first, unless it's a monorepo. basic check for node_modules
366
+ // folder as far as if already installed so we don't double install needlessly
367
+ if (!commandRun.options.isMonorepo && !fs.existsSync("./node_modules")) {
368
+ if (!commandRun.options.quiet) {
369
+ let s = p.spinner();
370
+ s.start((0, _statements.merlinSays)(`Installation magic (${commandRun.options.npmClient} install)`));
371
+ await exec(`${commandRun.options.npmClient} install`);
372
+ s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
373
+ } else {
374
+ await exec(`${commandRun.options.npmClient} install`);
375
+ }
376
+ }
377
+ await exec(`${commandRun.options.npmClient} start`);
378
+ } catch (e) {
379
+ // don't log bc output is odd
380
+ }
381
+ break;
382
+ case "wc:status":
383
+ case "wc:stats":
384
+ case "webcomponent:status":
385
+ case "webcomponent:stats":
386
+ try {
387
+ let webcomponentStats = {};
388
+ if (packageData) {
389
+ webcomponentStats.title = packageData.name;
390
+ webcomponentStats.description = packageData.description;
391
+ webcomponentStats.git = packageData.repository.url;
392
+ }
393
+ webcomponentStats.modules = [];
394
+ webcomponentStats.superclasses = [];
395
+ if (fs.existsSync(`${process.cwd()}/custom-elements.json`)) {
396
+ let components = JSON.parse(fs.readFileSync(`${process.cwd()}/custom-elements.json`, 'utf8')).modules;
397
+ for (var i in components) {
398
+ webcomponentStats.modules.push(`${components[i].path}`);
399
+ if (components[i].declarations[0].superclass && !webcomponentStats.superclasses.includes(components[i].declarations[0].superclass.name)) {
400
+ webcomponentStats.superclasses.push(`${components[i].declarations[0].superclass.name}`);
401
+ }
402
+ }
403
+ }
404
+ if (!commandRun.options.format && !commandRun.options.quiet) {
405
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Title: ${webcomponentStats.title} `))}`);
406
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Description: ${webcomponentStats.description} `))}`);
407
+ if (webcomponentStats.git) {
408
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Git: ${webcomponentStats.git} `))}`);
409
+ }
410
+ if (webcomponentStats.modules.length !== 0) {
411
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Modules: ${webcomponentStats.modules} `))}`);
412
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Number of modules: ${webcomponentStats.modules.length} `))}`);
413
+ }
414
+ if (webcomponentStats.superclasses.length !== 0) {
415
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Inherited superclasses: ${webcomponentStats.superclasses} `))}`);
416
+ }
417
+ }
418
+ } catch (e) {
419
+ (0, _logging.log)(e.stderr);
420
+ }
421
+ break;
422
+ case "wc:element":
423
+ case "webcomponent:element":
424
+ try {
425
+ if (!commandRun.options.name) {
426
+ commandRun.options.name = await p.text({
427
+ message: 'Component name:',
428
+ placeholder: 'my-component',
429
+ required: true,
430
+ validate: value => {
431
+ if (!value) {
432
+ return "Name is required (tab writes default)";
433
+ }
434
+ if (value.toLocaleLowerCase() !== value) {
435
+ return "Name must be lowercase";
436
+ }
437
+ if (/^\d/.test(value)) {
438
+ return "Name cannot start with a number";
439
+ }
440
+ if (value.indexOf(' ') !== -1) {
441
+ return "No spaces allowed in name";
442
+ }
443
+ if (value.indexOf('-') === -1 || value.replace('--', '') !== value || value[0] === '-' || value[value.length - 1] === '-') {
444
+ return "Name must include at least one `-` and must not start or end name.";
445
+ }
446
+ // assumes auto was selected in CLI
447
+ let joint = process.cwd();
448
+ if (commandRun.options.path) {
449
+ joint = commandRun.options.path;
450
+ }
451
+ if (fs.existsSync(path.join(joint, value))) {
452
+ return `${path.join(joint, value)} exists, rename this project`;
453
+ }
454
+ }
455
+ });
456
+ } else {
457
+ let value = commandRun.options.name;
458
+ if (!value) {
459
+ console.error(_picocolors.default.red("Name is required (tab writes default)"));
460
+ process.exit(1);
461
+ }
462
+ if (value.toLocaleLowerCase() !== value) {
463
+ console.error(_picocolors.default.red("Name must be lowercase"));
464
+ process.exit(1);
465
+ }
466
+ if (/^\d/.test(value)) {
467
+ console.error(_picocolors.default.red("Name cannot start with a number"));
468
+ }
469
+ if (value.indexOf(' ') !== -1) {
470
+ console.error(_picocolors.default.red("No spaces allowed in name"));
471
+ process.exit(1);
472
+ }
473
+ if (value.indexOf('-') === -1 || value.replace('--', '') !== value || value[0] === '-' || value[value.length - 1] === '-') {
474
+ console.error(_picocolors.default.red("Name must include at least one `-` and must not start or end name."));
475
+ process.exit(1);
476
+ }
477
+ // assumes auto was selected in CLI
478
+ let joint = process.cwd();
479
+ if (commandRun.options.path) {
480
+ joint = commandRun.options.path;
481
+ }
482
+ if (fs.existsSync(path.join(joint, value))) {
483
+ console.error(_picocolors.default.red(`${path.join(joint, value)} exists, rename this project`));
484
+ process.exit(1);
485
+ }
486
+ }
487
+ const project = {
488
+ name: commandRun.options.name,
489
+ mainModule: packageData.name,
490
+ path: process.cwd(),
491
+ className: (0, _utils.dashToCamel)(commandRun.options.name),
492
+ year: new Date().getFullYear()
493
+ };
494
+ if (packageData.author) {
495
+ project.author = packageData.author.name;
496
+ }
497
+ const filePath = `${project.path}/${project.name}.js`;
498
+ await fs.copyFileSync(`${process.mainModule.path}/templates/generic/webcomponent.js`, filePath);
499
+ const ejsString = ejs.fileLoader(filePath, 'utf8');
500
+ let content = ejs.render(ejsString, project);
501
+ // file written successfully
502
+ fs.writeFileSync(filePath, content);
503
+ if (packageData.customElements) {
504
+ await webcomponentGenerateHAXSchema(commandRun, packageData);
505
+ }
506
+ p.note(`🧙 Add to another web component (.js): ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`import ./${project.name}.js`))))}
507
+ 💻 Add to an HTML file: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`<script type="module" src="${project.name}"></script>`)))}`);
508
+ // at least a second to see the message print at all
509
+ await (0, _promises.setTimeout)(1000);
510
+ } catch (e) {
511
+ (0, _logging.log)(e.stderr);
512
+ // Original ejs.render error checking
513
+ console.error(_picocolors.default.red(filePath));
514
+ console.error(_picocolors.default.red(e));
515
+ }
516
+ break;
517
+ case "wc:haxproperties":
518
+ case "webcomponent:haxproperties":
519
+ try {
520
+ if (packageData.customElements) {
521
+ await webcomponentGenerateHAXSchema(commandRun, packageData);
522
+ }
523
+ } catch (e) {
524
+ (0, _logging.log)(e.stderr);
525
+ }
526
+ break;
527
+ case "quit":
528
+ // quit
529
+ process.exit(0);
530
+ break;
531
+ }
532
+ // y or noi need to act like it ran and finish instead of looping options
533
+ if (commandRun.options.y || !commandRun.options.i || !actionAssigned) {
534
+ process.exit(0);
316
535
  }
536
+ operation.action = null;
317
537
  }
318
538
  }
319
539