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.
Files changed (121) hide show
  1. package/README.md +504 -5
  2. package/cayo.js +1 -298
  3. package/devlog.md +177 -0
  4. package/dist/cayo.svelte.js +80 -0
  5. package/dist/entry.svelte.js +16 -0
  6. package/dist/index.js +2 -0
  7. package/docs/config-reference.md +349 -0
  8. package/docs/how-cayo-works.md +28 -0
  9. package/docs/why-i-created-cayo.md +21 -0
  10. package/lib/cli/build.js +34 -0
  11. package/lib/cli/cli.js +152 -0
  12. package/lib/cli/dev.js +12 -0
  13. package/lib/cli/serve.js +25 -0
  14. package/lib/cli/watch.js +125 -0
  15. package/lib/core/bundle.js +155 -0
  16. package/lib/core/codegen.js +156 -0
  17. package/lib/core/compile/cayos.js +65 -0
  18. package/lib/core/compile/index.js +3 -0
  19. package/lib/core/compile/pages.js +61 -0
  20. package/lib/core/compile/template.js +24 -0
  21. package/lib/core/component.js +62 -0
  22. package/lib/core/config.js +206 -0
  23. package/lib/core/dependencies.js +167 -0
  24. package/lib/core/entry.js +24 -0
  25. package/lib/core/files.js +99 -0
  26. package/lib/core/logger.js +47 -0
  27. package/lib/core/page.js +59 -0
  28. package/lib/core/render/prerender.js +240 -0
  29. package/lib/core/render/renderer.js +52 -0
  30. package/lib/core/utils.js +60 -0
  31. package/package.json +21 -10
  32. package/scripts/build.js +60 -0
  33. package/src/cayo-warnings.js +37 -0
  34. package/src/cayo.svelte +36 -0
  35. package/src/entry.svelte +6 -0
  36. package/template/cayo.config.js +3 -0
  37. package/template/package.json +7 -0
  38. package/template/public/vite.svg +1 -0
  39. package/{tests/basic cases (old)/src/__index.svelte → template/src/__template.svelte} +3 -6
  40. package/template/src/components/counter.cayo.svelte +27 -0
  41. package/template/src/index.js +4 -0
  42. package/template/src/pages/index.svelte +15 -0
  43. package/template/src/style.css +13 -0
  44. package/lib/cli.js +0 -69
  45. package/lib/codegen.js +0 -79
  46. package/lib/components/Cayo.svelte +0 -25
  47. package/lib/config.js +0 -155
  48. package/lib/files.js +0 -84
  49. package/lib/prerender.js +0 -181
  50. package/lib/renderer.js +0 -49
  51. package/lib/runtime.js +0 -6
  52. package/lib/utils.js +0 -126
  53. package/lib/vite.config.js +0 -16
  54. package/notes.md +0 -3
  55. package/test/cayo.config.js +0 -35
  56. package/test/public/assets/cow.js +0 -1
  57. package/test/public/images/app-icon.png +0 -0
  58. package/test/src/__layout.svelte +0 -20
  59. package/test/src/components/Cool.cayo.svelte +0 -5
  60. package/test/src/components/Some.svelte +0 -1
  61. package/test/src/components/Test.cayo.svelte +0 -5
  62. package/test/src/index.js +0 -17
  63. package/test/src/main2.js +0 -1
  64. package/test/src/pages/hey.svelte +0 -8
  65. package/test/src/pages/howdy.svelte +0 -11
  66. package/test/src/pages/index.svelte +0 -38
  67. package/test/src/pages/some/page.svelte +0 -2
  68. package/tests/asset-dir/cayo.config.js +0 -38
  69. package/tests/asset-dir/package-lock.json +0 -1435
  70. package/tests/asset-dir/package.json +0 -19
  71. package/tests/asset-dir/public/images/app-icon.png +0 -0
  72. package/tests/asset-dir/src/__layout.svelte +0 -20
  73. package/tests/asset-dir/src/components/CayoExample.svelte +0 -5
  74. package/tests/asset-dir/src/components/Some.cayo.svelte +0 -6
  75. package/tests/asset-dir/src/index.js +0 -5
  76. package/tests/asset-dir/src/pages/index.svelte +0 -19
  77. package/tests/base-path/cayo.config.js +0 -36
  78. package/tests/base-path/package-lock.json +0 -1435
  79. package/tests/base-path/package.json +0 -19
  80. package/tests/base-path/public/assets/cow.js +0 -1
  81. package/tests/base-path/public/images/app-icon.png +0 -0
  82. package/tests/base-path/src/__layout.svelte +0 -20
  83. package/tests/base-path/src/components/CayoExample.svelte +0 -5
  84. package/tests/base-path/src/components/Some.cayo.svelte +0 -6
  85. package/tests/base-path/src/index.js +0 -5
  86. package/tests/base-path/src/pages/howdy.svelte +0 -12
  87. package/tests/base-path/src/pages/index.svelte +0 -20
  88. package/tests/basic/notcayo.config.js +0 -35
  89. package/tests/basic/package-lock.json +0 -1435
  90. package/tests/basic/package.json +0 -19
  91. package/tests/basic/public/assets/cow.js +0 -1
  92. package/tests/basic/public/images/app-icon.png +0 -0
  93. package/tests/basic/src/__layout.svelte +0 -20
  94. package/tests/basic/src/components/Cool.cayo.svelte +0 -4
  95. package/tests/basic/src/components/Some.svelte +0 -1
  96. package/tests/basic/src/index.js +0 -5
  97. package/tests/basic/src/main2.js +0 -1
  98. package/tests/basic/src/pages/hey.svelte +0 -8
  99. package/tests/basic/src/pages/howdy.svelte +0 -11
  100. package/tests/basic/src/pages/index.svelte +0 -33
  101. package/tests/basic/src/pages/some/some.svelte +0 -2
  102. package/tests/basic cases (old)/src/components/Cool.cayo.svelte +0 -4
  103. package/tests/basic cases (old)/src/components/Some.svelte +0 -1
  104. package/tests/basic cases (old)/src/components/dir/Cool.cayo.svelte +0 -4
  105. package/tests/basic cases (old)/src/main.js +0 -1
  106. package/tests/basic cases (old)/src/main2.js +0 -1
  107. package/tests/basic cases (old)/src/pages/hey.svelte +0 -2
  108. package/tests/basic cases (old)/src/pages/howdy.svelte +0 -11
  109. package/tests/basic cases (old)/src/pages/index.svelte +0 -27
  110. package/tests/nested-pages/cayo.config.js +0 -35
  111. package/tests/nested-pages/package-lock.json +0 -1435
  112. package/tests/nested-pages/package.json +0 -19
  113. package/tests/nested-pages/public/assets/cow.js +0 -1
  114. package/tests/nested-pages/public/images/app-icon.png +0 -0
  115. package/tests/nested-pages/src/__layout.svelte +0 -20
  116. package/tests/nested-pages/src/components/Cool.cayo.svelte +0 -4
  117. package/tests/nested-pages/src/index.js +0 -5
  118. package/tests/nested-pages/src/main2.js +0 -1
  119. package/tests/nested-pages/src/pages/index.svelte +0 -18
  120. package/tests/nested-pages/src/pages/some/other/page.svelte +0 -7
  121. package/tests/nested-pages/src/pages/some/page.svelte +0 -6
package/lib/utils.js DELETED
@@ -1,126 +0,0 @@
1
- import fs from 'fs-extra';
2
- import fg from 'fast-glob';
3
- import crypto from 'crypto';
4
- import chalk from 'chalk';
5
- import path from 'path';
6
-
7
- export function getPageModules(modules, config) {
8
- // TODO: build path from config
9
- const extRegex = new RegExp(String.raw`(\.svelte)$`);
10
-
11
- return Object.entries(modules).reduce((pages, [modulePath, page]) => {
12
- // Make these paths actually useful
13
- // /^(.+)\/pages/
14
- // /^(\/\w+)*\/pages/
15
- const filePath = modulePath.replace(/^(.+)\/pages\//, '').replace(extRegex, '')
16
- const urlPath = filePath === 'index' ? filePath.replace(/index$/, '/') : `${filePath}/`
17
- // name = name.split('.', 1)[0];
18
- pages[urlPath] = {
19
- Component: page.default,
20
- meta: page.meta ? page.meta : {},
21
- filePath,
22
- modulePath,
23
- urlPath
24
- }
25
- return pages;
26
- }, {})
27
- }
28
-
29
- export function getComponentModules(modules, config) {
30
-
31
- return Object.entries(modules).reduce((components, [modulePath, component]) => {
32
- const componentNameRegex = /\/(?<name>\w+)\.cayo\.svelte/; // Foo-{hash}
33
- const name = modulePath.match(componentNameRegex).groups.name;
34
- if (components[name]) {
35
- config.logger.info(
36
- chalk.red(
37
- `Cayo component with name '${name}' already exists. Cayo components must have unique file names.`
38
- ) + chalk.dim(`\n\t\t\t${modulePath}`),
39
- { timestamp: true, clear: true, }
40
- );
41
- }
42
- components[name] = {
43
- Component: component.default,
44
- modulePath,
45
- }
46
- return components;
47
- }, {})
48
- }
49
-
50
- export function hash(bytes = 5) {
51
- return crypto.randomBytes(bytes).toString('hex');
52
- }
53
-
54
- export async function getPageModulePaths(pagesPath) {
55
- return await fg([path.resolve(pagesPath, './**/*.svelte')]);
56
- }
57
-
58
- export async function getComponentModulePaths(srcPath) {
59
- return await fg([path.resolve(srcPath, './components/**/*.cayo.svelte')]);
60
- }
61
-
62
- export async function createPageManifest(pagesPath, outDir, srcPath) {
63
- const pagePaths = await getPageModulePaths(pagesPath);
64
- const componentPaths = await fg([path.resolve(srcPath, './components/**/*.svelte')]);
65
- let importPages = `import { createRequire } from 'module';\n`
66
- importPages += `const require = createRequire(import.meta.url);\n`
67
- importPages += `require('svelte/register');\n`;
68
- pagePaths.forEach((path, i) => {
69
- importPages += `delete require.cache['${path}'];\n`
70
- importPages += `const page_${i} = require('${path}');\n`;
71
- });
72
- importPages += 'export const pages = {\n';
73
- pagePaths.forEach((path, i) => {
74
- importPages += ` '${path}': page_${i},\n`;
75
- })
76
- importPages += '}\n';
77
-
78
- componentPaths.forEach((path) => {
79
- importPages += `delete require.cache['${path}'];\n`;
80
- });
81
-
82
- return await fs.outputFile(path.resolve(outDir, './__cayo/pages.js'), importPages);
83
- }
84
-
85
- export async function createComponentManifest(srcPath, outDir) {
86
- const componentPaths = await getComponentModulePaths(srcPath);
87
- let importComponents = `import { createRequire } from 'module';\n`;
88
- importComponents += `const require = createRequire(import.meta.url);\n`;
89
- importComponents += `require('svelte/register');\n`;
90
- componentPaths.forEach((path, i) => {
91
- importComponents += `delete require.cache['${path}'];\n`;
92
- importComponents += `const component_${i} = require('${path}');\n`;
93
- });
94
- importComponents += 'export const components = {\n';
95
- componentPaths.forEach((path, i) => {
96
- importComponents += ` '${path}': component_${i},\n`;
97
- })
98
- importComponents += '}\n';
99
- return await fs.outputFile(path.resolve(outDir, './__cayo/components.js'), importComponents);
100
- }
101
-
102
-
103
- export async function createTemplateManifest(templatePath, outDir) {
104
- let importTemplate = `import { createRequire } from 'module';\n`;
105
- importTemplate += `const require = createRequire(import.meta.url);\n`;
106
- importTemplate += `require('svelte/register');\n`;
107
- importTemplate += `delete require.cache['${templatePath}'];\n`;
108
- importTemplate += `export const Template = require('${templatePath}').default;\n`;
109
- return await fs.outputFile(path.resolve(outDir, './__cayo/template.js'), importTemplate);
110
- }
111
-
112
-
113
- // Credit: https://github.com/snowpackjs/astro
114
- /** Add / to the end of string (but don’t double-up) */
115
- export function addTrailingSlash(_path) {
116
- return _path.replace(/\/?$/, '/');
117
- }
118
-
119
- export function normalizePath(root, _path) {
120
- if (root === _path) return root;
121
- return path.normalize(path.join(root, addTrailingSlash(_path)));
122
- }
123
-
124
- export function getOutDir(config) {
125
- return config.mode === 'production' ? config.buildOptions.outDir : config.cayoPath;
126
- }
@@ -1,16 +0,0 @@
1
- import { defineConfig } from 'vite'
2
- import { svelte } from '@sveltejs/vite-plugin-svelte'
3
- import sveltePreprocess from 'svelte-preprocess'
4
-
5
- export default defineConfig({
6
- clearScreen: false,
7
- plugins: [svelte({
8
- preprocess: sveltePreprocess({ preserve: ['json'] }),
9
- compilerOptions: {
10
- hydratable: true,
11
- },
12
- })],
13
- server: {
14
- port: '5000',
15
- }
16
- });
package/notes.md DELETED
@@ -1,3 +0,0 @@
1
- ```bash
2
- vite build --outDir dist --ssr prerender.js --mode development && node dist/prerender.js
3
- ```
@@ -1,35 +0,0 @@
1
-
2
- // vite config example
3
- import { defineConfig } from 'vite'
4
- import { svelte } from '@sveltejs/vite-plugin-svelte'
5
- import sveltePreprocess from 'svelte-preprocess'
6
- // const viteConfig = defineConfig({
7
- // // root: './.cayo/',
8
- // plugins: [svelte({
9
- // preprocess: sveltePreprocess({ preserve: ['json'] }),
10
- // compilerOptions: {
11
- // hydratable: true,
12
- // },
13
- // })],
14
- // });
15
-
16
- export default {
17
- // projectRoot: '.',
18
- // css: {
19
- // internal: false,
20
- // },
21
- templateFileName: '__layout',
22
- viteConfig: {
23
- base: '/vite/',
24
- plugins: [svelte({
25
- preprocess: sveltePreprocess({ preserve: ['json'] }),
26
- compilerOptions: {
27
- hydratable: true,
28
- },
29
- })],
30
- server: {
31
- port: '5005',
32
- },
33
- },
34
- base: '/cayo/'
35
- }
@@ -1 +0,0 @@
1
- console.log("I'm main");
Binary file
@@ -1,20 +0,0 @@
1
- <!-- <!DOCTYPE html> -->
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" href="/favicon.ico" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- %cayo.title%
8
- %cayo.css%
9
- %cayo.head%
10
- </head>
11
- <body class="hey">
12
- <!--
13
- TODO: Show how to condtionally render any of these pieces based on dev vs. prod
14
- E.g., I need to remove head from prod, but want it there in dev
15
- -->
16
- %cayo.body%
17
- %cayo.script%
18
- </body>
19
-
20
- </html>
@@ -1,5 +0,0 @@
1
- <script>
2
- export let beans = '';
3
- </script>
4
- <div>{beans}</div>
5
- <p>I prob change don't i</p>
@@ -1 +0,0 @@
1
- HUH?
@@ -1,5 +0,0 @@
1
- <script>
2
-
3
- </script>
4
- ok
5
- <!-- <slot></slot> -->
package/test/src/index.js DELETED
@@ -1,17 +0,0 @@
1
- // console.log("I'm main");
2
-
3
- const cb = (node) => {
4
- console.log('im side effecting');
5
- console.log(node);
6
- return node;
7
- }
8
-
9
- function replaceContents ( node ) {
10
- node.innerHTML = '';
11
- return node;
12
- }
13
-
14
- import { default as renderComponents } from './cayo-runtime.js';
15
- document.addEventListener('DOMContentLoaded', () => {
16
- renderComponents(replaceContents);
17
- });
package/test/src/main2.js DELETED
@@ -1 +0,0 @@
1
- console.log("I'm main also");
@@ -1,8 +0,0 @@
1
- yessir
2
- <br><a href="/">Back</a>
3
-
4
- <style>
5
- br {
6
- display: block;
7
- }
8
- </style>
@@ -1,11 +0,0 @@
1
- <script>
2
- import Cayo from '../../../lib/components/Cayo.svelte';
3
- </script>
4
-
5
- howdyyy
6
- <br><a href="/">Back</a>
7
- <Cayo name="Cool" beans='on Howdy' />
8
-
9
- <slot name="entry">
10
- <script src="/main2.js" data-cayo-entry />
11
- </slot>
@@ -1,38 +0,0 @@
1
- <script context="module">
2
- export const meta = {
3
- title: 'Home',
4
- };
5
- </script>
6
- <script>
7
- import Cayo from '../../../lib/components/Cayo.svelte';
8
-
9
- import Some from '../components/Some.svelte';
10
- </script>
11
-
12
- <Some />
13
-
14
- I'm index howdy ok<br>
15
- <a href="/howdy/">Howdy</a><br>
16
- <a href="/hey/" class="red">Hey</a>
17
- <a href="/some/page/" class="red">Some</a>
18
-
19
- <Cayo name="Test" object={{ some: 'what?$staticlink$'}}><div>Default Content</div></Cayo>
20
-
21
- <Cayo name="Cool" beans='ayo'>Whaaat</Cayo>
22
- <Cayo name="Cool" beans='beeeeaaaaasnnss' />
23
- <Cayo name="Cool" beans='NOT BEANS' />
24
-
25
- <img src="/images/app-icon.png" alt="">
26
-
27
- <slot name="entry">
28
- <script src="/index.js" data-cayo-entry />
29
- </slot>
30
-
31
- <style>
32
- .red {
33
- color: red;
34
- }
35
- img {
36
- width: 50px;
37
- }
38
- </style>
@@ -1,2 +0,0 @@
1
- <div>hey</div>
2
- <br><a href="/">Back</a>
@@ -1,38 +0,0 @@
1
-
2
- // vite config example
3
- import { defineConfig } from 'vite'
4
- import { svelte } from '@sveltejs/vite-plugin-svelte'
5
- import sveltePreprocess from 'svelte-preprocess'
6
- // const viteConfig = defineConfig({
7
- // // root: './.cayo/',
8
- // plugins: [svelte({
9
- // preprocess: sveltePreprocess({ preserve: ['json'] }),
10
- // compilerOptions: {
11
- // hydratable: true,
12
- // },
13
- // })],
14
- // });
15
-
16
- export default {
17
- // projectRoot: '.',
18
- // css: {
19
- // internal: false,
20
- // },
21
- templateFileName: '__layout',
22
- viteConfig: {
23
- // base: '/vite/',
24
- plugins: [svelte({
25
- preprocess: sveltePreprocess({ preserve: ['json'] }),
26
- compilerOptions: {
27
- hydratable: true,
28
- },
29
- })],
30
- server: {
31
- // port: '5005',
32
- },
33
- },
34
- build: {
35
- assetsDir: 'some/specific/path',
36
- },
37
- base: '/some/specific/path/',
38
- }