coralite-scripts 0.28.0 → 0.28.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/bin/index.js +41 -11
- package/libs/server.js +27 -2
- package/package.json +2 -2
package/bin/index.js
CHANGED
|
@@ -39,6 +39,9 @@ if (!config) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if (mode === 'dev') {
|
|
42
|
+
config.output = join(process.cwd(), '.coralite')
|
|
43
|
+
await mkdir(config.output, { recursive: true })
|
|
44
|
+
|
|
42
45
|
await server(config, options)
|
|
43
46
|
} else if (mode === 'build') {
|
|
44
47
|
const PAD = ' '
|
|
@@ -69,31 +72,58 @@ if (mode === 'dev') {
|
|
|
69
72
|
let pageCount = 0
|
|
70
73
|
|
|
71
74
|
try {
|
|
75
|
+
let componentCount = 0
|
|
76
|
+
|
|
72
77
|
if (!options.verbose) {
|
|
73
78
|
spinner = ora('Building pages...').start()
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
// compile website
|
|
77
82
|
await coralite.build(async (result) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
if (result.type === 'component') {
|
|
84
|
+
const relativeDir = relative(config.components, result.path.dirname)
|
|
85
|
+
let outDir
|
|
86
|
+
if (config.standaloneOutput) {
|
|
87
|
+
outDir = join(config.output, config.standaloneOutput, relativeDir)
|
|
88
|
+
} else {
|
|
89
|
+
outDir = join(config.output, 'components', relativeDir)
|
|
90
|
+
}
|
|
91
|
+
const outFile = join(outDir, result.path.filename)
|
|
81
92
|
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
await mkdir(outDir, { recursive: true })
|
|
94
|
+
await writeFile(outFile, result.content)
|
|
95
|
+
|
|
96
|
+
if (options.verbose) {
|
|
97
|
+
process.stdout.write(toTime() + colours.bgCyan(' Compiled Component ') + dash + toMS(result.duration) + dash + result.path.pathname + '\n')
|
|
98
|
+
} else {
|
|
99
|
+
componentCount++
|
|
100
|
+
}
|
|
84
101
|
|
|
85
|
-
|
|
86
|
-
process.stdout.write(toTime() + toMS(result.duration) + dash + result.path.pathname + '\n')
|
|
102
|
+
return outFile
|
|
87
103
|
} else {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
const relativeDir = relative(config.pages, result.path.dirname)
|
|
105
|
+
const outDir = join(config.output, relativeDir)
|
|
106
|
+
const outFile = join(outDir, result.path.filename)
|
|
107
|
+
|
|
108
|
+
await mkdir(outDir, { recursive: true })
|
|
109
|
+
await writeFile(outFile, result.content)
|
|
110
|
+
|
|
111
|
+
if (options.verbose) {
|
|
112
|
+
process.stdout.write(toTime() + toMS(result.duration) + dash + result.path.pathname + '\n')
|
|
113
|
+
} else {
|
|
114
|
+
pageCount++
|
|
115
|
+
spinner.text = `Building pages... (${pageCount} completed)`
|
|
116
|
+
}
|
|
91
117
|
|
|
92
|
-
|
|
118
|
+
return outFile
|
|
119
|
+
}
|
|
93
120
|
})
|
|
94
121
|
|
|
95
122
|
if (!options.verbose) {
|
|
96
123
|
spinner.succeed(`Pages built (${pageCount} completed)`)
|
|
124
|
+
if (componentCount > 0) {
|
|
125
|
+
ora(`Components built (${componentCount} completed)`).succeed()
|
|
126
|
+
}
|
|
97
127
|
}
|
|
98
128
|
|
|
99
129
|
const publicDir = config.public
|
package/libs/server.js
CHANGED
|
@@ -5,7 +5,7 @@ import chokidar from 'chokidar'
|
|
|
5
5
|
import buildSass from './build-sass.js'
|
|
6
6
|
import { displayError, displayInfo, displaySuccess, toCode, toMS, toTime } from './build-utils.js'
|
|
7
7
|
import { extname, join, normalize, relative, sep } from 'path'
|
|
8
|
-
import {
|
|
8
|
+
import { access, constants, mkdir, writeFile } from 'fs/promises'
|
|
9
9
|
import Coralite from 'coralite'
|
|
10
10
|
import buildCSS from './build-css.js'
|
|
11
11
|
import { existsSync, mkdirSync } from 'fs'
|
|
@@ -86,6 +86,11 @@ async function server (config, options) {
|
|
|
86
86
|
next()
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
+
// serve compiled components directory
|
|
90
|
+
app.use(express.static(config.output, {
|
|
91
|
+
cacheControl: false
|
|
92
|
+
}))
|
|
93
|
+
|
|
89
94
|
// check if Sass is configured and add its input directory to watchPath for file changes.
|
|
90
95
|
if (config.styles) {
|
|
91
96
|
if (config.styles.input) {
|
|
@@ -258,7 +263,26 @@ async function server (config, options) {
|
|
|
258
263
|
|
|
259
264
|
await coralite.pages.setItem(pathname)
|
|
260
265
|
// build the HTML for this page using the built-in compiler.
|
|
261
|
-
const documents = await coralite.build(pathname, (result) => {
|
|
266
|
+
const documents = await coralite.build(pathname, async (result) => {
|
|
267
|
+
if (result.type === 'component') {
|
|
268
|
+
const relativeDir = relative(config.components, result.path.dirname)
|
|
269
|
+
let outDir
|
|
270
|
+
if (config.standaloneOutput) {
|
|
271
|
+
outDir = join(config.output, config.standaloneOutput, relativeDir)
|
|
272
|
+
} else {
|
|
273
|
+
outDir = join(config.output, 'components', relativeDir)
|
|
274
|
+
}
|
|
275
|
+
const outFile = join(outDir, result.path.filename)
|
|
276
|
+
|
|
277
|
+
await mkdir(outDir, { recursive: true })
|
|
278
|
+
await writeFile(outFile, result.content)
|
|
279
|
+
|
|
280
|
+
if (options.verbose) {
|
|
281
|
+
process.stdout.write(toTime() + colours.bgCyan(' Compiled Component ') + colours.gray(' ─ ') + toMS(result.duration) + colours.gray(' ─ ') + result.path.pathname + '\n')
|
|
282
|
+
}
|
|
283
|
+
return null
|
|
284
|
+
}
|
|
285
|
+
|
|
262
286
|
// inject a script to enable live reload via Server-Sent Events
|
|
263
287
|
const injectedHtml = result.content.replace(/<\/body>/i, rebuildScript)
|
|
264
288
|
|
|
@@ -288,6 +312,7 @@ async function server (config, options) {
|
|
|
288
312
|
|
|
289
313
|
// find the document that matches the request path
|
|
290
314
|
const doc = documents.find(doc => {
|
|
315
|
+
if (!doc) return false
|
|
291
316
|
const relPath = relative(config.pages, doc.path.pathname)
|
|
292
317
|
const normalizedKey = relPath.split(sep).join('/')
|
|
293
318
|
return normalizedKey === cacheKey
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coralite-scripts",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "Configuration and scripts for Create Coralite.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"portfinder": "^1.0.38",
|
|
59
59
|
"postcss": "^8.5.6",
|
|
60
60
|
"sass": "^1.91.0",
|
|
61
|
-
"coralite": "0.28.
|
|
61
|
+
"coralite": "0.28.1"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "premove dist && pnpm build-types",
|