@haxtheweb/create 9.0.12 → 9.0.13
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 +7 -5
- package/dist/lib/programs/site.js +169 -24
- package/package.json +2 -2
package/dist/create.js
CHANGED
|
@@ -28,7 +28,7 @@ exec('git --version', error => {
|
|
|
28
28
|
});
|
|
29
29
|
async function main() {
|
|
30
30
|
var commandRun = {};
|
|
31
|
-
_commander.program.option('--').option('--v', 'Verbose output').option('--debug', 'Output for developers').option('--format <char>', 'Output format; json (default), yaml').option('--path <char>', 'where to perform operation').option('--npm-client <char>', 'npm client to use (must be installed) npm, yarn, pnpm', 'npm').option('--y', 'yes to all questions').option('--skip', 'skip frills like animations').option('--auto', 'yes to all questions, alias of y')
|
|
31
|
+
_commander.program.option('--').option('--v', 'Verbose output').option('--debug', 'Output for developers').option('--format <char>', 'Output format; json (default), yaml').option('--path <char>', 'where to perform operation').option('--npm-client <char>', 'npm client to use (must be installed) npm, yarn, pnpm', 'npm').option('--y', 'yes to all questions').option('--skip', 'skip frills like animations').option('--auto', 'yes to all questions, alias of y').option('--no-i', 'prevent interactions / sub-process, good for scripting')
|
|
32
32
|
|
|
33
33
|
// options for webcomponent
|
|
34
34
|
.option('--org <char>', 'organization for package.json').option('--author <char>', 'author for site / package.json').option('--writeHaxProperties', 'Write haxProperties for the element')
|
|
@@ -61,7 +61,7 @@ async function main() {
|
|
|
61
61
|
commandRun.arguments.action = action;
|
|
62
62
|
commandRun.options.skip = true;
|
|
63
63
|
}
|
|
64
|
-
}).option('--path <char>', 'path the project should be created in').option('--import-site <char>', 'URL of site to import').option('--import-structure <char>', `import method to use:\n\rpressbooksToSite\n\relmslnToSite\n\rhaxcmsToSite\n\rnotionToSite\n\rgitbookToSite\n\revolutionToSite\n\rhtmlToSite\n\rdocxToSite`).option('--name <char>', 'name of the site (when creating a new one)').option('--domain <char>', 'published domain name').option('--node-op <char>', 'node operation to perform').version(await HAXCMS.getHAXCMSVersion());
|
|
64
|
+
}).option('--path <char>', 'path the project should be created in').option('--import-site <char>', 'URL of site to import').option('--import-structure <char>', `import method to use:\n\rpressbooksToSite\n\relmslnToSite\n\rhaxcmsToSite\n\rnotionToSite\n\rgitbookToSite\n\revolutionToSite\n\rhtmlToSite\n\rdocxToSite`).option('--name <char>', 'name of the site (when creating a new one)').option('--domain <char>', 'published domain name').option('--node-op <char>', 'node operation to perform').option('--no-i', 'prevent interactions / sub-process, good for scripting').version(await HAXCMS.getHAXCMSVersion());
|
|
65
65
|
let siteNodeOps = (0, _site.siteNodeOperations)();
|
|
66
66
|
for (var i in siteNodeOps) {
|
|
67
67
|
_commander.program.option(`--${(0, _utils.camelToDash)(siteNodeOps[i].value)} <char>`, `${siteNodeOps[i].label}`);
|
|
@@ -80,7 +80,7 @@ async function main() {
|
|
|
80
80
|
commandRun.arguments.name = name;
|
|
81
81
|
commandRun.options.skip = true;
|
|
82
82
|
}
|
|
83
|
-
}).option('--path <char>', 'path the project should be created in').option('--org <char>', 'organization for package.json').option('--author <char>', 'author for site / package.json').option('--writeHaxProperties', 'Write haxProperties for the element');
|
|
83
|
+
}).option('--path <char>', 'path the project should be created in').option('--org <char>', 'organization for package.json').option('--author <char>', 'author for site / package.json').option('--writeHaxProperties', 'Write haxProperties for the element').option('--no-i', 'prevent interactions / sub-process, good for scripting');
|
|
84
84
|
// process program arguments
|
|
85
85
|
_commander.program.parse();
|
|
86
86
|
commandRun.options = {
|
|
@@ -198,7 +198,7 @@ async function main() {
|
|
|
198
198
|
project = {
|
|
199
199
|
type: commandRun.command
|
|
200
200
|
};
|
|
201
|
-
} else {
|
|
201
|
+
} else if (commandRun.options.i) {
|
|
202
202
|
project = await p.group({
|
|
203
203
|
type: ({
|
|
204
204
|
results
|
|
@@ -224,6 +224,8 @@ async function main() {
|
|
|
224
224
|
process.exit(0);
|
|
225
225
|
}
|
|
226
226
|
});
|
|
227
|
+
} else if (!commandRun.options.i) {
|
|
228
|
+
process.exit(0);
|
|
227
229
|
}
|
|
228
230
|
// detect being in a haxcms scaffold. easiest way is _sites being in this directory
|
|
229
231
|
// set the path automatically so we skip the question
|
|
@@ -334,7 +336,7 @@ async function main() {
|
|
|
334
336
|
extras: ({
|
|
335
337
|
results
|
|
336
338
|
}) => {
|
|
337
|
-
if (!commandRun.options.auto) {
|
|
339
|
+
if (!commandRun.options.auto && commandRun.options.i) {
|
|
338
340
|
let options = [];
|
|
339
341
|
let initialValues = [];
|
|
340
342
|
if (commandRun.command === "webcomponent" || results.type === "webcomponent") {
|
|
@@ -17,6 +17,7 @@ var _picocolors = _interopRequireDefault(require("picocolors"));
|
|
|
17
17
|
var _jsYaml = require("js-yaml");
|
|
18
18
|
var _nodeHtmlParser = require("node-html-parser");
|
|
19
19
|
var _statements = require("../statements.js");
|
|
20
|
+
var _utils = require("../utils.js");
|
|
20
21
|
var _microFrontendRegistry = require("../micro-frontend-registry.js");
|
|
21
22
|
var haxcmsNodejsCli = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs/dist/cli.js"));
|
|
22
23
|
var hax = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs"));
|
|
@@ -30,7 +31,7 @@ globalThis.MicroFrontendRegistryConfig = {
|
|
|
30
31
|
base: `@haxtheweb/open-apis/`
|
|
31
32
|
};
|
|
32
33
|
// emable HAXcms routes so we have name => path just like on frontend!
|
|
33
|
-
_microFrontendRegistry.MicroFrontendRegistry.enableServices(['haxcms']);
|
|
34
|
+
_microFrontendRegistry.MicroFrontendRegistry.enableServices(['core', 'haxcms', 'experimental']);
|
|
34
35
|
const HAXCMS = hax.HAXCMS;
|
|
35
36
|
const exec = util.promisify(child_process.exec);
|
|
36
37
|
var sysSurge = true;
|
|
@@ -56,6 +57,10 @@ class Res {
|
|
|
56
57
|
this.statusCode = status;
|
|
57
58
|
return this;
|
|
58
59
|
}
|
|
60
|
+
json(data) {
|
|
61
|
+
this.data = JSON.parse(JSON.stringify(data));
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
59
64
|
setHeader() {
|
|
60
65
|
return this;
|
|
61
66
|
}
|
|
@@ -63,31 +68,37 @@ class Res {
|
|
|
63
68
|
function siteActions() {
|
|
64
69
|
return [{
|
|
65
70
|
value: 'start',
|
|
66
|
-
label: "
|
|
67
|
-
}, {
|
|
68
|
-
value: 'status',
|
|
69
|
-
label: "Status"
|
|
70
|
-
}, {
|
|
71
|
-
value: 'sync',
|
|
72
|
-
label: "Sync git"
|
|
73
|
-
}, {
|
|
74
|
-
value: 'theme',
|
|
75
|
-
label: "Change theme"
|
|
71
|
+
label: "Launch site (http://localhost)"
|
|
76
72
|
}, {
|
|
77
73
|
value: 'node:stats',
|
|
78
|
-
label: "
|
|
74
|
+
label: "Node: Stats"
|
|
79
75
|
}, {
|
|
80
76
|
value: 'node:add',
|
|
81
|
-
label: "Add page"
|
|
77
|
+
label: "Node: Add page"
|
|
82
78
|
}, {
|
|
83
79
|
value: 'node:edit',
|
|
84
|
-
label: "Edit page"
|
|
80
|
+
label: "Node: Edit page"
|
|
85
81
|
}, {
|
|
86
82
|
value: 'node:delete',
|
|
87
|
-
label: "Delete page"
|
|
83
|
+
label: "Node: Delete page"
|
|
84
|
+
}, {
|
|
85
|
+
value: 'status',
|
|
86
|
+
label: "Site: Status"
|
|
87
|
+
}, {
|
|
88
|
+
value: 'theme',
|
|
89
|
+
label: "Site: Change theme"
|
|
88
90
|
}, {
|
|
89
91
|
value: 'file:list',
|
|
90
|
-
label: "List files"
|
|
92
|
+
label: "Site: List files"
|
|
93
|
+
}, {
|
|
94
|
+
value: 'site:html',
|
|
95
|
+
label: "Site: Full site as HTML"
|
|
96
|
+
}, {
|
|
97
|
+
value: 'site:md',
|
|
98
|
+
label: "Site: Full site as Markdown"
|
|
99
|
+
}, {
|
|
100
|
+
value: 'sync',
|
|
101
|
+
label: "Site: Sync git"
|
|
91
102
|
}];
|
|
92
103
|
}
|
|
93
104
|
async function siteCommandDetected(commandRun) {
|
|
@@ -201,17 +212,28 @@ async function siteCommandDetected(commandRun) {
|
|
|
201
212
|
case 'schema':
|
|
202
213
|
// next up
|
|
203
214
|
let html = await activeHaxsite.getPageContent(page);
|
|
204
|
-
let dom = (0, _nodeHtmlParser.parse)(html);
|
|
205
|
-
|
|
215
|
+
let dom = (0, _nodeHtmlParser.parse)(`<div id="fullpage">${html}</div>`);
|
|
216
|
+
let els = [];
|
|
217
|
+
for (var i in dom.querySelector('#fullpage').childNodes) {
|
|
218
|
+
let node = dom.querySelector('#fullpage').childNodes[i];
|
|
219
|
+
if (node && node.getAttribute) {
|
|
220
|
+
els.push(await nodeToHaxElement(node, null));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
console.log(els);
|
|
206
224
|
break;
|
|
207
225
|
case 'md':
|
|
208
|
-
|
|
226
|
+
let resp = await openApiBroker('@core', 'htmlToMd', {
|
|
227
|
+
html: await activeHaxsite.getPageContent(page)
|
|
228
|
+
});
|
|
229
|
+
console.log(resp.res.data.data);
|
|
209
230
|
break;
|
|
210
231
|
}
|
|
211
232
|
}
|
|
212
233
|
}
|
|
213
234
|
} catch (e) {
|
|
214
235
|
console.log(e.stderr);
|
|
236
|
+
console.log(e);
|
|
215
237
|
}
|
|
216
238
|
break;
|
|
217
239
|
case "node:add":
|
|
@@ -453,6 +475,30 @@ async function siteCommandDetected(commandRun) {
|
|
|
453
475
|
console.log(res.data);
|
|
454
476
|
}
|
|
455
477
|
break;
|
|
478
|
+
case "site:html":
|
|
479
|
+
case "site:md":
|
|
480
|
+
let siteContent = '';
|
|
481
|
+
activeHaxsite = await hax.systemStructureContext();
|
|
482
|
+
let items = [];
|
|
483
|
+
if (commandRun.options.itemId != null) {
|
|
484
|
+
items = activeHaxsite.manifest.findBranch(commandRun.options.itemId);
|
|
485
|
+
} else {
|
|
486
|
+
items = activeHaxsite.manifest.orderTree(activeHaxsite.manifest.items);
|
|
487
|
+
}
|
|
488
|
+
for (var i in items) {
|
|
489
|
+
let page = activeHaxsite.loadNode(items[i].id);
|
|
490
|
+
siteContent += `<h1>${items[i].title}</h1>\n\r`;
|
|
491
|
+
siteContent += `<div data-jos-item-id="${items[i].id}">\n\r${await activeHaxsite.getPageContent(page)}\n\r</div>\n\r`;
|
|
492
|
+
}
|
|
493
|
+
if (operation.action === 'site:md') {
|
|
494
|
+
let resp = await openApiBroker('@core', 'htmlToMd', {
|
|
495
|
+
html: siteContent
|
|
496
|
+
});
|
|
497
|
+
console.log(resp.res.data.data);
|
|
498
|
+
} else {
|
|
499
|
+
console.log(siteContent);
|
|
500
|
+
}
|
|
501
|
+
break;
|
|
456
502
|
case "quit":
|
|
457
503
|
// quit
|
|
458
504
|
process.exit(0);
|
|
@@ -531,8 +577,8 @@ function siteNodeOperations(search = null) {
|
|
|
531
577
|
|
|
532
578
|
// broker a call to the open-api repo which is an express based wrapper for vercel (originally)
|
|
533
579
|
// this ensures the calls are identical and yet are converted to something the CLI can leverage
|
|
534
|
-
async function openApiBroker(call, body) {
|
|
535
|
-
let mfItem = _microFrontendRegistry.MicroFrontendRegistry.get(
|
|
580
|
+
async function openApiBroker(scope, call, body) {
|
|
581
|
+
let mfItem = _microFrontendRegistry.MicroFrontendRegistry.get(`${scope}/${call}`);
|
|
536
582
|
// ensure we have a MFR record to do the connection
|
|
537
583
|
// fun thing is this is local file access directly via import()
|
|
538
584
|
if (mfItem) {
|
|
@@ -557,8 +603,10 @@ async function openApiBroker(call, body) {
|
|
|
557
603
|
async function siteProcess(commandRun, project, port = '3000') {
|
|
558
604
|
// auto select operations to perform if requested
|
|
559
605
|
if (!project.extras) {
|
|
560
|
-
|
|
561
|
-
|
|
606
|
+
project.extras = [];
|
|
607
|
+
if (commandRun.options.i) {
|
|
608
|
+
project.extras = ['launch'];
|
|
609
|
+
}
|
|
562
610
|
}
|
|
563
611
|
let s = p.spinner();
|
|
564
612
|
s.start((0, _statements.merlinSays)(`Creating new site: ${project.name}`));
|
|
@@ -587,7 +635,7 @@ async function siteProcess(commandRun, project, port = '3000') {
|
|
|
587
635
|
}
|
|
588
636
|
// verify this is a valid way to do an import
|
|
589
637
|
if (commandRun.options.importStructure && _microFrontendRegistry.MicroFrontendRegistry.get(`@haxcms/${commandRun.options.importStructure}`)) {
|
|
590
|
-
let resp = await openApiBroker(commandRun.options.importStructure, {
|
|
638
|
+
let resp = await openApiBroker('@haxcms', commandRun.options.importStructure, {
|
|
591
639
|
repoUrl: commandRun.options.importSite
|
|
592
640
|
});
|
|
593
641
|
if (resp.res.data && resp.res.data.data && resp.res.data.data.items) {
|
|
@@ -685,4 +733,101 @@ async function siteThemeList() {
|
|
|
685
733
|
});
|
|
686
734
|
}
|
|
687
735
|
return items;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// @fork of the hax core util for this so that we avoid api difference between real dom and parse nodejs dom
|
|
739
|
+
async function nodeToHaxElement(node, eventName = "insert-element") {
|
|
740
|
+
if (!node) {
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
// build out the properties to send along
|
|
744
|
+
var props = {};
|
|
745
|
+
// support basic styles
|
|
746
|
+
if (typeof node.getAttribute("style") !== typeof undefined) {
|
|
747
|
+
props.style = node.getAttribute("style");
|
|
748
|
+
}
|
|
749
|
+
// don't set a null style
|
|
750
|
+
if (props.style === null || props.style === "null") {
|
|
751
|
+
delete props.style;
|
|
752
|
+
}
|
|
753
|
+
// test if a class exists, not everything scopes
|
|
754
|
+
if (typeof node.getAttribute('class') !== typeof undefined) {
|
|
755
|
+
props.class = node.getAttribute('class').replace("hax-active", "");
|
|
756
|
+
}
|
|
757
|
+
// test if a id exists as its a special case in attributes... of course
|
|
758
|
+
if (typeof node.getAttribute('id') !== typeof undefined) {
|
|
759
|
+
props.id = node.getAttribute("id");
|
|
760
|
+
}
|
|
761
|
+
let tmpProps;
|
|
762
|
+
// weak fallback
|
|
763
|
+
if (typeof tmpProps === typeof undefined) {
|
|
764
|
+
tmpProps = node.__data;
|
|
765
|
+
}
|
|
766
|
+
// complex elements need complex support
|
|
767
|
+
if (typeof tmpProps !== typeof undefined) {
|
|
768
|
+
// run through attributes, though non-reflected props won't be here
|
|
769
|
+
// run through props, we always defer to property values
|
|
770
|
+
for (var property in tmpProps) {
|
|
771
|
+
// make sure we only set things that have a value
|
|
772
|
+
if (property != "class" && property != "style" && tmpProps.hasOwnProperty(property) && typeof node[property] !== undefined && node[property] != null && node[property] != "") {
|
|
773
|
+
props[property] = node[property];
|
|
774
|
+
}
|
|
775
|
+
// special support for false boolean
|
|
776
|
+
else if (node[property] === false) {
|
|
777
|
+
props[property] = false;
|
|
778
|
+
} else if (node[property] === true) {
|
|
779
|
+
props[property] = true;
|
|
780
|
+
} else if (node[property] === 0) {
|
|
781
|
+
props[property] = 0;
|
|
782
|
+
} else {
|
|
783
|
+
// unknown prop setting / ignored
|
|
784
|
+
//console.warn(node[property], property);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
for (var attribute in node._attrs) {
|
|
788
|
+
// make sure we only set things that have a value
|
|
789
|
+
if (typeof node._attrs[attribute] !== typeof undefined && attribute != "class" && attribute != "style" && attribute != "id" && typeof node._attrs[attribute] !== undefined && node._attrs[attribute] != null && node._attrs[attribute] != "") {
|
|
790
|
+
props[attribute] = node._attrs[attribute];
|
|
791
|
+
} else if (node._attrs[attribute] == "0") {
|
|
792
|
+
props[attribute] = node._attrs[attribute];
|
|
793
|
+
} else {
|
|
794
|
+
// note: debug here if experiencing attributes that won't bind
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
} else {
|
|
798
|
+
// much easier case, usually just in primatives
|
|
799
|
+
for (var attribute in node._attrs) {
|
|
800
|
+
// make sure we only set things that have a value
|
|
801
|
+
if (typeof node._attrs[attribute] !== typeof undefined && attribute != "class" && attribute != "style" && attribute != "id" && typeof node._attrs[attribute] !== undefined && node._attrs[attribute] != null && node._attrs[attribute] != "") {
|
|
802
|
+
props[attribute] = node._attrs[attribute];
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
// support sandboxed environments which
|
|
807
|
+
// will hate iframe tags but love webview
|
|
808
|
+
let tag = node.tagName.toLowerCase();
|
|
809
|
+
if (globalThis.HaxStore && globalThis.HaxStore.instance && globalThis.HaxStore.instance._isSandboxed && tag === "iframe") {
|
|
810
|
+
tag = "webview";
|
|
811
|
+
}
|
|
812
|
+
let slotContent = '';
|
|
813
|
+
// if hax store around, allow it to get slot content of the node
|
|
814
|
+
if (globalThis.HaxStore && globalThis.HaxStore.instance) {
|
|
815
|
+
slotContent = await globalThis.HaxStore.instance.getHAXSlot(node);
|
|
816
|
+
} else {
|
|
817
|
+
// if HAX isn't around, just return the innerHTML as a string for asignment to content
|
|
818
|
+
slotContent = node.innerHTML;
|
|
819
|
+
}
|
|
820
|
+
// support fallback on inner text if there were no nodes
|
|
821
|
+
if (slotContent == "") {
|
|
822
|
+
slotContent = node.innerText;
|
|
823
|
+
}
|
|
824
|
+
let element = {
|
|
825
|
+
tag: tag,
|
|
826
|
+
properties: props,
|
|
827
|
+
content: slotContent
|
|
828
|
+
};
|
|
829
|
+
if (eventName !== null) {
|
|
830
|
+
element.eventName = eventName;
|
|
831
|
+
}
|
|
832
|
+
return element;
|
|
688
833
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haxtheweb/create",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.13",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@clack/core": "0.3.4",
|
|
44
44
|
"@clack/prompts": "0.7.0",
|
|
45
|
-
"@haxtheweb/haxcms-nodejs": "^9.0.
|
|
45
|
+
"@haxtheweb/haxcms-nodejs": "^9.0.18",
|
|
46
46
|
"@haxtheweb/open-apis": "^9.0.11",
|
|
47
47
|
"commander": "12.1.0",
|
|
48
48
|
"node-html-parser": "6.1.13",
|