coralite 0.6.0 → 0.6.1

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 CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  coralite is a static site generator library built around the emerging [HTML modules proposal](https://github.com/WICG/webcomponents/blob/gh-pages/proposals/html-modules-explainer.md).
4
4
 
5
- [Getting started: Basic templating](./docs/basic-templating.md)
5
+ - Getting started
6
+ [Basic templating](./docs/basic-templating.md)
7
+ - Reference
8
+ [Coralite CLI](./docs/coralite-cli.md)
9
+ [Coralite](./docs/coralite.md)
6
10
 
7
11
  ## Installation
8
12
 
@@ -15,6 +19,7 @@ yarn global add coralite
15
19
  # or
16
20
  pnpm add -g coralite
17
21
  ```
22
+
18
23
  You can also install coralite as a development dependency:
19
24
 
20
25
  ```bash
@@ -32,6 +37,7 @@ Coralite uses **ECMAScript Modules** which requires to run Node.js with the **`-
32
37
  ```bash
33
38
  node --experimental-vm-modules node_modules/coralite/bin/coralite.js [options]
34
39
  ```
40
+
35
41
  or using NODE_OPTIONS
36
42
 
37
43
  ```bash
@@ -64,10 +70,10 @@ coralite --templates ./src/templates --pages ./src/pages --output ./dist
64
70
 
65
71
  ## Optional Options
66
72
 
67
- ### -d or --dry
73
+ ### -d or --dry-run
68
74
 
69
75
  Run the CLI in dry-run mode to preview the actions that would be performed without actually generating the website. This is useful for debugging or when you want to check potential issues before committing changes:
70
76
 
71
77
  ```bash
72
- coralite --templates ./src/templates --pages ./src/pages --output ./dist --dry
78
+ coralite --templates ./src/templates --pages ./src/pages --output ./dist --dry-run
73
79
  ```
package/lib/coralite.js CHANGED
@@ -7,7 +7,8 @@ import render from 'dom-serializer'
7
7
  * CoraliteTextNode,
8
8
  * CoraliteAggregateTemplate,
9
9
  * CoraliteAnyNode,
10
- * CoraliteModule } from '#types'
10
+ * CoraliteModule,
11
+ * CoraliteResult} from '#types'
11
12
  */
12
13
 
13
14
  /**
@@ -53,9 +54,26 @@ export async function aggregate (options) {
53
54
 
54
55
  /**
55
56
  * @param {Object} options
56
- * @param {string} options.templates
57
- * @param {string} options.pages
58
- * @param {Array<string[]>} [options.ignoreByAttribute]
57
+ * @param {string} options.templates - The path to the directory containing Coralite templates.
58
+ * @param {string} options.pages - The path to the directory containing pages that will be rendered using the provided templates.
59
+ * @param {[string, string][]} [options.ignoreByAttribute] - Elements to ignore with attribute name value pair
60
+ *
61
+ * @return {Promise<Array<CoraliteResult>>} - An array of objects containing the document and HTML content for each page in pages directory with their respective render times.
62
+ * @example
63
+ * ```
64
+ * coralite({
65
+ * templates: './path/to/templates',
66
+ * pages: './path/to/pages'
67
+ * ignoreByAttribute: [['data-dev', 'true']]
68
+ * })
69
+ * .then((documents) => {
70
+ * documents.forEach(({ document, html, duration }) => {
71
+ * console.log(`Rendered ${document.title} in ${duration}ms.`);
72
+ * console.log(html);
73
+ * });
74
+ * })
75
+ * .catch(console.error);
76
+ * ```
59
77
  */
60
78
  export async function coralite ({
61
79
  templates,
@@ -74,6 +92,7 @@ export async function coralite ({
74
92
 
75
93
  /** @type {Object.<string, CoraliteModule>} */
76
94
  const coraliteModules = {}
95
+ /** @type {CoraliteResult[]} */
77
96
  const documents = []
78
97
 
79
98
  // create templates
package/lib/parse.js CHANGED
@@ -694,7 +694,7 @@ export async function parseScript (component, values, element, components, docum
694
694
  }
695
695
 
696
696
  // compute slot nodes
697
- const result = computedSlot(slotContent)
697
+ const result = computedSlot(slotContent) || slotContent
698
698
 
699
699
  // append new slot nodes
700
700
  for (let index = 0; index < result.length; index++) {
@@ -776,8 +776,26 @@ async function moduleLinker (specifier, referencingModule) {
776
776
  export default { tokens, defineComponent, aggregate };
777
777
  `, { context: referencingModule.context })
778
778
  }
779
+ const module = await import(specifier)
780
+ let exportModule = ''
779
781
 
780
- throw new Error(`Unable to resolve dependency: ${specifier}`)
782
+ for (const key in module) {
783
+ if (Object.prototype.hasOwnProperty.call(module, key)) {
784
+ const name = 'globalThis["'+ specifier + '"].'
785
+
786
+ if (key === 'default') {
787
+ exportModule += 'export default ' + name + key + ';\n'
788
+ } else {
789
+ exportModule += 'export const '+ key + ' = ' + name + key + ';\n'
790
+ }
791
+ }
792
+
793
+ referencingModule.context[specifier] = module
794
+ }
795
+
796
+ return new vm.SourceTextModule(exportModule, {
797
+ context: referencingModule.context
798
+ })
781
799
  }
782
800
 
783
801
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coralite",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "HTML modules static site generator",
5
5
  "main": "./lib/coralite.js",
6
6
  "type": "module",
package/types/index.js CHANGED
@@ -129,3 +129,10 @@
129
129
  * @typedef {Object} CoraliteAggregateTemplate - Templates used to display the result
130
130
  * @property {string} item - Unique identifier for the component used for each document
131
131
  */
132
+
133
+ /**
134
+ * @typedef {Object} CoraliteResult
135
+ * @property {CoraliteDocument} item - The document object from the rendering process
136
+ * @property {string} html - Raw HTML content of the render process as a string
137
+ * @property {number} duration - The duration of the render process in milliseconds
138
+ */