cayo 1.1.2 → 1.2.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/lib/core/bundle.js
CHANGED
|
@@ -70,10 +70,15 @@ export async function getDeps(input, config) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export async function build(input, config, type = 'page') {
|
|
73
|
-
const
|
|
73
|
+
const template = (type === 'page' || type === 'template');
|
|
74
74
|
const requiredCompilerOptions = {
|
|
75
|
-
generate:
|
|
76
|
-
hydratable:
|
|
75
|
+
generate: template ? 'ssr' : 'dom',
|
|
76
|
+
hydratable: template ? false : true,
|
|
77
|
+
preserveComments: template
|
|
78
|
+
? false
|
|
79
|
+
: config.svelte.compilerOptions.preserveComments
|
|
80
|
+
? config.svelte.compilerOptions.preserveComments
|
|
81
|
+
: true,
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
let bundle;
|
|
@@ -95,7 +100,6 @@ export async function build(input, config, type = 'page') {
|
|
|
95
100
|
...preprocessors,
|
|
96
101
|
],
|
|
97
102
|
compilerOptions: {
|
|
98
|
-
preserveComments: true,
|
|
99
103
|
preserveWhitespace: true,
|
|
100
104
|
...config.svelte.compilerOptions,
|
|
101
105
|
...requiredCompilerOptions,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { JSDOM } from 'jsdom';
|
|
4
|
+
import chalk from 'chalk';
|
|
4
5
|
import { Renderer } from './renderer.js';
|
|
5
6
|
import { compileCayos } from '../compile/cayos.js';
|
|
6
7
|
import { generateCayoRuntime, generateRuntimeIssuesScript } from '../codegen.js';
|
|
@@ -116,7 +117,16 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
const cayoAssetsCssMarker = document.querySelector('link[data-cayo-assets-css]');
|
|
119
|
-
cayoAssetsCssMarker.outerHTML
|
|
120
|
+
if (cayoAssetsCssMarker && cayoAssetsCssMarker.outerHTML) {
|
|
121
|
+
cayoAssetsCssMarker.outerHTML = cayoAssetCssElements;
|
|
122
|
+
} else {
|
|
123
|
+
if (cayoAssetCssElements) {
|
|
124
|
+
logger.log.info(
|
|
125
|
+
chalk.yellow.bold('Warning') + chalk.yellow(': No %cayo.css% found in template, but there is CSS used in source files.'),
|
|
126
|
+
{ timestamp: true, clear: false, }
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
120
130
|
|
|
121
131
|
// Get user-specified entry placeholder
|
|
122
132
|
const entryScriptPlaceholder = document.querySelector('script[data-cayo-entry]');
|
|
@@ -138,7 +148,7 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
138
148
|
log: `Entry file '${entryScriptSrc}' does not exist.`,
|
|
139
149
|
}
|
|
140
150
|
// Remove the entry file script because the file doesn't exist
|
|
141
|
-
entryScript
|
|
151
|
+
entryScript?.remove();
|
|
142
152
|
} else {
|
|
143
153
|
entry.path = absoluteEntrySrcPath;
|
|
144
154
|
_cayo.stats.dependencies.pages[page.sourcePath].add(absoluteEntrySrcPath);
|
|
@@ -154,7 +164,7 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
154
164
|
}
|
|
155
165
|
} else {
|
|
156
166
|
// Remove the entry point script tag because the page doesn't need any JS
|
|
157
|
-
entryScript
|
|
167
|
+
entryScript?.remove();
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
170
|
|
|
@@ -199,22 +209,32 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
199
209
|
let processedHTML = '';
|
|
200
210
|
if (tags.doctype) {
|
|
201
211
|
processedHTML += tags.doctype;
|
|
202
|
-
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let html; // html element parts (open/close tag, inner)
|
|
215
|
+
let head;
|
|
203
216
|
if (tags.html) {
|
|
204
|
-
|
|
217
|
+
({groups: html} = document.documentElement.outerHTML
|
|
218
|
+
.match(/(?<open><html[\s\S]*?>)(?<innerHTML>[\s\S]*)(?<close><\/html>)/)
|
|
219
|
+
)
|
|
220
|
+
processedHTML += html.open;
|
|
221
|
+
}
|
|
222
|
+
if (tags.head) {
|
|
223
|
+
({groups: head} = document.head.outerHTML
|
|
224
|
+
.match(/(?<open><head[\s\S]*?>)(?<innerHTML>[\s\S]*)(?<close><\/head>)/)
|
|
225
|
+
)
|
|
226
|
+
processedHTML += document.head.outerHTML;
|
|
205
227
|
} else {
|
|
206
|
-
|
|
207
|
-
processedHTML += document.head.outerHTML;
|
|
208
|
-
} else {
|
|
209
|
-
processedHTML += document.head.innerHTML;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (tags.body) {
|
|
213
|
-
processedHTML += document.body.outerHTML;
|
|
214
|
-
} else {
|
|
215
|
-
processedHTML += document.body.innerHTML;
|
|
216
|
-
}
|
|
228
|
+
processedHTML += document.head.innerHTML;
|
|
217
229
|
}
|
|
230
|
+
if (tags.body) {
|
|
231
|
+
processedHTML += document.body.outerHTML;
|
|
232
|
+
} else {
|
|
233
|
+
processedHTML += document.body.innerHTML;
|
|
234
|
+
}
|
|
235
|
+
if (tags.html) {
|
|
236
|
+
processedHTML += html.close;
|
|
237
|
+
}
|
|
218
238
|
|
|
219
239
|
return {
|
|
220
240
|
html: processedHTML,
|
|
@@ -227,14 +247,14 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
227
247
|
}
|
|
228
248
|
|
|
229
249
|
function tagsExist(source) {
|
|
230
|
-
const doctype = source.match(
|
|
231
|
-
const head = source.match(
|
|
232
|
-
const body = source.match(
|
|
233
|
-
const html = source.match(
|
|
250
|
+
const doctype = source.match(/<!DOCTYPE[\s\S]*>/);
|
|
251
|
+
const head = source.match(/<head[\s\S]*>(?<innerHTML>[\s\S]*)<\/head>/);
|
|
252
|
+
const body = source.match(/<body[\s\S]*>(?<innerHTML>[\s\S]*)<\/body>/);
|
|
253
|
+
const html = source.match(/<html[\s\S]*>(?<innerHTML>[\s\S]*)<\/html>/);
|
|
234
254
|
return {
|
|
235
255
|
doctype: doctype === null ? false : doctype,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
256
|
+
html: html === null ? false : html.groups,
|
|
257
|
+
head: head === null ? false : head.groups,
|
|
258
|
+
body: body === null ? false : body.groups,
|
|
239
259
|
};
|
|
240
260
|
}
|
|
@@ -37,9 +37,9 @@ export class Renderer {
|
|
|
37
37
|
// https://stackoverflow.com/questions/9423722/string-replace-weird-behavior-when-using-dollar-sign-as-replacement
|
|
38
38
|
return {
|
|
39
39
|
html: this.template.html
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
// Strip placeholders wrapped in HTML comments
|
|
41
|
+
.replace(/<!--[\s\S]?%cayo\.\w+%[\s\S]*?(-->)/g, '')
|
|
42
|
+
// Inject markup in the cayo placeholders
|
|
43
43
|
.replace('%cayo.title%', () => !head.includes('<title>') ? title() : '')
|
|
44
44
|
.replace('%cayo.head%', () => head)
|
|
45
45
|
.replace('%cayo.body%', () => html)
|