@haxtheweb/create 10.0.8 → 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.
@@ -14,6 +14,7 @@ exports.siteThemeList = siteThemeList;
14
14
  var _promises = require("node:timers/promises");
15
15
  var fs = _interopRequireWildcard(require("node:fs"));
16
16
  var path = _interopRequireWildcard(require("node:path"));
17
+ var _open = _interopRequireDefault(require("open"));
17
18
  var p = _interopRequireWildcard(require("@clack/prompts"));
18
19
  var ejs = _interopRequireWildcard(require("ejs"));
19
20
  var _picocolors = _interopRequireDefault(require("picocolors"));
@@ -27,8 +28,6 @@ var _microFrontendRegistry = require("../micro-frontend-registry.js");
27
28
  var haxcmsNodejsCli = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs/dist/cli.js"));
28
29
  var hax = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs"));
29
30
  var josfile = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs/dist/lib/JSONOutlineSchema.js"));
30
- var child_process = _interopRequireWildcard(require("child_process"));
31
- var util = _interopRequireWildcard(require("node:util"));
32
31
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
32
  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); }
34
33
  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; }
@@ -40,29 +39,8 @@ globalThis.MicroFrontendRegistryConfig = {
40
39
  _microFrontendRegistry.MicroFrontendRegistry.enableServices(['core', 'haxcms', 'experimental']);
41
40
  const JSONOutlineSchema = josfile.default;
42
41
  const HAXCMS = hax.HAXCMS;
43
- const exec = util.promisify(child_process.exec);
44
- const spawn = child_process.spawn;
45
- async function interactiveExec(command, args = [], options = {}) {
46
- return new Promise((resolve, reject) => {
47
- process.env.NODE_NO_WARNINGS = 1;
48
- const child = spawn(command, args, {
49
- stdio: 'inherit',
50
- ...options
51
- });
52
- child.on('exit', code => {
53
- if (code === 0) {
54
- resolve();
55
- } else {
56
- reject(new Error(`Command failed with code ${code}`));
57
- }
58
- });
59
- child.on('error', err => {
60
- reject(err);
61
- });
62
- });
63
- }
64
42
  var sysSurge = true;
65
- exec('surge --version', error => {
43
+ (0, _utils.exec)('surge --version', error => {
66
44
  if (error) {
67
45
  sysSurge = false;
68
46
  }
@@ -100,6 +78,9 @@ function siteActions() {
100
78
  return [{
101
79
  value: 'start',
102
80
  label: "Launch site in browser (http://localhost)"
81
+ }, {
82
+ value: 'serve',
83
+ label: "Launch site in development mode"
103
84
  }, {
104
85
  value: 'node:stats',
105
86
  label: "Node Stats / data"
@@ -127,6 +108,9 @@ function siteActions() {
127
108
  }, {
128
109
  value: 'site:theme',
129
110
  label: "Change theme"
111
+ }, {
112
+ value: 'site:element',
113
+ label: "Add new Lit component to custom/src"
130
114
  }, {
131
115
  value: 'site:html',
132
116
  label: "Full site as HTML"
@@ -148,6 +132,12 @@ function siteActions() {
148
132
  }, {
149
133
  value: 'recipe:play',
150
134
  label: "Play recipe file"
135
+ }, {
136
+ value: 'issue:general',
137
+ label: "Issue: Submit an issue or suggestion"
138
+ }, {
139
+ value: 'issue:theme',
140
+ label: "Issue: Suggest custom theme"
151
141
  }];
152
142
  }
153
143
  async function siteCommandDetected(commandRun) {
@@ -375,9 +365,23 @@ async function siteCommandDetected(commandRun) {
375
365
  try {
376
366
  if (!commandRun.options.quiet) {
377
367
  p.intro(`Starting server.. `);
378
- p.intro(`⌨️ To stop server, press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}`);
368
+ p.note(`🚀 Server running at: ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:3000`))}
369
+ ⌨️ To stop server, press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C or CTRL + BREAK `)))}`);
370
+ }
371
+ await (0, _utils.exec)(`cd ${activeHaxsite.directory} && npx @haxtheweb/haxcms-nodejs`);
372
+ } catch (e) {
373
+ (0, _logging.log)(e.stderr);
374
+ }
375
+ break;
376
+ case "serve":
377
+ try {
378
+ if (!commandRun.options.quiet) {
379
+ p.intro(`Starting server in development mode.. `);
380
+ p.note(`🚀 Server running at: ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:3000`))}
381
+ 💻 Site will live reload on changes to ${_picocolors.default.bold('custom/src')}
382
+ ⌨️ To stop server, press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C or CTRL + BREAK `)))}`);
379
383
  }
380
- await exec(`cd ${activeHaxsite.directory} && npx @haxtheweb/haxcms-nodejs`);
384
+ await (0, _utils.exec)(`cd ${activeHaxsite.directory} && NODE_ENV=development npx @haxtheweb/haxcms-nodejs`);
381
385
  } catch (e) {
382
386
  (0, _logging.log)(e.stderr);
383
387
  }
@@ -756,7 +760,7 @@ async function siteCommandDetected(commandRun) {
756
760
  case "site:sync":
757
761
  // @todo git sync might need other arguments / be combined with publishing
758
762
  try {
759
- await exec(`cd ${activeHaxsite.directory} && git pull && git push`);
763
+ await (0, _utils.exec)(`cd ${activeHaxsite.directory} && git pull && git push`);
760
764
  } catch (e) {
761
765
  (0, _logging.log)(e.stderr);
762
766
  }
@@ -845,6 +849,135 @@ async function siteCommandDetected(commandRun) {
845
849
  (0, _logging.log)(e.stderr);
846
850
  }
847
851
  break;
852
+ case "site:element":
853
+ try {
854
+ const reservedNames = ["annotation-xml", "color-profile", "font-face", "font-face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph"];
855
+ activeHaxsite = await hax.systemStructureContext();
856
+ if (!commandRun.options.name) {
857
+ commandRun.options.name = await p.text({
858
+ message: 'Component name:',
859
+ placeholder: 'my-component',
860
+ required: true,
861
+ validate: value => {
862
+ if (!value) {
863
+ return "Name is required (tab writes default)";
864
+ }
865
+ if (reservedNames.includes(value)) {
866
+ return `Reserved name ${_picocolors.default.bold(value)} cannot be used`;
867
+ }
868
+ if (value.toLocaleLowerCase() !== value) {
869
+ return "Name must be lowercase";
870
+ }
871
+ if (/^\d/.test(value)) {
872
+ return "Name cannot start with a number";
873
+ }
874
+ if (/[`~!@#$%^&*()_=+\[\]{}|;:\'",<.>\/?\\]/.test(value)) {
875
+ return "No special characters allowed in name";
876
+ }
877
+ if (value.indexOf(' ') !== -1) {
878
+ return "No spaces allowed in name";
879
+ }
880
+ if (value.indexOf('-') === -1 || value.replace('--', '') !== value || value[0] === '-' || value[value.length - 1] === '-') {
881
+ return "Name must include at least one `-` and must not start or end name.";
882
+ }
883
+ // Check for any other syntax errors
884
+ if (!/^[a-z][a-z0-9.\-]*\-[a-z0-9.\-]*$/.test(value)) {
885
+ return `Name must follow the syntax ${_picocolors.default.bold("my-component")}`;
886
+ }
887
+ // assumes auto was selected in CLI
888
+ let joint = process.cwd();
889
+ if (commandRun.options.path) {
890
+ joint = commandRun.options.path;
891
+ }
892
+ if (fs.existsSync(path.join(joint, value))) {
893
+ return `${path.join(joint, value)} exists, rename this project`;
894
+ }
895
+ }
896
+ });
897
+ } else {
898
+ let value = commandRun.options.name;
899
+ if (!value) {
900
+ console.error(_picocolors.default.red("Name is required (tab writes default)"));
901
+ process.exit(1);
902
+ }
903
+ if (reservedNames.includes(value)) {
904
+ console.error(_picocolors.default.red(`Reserved name ${_picocolors.default.bold(value)} cannot be used`));
905
+ process.exit(1);
906
+ }
907
+ if (value.toLocaleLowerCase() !== value) {
908
+ console.error(_picocolors.default.red("Name must be lowercase"));
909
+ process.exit(1);
910
+ }
911
+ if (/^\d/.test(value)) {
912
+ console.error(_picocolors.default.red("Name cannot start with a number"));
913
+ process.exit(1);
914
+ }
915
+ if (/[`~!@#$%^&*()_=+\[\]{}|;:\'",<.>\/?\\]/.test(value)) {
916
+ console.error(_picocolors.default.red("No special characters allowed in name"));
917
+ process.exit(1);
918
+ }
919
+ if (value.indexOf(' ') !== -1) {
920
+ console.error(_picocolors.default.red("No spaces allowed in name"));
921
+ process.exit(1);
922
+ }
923
+ if (value.indexOf('-') === -1 || value.replace('--', '') !== value || value[0] === '-' || value[value.length - 1] === '-') {
924
+ console.error(_picocolors.default.red("Name must include at least one `-` and must not start or end name."));
925
+ process.exit(1);
926
+ }
927
+ // Check for any other syntax errors
928
+ if (!/^[a-z][a-z0-9.\-]*\-[a-z0-9.\-]*$/.test(value)) {
929
+ console.error(_picocolors.default.red(`Name must follow the syntax ${_picocolors.default.bold("my-component")}`));
930
+ process.exit(1);
931
+ }
932
+ // assumes auto was selected in CLI
933
+ let joint = process.cwd();
934
+ if (commandRun.options.path) {
935
+ joint = commandRun.options.path;
936
+ }
937
+ if (fs.existsSync(path.join(joint, value))) {
938
+ console.error(_picocolors.default.red(`${path.join(joint, value)} exists, rename this project`));
939
+ process.exit(1);
940
+ }
941
+ }
942
+ const project = {
943
+ name: commandRun.options.name,
944
+ path: activeHaxsite.directory,
945
+ className: (0, _utils.dashToCamel)(commandRun.options.name),
946
+ year: new Date().getFullYear()
947
+ };
948
+ if (!project.author) {
949
+ try {
950
+ let value = await (0, _utils.exec)(`git config user.name`);
951
+ project.author = value.stdout.trim();
952
+ } catch (e) {
953
+ (0, _logging.log)(`
954
+ git user name not configured. Run the following to do this:\n
955
+ git config --global user.name "namehere"\n
956
+ git config --global user.email "email@here`, 'debug');
957
+ }
958
+ }
959
+ const filePath = `${project.path}/custom/src/${project.name}.js`;
960
+ await fs.copyFileSync(`${process.mainModule.path}/templates/generic/sitecomponent.js`, filePath);
961
+ const ejsString = ejs.fileLoader(filePath, 'utf8');
962
+ let content = ejs.render(ejsString, project);
963
+ // file written successfully
964
+ fs.writeFileSync(filePath, content);
965
+ if (!commandRun.options.npmClient) {
966
+ commandRun.options.npmClient = 'npm';
967
+ }
968
+ if (fs.existsSync(`${project.path}/custom/custom-elements.json`)) {
969
+ await (0, _utils.exec)(`cd custom && ${commandRun.options.npmClient} run analyze`);
970
+ }
971
+ p.note(`🧙 Add to another web component (.js): ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`import ./${project.name}.js`))))}`);
972
+ // at least a second to see the message print at all
973
+ await (0, _promises.setTimeout)(1000);
974
+ } catch (e) {
975
+ (0, _logging.log)(e.stderr);
976
+ // Original ejs.render error checking
977
+ console.error(_picocolors.default.red(process.cwd()));
978
+ console.error(_picocolors.default.red(e));
979
+ }
980
+ break;
848
981
  case "site:surge":
849
982
  try {
850
983
  // attempt to install; implies they asked to publish with surge but
@@ -852,7 +985,7 @@ async function siteCommandDetected(commandRun) {
852
985
  if (!sysSurge) {
853
986
  let s = p.spinner();
854
987
  s.start((0, _statements.merlinSays)('Installing Surge.sh globally so we can publish'));
855
- let execOutput = await exec(`npm install --global surge`);
988
+ let execOutput = await (0, _utils.exec)(`npm install --global surge`);
856
989
  s.stop((0, _statements.merlinSays)('surge.sh installed globally'));
857
990
  (0, _logging.log)(execOutput.stdout.trim());
858
991
  sysSurge = true;
@@ -861,7 +994,7 @@ async function siteCommandDetected(commandRun) {
861
994
  if (commandRun.options.domain && commandRun.options.y) {
862
995
  let s = p.spinner();
863
996
  s.start((0, _statements.merlinSays)('Sending site to Surge.sh ..'));
864
- execOutput = await exec(`cd ${activeHaxsite.directory} && surge . ${commandRun.options.domain}`);
997
+ execOutput = await (0, _utils.exec)(`cd ${activeHaxsite.directory} && surge . ${commandRun.options.domain}`);
865
998
  (0, _logging.log)(execOutput.stdout.trim());
866
999
  s.stop((0, _statements.merlinSays)(`Site published: https://${commandRun.options.domain}`));
867
1000
  } else {
@@ -870,7 +1003,7 @@ async function siteCommandDetected(commandRun) {
870
1003
  if (commandRun.options.domain) {
871
1004
  surgeArgs.push(commandRun.options.domain);
872
1005
  }
873
- execOutput = await interactiveExec('surge', surgeArgs, {
1006
+ execOutput = await (0, _utils.interactiveExec)('surge', surgeArgs, {
874
1007
  cwd: activeHaxsite.directory
875
1008
  });
876
1009
  (0, _logging.log)((0, _statements.merlinSays)(`Site published: https://${commandRun.options.domain}`));
@@ -1013,14 +1146,14 @@ async function siteCommandDetected(commandRun) {
1013
1146
  let commandMatch = siteActions().filter(action => action.value === commandList[i].split(' ')[2]);
1014
1147
  // if we found a command that means it is a valid command to run against the site
1015
1148
  if (commandMatch.length > 0) {
1016
- await exec(`${commandList[i]} --y --no-i --auto --quiet${rootDir}`);
1149
+ await (0, _utils.exec)(`${commandList[i]} --y --no-i --auto --quiet${rootDir}`);
1017
1150
  }
1018
1151
  // 1st command won't match as the argument creates a new site
1019
1152
  // but ensure we don't have a site context prior to running this
1020
1153
  // or we'll get a site in a site with the same name which is not
1021
1154
  // the desired result
1022
1155
  else if (!(await hax.systemStructureContext())) {
1023
- await exec(`${commandList[i]} --y --no-i --auto --quiet --no-extras`);
1156
+ await (0, _utils.exec)(`${commandList[i]} --y --no-i --auto --quiet --no-extras`);
1024
1157
  // site will have been created, obtain the site name and set root so
1025
1158
  // the other commands get piped into it correctly
1026
1159
  rootDir = ` --root ${commandList[i].split(' ')[2]}`;
@@ -1032,6 +1165,40 @@ async function siteCommandDetected(commandRun) {
1032
1165
  }
1033
1166
  }
1034
1167
  break;
1168
+ case "issue:general":
1169
+ // open the issues
1170
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Submit issue / suggestion on Github `))}`);
1171
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Opening in browser `))}`);
1172
+ await (0, _open.default)("https://github.com/haxtheweb/issues/issues/new");
1173
+ p.outro(`${_picocolors.default.bgBlue(_picocolors.default.white(` https://github.com/haxtheweb/issues/issues/new `))}`);
1174
+ break;
1175
+ case "issue:theme":
1176
+ // open the issues
1177
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Submit custom theme on Github `))}`);
1178
+ p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Opening in browser `))}`);
1179
+ let allContents = '';
1180
+ fs.readdir(`${activeHaxsite.directory}/custom/src`, (err, files) => {
1181
+ if (err) {
1182
+ console.error('Error reading directory:', err);
1183
+ return;
1184
+ }
1185
+ files.forEach((file, index) => {
1186
+ const filePath = path.join(`${activeHaxsite.directory}/custom/src`, file);
1187
+ if (fs.lstatSync(filePath).isFile()) {
1188
+ const content = fs.readFileSync(filePath, 'utf-8');
1189
+ // append file name as a JS comment
1190
+ allContents += `\n// FILENAME: ${file}\n` + content + '\n'; // Add newline between files if desired
1191
+ }
1192
+ if (index === files.length - 1) {
1193
+ console.log('Combined contents of all files:\n', allContents);
1194
+ }
1195
+ });
1196
+ });
1197
+ console.log(allContents);
1198
+ await (0, _open.default)(`https://github.com/haxtheweb/issues/issues/new?template=new-design.md`);
1199
+ p.outro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Copy the output of the console into the issue's js template area `))}`);
1200
+ p.outro(`${_picocolors.default.bgBlue(_picocolors.default.white(` https://github.com/haxtheweb/issues/issues/new?template=new-design.md `))}`);
1201
+ break;
1035
1202
  case "quit":
1036
1203
  // quit
1037
1204
  process.exit(0);
@@ -1311,7 +1478,7 @@ async function siteProcess(commandRun, project, port = '3000') {
1311
1478
  }
1312
1479
  if (project.gitRepo && !commandRun.options.isMonorepo) {
1313
1480
  try {
1314
- 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}` : ''}`);
1481
+ 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}` : ''}`);
1315
1482
  } catch (e) {}
1316
1483
  }
1317
1484
  // ensure dot files is there because it doesn't copy for some reason for sites :\
@@ -1341,13 +1508,13 @@ ${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${por
1341
1508
  📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${optionPath}`)))}
1342
1509
  🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${command}`)))}
1343
1510
 
1344
- ⌨️ To resume 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
1511
+ ⌨️ To resume 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C or CTRL + BREAK `)))}
1345
1512
  `);
1346
1513
  }
1347
1514
  // at least a second to see the message print at all
1348
1515
  await (0, _promises.setTimeout)(1000);
1349
1516
  try {
1350
- await exec(`cd ${optionPath} && ${command}`);
1517
+ await (0, _utils.exec)(`cd ${optionPath} && ${command}`);
1351
1518
  } catch (e) {
1352
1519
  // don't log bc output is weird
1353
1520
  }
@@ -1384,17 +1551,14 @@ async function siteThemeList(coreOnly = true, directory = null) {
1384
1551
  value: 'clean-portfolio-theme',
1385
1552
  label: 'Clean Portfolio'
1386
1553
  }, {
1387
- value: 'haxor-slevin',
1388
- label: 'Haxor Blog'
1554
+ value: 'journey-theme',
1555
+ label: 'Journey'
1389
1556
  }, {
1390
1557
  value: 'polaris-flex-theme',
1391
- label: 'Polaris - Flex'
1558
+ label: 'Flex'
1392
1559
  }, {
1393
1560
  value: 'polaris-flex-sidebar',
1394
- label: 'Polaris - Flex Sidebar'
1395
- }, {
1396
- value: 'polaris-invent-theme',
1397
- label: 'Polaris - Invent'
1561
+ label: 'Flex Sidebar'
1398
1562
  }, {
1399
1563
  value: 'custom-theme',
1400
1564
  label: 'Create Custom Theme'
@@ -1456,7 +1620,7 @@ async function customSiteTheme(commandRun, project) {
1456
1620
  }
1457
1621
  if (!project.author) {
1458
1622
  try {
1459
- let value = await exec(`git config user.name`);
1623
+ let value = await (0, _utils.exec)(`git config user.name`);
1460
1624
  project.author = value.stdout.trim();
1461
1625
  } catch (e) {
1462
1626
  (0, _logging.log)(`
@@ -1493,7 +1657,7 @@ async function customSiteTheme(commandRun, project) {
1493
1657
  }
1494
1658
 
1495
1659
  // import theme to custom.js
1496
- await fs.appendFileSync(`${sitePath}/custom/src/custom.js`, `\n import "./${project.customThemeName}.js"`);
1660
+ await fs.appendFileSync(`${sitePath}/custom/src/custom.js`, `\n import "./${project.customThemeName}.js";`);
1497
1661
  var activeHaxsite = await hax.systemStructureContext(sitePath);
1498
1662
 
1499
1663
  // add theme to site.json
@@ -1506,7 +1670,7 @@ async function customSiteTheme(commandRun, project) {
1506
1670
  activeHaxsite.manifest.save(false);
1507
1671
 
1508
1672
  // install and build theme dependencies
1509
- await exec(`cd ${sitePath}/custom/ && ${commandRun.options.npmClient} install && ${commandRun.options.npmClient} run build && ${commandRun.options.npmClient} run analyze && cd ${sitePath}`);
1673
+ await (0, _utils.exec)(`cd ${sitePath}/custom/ && ${commandRun.options.npmClient} install && ${commandRun.options.npmClient} run build && ${commandRun.options.npmClient} run analyze && cd ${sitePath}`);
1510
1674
  }
1511
1675
 
1512
1676
  // @fork of the hax core util for this so that we avoid api difference between real dom and parse nodejs dom
@@ -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) => {