cook-ssg 2.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.
- package/LICENSE +21 -0
- package/README.md +445 -0
- package/bin/cook.js +66 -0
- package/package.json +75 -0
- package/patches/jsdom-fetch-fix.js +52 -0
- package/scripts/build.js +212 -0
- package/scripts/dev.js +119 -0
- package/scripts/plugins/apply-template.js +226 -0
- package/scripts/plugins/auto-components.js +215 -0
- package/scripts/plugins/bundle.js +338 -0
- package/scripts/plugins/copy-src.js +89 -0
- package/scripts/plugins/create-dir-from-file.js +144 -0
- package/scripts/plugins/create-dist.js +55 -0
- package/scripts/plugins/custom-plugins.js +118 -0
- package/scripts/plugins/declarative-shadow-dom.js +164 -0
- package/scripts/plugins/escape-code-blocks.js +54 -0
- package/scripts/plugins/generate-formats.js +361 -0
- package/scripts/plugins/generate-fragments.js +126 -0
- package/scripts/plugins/generate-sitemap-xml.js +216 -0
- package/scripts/plugins/minify-src.js +253 -0
- package/scripts/plugins/optimize-images.js +389 -0
- package/scripts/plugins/process-html-frontmatter.js +75 -0
- package/scripts/plugins/process-markdown.js +384 -0
- package/scripts/plugins/repeat-collection.js +296 -0
- package/scripts/plugins/replace-components.js +496 -0
- package/scripts/plugins/replace-external-link-protocol.js +171 -0
- package/scripts/plugins/replace-include.js +273 -0
- package/scripts/plugins/replace-inline.js +217 -0
- package/scripts/plugins/replace-template-strings.js +121 -0
- package/scripts/plugins/set-active-links.js +175 -0
- package/scripts/utils/config/config.js +277 -0
- package/scripts/utils/get-src/get-src.js +241 -0
- package/scripts/utils/logger/logger.js +47 -0
- package/scripts/utils/performance/performance.js +35 -0
- package/scripts/utils/spinner/spinner.js +112 -0
- package/scripts/utils/timer/timer.js +40 -0
- package/scripts/utils/util/util.js +719 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// IMPORTS
|
|
2
|
+
// ----------------------------------
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
5
|
+
|
|
6
|
+
// DEFINE
|
|
7
|
+
// ----------------------------------
|
|
8
|
+
let types = {
|
|
9
|
+
break: () => console.log('\n'),
|
|
10
|
+
done: (message, indent=0) => console.log(`${setIndent(indent)}${ chalk.magenta('» done') + chalk.gray(` | ${message}`) }`),
|
|
11
|
+
error: (message, indent=0) => console.log(`${setIndent(indent)}${ chalk.red('error') }`, message),
|
|
12
|
+
header: (message, indent=0) => console.log(`${setIndent(indent)}${ chalk.grey.underline(message) }`),
|
|
13
|
+
info: (message, indent=0) => console.log(`${setIndent(indent)}${ chalk.blue('info') }`, message),
|
|
14
|
+
msg: (message, indent=0) => console.log(`${setIndent(indent)}${ message }`),
|
|
15
|
+
skip: (message, indent=0) => console.log(`${setIndent(indent)}${chalk.green('✓ success')} ${message} ${chalk.grey('(skipped) | 0s')}`),
|
|
16
|
+
success: (message, indent=0) => console.log(`${setIndent(indent)}${ chalk.green('✓ success')}`, message),
|
|
17
|
+
system: (message, indent=0) => console.log(`${setIndent(indent)}${ chalk.blue(message) }`),
|
|
18
|
+
warning: (message, indent=0) => console.log(`${setIndent(indent)}${ chalk.yellow('warn') }`, message),
|
|
19
|
+
}
|
|
20
|
+
// Clone types for persistance option
|
|
21
|
+
const persist = cloneDeep(types);
|
|
22
|
+
|
|
23
|
+
// DISABLE OUTPUT IF ENV VARIABLE SET
|
|
24
|
+
// ------------------------------------
|
|
25
|
+
// Mute logging if environment var set
|
|
26
|
+
if (!process.env.LOGGER) Object.keys(types).forEach(key => types[key] = () => ({}));
|
|
27
|
+
|
|
28
|
+
// 'ALWAYS SHOW' OPTION
|
|
29
|
+
// ----------------------------------
|
|
30
|
+
// Always show loggers marked 'persist': `Logger.persist.header(...)`
|
|
31
|
+
types.persist = persist;
|
|
32
|
+
|
|
33
|
+
// HELPER METHODS
|
|
34
|
+
// ----------------------------------
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @description Return designated amount of spaces
|
|
38
|
+
* @param {Number} indent - The number of indents
|
|
39
|
+
*/
|
|
40
|
+
function setIndent(indent) {
|
|
41
|
+
const indentSrc = ' ';
|
|
42
|
+
return indentSrc.substr(0, indent);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// EXPORT
|
|
46
|
+
// ----------------------------------
|
|
47
|
+
export default types;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file performance.js
|
|
3
|
+
* @description Create X dummy pages to test build speed
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// IMPORTS
|
|
7
|
+
// -----------------------------
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import Logger from '../logger/logger.js';
|
|
10
|
+
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// DEFINE
|
|
15
|
+
// -----------------------------
|
|
16
|
+
/**
|
|
17
|
+
* @description Generate fake pages for performance testing
|
|
18
|
+
* @param {Number} num Number of pages to generate
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
function generatePages(num) {
|
|
22
|
+
|
|
23
|
+
for (let i=0;i<num;i++) {
|
|
24
|
+
const html = "<!DOCTYPE html><html><head><title>${'Generated Page " + i + "' + siteTitleSeperator + siteTitle}</title><meta data-include='/includes/global-head'></head><body><h1> Generated Page ${1}</h1><img src='/assets/img/rick-morty-ship.jpg' alt='Rick and Morty Poster'><p>Are these pills supposed to wake me up or something? It's a device Morty, that when you put it in your ear, you can enter people's dreams Morty. Its just like that movie that you keep crowing about. Aids! I am not putting my father in a home! He just came back into my life, and you want to, grab him and, stuff him under a mattress like last month's Victoria's Secret?!</p><div include='/includes/global-scripts'></div></body></html>";
|
|
25
|
+
fs.writeFileSync(`${cwd}/dist/generated-file-${i}.html`, html, { encoding: 'utf8', flag: 'wx' }, err => {
|
|
26
|
+
Logger.error(`Error generating file: ${err}`);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
Logger.warning(`STRESS TEST: Generated ${num} pages.`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// EXPORT
|
|
34
|
+
// -----------------------------
|
|
35
|
+
export { generatePages };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file spinner.js
|
|
3
|
+
* @description Custom terminal spinner message
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// IMPORTS
|
|
7
|
+
// ----------------------------------
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import cliCursor from 'cli-cursor';
|
|
10
|
+
import cliSpinners from 'cli-spinners';
|
|
11
|
+
import readline from 'node:readline';
|
|
12
|
+
import Logger from '../logger/logger.js';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// DEFINE
|
|
16
|
+
// ----------------------------------
|
|
17
|
+
class Spinner {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.allowNewLine = false;
|
|
20
|
+
this.color = 'green';
|
|
21
|
+
this.delay = cliSpinners.dots.interval;
|
|
22
|
+
this.interval = null;
|
|
23
|
+
this.label = null;
|
|
24
|
+
this.spinCurr = 0;
|
|
25
|
+
this.spinMax = cliSpinners.dots.frames.length;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setDisplay() {
|
|
29
|
+
this.clearLine();
|
|
30
|
+
// Add new line if Logging is enabled
|
|
31
|
+
const newLine = this.allowNewLine ? '\n' : '';
|
|
32
|
+
process.stdout.write(`${chalk[this.color](cliSpinners.dots.frames[this.spinCurr])} ${this.label}${newLine}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
start(label, color) {
|
|
36
|
+
// Set spinner color, if provided
|
|
37
|
+
if (color) this.color = color;
|
|
38
|
+
// Hide terminal cursor
|
|
39
|
+
cliCursor.hide();
|
|
40
|
+
// Set display label
|
|
41
|
+
this.label = label;
|
|
42
|
+
// Start spinner interval
|
|
43
|
+
this.setDisplay();
|
|
44
|
+
this.interval = setInterval(() => {
|
|
45
|
+
this.setDisplay();
|
|
46
|
+
// Set index to change spinner icon position
|
|
47
|
+
this.spinCurr = this.spinCurr === this.spinMax - 1 ? 0 : this.spinCurr += 1;
|
|
48
|
+
}, this.delay);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
stop(label, isError) {
|
|
52
|
+
this.clearLine();
|
|
53
|
+
if (isError) Logger.persist.error(label);
|
|
54
|
+
else Logger.persist.success(label);
|
|
55
|
+
clearInterval(this.interval);
|
|
56
|
+
cliCursor.show();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Like `stop()`, this finishes the sequence (clears interval),
|
|
60
|
+
// but displays nothing on the line in the terminal.
|
|
61
|
+
// Great for conditionals...show final display if plugin found matches or not
|
|
62
|
+
kill() {
|
|
63
|
+
this.clearLine();
|
|
64
|
+
clearInterval(this.interval);
|
|
65
|
+
cliCursor.show();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
update(label, color) {
|
|
69
|
+
// Set spinner color, if provided
|
|
70
|
+
if (color) this.color = color;
|
|
71
|
+
this.label = label;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
updateAsPercentage(label, count, total, reverse) {
|
|
75
|
+
// Configure percentage
|
|
76
|
+
const percentage = count / total * 100;
|
|
77
|
+
let currentColor = 'green';
|
|
78
|
+
if (percentage < 25) currentColor = 'red';
|
|
79
|
+
else if (percentage < 50) currentColor = 'yellow';
|
|
80
|
+
else if (percentage < 75) currentColor = 'cyan';
|
|
81
|
+
// Store label parts
|
|
82
|
+
const percentageLabel = `[${count}/${total}] (${chalk[currentColor](percentage.toFixed(2) + '%')})`;
|
|
83
|
+
const userLabel = chalk.magenta(label);
|
|
84
|
+
let outputLabel = `${userLabel} ${percentageLabel}`;
|
|
85
|
+
// Format label
|
|
86
|
+
// Note: by default it is user label then percentages but if `reverse` is TRUE, reverse the output order
|
|
87
|
+
if (reverse) outputLabel = `${percentageLabel} ${userLabel}`;
|
|
88
|
+
// Set flag if build process is in 'logging enabled' mode (LOGGER=true)
|
|
89
|
+
this.allowNewLine = process.env.LOGGER;
|
|
90
|
+
// Update spinner
|
|
91
|
+
this.update(outputLabel, currentColor);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
// HELPER METHODS
|
|
96
|
+
// ----------------------------------
|
|
97
|
+
|
|
98
|
+
clearLine() {
|
|
99
|
+
if (process && process.stdout && process.stdout.clearLine) {
|
|
100
|
+
process.stdout.clearLine();
|
|
101
|
+
process.stdout.cursorTo(0);
|
|
102
|
+
}
|
|
103
|
+
// Run this for Gitlab deploy logging
|
|
104
|
+
// Note: Not using this for local dev as the line doesn't clear correctly
|
|
105
|
+
else readline.cursorTo(process.stdout, 0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// EXPORT
|
|
111
|
+
// -----------------------------
|
|
112
|
+
export default Spinner;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file timer.js
|
|
3
|
+
* @description Custom terminal timer for tracking operation duration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// IMPORTS
|
|
7
|
+
// ----------------------------------
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
|
|
10
|
+
// DEFINE
|
|
11
|
+
// ----------------------------------
|
|
12
|
+
class Timer {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.timeEnd = null;
|
|
15
|
+
this.timeSplit = null;
|
|
16
|
+
this.timeStart = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
start() {
|
|
20
|
+
this.timeStart = new Date().getTime();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
split() {
|
|
24
|
+
const prevTime = !this.timeSplit ? this.timeStart : this.timeSplit;
|
|
25
|
+
this.timeSplit = new Date().getTime();
|
|
26
|
+
const diff = (this.timeSplit - prevTime) / 1000;
|
|
27
|
+
return chalk.grey(`| ${diff}s`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
end() {
|
|
31
|
+
this.timeEnd = new Date().getTime();
|
|
32
|
+
const diff = (this.timeEnd - this.timeStart) / 1000;
|
|
33
|
+
return chalk.grey(`| ${diff}s`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// EXPORT
|
|
39
|
+
// -----------------------------
|
|
40
|
+
export default Timer;
|