coralite 0.8.0 → 0.9.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.
@@ -28,6 +28,9 @@ jobs:
28
28
  - name: Install dependencies
29
29
  run: pnpm install
30
30
 
31
+ - name: Add symlink
32
+ run: pnpm link
33
+
31
34
  - name: Build HTML from templates
32
35
  run: pnpm run html
33
36
 
@@ -51,5 +51,8 @@ jobs:
51
51
  - name: Install dependencies
52
52
  run: pnpm install
53
53
 
54
+ - name: Add symlink
55
+ run: pnpm link
56
+
54
57
  - name: Build HTML from templates
55
58
  run: pnpm run html
package/bin/coralite.js CHANGED
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env node --experimental-vm-modules --experimental-import-meta-resolve
2
2
 
3
- import { getSubDirectory, getPkg, coralite } from '#lib'
3
+ import { getPkg, Coralite } from '#lib'
4
4
  import { Command } from 'commander'
5
5
  import { join } from 'node:path'
6
6
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
7
7
  import kleur from 'kleur'
8
+ import { loadConfig } from '../lib/loader.js'
8
9
 
9
10
  // Remove all Node warnings before doing anything else
10
11
  process.removeAllListeners('warning')
11
12
 
12
13
  const pkg = await getPkg()
13
14
  const program = new Command()
15
+ const config = await loadConfig()
14
16
 
15
17
  program
16
18
  .name(pkg.name)
@@ -32,6 +34,13 @@ const pages = options.pages
32
34
  const output = options.output
33
35
  const ignoreByAttribute = []
34
36
 
37
+ const coraliteOptions = {
38
+ templates: options.templates,
39
+ pages,
40
+ ignoreByAttribute,
41
+ plugins: []
42
+ }
43
+
35
44
  for (let i = 0; i < options.ignoreAttribute.length; i++) {
36
45
  const pair = options.ignoreAttribute[i].split('=')
37
46
 
@@ -42,38 +51,37 @@ for (let i = 0; i < options.ignoreAttribute.length; i++) {
42
51
  ignoreByAttribute.push(pair)
43
52
  }
44
53
 
45
- const documents = await coralite({
46
- templates: options.templates,
47
- pages,
48
- ignoreByAttribute
49
- })
54
+ if (config && config.plugins) {
55
+ coraliteOptions.plugins = coraliteOptions.plugins.concat(config.plugins)
56
+ }
57
+
58
+ const coralite = new Coralite(coraliteOptions)
59
+ const collection = await coralite.compile()
50
60
 
51
61
  if (options.dryRun) {
52
62
  const PAD = ' '
53
63
  const border = '─'.repeat(Math.min(process.stdout.columns, 36) / 2)
54
64
 
55
- for (let i = 0; i < documents.length; i++) {
56
- const document = documents[i]
65
+ for (let i = 0; i < collection.length; i++) {
66
+ const document = collection[i]
57
67
 
58
68
  process.stdout.write('\n' + PAD + kleur.green('Document is ready!\n\n'))
59
- process.stdout.write(PAD + `${kleur.bold('- Path:')} ${join(document.item.parentPath, document.item.name)}\n`)
60
- process.stdout.write(PAD + `${kleur.bold('- Built in:')} ${Math.floor(document.duration)}ms\n\n`)
69
+ process.stdout.write(PAD + `${kleur.bold('- Path:')} ${document.item.path.pathname}\n`)
70
+ process.stdout.write(PAD + `${kleur.bold('- Built in:')} ${Math.floor(document.duration)}ms\n\n`)
61
71
  process.stdout.write(border + kleur.inverse(' Content start ') + border + '\n\n')
62
72
  process.stdout.write(document.html)
63
73
  process.stdout.write('\n\n' + border + kleur.inverse(' Content end ') + border + '\n')
64
74
  }
65
75
  } else {
66
- for (let i = 0; i < documents.length; i++) {
67
- const document = documents[i]
68
- // get pages sub directory
69
- const subDir = getSubDirectory(pages, document.item.parentPath)
70
- const dir = join(output, subDir)
76
+ for (let i = 0; i < collection.length; i++) {
77
+ const document = collection[i]
78
+ const dir = join(output, document.item.path.dirname)
71
79
 
72
80
  if (!existsSync(dir)) {
73
81
  // create directory
74
82
  mkdirSync(dir)
75
83
  }
76
84
 
77
- writeFileSync(join(dir, document.item.name), document.html)
85
+ writeFileSync(join(output, document.item.path.pathname), document.html)
78
86
  }
79
87
  }