@haxtheweb/create 9.0.13 → 9.0.14
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/lib/programs/site.js +119 -55
- package/package.json +1 -1
|
@@ -68,37 +68,43 @@ class Res {
|
|
|
68
68
|
function siteActions() {
|
|
69
69
|
return [{
|
|
70
70
|
value: 'start',
|
|
71
|
-
label: "Launch site (http://localhost)"
|
|
71
|
+
label: "Launch site in browser (http://localhost)"
|
|
72
72
|
}, {
|
|
73
73
|
value: 'node:stats',
|
|
74
|
-
label: "Node
|
|
74
|
+
label: "Node Stats / data"
|
|
75
75
|
}, {
|
|
76
76
|
value: 'node:add',
|
|
77
|
-
label: "
|
|
77
|
+
label: "Add a new page"
|
|
78
78
|
}, {
|
|
79
79
|
value: 'node:edit',
|
|
80
|
-
label: "
|
|
80
|
+
label: "Edit a page"
|
|
81
81
|
}, {
|
|
82
82
|
value: 'node:delete',
|
|
83
|
-
label: "
|
|
83
|
+
label: "Delete a page"
|
|
84
84
|
}, {
|
|
85
|
-
value: '
|
|
86
|
-
label: "Site
|
|
85
|
+
value: 'site:stats',
|
|
86
|
+
label: "Site Status / stats"
|
|
87
87
|
}, {
|
|
88
|
-
value: '
|
|
89
|
-
label: "Site
|
|
88
|
+
value: 'site:items',
|
|
89
|
+
label: "Site items"
|
|
90
|
+
}, {
|
|
91
|
+
value: 'site:list-files',
|
|
92
|
+
label: "List site files"
|
|
90
93
|
}, {
|
|
91
|
-
value: '
|
|
92
|
-
label: "
|
|
94
|
+
value: 'site:theme',
|
|
95
|
+
label: "Change theme"
|
|
93
96
|
}, {
|
|
94
97
|
value: 'site:html',
|
|
95
|
-
label: "
|
|
98
|
+
label: "Full site as HTML"
|
|
96
99
|
}, {
|
|
97
100
|
value: 'site:md',
|
|
98
|
-
label: "
|
|
101
|
+
label: "Full site as Markdown"
|
|
99
102
|
}, {
|
|
100
|
-
value: '
|
|
101
|
-
label: "
|
|
103
|
+
value: 'site:schema',
|
|
104
|
+
label: "Full site as HAXElementSchema"
|
|
105
|
+
}, {
|
|
106
|
+
value: 'site:sync',
|
|
107
|
+
label: "Sync git repo"
|
|
102
108
|
}];
|
|
103
109
|
}
|
|
104
110
|
async function siteCommandDetected(commandRun) {
|
|
@@ -107,9 +113,11 @@ async function siteCommandDetected(commandRun) {
|
|
|
107
113
|
if (!commandRun.arguments.action) {
|
|
108
114
|
commandRun.arguments.action = 'status';
|
|
109
115
|
}
|
|
110
|
-
p.intro(`${_picocolors.default.bgBlack(_picocolors.default.white(` HAXTheWeb : Site detected `))}`);
|
|
111
116
|
commandRun.command = "site";
|
|
112
|
-
|
|
117
|
+
if (!commandRun.options.y && commandRun.options.i) {
|
|
118
|
+
p.intro(`${_picocolors.default.bgBlack(_picocolors.default.white(` HAXTheWeb : Site detected `))}`);
|
|
119
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Name: ${activeHaxsite.name} `))}`);
|
|
120
|
+
}
|
|
113
121
|
// defaults if nothing set via CLI
|
|
114
122
|
let operation = {
|
|
115
123
|
...commandRun.arguments,
|
|
@@ -126,8 +134,8 @@ async function siteCommandDetected(commandRun) {
|
|
|
126
134
|
let actions = siteActions();
|
|
127
135
|
if (sysSurge) {
|
|
128
136
|
actions.push({
|
|
129
|
-
value: 'surge',
|
|
130
|
-
label: "Publish site
|
|
137
|
+
value: 'site:surge',
|
|
138
|
+
label: "Publish site to Surge.sh"
|
|
131
139
|
});
|
|
132
140
|
}
|
|
133
141
|
actions.push({
|
|
@@ -158,13 +166,58 @@ async function siteCommandDetected(commandRun) {
|
|
|
158
166
|
});
|
|
159
167
|
}
|
|
160
168
|
switch (operation.action) {
|
|
161
|
-
case "
|
|
162
|
-
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Title: ${activeHaxsite.manifest.title} `))}`);
|
|
163
|
-
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Description: ${activeHaxsite.manifest.description} `))}`);
|
|
164
|
-
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Theme: ${activeHaxsite.manifest.metadata.theme.name} (${activeHaxsite.manifest.metadata.theme.element})`))}`);
|
|
165
|
-
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Pages: ${activeHaxsite.manifest.items.length} `))}`);
|
|
169
|
+
case "site:stats":
|
|
166
170
|
const date = new Date(activeHaxsite.manifest.metadata.site.updated * 1000);
|
|
167
|
-
|
|
171
|
+
let siteItems = [];
|
|
172
|
+
if (commandRun.options.itemId != null) {
|
|
173
|
+
siteItems = activeHaxsite.manifest.findBranch(commandRun.options.itemId);
|
|
174
|
+
} else {
|
|
175
|
+
siteItems = activeHaxsite.manifest.orderTree(activeHaxsite.manifest.items);
|
|
176
|
+
}
|
|
177
|
+
let els = {};
|
|
178
|
+
for (var i in siteItems) {
|
|
179
|
+
let page = activeHaxsite.loadNode(siteItems[i].id);
|
|
180
|
+
let html = await activeHaxsite.getPageContent(page);
|
|
181
|
+
let dom = (0, _nodeHtmlParser.parse)(`<div id="fullpage">${html}</div>`);
|
|
182
|
+
for (var j in dom.querySelector('#fullpage').childNodes) {
|
|
183
|
+
let node = dom.querySelector('#fullpage').childNodes[j];
|
|
184
|
+
if (node && node.getAttribute) {
|
|
185
|
+
let haxel = await nodeToHaxElement(node, null);
|
|
186
|
+
if (!els[haxel.tag]) {
|
|
187
|
+
els[haxel.tag] = 0;
|
|
188
|
+
}
|
|
189
|
+
els[haxel.tag]++;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
let siteStats = {
|
|
194
|
+
title: activeHaxsite.manifest.title,
|
|
195
|
+
description: activeHaxsite.manifest.description,
|
|
196
|
+
themeName: activeHaxsite.manifest.metadata.theme.name,
|
|
197
|
+
themeElement: activeHaxsite.manifest.metadata.theme.element,
|
|
198
|
+
pageCount: activeHaxsite.manifest.items.length,
|
|
199
|
+
lastUpdated: date.toLocaleDateString("en-US"),
|
|
200
|
+
tagUsage: els
|
|
201
|
+
};
|
|
202
|
+
if (!commandRun.options.format) {
|
|
203
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Title: ${siteStats.title} `))}`);
|
|
204
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Description: ${siteStats.description} `))}`);
|
|
205
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Theme: ${siteStats.themeName} (${siteStats.themeElement})`))}`);
|
|
206
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Pages: ${siteStats.pageCount} `))}`);
|
|
207
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Last updated: ${siteStats.lastUpdated} `))}`);
|
|
208
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Tags used: ${JSON.stringify(siteStats.tagUsage, null, 2)} `))}`);
|
|
209
|
+
} else if (commandRun.options.format === 'yaml') {
|
|
210
|
+
console.log((0, _jsYaml.dump)(siteStats));
|
|
211
|
+
} else {
|
|
212
|
+
console.log(siteStats);
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case "site:items":
|
|
216
|
+
if (commandRun.options.format === 'yaml') {
|
|
217
|
+
console.log((0, _jsYaml.dump)(activeHaxsite.manifest.items));
|
|
218
|
+
} else {
|
|
219
|
+
console.log(activeHaxsite.manifest.items);
|
|
220
|
+
}
|
|
168
221
|
break;
|
|
169
222
|
case "start":
|
|
170
223
|
try {
|
|
@@ -412,7 +465,7 @@ async function siteCommandDetected(commandRun) {
|
|
|
412
465
|
console.log(e.stderr);
|
|
413
466
|
}
|
|
414
467
|
break;
|
|
415
|
-
case "sync":
|
|
468
|
+
case "site:sync":
|
|
416
469
|
// @todo git sync might need other arguments / be combined with publishing
|
|
417
470
|
try {
|
|
418
471
|
await exec(`cd ${activeHaxsite.directory} && git pull && git push`);
|
|
@@ -420,7 +473,7 @@ async function siteCommandDetected(commandRun) {
|
|
|
420
473
|
console.log(e.stderr);
|
|
421
474
|
}
|
|
422
475
|
break;
|
|
423
|
-
case "theme":
|
|
476
|
+
case "site:theme":
|
|
424
477
|
try {
|
|
425
478
|
//theme
|
|
426
479
|
let list = await siteThemeList();
|
|
@@ -443,7 +496,7 @@ async function siteCommandDetected(commandRun) {
|
|
|
443
496
|
console.log(e.stderr);
|
|
444
497
|
}
|
|
445
498
|
break;
|
|
446
|
-
case "surge":
|
|
499
|
+
case "site:surge":
|
|
447
500
|
try {
|
|
448
501
|
if (!commandRun.options.domain) {
|
|
449
502
|
commandRun.options.domain = await p.text({
|
|
@@ -463,7 +516,7 @@ async function siteCommandDetected(commandRun) {
|
|
|
463
516
|
console.log(e.stderr);
|
|
464
517
|
}
|
|
465
518
|
break;
|
|
466
|
-
case "file
|
|
519
|
+
case "site:file-list":
|
|
467
520
|
let res = new Res();
|
|
468
521
|
await hax.RoutesMap.get.listFiles({
|
|
469
522
|
query: activeHaxsite.name,
|
|
@@ -477,6 +530,7 @@ async function siteCommandDetected(commandRun) {
|
|
|
477
530
|
break;
|
|
478
531
|
case "site:html":
|
|
479
532
|
case "site:md":
|
|
533
|
+
case "site:schema":
|
|
480
534
|
let siteContent = '';
|
|
481
535
|
activeHaxsite = await hax.systemStructureContext();
|
|
482
536
|
let items = [];
|
|
@@ -485,18 +539,41 @@ async function siteCommandDetected(commandRun) {
|
|
|
485
539
|
} else {
|
|
486
540
|
items = activeHaxsite.manifest.orderTree(activeHaxsite.manifest.items);
|
|
487
541
|
}
|
|
488
|
-
|
|
489
|
-
let
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
542
|
+
if (operation.action === 'site:schema') {
|
|
543
|
+
let els = [];
|
|
544
|
+
for (var i in items) {
|
|
545
|
+
let page = activeHaxsite.loadNode(items[i].id);
|
|
546
|
+
let html = await activeHaxsite.getPageContent(page);
|
|
547
|
+
let dom = (0, _nodeHtmlParser.parse)(`<div id="fullpage">${html}</div>`);
|
|
548
|
+
els.push({
|
|
549
|
+
tag: "h1",
|
|
550
|
+
properties: {
|
|
551
|
+
"data-jos-item-id": items[i].id
|
|
552
|
+
},
|
|
553
|
+
content: `${items[i].title}`
|
|
554
|
+
});
|
|
555
|
+
for (var j in dom.querySelector('#fullpage').childNodes) {
|
|
556
|
+
let node = dom.querySelector('#fullpage').childNodes[j];
|
|
557
|
+
if (node && node.getAttribute) {
|
|
558
|
+
els.push(await nodeToHaxElement(node, null));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
console.log(els);
|
|
498
563
|
} else {
|
|
499
|
-
|
|
564
|
+
for (var i in items) {
|
|
565
|
+
let page = activeHaxsite.loadNode(items[i].id);
|
|
566
|
+
siteContent += `<h1>${items[i].title}</h1>\n\r`;
|
|
567
|
+
siteContent += `<div data-jos-item-id="${items[i].id}">\n\r${await activeHaxsite.getPageContent(page)}\n\r</div>\n\r`;
|
|
568
|
+
}
|
|
569
|
+
if (operation.action === 'site:md') {
|
|
570
|
+
let resp = await openApiBroker('@core', 'htmlToMd', {
|
|
571
|
+
html: siteContent
|
|
572
|
+
});
|
|
573
|
+
console.log(resp.res.data.data);
|
|
574
|
+
} else {
|
|
575
|
+
console.log(siteContent);
|
|
576
|
+
}
|
|
500
577
|
}
|
|
501
578
|
break;
|
|
502
579
|
case "quit":
|
|
@@ -668,19 +745,6 @@ async function siteProcess(commandRun, project, port = '3000') {
|
|
|
668
745
|
}
|
|
669
746
|
// options for install, git and other extras
|
|
670
747
|
// can't launch if we didn't install first so launch implies installation
|
|
671
|
-
if (project.extras.includes('launch') || project.extras.includes('install')) {
|
|
672
|
-
s.start((0, _statements.merlinSays)(`Installation magic (${commandRun.options.npmClient} install)`));
|
|
673
|
-
try {
|
|
674
|
-
// monorepos install from top but then still need to launch from local location
|
|
675
|
-
if (!commandRun.options.isMonorepo) {
|
|
676
|
-
await exec(`cd ${project.path}/${project.name} && ${commandRun.options.npmClient} install`);
|
|
677
|
-
}
|
|
678
|
-
} catch (e) {
|
|
679
|
-
console.log(e);
|
|
680
|
-
}
|
|
681
|
-
s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
|
|
682
|
-
}
|
|
683
|
-
// autolaunch if default was selected
|
|
684
748
|
if (project.extras.includes('launch')) {
|
|
685
749
|
let optionPath = `${project.path}/${project.name}`;
|
|
686
750
|
let command = `npx @haxtheweb/haxcms-nodejs`;
|
|
@@ -705,8 +769,8 @@ async function siteProcess(commandRun, project, port = '3000') {
|
|
|
705
769
|
// don't log bc output is weird
|
|
706
770
|
}
|
|
707
771
|
} else {
|
|
708
|
-
let nextSteps = `cd ${project.path}/${project.name} &&
|
|
709
|
-
p.note(`${project.name} is ready to go. Run the following to start
|
|
772
|
+
let nextSteps = `cd ${project.path}/${project.name} && hax start`;
|
|
773
|
+
p.note(`${project.name} is ready to go. Run the following to start working with it:`);
|
|
710
774
|
p.outro(nextSteps);
|
|
711
775
|
}
|
|
712
776
|
}
|