@haxtheweb/create 10.0.7 → 11.0.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.
@@ -18,15 +18,12 @@ var _statements = require("../statements.js");
18
18
  var _logging = require("../logging.js");
19
19
  var _utils = require("../utils.js");
20
20
  var hax = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs"));
21
- var child_process = _interopRequireWildcard(require("child_process"));
22
- var util = _interopRequireWildcard(require("node:util"));
23
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
22
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
25
23
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
26
24
  const HAXCMS = hax.HAXCMS;
27
- const exec = util.promisify(child_process.exec);
28
25
  let sysGit = true;
29
- exec('git --version', error => {
26
+ (0, _utils.exec)('which git', error => {
30
27
  if (error) {
31
28
  sysGit = false;
32
29
  }
@@ -228,7 +225,7 @@ async function webcomponentProcess(commandRun, project, port = "8000") {
228
225
  s.stop('Files are now awesome!');
229
226
  if (project.gitRepo && !commandRun.options.isMonorepo) {
230
227
  try {
231
- 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}` : ''}`);
228
+ await (0, _utils.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}` : ''}`);
232
229
  } catch (e) {}
233
230
  }
234
231
  // options for install, git and other extras
@@ -238,7 +235,7 @@ async function webcomponentProcess(commandRun, project, port = "8000") {
238
235
  try {
239
236
  // monorepos install from top but then still need to launch from local location
240
237
  if (!commandRun.options.isMonorepo) {
241
- await exec(`cd ${project.path}/${project.name} && ${commandRun.options.npmClient} install`);
238
+ await (0, _utils.exec)(`cd ${project.path}/${project.name} && ${commandRun.options.npmClient} install`);
242
239
  }
243
240
  } catch (e) {
244
241
  console.warn(e);
@@ -260,12 +257,12 @@ ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${por
260
257
  📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${optionPath}`)))}
261
258
  🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${command}`)))}
262
259
 
263
- ⌨️ To resume 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
260
+ ⌨️ To resume 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C or CTRL + BREAK `)))}
264
261
  `);
265
262
  // at least a second to see the message print at all
266
263
  await (0, _promises.setTimeout)(1000);
267
264
  try {
268
- await exec(`cd ${optionPath} && ${command} && ${commandRun.options.npmClient} run analyze`);
265
+ await (0, _utils.exec)(`cd ${optionPath} && ${command} && ${commandRun.options.npmClient} run analyze`);
269
266
  } catch (e) {
270
267
  // don't log bc output is weird
271
268
  }
@@ -284,7 +281,7 @@ function webcomponentActions() {
284
281
  label: "Check status of web component"
285
282
  }, {
286
283
  value: 'wc:element',
287
- label: "Add a new Lit module to an existing project"
284
+ label: "Add new Lit component to existing project"
288
285
  }, {
289
286
  value: 'wc:haxproperties',
290
287
  label: "Write haxProperties schema"
@@ -358,7 +355,7 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
358
355
  📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${process.cwd()}`)))}
359
356
  🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${commandRun.options.npmClient} start`)))}
360
357
 
361
- ⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
358
+ ⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C or CTRL + BREAK `)))}
362
359
  `);
363
360
  }
364
361
  try {
@@ -368,17 +365,63 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
368
365
  if (!commandRun.options.quiet) {
369
366
  let s = p.spinner();
370
367
  s.start((0, _statements.merlinSays)(`Installation magic (${commandRun.options.npmClient} install)`));
371
- await exec(`${commandRun.options.npmClient} install`);
368
+ await (0, _utils.exec)(`${commandRun.options.npmClient} install`);
372
369
  s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
373
370
  } else {
374
- await exec(`${commandRun.options.npmClient} install`);
371
+ await (0, _utils.exec)(`${commandRun.options.npmClient} install`);
375
372
  }
376
373
  }
377
- await exec(`${commandRun.options.npmClient} start`);
374
+ await (0, _utils.exec)(`${commandRun.options.npmClient} start`);
378
375
  } catch (e) {
379
376
  // don't log bc output is odd
380
377
  }
381
378
  break;
379
+ case "serve":
380
+ try {
381
+ if (!commandRun.options.quiet) {
382
+ p.intro(`Launching development server.. `);
383
+ }
384
+ if (packageData.scripts.serve) {
385
+ if (!commandRun.options.quiet) {
386
+ p.note(`${(0, _statements.merlinSays)(`Project launched in development mode`)}
387
+
388
+ 🚀 Running your ${_picocolors.default.bold('webcomponent')} ${_picocolors.default.bold(packageData.name)}:
389
+ ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
390
+
391
+ 🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${process.cwd()}`))))}
392
+ 💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${process.cwd()}`)))}
393
+ 📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${process.cwd()}`)))}
394
+ 📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${process.cwd()}`)))}
395
+ 🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${commandRun.options.npmClient} serve`)))}
396
+
397
+ ⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C or CTRL + BREAK `)))}
398
+ `);
399
+ }
400
+ await (0, _utils.exec)(`${commandRun.options.npmClient} run serve`);
401
+ } else {
402
+ // if no serve script, run start instead
403
+ if (!commandRun.options.quiet) {
404
+ p.note(`${(0, _statements.merlinSays)(`No ${_picocolors.default.bold('serve')} script found, running ${_picocolors.default.bold(`${commandRun.options.npmClient} start`)} instead`)}
405
+
406
+ 🚀 Running your ${_picocolors.default.bold('webcomponent')} ${_picocolors.default.bold(packageData.name)}:
407
+ ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
408
+
409
+ 🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${process.cwd()}`))))}
410
+ 💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${process.cwd()}`)))}
411
+ 📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${process.cwd()}`)))}
412
+ 📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${process.cwd()}`)))}
413
+ 🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${commandRun.options.npmClient} start`)))}
414
+
415
+ ⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C or CTRL + BREAK `)))}
416
+ `);
417
+ }
418
+ await (0, _utils.exec)(`${commandRun.options.npmClient} start`);
419
+ }
420
+ } catch (e) {
421
+ // don't log bc output is odd
422
+ console.log("error", e);
423
+ }
424
+ break;
382
425
  case "wc:status":
383
426
  case "wc:stats":
384
427
  case "webcomponent:status":
@@ -422,6 +465,7 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
422
465
  case "wc:element":
423
466
  case "webcomponent:element":
424
467
  try {
468
+ const reservedNames = ["annotation-xml", "color-profile", "font-face", "font-face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph"];
425
469
  if (!commandRun.options.name) {
426
470
  commandRun.options.name = await p.text({
427
471
  message: 'Component name:',
@@ -431,18 +475,28 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
431
475
  if (!value) {
432
476
  return "Name is required (tab writes default)";
433
477
  }
478
+ if (reservedNames.includes(value)) {
479
+ return `Reserved name ${_picocolors.default.bold(value)} cannot be used`;
480
+ }
434
481
  if (value.toLocaleLowerCase() !== value) {
435
482
  return "Name must be lowercase";
436
483
  }
437
484
  if (/^\d/.test(value)) {
438
485
  return "Name cannot start with a number";
439
486
  }
487
+ if (/[`~!@#$%^&*()_=+\[\]{}|;:\'",<.>\/?\\]/.test(value)) {
488
+ return "No special characters allowed in name";
489
+ }
440
490
  if (value.indexOf(' ') !== -1) {
441
491
  return "No spaces allowed in name";
442
492
  }
443
493
  if (value.indexOf('-') === -1 || value.replace('--', '') !== value || value[0] === '-' || value[value.length - 1] === '-') {
444
494
  return "Name must include at least one `-` and must not start or end name.";
445
495
  }
496
+ // Check for any other syntax errors
497
+ if (!/^[a-z][a-z0-9.\-]*\-[a-z0-9.\-]*$/.test(value)) {
498
+ return `Name must follow the syntax ${_picocolors.default.bold("my-component")}`;
499
+ }
446
500
  // assumes auto was selected in CLI
447
501
  let joint = process.cwd();
448
502
  if (commandRun.options.path) {
@@ -459,12 +513,21 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
459
513
  console.error(_picocolors.default.red("Name is required (tab writes default)"));
460
514
  process.exit(1);
461
515
  }
516
+ if (reservedNames.includes(value)) {
517
+ console.error(_picocolors.default.red(`Reserved name ${_picocolors.default.bold(value)} cannot be used`));
518
+ process.exit(1);
519
+ }
462
520
  if (value.toLocaleLowerCase() !== value) {
463
521
  console.error(_picocolors.default.red("Name must be lowercase"));
464
522
  process.exit(1);
465
523
  }
466
524
  if (/^\d/.test(value)) {
467
525
  console.error(_picocolors.default.red("Name cannot start with a number"));
526
+ process.exit(1);
527
+ }
528
+ if (/[`~!@#$%^&*()_=+\[\]{}|;:\'",<.>\/?\\]/.test(value)) {
529
+ console.error(_picocolors.default.red("No special characters allowed in name"));
530
+ process.exit(1);
468
531
  }
469
532
  if (value.indexOf(' ') !== -1) {
470
533
  console.error(_picocolors.default.red("No spaces allowed in name"));
@@ -474,6 +537,11 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
474
537
  console.error(_picocolors.default.red("Name must include at least one `-` and must not start or end name."));
475
538
  process.exit(1);
476
539
  }
540
+ // Check for any other syntax errors
541
+ if (!/^[a-z][a-z0-9.\-]*\-[a-z0-9.\-]*$/.test(value)) {
542
+ console.error(_picocolors.default.red(`Name must follow the syntax ${_picocolors.default.bold("my-component")}`));
543
+ process.exit(1);
544
+ }
477
545
  // assumes auto was selected in CLI
478
546
  let joint = process.cwd();
479
547
  if (commandRun.options.path) {
@@ -500,9 +568,6 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
500
568
  let content = ejs.render(ejsString, project);
501
569
  // file written successfully
502
570
  fs.writeFileSync(filePath, content);
503
- if (packageData.customElements) {
504
- await webcomponentGenerateHAXSchema(commandRun, packageData);
505
- }
506
571
  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
572
  💻 Add to an HTML file: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`<script type="module" src="${project.name}"></script>`)))}`);
508
573
  // at least a second to see the message print at all
@@ -510,7 +575,7 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
510
575
  } catch (e) {
511
576
  (0, _logging.log)(e.stderr);
512
577
  // Original ejs.render error checking
513
- console.error(_picocolors.default.red(filePath));
578
+ console.error(_picocolors.default.red(process.cwd()));
514
579
  console.error(_picocolors.default.red(e));
515
580
  }
516
581
  break;
@@ -541,7 +606,7 @@ async function webcomponentCommandDetected(commandRun, packageData = {}, port =
541
606
  async function webcomponentGenerateHAXSchema(commandRun, packageData) {
542
607
  // run analyzer automatically if we have it so that it's up to date
543
608
  if (packageData.scripts.analyze) {
544
- await exec(`${commandRun.options.npmClient} run analyze`);
609
+ await (0, _utils.exec)(`${commandRun.options.npmClient} run analyze`);
545
610
  }
546
611
  if (fs.existsSync(`${process.cwd()}/${packageData.customElements}`)) {
547
612
  const ceFileData = fs.readFileSync(`${process.cwd()}/${packageData.customElements}`, 'utf8', (error, data) => {
package/dist/lib/utils.js CHANGED
@@ -7,15 +7,90 @@ exports.SITE_FILE_NAME = void 0;
7
7
  exports.camelToDash = camelToDash;
8
8
  exports.capitalizeFirstLetter = capitalizeFirstLetter;
9
9
  exports.dashToCamel = dashToCamel;
10
+ exports.exec = void 0;
10
11
  exports.generateUUID = generateUUID;
12
+ exports.getTimeDifference = getTimeDifference;
13
+ exports.interactiveExec = interactiveExec;
11
14
  exports.readAllFiles = readAllFiles;
15
+ exports.readConfigFile = readConfigFile;
16
+ exports.spawn = void 0;
17
+ exports.writeConfigFile = writeConfigFile;
12
18
  var fs = _interopRequireWildcard(require("node:fs"));
19
+ var os = _interopRequireWildcard(require("node:os"));
13
20
  var path = _interopRequireWildcard(require("node:path"));
14
21
  var child_process = _interopRequireWildcard(require("child_process"));
15
22
  var util = _interopRequireWildcard(require("node:util"));
16
23
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
24
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
- const exec = util.promisify(child_process.exec);
25
+ const exec = exports.exec = util.promisify(child_process.exec);
26
+ const spawn = exports.spawn = child_process.spawn;
27
+ function getTimeDifference(timestamp1, timestamp2) {
28
+ const time1 = new Date(timestamp1).getTime();
29
+ const time2 = new Date(timestamp2).getTime();
30
+ if (isNaN(time1) || isNaN(time2)) {
31
+ return "Invalid date format";
32
+ }
33
+ const difference = Math.abs(time2 - time1);
34
+ const seconds = Math.floor(difference / 1000);
35
+ const minutes = Math.floor(seconds / 60);
36
+ const hours = Math.floor(minutes / 60);
37
+ const days = Math.floor(hours / 24);
38
+ return {
39
+ days,
40
+ hours: hours % 24,
41
+ minutes: minutes % 60,
42
+ seconds: seconds % 60
43
+ };
44
+ }
45
+
46
+ // write user config file
47
+ function writeConfigFile(filename, data) {
48
+ let tempDir = os.homedir();
49
+ if (process.env.VERCEL_ENV) {
50
+ tempDir = "/tmp/";
51
+ }
52
+ const filePath = path.join(tempDir, '.haxtheweb', filename);
53
+ try {
54
+ fs.writeFileSync(filePath, data);
55
+ return filePath;
56
+ } catch (error) {
57
+ return null;
58
+ }
59
+ }
60
+
61
+ // read user config file
62
+ function readConfigFile(filename) {
63
+ let tempDir = os.homedir();
64
+ if (process.env.VERCEL_ENV) {
65
+ tempDir = "/tmp/";
66
+ }
67
+ const filePath = path.join(tempDir, '.haxtheweb', filename);
68
+ try {
69
+ let file = fs.readFileSync(filePath, 'utf8');
70
+ return file;
71
+ } catch (error) {
72
+ return null;
73
+ }
74
+ }
75
+ async function interactiveExec(command, args = [], options = {}) {
76
+ return new Promise((resolve, reject) => {
77
+ process.env.NODE_NO_WARNINGS = 1;
78
+ const child = spawn(command, args, {
79
+ stdio: 'inherit',
80
+ ...options
81
+ });
82
+ child.on('exit', code => {
83
+ if (code === 0) {
84
+ resolve();
85
+ } else {
86
+ reject(new Error(`Command failed with code ${code}`));
87
+ }
88
+ });
89
+ child.on('error', err => {
90
+ reject(err);
91
+ });
92
+ });
93
+ }
19
94
  const SITE_FILE_NAME = exports.SITE_FILE_NAME = "site.json";
20
95
  /**
21
96
  * Helper to convert dash to camel; important when reading attributes.