@haxtheweb/create 10.0.0 → 10.0.2

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
@@ -363,6 +363,11 @@ async function main() {
363
363
  results
364
364
  }) => {
365
365
  let themes = await (0, _site.siteThemeList)();
366
+ let custom = {
367
+ value: 'custom-theme',
368
+ label: 'Create Custom Theme'
369
+ };
370
+ themes.push(custom);
366
371
  if (results.type === "site" && !commandRun.options.theme) {
367
372
  // support having no theme but autoselecting
368
373
  if (commandRun.options.auto && commandRun.options.skip) {
@@ -377,6 +382,53 @@ async function main() {
377
382
  }
378
383
  }
379
384
  },
385
+ customName({
386
+ results
387
+ }) {
388
+ if (results.theme === "custom-theme") {
389
+ return p.text({
390
+ message: 'Theme Name:',
391
+ placeholder: results.theme,
392
+ required: false,
393
+ validate: value => {
394
+ if (!value) {
395
+ return "Name is required (tab writes default)";
396
+ }
397
+ if (/^\d/.test(value)) {
398
+ return "Name cannot start with a number";
399
+ }
400
+ if (value.indexOf(' ') !== -1) {
401
+ return "No spaces allowed in project name";
402
+ }
403
+ if (value.indexOf('-') === -1 && value.indexOf('-') !== 0 && value.indexOf('-') !== value.length - 1) {
404
+ return "Name must include at least one `-` and must not start or end name.";
405
+ }
406
+ }
407
+ });
408
+ }
409
+ },
410
+ customTemplate({
411
+ results
412
+ }) {
413
+ if (results.theme === "custom-theme") {
414
+ const options = [{
415
+ value: 'base',
416
+ label: 'Vanilla Theme with Hearty Documentation'
417
+ }, {
418
+ value: 'polaris-flex',
419
+ label: 'Minimalist Theme with Horizontal Nav'
420
+ }, {
421
+ value: 'polaris-sidebar',
422
+ label: 'Content-Focused Theme with Flexible Sidebar'
423
+ }];
424
+ return p.select({
425
+ message: 'Template:',
426
+ required: false,
427
+ options: options,
428
+ initialValue: `${results.theme}`
429
+ });
430
+ }
431
+ },
380
432
  extras: ({
381
433
  results
382
434
  }) => {
@@ -15,11 +15,13 @@ var _promises = require("node:timers/promises");
15
15
  var fs = _interopRequireWildcard(require("node:fs"));
16
16
  var path = _interopRequireWildcard(require("node:path"));
17
17
  var p = _interopRequireWildcard(require("@clack/prompts"));
18
+ var ejs = _interopRequireWildcard(require("ejs"));
18
19
  var _picocolors = _interopRequireDefault(require("picocolors"));
19
20
  var _jsYaml = require("js-yaml");
20
21
  var winston = _interopRequireWildcard(require("winston"));
21
22
  var _nodeHtmlParser = require("node-html-parser");
22
23
  var _statements = require("../statements.js");
24
+ var _utils = require("../utils.js");
23
25
  var _logging = require("../logging.js");
24
26
  var _microFrontendRegistry = require("../micro-frontend-registry.js");
25
27
  var haxcmsNodejsCli = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs/dist/cli.js"));
@@ -752,12 +754,12 @@ async function siteCommandDetected(commandRun) {
752
754
  initialValue: val,
753
755
  options: list
754
756
  });
755
- let themes = await HAXCMS.getThemes();
756
- if (themes && commandRun.options.theme && themes[commandRun.options.theme]) {
757
- activeHaxsite.manifest.metadata.theme = themes[commandRun.options.theme];
758
- activeHaxsite.manifest.save(false);
759
- recipe.log(siteLoggingName, (0, _logging.commandString)(commandRun));
760
- }
757
+ }
758
+ 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));
761
763
  }
762
764
  } catch (e) {
763
765
  (0, _logging.log)(e.stderr);
@@ -1208,6 +1210,13 @@ async function siteProcess(commandRun, project, port = '3000') {
1208
1210
  s.stop((0, _statements.merlinSays)(`${project.name} created!`));
1209
1211
  await (0, _promises.setTimeout)(500);
1210
1212
  }
1213
+
1214
+ // Write theme template to site/custom
1215
+ if (project.customName && project.customTemplate) {
1216
+ s.start((0, _statements.merlinSays)(`Creating new theme: ${project.customName}`));
1217
+ await customSiteTheme(commandRun, project);
1218
+ s.stop((0, _statements.merlinSays)(`${project.customName} theme created!`));
1219
+ }
1211
1220
  if (project.gitRepo && !commandRun.options.isMonorepo) {
1212
1221
  try {
1213
1222
  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}` : ''}`);
@@ -1271,6 +1280,43 @@ async function siteThemeList() {
1271
1280
  }
1272
1281
  return items;
1273
1282
  }
1283
+ async function customSiteTheme(commandRun, project) {
1284
+ project.className = (0, _utils.dashToCamel)(project.customName);
1285
+ var sitePath = `${project.path}/${project.name}`;
1286
+ const filePath = `${sitePath}/custom/src/${project.customName}.js`;
1287
+ if (project.customTemplate === "base") {
1288
+ await fs.copyFileSync(`${process.mainModule.path}/templates/sitetheme/base-theme.js`, `${sitePath}/custom/src/base-theme.js`);
1289
+ await fs.renameSync(`${sitePath}/custom/src/base-theme.js`, filePath);
1290
+ } else if (project.customTemplate === "polaris-flex") {
1291
+ await fs.copyFileSync(`${process.mainModule.path}/templates/sitetheme/flex-theme.js`, `${sitePath}/custom/src/flex-theme.js`);
1292
+ await fs.renameSync(`${sitePath}/custom/src/flex-theme.js`, filePath);
1293
+ } else if (project.customTemplate === "polaris-sidebar") {
1294
+ await fs.copyFileSync(`${process.mainModule.path}/templates/sitetheme/sidebar-theme.js`, `${sitePath}/custom/src/sidebar-theme.js`);
1295
+ await fs.renameSync(`${sitePath}/custom/src/sidebar-theme.js`, filePath);
1296
+ }
1297
+ try {
1298
+ // ensure we don't try to pattern rewrite image files
1299
+ if (!filePath.endsWith('.jpg') && !filePath.endsWith('.png')) {
1300
+ const ejsString = ejs.fileLoader(filePath, 'utf8');
1301
+ let content = ejs.render(ejsString, project);
1302
+ // file written successfully
1303
+ fs.writeFileSync(filePath, content);
1304
+ }
1305
+ } catch (err) {
1306
+ console.error(filePath);
1307
+ console.error(err);
1308
+ }
1309
+ await fs.appendFileSync(`${sitePath}/custom/src/custom.js`, `\n import "./${project.customName}.js"`);
1310
+ var activeHaxsite = await hax.systemStructureContext(sitePath);
1311
+ let themeObj = {
1312
+ element: project.customName,
1313
+ path: filePath,
1314
+ name: project.className
1315
+ };
1316
+ activeHaxsite.manifest.metadata.theme = themeObj;
1317
+ activeHaxsite.manifest.save(false);
1318
+ await exec(`cd ${sitePath}/custom/ && ${commandRun.options.npmClient} install && ${commandRun.options.npmClient} run build && cd ${sitePath}`);
1319
+ }
1274
1320
 
1275
1321
  // @fork of the hax core util for this so that we avoid api difference between real dom and parse nodejs dom
1276
1322
  async function nodeToHaxElement(node, eventName = "insert-element") {
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright <%= year %> <%= author %>
3
+ * @license Apache-2.0, see License.md for full text.
4
+ */
5
+ import { html, css, HAXCMSLitElementTheme } from "@haxtheweb/haxcms-elements/lib/core/HAXCMSLitElementTheme.js";
6
+
7
+ /**
8
+ * `<%= className %>`
9
+ * `<%= className %> based on modern flex design system`
10
+ * `This theme is an example of extending an existing theme component`
11
+ *
12
+ * @microcopy - language worth noting:
13
+ * - HAXcms - A headless content management system
14
+ * - HAXCMSTheme - A super class that provides correct baseline wiring to build a new theme
15
+ *
16
+ * @demo demo/index.html
17
+ * @element <%= customName %>
18
+ */
19
+ class <%= className %> extends HAXCMSLitElementTheme {
20
+ //styles function
21
+ static get styles() {
22
+ return [
23
+ super.styles,
24
+ css`
25
+ :host {
26
+ display: block;
27
+ }
28
+ `,
29
+ ];
30
+ }
31
+
32
+ /**
33
+ * Store the tag name to make it easier to obtain directly.
34
+ * @notice function name must be here for tooling to operate correctly
35
+ */
36
+ static get tag() {
37
+ return "<%= customName %>";
38
+ }
39
+
40
+ constructor() {
41
+ super();
42
+ }
43
+ }
44
+ customElements.define(<%= className %>.tag, <%= className %>);
45
+ export { <%= className %> };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Copyright <%= year %> <%= author %>
3
+ * @license Apache-2.0, see License.md for full text.
4
+ */
5
+ import { html, css, HAXCMSLitElementTheme } from "@haxtheweb/haxcms-elements/lib/core/HAXCMSLitElementTheme.js";
6
+ import { PolarisFlexTheme } from "@haxtheweb/polaris-theme/lib/polaris-flex-theme";
7
+ import "@haxtheweb/haxcms-elements/lib/ui-components/blocks/site-children-block.js";
8
+
9
+ /**
10
+ * `<%= className %>`
11
+ * `<%= className %> based on modern flex design system`
12
+ * `This theme is an example of extending an existing theme component`
13
+ *
14
+ * @microcopy - language worth noting:
15
+ * - HAXcms - A headless content management system
16
+ * - HAXCMSTheme - A super class that provides correct baseline wiring to build a new theme
17
+ *
18
+ * @demo demo/index.html
19
+ * @element <%= customName %>
20
+ */
21
+ class <%= className %> extends PolarisFlexTheme {
22
+ //styles function
23
+ static get styles() {
24
+ return [
25
+ super.styles,
26
+ css`
27
+ :host {
28
+ display: block;
29
+ }
30
+ `,
31
+ ];
32
+ }
33
+
34
+ /**
35
+ * Overload methods for customization of slots from the base class
36
+ */
37
+ renderHeaderSlot() {
38
+ return html``
39
+ }
40
+
41
+ renderFooterContactInformation() {
42
+ return html``
43
+ }
44
+
45
+ renderFooterSecondarySlot() {
46
+ return html``
47
+ }
48
+
49
+ renderFooterPrimarySlot() {
50
+ return html``
51
+ }
52
+
53
+ /**
54
+ * Store the tag name to make it easier to obtain directly.
55
+ * @notice function name must be here for tooling to operate correctly
56
+ */
57
+ static get tag() {
58
+ return "<%= customName %>";
59
+ }
60
+
61
+ constructor() {
62
+ super();
63
+ }
64
+ }
65
+ customElements.define(<%= className %>.tag, <%= className %>);
66
+ export { <%= className %> };
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Copyright <%= year %> <%= author %>
3
+ * @license Apache-2.0, see License.md for full text.
4
+ */
5
+ import { html, css, HAXCMSLitElementTheme } from "@haxtheweb/haxcms-elements/lib/core/HAXCMSLitElementTheme.js";
6
+ import { PolarisFlexTheme } from "@haxtheweb/polaris-theme/lib/polaris-flex-theme";
7
+ import "@haxtheweb/haxcms-elements/lib/ui-components/blocks/site-children-block.js";
8
+
9
+ /**
10
+ * `<%= className %>`
11
+ * `<%= className %> based on modern flex design system`
12
+ * `This theme is an example of extending an existing theme component`
13
+ *
14
+ * @microcopy - language worth noting:
15
+ * - HAXcms - A headless content management system
16
+ * - HAXCMSTheme - A super class that provides correct baseline wiring to build a new theme
17
+ *
18
+ * @demo demo/index.html
19
+ * @element <%= customName %>
20
+ */
21
+ class <%= className %> extends PolarisFlexTheme {
22
+ //styles function
23
+ static get styles() {
24
+ return [
25
+ super.styles,
26
+ css`
27
+ :host {
28
+ display: block;
29
+ }
30
+ aside {
31
+ float: left;
32
+ width: 240px;
33
+ }
34
+ aside section h4 {
35
+ font-size: 16px;
36
+ margin: 0 0 24px 0;
37
+ text-transform: uppercase;
38
+ font-family: "Open Sans", sans-serif;
39
+ font-weight: 300;
40
+ }
41
+
42
+ aside section {
43
+ background-color: #fff;
44
+ border-radius: 3px;
45
+ margin-bottom: 40px;
46
+ padding: 0px 40px 40px 0px;
47
+ }
48
+
49
+ site-children-block {
50
+ --site-children-block-border-bottom: lightblue 1px solid;
51
+ --site-children-block-li-padding: 8px 0;
52
+ --site-children-block-link-hover-color: rgb(0, 95, 169);
53
+ --site-children-block-active-border-left: rgb(0, 95, 169) 3px solid;
54
+ --site-children-block-link-active-color: rgb(0, 30, 68);
55
+ font-family: "Roboto Condensed", sans-serif;
56
+ font-size: 16px;
57
+ }
58
+ `,
59
+ ];
60
+ }
61
+
62
+ /**
63
+ * Overload methods for customization of slots from the base class
64
+ */
65
+ renderHeaderSlot() {
66
+ return html``
67
+ }
68
+
69
+ renderSideBar() {
70
+ return html`
71
+ <aside
72
+ role="complementary"
73
+ aria-label="Primary Sidebar"
74
+ itemtype="http://schema.org/WPSideBar"
75
+ part="page-primary-sidebar"
76
+ >
77
+ <section>
78
+ <site-children-block
79
+ part="page-children-block"
80
+ dynamic-methodology="ancestor"
81
+ ></site-children-block>
82
+ </section>
83
+ </aside>
84
+ `
85
+ }
86
+
87
+ renderFooterContactInformation() {
88
+ return html``
89
+ }
90
+
91
+ renderFooterSecondarySlot() {
92
+ return html``
93
+ }
94
+
95
+ renderFooterPrimarySlot() {
96
+ return html``
97
+ }
98
+
99
+ /**
100
+ * Store the tag name to make it easier to obtain directly.
101
+ * @notice function name must be here for tooling to operate correctly
102
+ */
103
+ static get tag() {
104
+ return "<%= customName %>";
105
+ }
106
+
107
+ constructor() {
108
+ super();
109
+ }
110
+ }
111
+ customElements.define(<%= className %>.tag, <%= className %>);
112
+ export { <%= className %> };
@@ -28,8 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "lit": "^3.2.1",
31
- "@haxtheweb/d-d-d": "^9.0.21",
32
- "@haxtheweb/i18n-manager": "^9.0.18"
31
+ "@haxtheweb/d-d-d": "^10.0.1",
32
+ "@haxtheweb/i18n-manager": "^10.0.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@babel/preset-env": "^7.16.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haxtheweb/create",
3
- "version": "10.0.0",
3
+ "version": "10.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -45,12 +45,12 @@
45
45
  "dependencies": {
46
46
  "@clack/core": "0.3.4",
47
47
  "@clack/prompts": "0.7.0",
48
- "@haxtheweb/haxcms-nodejs": "^10.0.0",
48
+ "@haxtheweb/haxcms-nodejs": "^10.0.1",
49
49
  "@haxtheweb/open-apis": "^10.0.1",
50
50
  "commander": "12.1.0",
51
- "node-html-parser": "6.1.13",
52
51
  "ejs": "3.1.10",
53
52
  "js-yaml": "4.1.0",
53
+ "node-html-parser": "6.1.13",
54
54
  "picocolors": "1.0.1",
55
55
  "winston": "3.17.0"
56
56
  },