coralite-scripts 0.28.1 → 0.28.3

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
@@ -1,5 +1,3 @@
1
- > ⚠️ **NOTE: This is a read-only mirror.** Development happens on [Codeberg](https://codeberg.org/tjdavid/coralite).
2
-
3
1
  # Coralite Development Environment Guide
4
2
 
5
3
  Welcome to **Coralite starter script**, a lightweight Static Site Generator (SSG) built for rapid development and clean output. This guide walks you through setting up your local development environment using the provided `coralite-scripts` package and configuration files.
package/bin/index.js CHANGED
@@ -64,7 +64,8 @@ if (mode === 'dev') {
64
64
  const coralite = new Coralite({
65
65
  components: config.components,
66
66
  pages: config.pages,
67
- plugins: config.plugins
67
+ plugins: config.plugins,
68
+ output: config.output
68
69
  })
69
70
  await coralite.initialise()
70
71
 
@@ -1,6 +1,3 @@
1
- /**
2
- * @import {CoraliteScriptConfig} from '../types/index.js'
3
- */
4
1
  /**
5
2
  * Defines the Coralite configuration for the project.
6
3
  *
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../libs/config.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,sCArBW,oBAAoB,GAClB,oBAAoB,CAmHhC;0CA7HsC,mBAAmB"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../libs/config.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,sCArBW,oBAAoB,GAClB,oBAAoB,CA2HhC;0CAtIsC,mBAAmB"}
package/libs/config.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @import {CoraliteScriptConfig} from '../types/index.js'
3
3
  */
4
+ import { staticAssetPlugin } from 'coralite/plugins'
4
5
 
5
6
  /**
6
7
  * Defines the Coralite configuration for the project.
@@ -123,5 +124,13 @@ export function defineConfig (options) {
123
124
  }
124
125
  }
125
126
 
127
+ if (options.assets) {
128
+ if (!Array.isArray(options.assets)) {
129
+ throw new Error('Configuration "assets" must be an array')
130
+ }
131
+ options.plugins = options.plugins || []
132
+ options.plugins.push(staticAssetPlugin(options.assets))
133
+ }
134
+
126
135
  return options
127
136
  }
package/libs/server.js CHANGED
@@ -3,7 +3,7 @@ import colours from 'kleur'
3
3
  import localAccess from 'local-access'
4
4
  import chokidar from 'chokidar'
5
5
  import buildSass from './build-sass.js'
6
- import { displayError, displayInfo, displaySuccess, toCode, toMS, toTime } from './build-utils.js'
6
+ import { displayError, displayInfo, displaySuccess, toCode, toMS, toTime, deleteDirectoryRecursive } from './build-utils.js'
7
7
  import { extname, join, normalize, relative, sep } from 'path'
8
8
  import { access, constants, mkdir, writeFile } from 'fs/promises'
9
9
  import Coralite from 'coralite'
@@ -39,7 +39,8 @@ async function server (config, options) {
39
39
  plugins: config.plugins,
40
40
  ignoreByAttribute: config.ignoreByAttribute,
41
41
  skipRenderByAttribute: config.skipRenderByAttribute,
42
- mode: 'development'
42
+ mode: 'development',
43
+ output: config.output
43
44
  })
44
45
  await coralite.initialise()
45
46
  displaySuccess('Coralite initialized successfully')
@@ -86,10 +87,17 @@ async function server (config, options) {
86
87
  next()
87
88
  })
88
89
 
90
+ const staticOptions = {
91
+ cacheControl: false,
92
+ setHeaders: (res, path) => {
93
+ if (path.endsWith('.wasm')) {
94
+ res.setHeader('Content-Type', 'application/wasm')
95
+ }
96
+ }
97
+ }
98
+
89
99
  // serve compiled components directory
90
- app.use(express.static(config.output, {
91
- cacheControl: false
92
- }))
100
+ app.use(express.static(config.output, staticOptions))
93
101
 
94
102
  // check if Sass is configured and add its input directory to watchPath for file changes.
95
103
  if (config.styles) {
@@ -139,9 +147,7 @@ async function server (config, options) {
139
147
  }
140
148
 
141
149
  app
142
- .use(express.static(config.public, {
143
- cacheControl: false
144
- }))
150
+ .use(express.static(config.public, staticOptions))
145
151
  .get('/_/rebuild', (req, res) => {
146
152
  // set headers for SSE
147
153
  res.writeHead(200, {
@@ -474,6 +480,14 @@ async function server (config, options) {
474
480
  process.stdout.write(PAD + `${colours.bold('- Network:')} ${access.network}\n\n`)
475
481
  process.stdout.write(border + colours.inverse(' LOGS ') + border + '\n\n')
476
482
  })
483
+
484
+ const gracefulShutdown = () => {
485
+ deleteDirectoryRecursive(config.output)
486
+ process.exit(0)
487
+ }
488
+
489
+ process.on('SIGINT', gracefulShutdown)
490
+ process.on('SIGTERM', gracefulShutdown)
477
491
  } catch (error) {
478
492
  displayError('Failed to start server', error)
479
493
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coralite-scripts",
3
- "version": "0.28.1",
3
+ "version": "0.28.3",
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.1"
61
+ "coralite": "0.28.2"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "premove dist && pnpm build-types",