cayo 0.9.10 → 0.9.11
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/README.md +504 -5
- package/cayo.js +1 -298
- package/devlog.md +177 -0
- package/dist/cayo.svelte.js +80 -0
- package/dist/entry.svelte.js +16 -0
- package/dist/index.js +2 -0
- package/docs/config-reference.md +349 -0
- package/docs/how-cayo-works.md +28 -0
- package/docs/why-i-created-cayo.md +21 -0
- package/lib/cli/build.js +34 -0
- package/lib/cli/cli.js +152 -0
- package/lib/cli/dev.js +12 -0
- package/lib/cli/serve.js +25 -0
- package/lib/cli/watch.js +125 -0
- package/lib/core/bundle.js +155 -0
- package/lib/core/codegen.js +156 -0
- package/lib/core/compile/cayos.js +65 -0
- package/lib/core/compile/index.js +3 -0
- package/lib/core/compile/pages.js +61 -0
- package/lib/core/compile/template.js +24 -0
- package/lib/core/component.js +62 -0
- package/lib/core/config.js +206 -0
- package/lib/core/dependencies.js +167 -0
- package/lib/core/entry.js +24 -0
- package/lib/core/files.js +99 -0
- package/lib/core/logger.js +47 -0
- package/lib/core/page.js +59 -0
- package/lib/core/render/prerender.js +240 -0
- package/lib/core/render/renderer.js +52 -0
- package/lib/core/utils.js +60 -0
- package/package.json +21 -10
- package/scripts/build.js +60 -0
- package/src/cayo-warnings.js +37 -0
- package/src/cayo.svelte +36 -0
- package/src/entry.svelte +6 -0
- package/template/cayo.config.js +3 -0
- package/template/package.json +7 -0
- package/template/public/vite.svg +1 -0
- package/{tests/basic cases (old)/src/__index.svelte → template/src/__template.svelte} +3 -6
- package/template/src/components/counter.cayo.svelte +27 -0
- package/template/src/index.js +4 -0
- package/template/src/pages/index.svelte +15 -0
- package/template/src/style.css +13 -0
- package/lib/cli.js +0 -69
- package/lib/codegen.js +0 -79
- package/lib/components/Cayo.svelte +0 -25
- package/lib/config.js +0 -155
- package/lib/files.js +0 -84
- package/lib/prerender.js +0 -181
- package/lib/renderer.js +0 -49
- package/lib/runtime.js +0 -6
- package/lib/utils.js +0 -126
- package/lib/vite.config.js +0 -16
- package/notes.md +0 -3
- package/test/cayo.config.js +0 -35
- package/test/public/assets/cow.js +0 -1
- package/test/public/images/app-icon.png +0 -0
- package/test/src/__layout.svelte +0 -20
- package/test/src/components/Cool.cayo.svelte +0 -5
- package/test/src/components/Some.svelte +0 -1
- package/test/src/components/Test.cayo.svelte +0 -5
- package/test/src/index.js +0 -17
- package/test/src/main2.js +0 -1
- package/test/src/pages/hey.svelte +0 -8
- package/test/src/pages/howdy.svelte +0 -11
- package/test/src/pages/index.svelte +0 -38
- package/test/src/pages/some/page.svelte +0 -2
- package/tests/asset-dir/cayo.config.js +0 -38
- package/tests/asset-dir/package-lock.json +0 -1435
- package/tests/asset-dir/package.json +0 -19
- package/tests/asset-dir/public/images/app-icon.png +0 -0
- package/tests/asset-dir/src/__layout.svelte +0 -20
- package/tests/asset-dir/src/components/CayoExample.svelte +0 -5
- package/tests/asset-dir/src/components/Some.cayo.svelte +0 -6
- package/tests/asset-dir/src/index.js +0 -5
- package/tests/asset-dir/src/pages/index.svelte +0 -19
- package/tests/base-path/cayo.config.js +0 -36
- package/tests/base-path/package-lock.json +0 -1435
- package/tests/base-path/package.json +0 -19
- package/tests/base-path/public/assets/cow.js +0 -1
- package/tests/base-path/public/images/app-icon.png +0 -0
- package/tests/base-path/src/__layout.svelte +0 -20
- package/tests/base-path/src/components/CayoExample.svelte +0 -5
- package/tests/base-path/src/components/Some.cayo.svelte +0 -6
- package/tests/base-path/src/index.js +0 -5
- package/tests/base-path/src/pages/howdy.svelte +0 -12
- package/tests/base-path/src/pages/index.svelte +0 -20
- package/tests/basic/notcayo.config.js +0 -35
- package/tests/basic/package-lock.json +0 -1435
- package/tests/basic/package.json +0 -19
- package/tests/basic/public/assets/cow.js +0 -1
- package/tests/basic/public/images/app-icon.png +0 -0
- package/tests/basic/src/__layout.svelte +0 -20
- package/tests/basic/src/components/Cool.cayo.svelte +0 -4
- package/tests/basic/src/components/Some.svelte +0 -1
- package/tests/basic/src/index.js +0 -5
- package/tests/basic/src/main2.js +0 -1
- package/tests/basic/src/pages/hey.svelte +0 -8
- package/tests/basic/src/pages/howdy.svelte +0 -11
- package/tests/basic/src/pages/index.svelte +0 -33
- package/tests/basic/src/pages/some/some.svelte +0 -2
- package/tests/basic cases (old)/src/components/Cool.cayo.svelte +0 -4
- package/tests/basic cases (old)/src/components/Some.svelte +0 -1
- package/tests/basic cases (old)/src/components/dir/Cool.cayo.svelte +0 -4
- package/tests/basic cases (old)/src/main.js +0 -1
- package/tests/basic cases (old)/src/main2.js +0 -1
- package/tests/basic cases (old)/src/pages/hey.svelte +0 -2
- package/tests/basic cases (old)/src/pages/howdy.svelte +0 -11
- package/tests/basic cases (old)/src/pages/index.svelte +0 -27
- package/tests/nested-pages/cayo.config.js +0 -35
- package/tests/nested-pages/package-lock.json +0 -1435
- package/tests/nested-pages/package.json +0 -19
- package/tests/nested-pages/public/assets/cow.js +0 -1
- package/tests/nested-pages/public/images/app-icon.png +0 -0
- package/tests/nested-pages/src/__layout.svelte +0 -20
- package/tests/nested-pages/src/components/Cool.cayo.svelte +0 -4
- package/tests/nested-pages/src/index.js +0 -5
- package/tests/nested-pages/src/main2.js +0 -1
- package/tests/nested-pages/src/pages/index.svelte +0 -18
- package/tests/nested-pages/src/pages/some/other/page.svelte +0 -7
- package/tests/nested-pages/src/pages/some/page.svelte +0 -6
package/cayo.js
CHANGED
|
@@ -1,302 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import chokidar from 'chokidar';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
import merge from 'deepmerge';
|
|
8
|
-
import { createServer, createLogger, build as viteBuild } from 'vite';
|
|
9
|
-
import { loadConfig, checkConfigPaths } from './lib/config.js';
|
|
10
|
-
import { prerender } from './lib/prerender.js';
|
|
11
|
-
import {
|
|
12
|
-
writePageFiles,
|
|
13
|
-
writeComponentFile,
|
|
14
|
-
cleanCayoPath,
|
|
15
|
-
writeTemplateCSS,
|
|
16
|
-
} from './lib/files.js';
|
|
17
|
-
import {
|
|
18
|
-
hash,
|
|
19
|
-
getPageModules,
|
|
20
|
-
getComponentModules,
|
|
21
|
-
createTemplateManifest,
|
|
22
|
-
createPageManifest,
|
|
23
|
-
createComponentManifest,
|
|
24
|
-
} from './lib/utils.js';
|
|
25
|
-
|
|
26
|
-
const logger = createLogger('info', {
|
|
27
|
-
prefix: chalk.magenta.bold('[cayo]'),
|
|
28
|
-
// allowClearScreen: true,
|
|
29
|
-
});
|
|
30
|
-
const errorLogger = createLogger('warn', {
|
|
31
|
-
prefix: chalk.red.bold('[cayo]'),
|
|
32
|
-
// allowClearScreen: true,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const data = {
|
|
36
|
-
template: undefined,
|
|
37
|
-
pages: undefined,
|
|
38
|
-
components: undefined,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// / Handle arguments
|
|
42
|
-
function resolveArgs(argv) {
|
|
43
|
-
const cmd = argv._[2];
|
|
44
|
-
|
|
45
|
-
const options = {
|
|
46
|
-
projectRoot: typeof argv.projectRoot === 'string' ? argv.projectRoot : undefined,
|
|
47
|
-
configPath: typeof argv.config === 'string' ? argv.config : undefined,
|
|
48
|
-
mode: cmd === 'build' ? 'production' : 'development',
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
switch (cmd) {
|
|
52
|
-
case 'build':
|
|
53
|
-
case 'dev':
|
|
54
|
-
case 'help':
|
|
55
|
-
return { cmd: cmd, options };
|
|
56
|
-
default:
|
|
57
|
-
return { cmd: 'help', options };
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function printHelp() {
|
|
62
|
-
// TODO: help info
|
|
63
|
-
console.log('help');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Run
|
|
67
|
-
export async function cli(args) {
|
|
68
|
-
const argv = yargs(args);
|
|
69
|
-
const command = resolveArgs(argv);
|
|
70
|
-
|
|
71
|
-
switch(command.cmd) {
|
|
72
|
-
case 'dev':
|
|
73
|
-
case 'build':
|
|
74
|
-
run(command);
|
|
75
|
-
break;
|
|
76
|
-
case 'help':
|
|
77
|
-
default:
|
|
78
|
-
printHelp();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const commands = new Map([
|
|
83
|
-
['build', async (config) => {
|
|
84
|
-
await prerenderPages(config).then((pages)=> {
|
|
85
|
-
build(config, pages);
|
|
86
|
-
});
|
|
87
|
-
}],
|
|
88
|
-
['dev', (config) => {
|
|
89
|
-
prerenderPages(config);
|
|
90
|
-
watch(config);
|
|
91
|
-
serve(config);
|
|
92
|
-
}]
|
|
93
|
-
]);
|
|
94
|
-
|
|
95
|
-
async function run(command) {
|
|
96
|
-
const { cmd, options } = command;
|
|
97
|
-
|
|
98
|
-
logger.info(
|
|
99
|
-
`\n ${chalk.magenta.bold(`cayo.${cmd}`)}${chalk.dim(` starting`)}`,
|
|
100
|
-
{ timestamp: false }
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const config = await loadConfig(options);
|
|
105
|
-
checkConfigPaths(config, errorLogger);
|
|
106
|
-
|
|
107
|
-
// Create a fresh cayo folder for this run
|
|
108
|
-
cleanCayoPath(config.cayoPath);
|
|
109
|
-
|
|
110
|
-
getTemplate(config)
|
|
111
|
-
.then(() => getPages(config))
|
|
112
|
-
.then(() => getCayoComponents(config))
|
|
113
|
-
.then((components) => {
|
|
114
|
-
handleCayoComponents(components, config);
|
|
115
|
-
})
|
|
116
|
-
.then(() => {
|
|
117
|
-
const runCommand = commands.get(cmd);
|
|
118
|
-
runCommand(config);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
} catch (err) {
|
|
122
|
-
console.error(err);
|
|
123
|
-
process.exit(1);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function getTemplate(config) {
|
|
128
|
-
const { src, cayoPath, templateFileName } = config;
|
|
129
|
-
return createTemplateManifest(path.resolve(src, `${templateFileName}.svelte`), cayoPath)
|
|
130
|
-
.then(async () => {
|
|
131
|
-
const { Template } = await import(path.resolve(cayoPath, `./__cayo/template.js?v=${hash()}`))
|
|
132
|
-
data.template = Template;
|
|
133
|
-
return data.template;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function getPages(config) {
|
|
138
|
-
const { src, pages, cayoPath } = config;
|
|
139
|
-
return createPageManifest(pages, cayoPath, src)
|
|
140
|
-
.then(async () => await import(path.resolve(cayoPath, `./__cayo/pages.js?v=${hash()}`)))
|
|
141
|
-
.then(({ pages }) => {
|
|
142
|
-
data.pages = getPageModules(pages, config);
|
|
143
|
-
return data.pages;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async function getCayoComponents(config) {
|
|
148
|
-
const { src, cayoPath } = config;
|
|
149
|
-
return createComponentManifest(src, cayoPath)
|
|
150
|
-
.then(async () => await import(path.resolve(cayoPath, `./__cayo/components.js?v=${hash()}`)))
|
|
151
|
-
.then(({ components }) => {
|
|
152
|
-
data.components = getComponentModules(components, config);
|
|
153
|
-
return data.components;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function watch(config) {
|
|
158
|
-
|
|
159
|
-
const watcher = chokidar.watch(config.src, {
|
|
160
|
-
// awaitWriteFinish: {
|
|
161
|
-
// stabilityThreshold: 1,
|
|
162
|
-
// pollInterval: 250
|
|
163
|
-
// },
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const configWatcher = chokidar.watch(path.resolve(config.src, '../cayo.config.js'));
|
|
167
|
-
configWatcher.on('change', (filePath) => {
|
|
168
|
-
logger.info(
|
|
169
|
-
chalk.yellow(`> config updated... restart dev server to use new config.`),
|
|
170
|
-
{ timestamp: true, clear: true, }
|
|
171
|
-
);
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
const logChange = (type) => {
|
|
175
|
-
logger.info(
|
|
176
|
-
`> ${type} updated`,
|
|
177
|
-
{ timestamp: true, clear: true, }
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
watcher.on('change', async (filePath) => {
|
|
182
|
-
if (filePath.endsWith('.svelte')) {
|
|
183
|
-
if (filePath.endsWith(`${config.templateFileName}.svelte`)) {
|
|
184
|
-
logChange('template')
|
|
185
|
-
getTemplate(config)
|
|
186
|
-
.then(() => prerenderPages(config));
|
|
187
|
-
|
|
188
|
-
} else if (filePath.startsWith(config.pages)) {
|
|
189
|
-
logChange('page');
|
|
190
|
-
getPages(config)
|
|
191
|
-
.then((pages) => {
|
|
192
|
-
let pageModule = Object.entries(pages).find(([, { modulePath }]) => modulePath === filePath);
|
|
193
|
-
let page = pageModule ? { [`${pageModule[0]}`]: pageModule[1] } : {}
|
|
194
|
-
prerenderPages(config, page);
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
} else if (filePath.includes(`.${config.cayoComponentInfix}`)) {
|
|
198
|
-
logChange('cayo component');
|
|
199
|
-
getCayoComponents(config)
|
|
200
|
-
.then((components) => {
|
|
201
|
-
let componentModule = Object.entries(components).find(([, { modulePath }]) => modulePath === filePath);
|
|
202
|
-
handleCayoComponent(componentModule[0], componentModule[1].modulePath, config);
|
|
203
|
-
})
|
|
204
|
-
} else if (filePath.includes('/components')) {
|
|
205
|
-
logChange('component');
|
|
206
|
-
getPages(config)
|
|
207
|
-
.then(() => {
|
|
208
|
-
prerenderPages(config);
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
// TODO: watch component changes
|
|
212
|
-
// } else if (componentFileChanged) {
|
|
213
|
-
// find out which pages are affected
|
|
214
|
-
// find out which components are affected (imports)?
|
|
215
|
-
} else {
|
|
216
|
-
prerenderPages(config);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
// watcher.close();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async function serve(config) {
|
|
224
|
-
|
|
225
|
-
const internalConfig = {
|
|
226
|
-
root: config.cayoPath,
|
|
227
|
-
publicDir: config.publicDir,
|
|
228
|
-
mode: config.mode,
|
|
229
|
-
base: config.base,
|
|
230
|
-
configFile: false,
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const mergedConfig = merge(config.viteConfig, internalConfig);
|
|
234
|
-
|
|
235
|
-
const server = await createServer({
|
|
236
|
-
...mergedConfig,
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
await server.listen()
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
async function build(config, pages) {
|
|
243
|
-
|
|
244
|
-
// Create inputs for rollup based on the pages
|
|
245
|
-
const inputs = {};
|
|
246
|
-
|
|
247
|
-
for (const [, page] of Object.entries(pages)) {
|
|
248
|
-
if (page.filePath === 'index') {
|
|
249
|
-
inputs['main'] = path.resolve(config.cayoPath, 'index.html');
|
|
250
|
-
} else {
|
|
251
|
-
inputs[page.filePath] = path.resolve(config.cayoPath, `${page.filePath}/index.html`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const internalConfig = {
|
|
256
|
-
root: config.cayoPath,
|
|
257
|
-
publicDir: config.publicDir,
|
|
258
|
-
base: config.base,
|
|
259
|
-
mode: config.mode,
|
|
260
|
-
build: {
|
|
261
|
-
outDir: config.build.outDir,
|
|
262
|
-
assetsDir: config.build.assetsDir,
|
|
263
|
-
emptyOutDir: true,
|
|
264
|
-
rollupOptions: {
|
|
265
|
-
input: { ...inputs },
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const mergedConfig = merge(config.viteConfig, internalConfig);
|
|
271
|
-
|
|
272
|
-
return await viteBuild({
|
|
273
|
-
...mergedConfig,
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
async function prerenderPages(config, pages = data.pages) {
|
|
278
|
-
const { template: Template, components } = data;
|
|
279
|
-
const { prerendered, template } = prerender(Template, pages, components, config, logger);
|
|
280
|
-
|
|
281
|
-
for (const [, page] of Object.entries(prerendered)) {
|
|
282
|
-
await writePageFiles(page, config.cayoPath, logger, config);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Does nothing, if no CSS generated by template file render
|
|
286
|
-
await writeTemplateCSS(template.css, config.cayoPath, logger, config);
|
|
287
|
-
|
|
288
|
-
return prerendered;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
async function handleCayoComponent(name, modulePath, config) {
|
|
292
|
-
writeComponentFile(name, modulePath, config.cayoPath, logger);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
async function handleCayoComponents(components = data.components, config) {
|
|
296
|
-
Object.keys(components).forEach(name => {
|
|
297
|
-
let component = components[name];
|
|
298
|
-
handleCayoComponent(name, component.modulePath, config);
|
|
299
|
-
})
|
|
300
|
-
}
|
|
3
|
+
import { cli } from './lib/cli/cli.js';
|
|
301
4
|
|
|
302
5
|
cli(process.argv);
|
package/devlog.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
I keep forgetting what the heck I'm doing with this code, so here is where I'll log current progress
|
|
2
|
+
|
|
3
|
+
## 2022.5.28
|
|
4
|
+
|
|
5
|
+
- I think I was working on getting components to work in the new rollup workflow
|
|
6
|
+
- Noticed last time that saving a component file causes an error, so
|
|
7
|
+
|
|
8
|
+
Thinking that maybe this problem is from leftovers; before rollup we needed to create JS module versions of Svelte components, but now they get bundled with the page's module. The only components that do need to exist as a separate dependency (that gets module-ified) are Cayo components. Think I can just remove all the dependency handling stuff for components, and just make sure their dependee pages are rerendered
|
|
9
|
+
|
|
10
|
+
Also, prerender can't seem to get the Cayo component names anymore. groups is null, which may just mean it needs a try-catch?
|
|
11
|
+
|
|
12
|
+
So I think some re-org needs to happen, because the error is indeed happening where the regex is. I can write a new regex, but the format of the component name/id is the src version (user input, which is just a path), instead of the dependency processed version, which creates a unique name based on the folder structure. I could do a few things:
|
|
13
|
+
1. abstract the processing code to a utility function that I can use both in dependencies.js and prerender.js
|
|
14
|
+
- depdencies.js actually uses it to replace the import name at the top of the file, I think
|
|
15
|
+
2. reorg the workflow for components, still abstract the unique rename utility function, but preprocess the markup during the preprocess step instead. That way, anything looking at the code
|
|
16
|
+
|
|
17
|
+
So I actually already noted that #2 is [what to do here](https://github.com/matthew-ia/cayo/issues/50#issuecomment-1086516314), lmao.
|
|
18
|
+
|
|
19
|
+
Breaking down what actuall needs to be done:
|
|
20
|
+
1. Internal preprocessor (cayoPreprocess) should be passed to rollup.bundle before sveltePreprocess
|
|
21
|
+
2. cayoPreprocess runs a markup preprocessor function; that preprocessor runs multiple transformers, including one to specifically handle the unique cayo component names
|
|
22
|
+
- cayo src (prop name) -> cayo ID (unique name based on src + hash)
|
|
23
|
+
- src: needed by dependencies.js at the moment to run
|
|
24
|
+
- id: needed by runtime stuff, should match the filename of the bundled cayo component module
|
|
25
|
+
|
|
26
|
+
Right now, prerender.js does create a list of the cayoComponenents and update the stats list, but I think it does that there only because that's where I had been doing the markup processing to get those Cayo component names. I should be able to do the stats stuff in preprocess just fine.
|
|
27
|
+
|
|
28
|
+
I think most of prerender.js should actually be in preprocess; the only thing that it should do is actually prerender the page with the template.
|
|
29
|
+
|
|
30
|
+
P.S. stats might be broken because I see it write a mostly empty object; no pages or components are listed. I think when the rollup switchover happened it prob stopped working
|
|
31
|
+
|
|
32
|
+
## 2022.6.22
|
|
33
|
+
|
|
34
|
+
Worked mostly regarding the imports stuff in preprocess/index.js. I think a new bug has been introduced somewhere with aliases, when trying to use the #cayo alias in the temporary test/ folder in cayo itself. To fix, I created a new test repo outside of the cayo repo in order to test as a normal package. This is probably better, and now it's working. Just had to add some "library/package" support as detailed by Svelte folks within the package.json of cayo, and change the path references in the test/src. E.g., `import Cayo from 'cayo'` is valid now.
|
|
35
|
+
|
|
36
|
+
## 2022.7.31
|
|
37
|
+
|
|
38
|
+
### Import Stuff
|
|
39
|
+
|
|
40
|
+
Fixed the import/export stuff. `import Cayo from 'cayo/component'` works now.
|
|
41
|
+
|
|
42
|
+
`import Cayo from 'cayo'` still works too, but I think I might deprecate that. In case anything makes sense to expose directly from the root of the package. Unless, I want to make the this work:
|
|
43
|
+
`import { component as Cayo } from 'cayo'`, but I think the new 'cayo/component' one works more like how Svelte looks/works when you're working within your own project (always exports component as default).
|
|
44
|
+
|
|
45
|
+
### Actual Stuff
|
|
46
|
+
|
|
47
|
+
Question to answer: do we need the src string at all, since we are compiling the child components into each page?
|
|
48
|
+
|
|
49
|
+
We do need to recompile the page when a child component changes. Maybe that's why we need it? (Could it from here, but use it elsewhere).
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
Okay so I got the markup preprocessor working with the AST -> string manipulation thing for Cayo IDs. Next up: make sure the IDs are correct, and would match how they'll be named in the actual output.
|
|
54
|
+
|
|
55
|
+
## 2022.8.1
|
|
56
|
+
|
|
57
|
+
Moved the cayoID stuff back to prerender, bc it's easier to just do it with JSDOM and after it's compiled to HTML.
|
|
58
|
+
However, I'm running into the issue of the original paths for the Cayo component src attribute being relative to the component rendering it, not the page. And at the HTML level, I don't know where it was.
|
|
59
|
+
|
|
60
|
+
I think I Do still need to do some preprocessing to change the Cayo src's to be relative to the project root, so I know where the actual component is in the src files when I'm creating those IDs and getting a list of Cayo components. Unless I should just grab those Cayo component paths early, and pass them along. Not sure yet.
|
|
61
|
+
|
|
62
|
+
Think if we do it in preprocess, we'll need to parse -> walk the ast in both script and markup. Change src=<this>
|
|
63
|
+
or if it's an object defined in script, just find it by any instance of '.cayo.svelte' and replace it with the relative-to-root path. The getRelativeToRootPath logic can be extracted into a helper, but the walking has to be done
|
|
64
|
+
individually, because we'll be looking for different AST types. Prob just Text in scriptPreprocessor and then what we
|
|
65
|
+
already had in markupPreprocessor
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
Decided to simply change the requirements of the src prop to be that it has
|
|
70
|
+
to be relative to your components dir. Bam, all the problems solved, and no
|
|
71
|
+
path math required.
|
|
72
|
+
|
|
73
|
+
## 2022.8.2
|
|
74
|
+
|
|
75
|
+
Alright so I pretty much fixed handleDependencies (and thus, stats), which is cool, but components are still structured to "compile" even though I just need to get their deps, so
|
|
76
|
+
I have the dep tree.
|
|
77
|
+
|
|
78
|
+
When _needs_ to happen when a component is touched, instead of compile it, we need to compile any pages that render it, either directly or via another component.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## 2022.8.7
|
|
82
|
+
|
|
83
|
+
Made it so pages compiled and written on start. This may have worked at one point, and this is a revival? But even if it used to work, it needed to be reworked because with the latest structure, a page can be compiled to a bundle, that bundle can be written to a file, and that bundle can be loaded as a module, all as a part of the Page API.
|
|
84
|
+
|
|
85
|
+
E.g.,
|
|
86
|
+
```js
|
|
87
|
+
// some.js
|
|
88
|
+
let pages = [srcPageFilePath]
|
|
89
|
+
// Normally, we'd be working with more than one page, but this is how you'd
|
|
90
|
+
// work with just one page, for explanation purposes.
|
|
91
|
+
//
|
|
92
|
+
// Compile the page (always expects an array of pages, but can be one)
|
|
93
|
+
// We also get an array back, of Page objects. So here, we are just
|
|
94
|
+
// destructuring the array to get the one result of the one path put in
|
|
95
|
+
const [ page ] = compile.pages(pages, ...)
|
|
96
|
+
// Write the bundle to a file
|
|
97
|
+
await page.writeModule()
|
|
98
|
+
// Loads with cash-busting method, so it's always up to date
|
|
99
|
+
await page.loadModule()
|
|
100
|
+
// Render the page
|
|
101
|
+
await page.render(false, stats.cayoComponents);
|
|
102
|
+
// Finally, write all of the prerendered page files (HTML, JS, CSS)
|
|
103
|
+
writePageFiles(page, config.cayoPath, config);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Only optimization I'd consider it making these Page methods runnable from a single function. Maybe something like:
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
// page.js
|
|
110
|
+
class Page {
|
|
111
|
+
// ...
|
|
112
|
+
process(cayoComponents) {
|
|
113
|
+
this.writeModule()
|
|
114
|
+
this.loadModule()
|
|
115
|
+
this.render(false, cayoComponents);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// some.js
|
|
120
|
+
await page.process(stats.cayoComponents)
|
|
121
|
+
writePageFiles(page, config.cayoPath, config);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Right now, a similar usage for compiling pages is only used in `handlePages` in `cli/watch.js` and in the main function `run` in `cli/index/js`, as far as I know.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
Just realized I was wrong, `writeModule` actually does nothing now. That is handled in `compile/pages.js`. So we could more reasonably update the usage to just have `page.render(...)` run load before it runs prerender. (There was already a `load` arg defaulted to false, that is in the signature for `render`. I had forgotten what that did, and it looks like I either removed its functionality or never added it. Now I think I can, since we've figured out how the compile/bundling works (now with Rollup)
|
|
129
|
+
|
|
130
|
+
Edit: I went ahead and did this, but changed the load arg to a member of an options object:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
await page.render(stats.cayoComponents, { load: true })
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### This is what's Next
|
|
138
|
+
|
|
139
|
+
- [ ] Make sure the above doesn't need to apply to Layout in a similar way
|
|
140
|
+
- [x] Getting the client-side Cayo component files to be output
|
|
141
|
+
```
|
|
142
|
+
[plugin:vite:import-analysis] Failed to resolve import "/__cayo/components/Test.js" from ".cayo/cayo-runtime.js". Does the file exist?
|
|
143
|
+
|
|
144
|
+
/Users/malicea/home/main/01 dev/code/test-cayo/.cayo/cayo-runtime.js:1:23
|
|
145
|
+
|
|
146
|
+
1 | import { Test } from '/__cayo/components/Test.js';
|
|
147
|
+
| ^
|
|
148
|
+
2 |
|
|
149
|
+
3 | function getProps(cayoId) {
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- [ ] Rewrite handleComponents in `cli/watch.js` to work with the new structure, and recompile and rerender pages that its changes affect.
|
|
153
|
+
- [ ] Consider renaming `__cayo` to `__compiled` to be more indicative of what those files are. Also, at the very least, the double "cayo" in `.cayo/__cayo` looks kind of confusing.
|
|
154
|
+
|
|
155
|
+
### Later that day...
|
|
156
|
+
|
|
157
|
+
Got Client-side Cayo components to output. Next: watching components and rebuilding their pages, and watching cayo components and rebuilding their client-side component version.
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
## 2022.8.9
|
|
161
|
+
|
|
162
|
+
Got watching to work, and the pages get rerendered. Still need to do the cross-dependency analysis for instances where I edit B.svelte, which is imported into A.svelte, but page.svelte imports only A.svelte.
|
|
163
|
+
|
|
164
|
+
When editing B, need to see the dependency chain: B -> A -> page.
|
|
165
|
+
|
|
166
|
+
Since we start with B path, we have to look through the dep tree for an instance of B, then get the depender path. Then once we have the depender (A) path, do the same thing: look through dep tree for an instance of A.
|
|
167
|
+
|
|
168
|
+
So, recursively search for a dependee's dependers until we hit a page, then rerender it.
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
## 2022.8.13
|
|
172
|
+
|
|
173
|
+
For Docs:
|
|
174
|
+
Need to note that the output `cayo-runtime.js`'s `render(cb)` callback function should look like `(node) => { return node; }`
|
|
175
|
+
|
|
176
|
+
Does it need the function keyword? (Needs "this"? might)
|
|
177
|
+
in codegen, the default cb is: `function (node) { return node; }`
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { create_ssr_component, compute_rest_props, spread, escape_object } from 'svelte/internal';
|
|
2
|
+
|
|
3
|
+
function getWarnings(src, badProps) {
|
|
4
|
+
const warnings = {};
|
|
5
|
+
checkInvalidSrc(warnings, src);
|
|
6
|
+
checkBadProps(warnings, src, badProps);
|
|
7
|
+
return warnings;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Warning: invalid src prop')
|
|
11
|
+
function checkInvalidSrc(warnings, src) {
|
|
12
|
+
if (!src || typeof src !== 'string') {
|
|
13
|
+
warnings.invalidSrc = {
|
|
14
|
+
title: `Invalid src prop`,
|
|
15
|
+
src: !src ? 'undefined' : typeof src,
|
|
16
|
+
message: `The src prop is required and must be a string.`,
|
|
17
|
+
log: `Use of <Cayo> without a src prop found. No cayo instance will be rendered.`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Warning: unserializable props
|
|
23
|
+
function checkBadProps(warnings, src, keys) {
|
|
24
|
+
if (keys.length > 0) {
|
|
25
|
+
let propsStr = '';
|
|
26
|
+
for (let i = 0; i < keys.length; i++) {
|
|
27
|
+
propsStr += `'${keys[i]}'`;
|
|
28
|
+
if (i+1 < keys.length) {
|
|
29
|
+
propsStr += `, `;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
warnings.badProps = {
|
|
33
|
+
title: `Bad props`,
|
|
34
|
+
src,
|
|
35
|
+
message: `Unserializable props found: ${propsStr}. Cayo component props must be serializable in order to be used for hydration.`,
|
|
36
|
+
log: `Unserializable instance props found: ${propsStr}.`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* src/cayo.svelte generated by Svelte v3.49.0 */
|
|
42
|
+
|
|
43
|
+
const Cayo = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
44
|
+
let $$restProps = compute_rest_props($$props, ["src"]);
|
|
45
|
+
let { src } = $$props;
|
|
46
|
+
|
|
47
|
+
// Save unserializable prop keys (during stringification)
|
|
48
|
+
// so we can report them later
|
|
49
|
+
const badProps = [];
|
|
50
|
+
|
|
51
|
+
function replacer(key, value) {
|
|
52
|
+
const type = typeof value;
|
|
53
|
+
|
|
54
|
+
if (type === 'function' || type === 'undefined' || type === 'symbol') {
|
|
55
|
+
badProps.push(key);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
const json = JSON.stringify({ ...$$restProps }, replacer);
|
|
61
|
+
const warnings = getWarnings(src, badProps);
|
|
62
|
+
|
|
63
|
+
const cayoInstanceData = {
|
|
64
|
+
'data-cayo-id': '',
|
|
65
|
+
'data-cayo-src': !warnings.invalidSrc ? `${src}` : '',
|
|
66
|
+
'data-cayo-props': json
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (warnings) {
|
|
70
|
+
cayoInstanceData['data-cayo-warn'] = JSON.stringify(warnings);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if ($$props.src === void 0 && $$bindings.src && src !== void 0) $$bindings.src(src);
|
|
74
|
+
|
|
75
|
+
return `<div${spread([escape_object(cayoInstanceData)], {})}>
|
|
76
|
+
${slots.default ? slots.default({}) : ``}
|
|
77
|
+
</div>`;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export { Cayo as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { create_ssr_component, add_attribute } from 'svelte/internal';
|
|
2
|
+
|
|
3
|
+
/* src/entry.svelte generated by Svelte v3.49.0 */
|
|
4
|
+
|
|
5
|
+
const Entry = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
6
|
+
let { src } = $$props;
|
|
7
|
+
if ($$props.src === void 0 && $$bindings.src && src !== void 0) $$bindings.src(src);
|
|
8
|
+
|
|
9
|
+
return `${slots.default
|
|
10
|
+
? slots.default({})
|
|
11
|
+
: `
|
|
12
|
+
<script${add_attribute("src", src, 0)} data-cayo-entry></script>
|
|
13
|
+
`}`;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export { Entry as default };
|
package/dist/index.js
ADDED