coralite 0.8.1 → 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.
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 { 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,18 +51,19 @@ 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
69
  process.stdout.write(PAD + `${kleur.bold('- Path:')} ${document.item.path.pathname}\n`)
@@ -63,8 +73,8 @@ if (options.dryRun) {
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]
76
+ for (let i = 0; i < collection.length; i++) {
77
+ const document = collection[i]
68
78
  const dir = join(output, document.item.path.dirname)
69
79
 
70
80
  if (!existsSync(dir)) {