Skip to content

Commit 499db53

Browse files
committedApr 20, 2021
config.DIR.STATIC can be an array of directories. config.ADD_STATIC can be used to add
1 parent 0d8f747 commit 499db53

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed
 

‎src/config.mjs

+11-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ export const runConfig = async (args = {}) => {
8181
const MODULES = path.join(ASSETS, 'modules')
8282

8383
// static directory, files in this dir get copied to conf.PUBLIC
84-
const STATIC = path.join(ASSETS, 'static')
84+
let STATIC = path.join(ASSETS, 'static')
85+
86+
if (conf.ADD_STATIC) {
87+
if (!is.array(conf.ADD_STATIC)) {
88+
conf.ADD_STATIC = [conf.ADD_STATIC]
89+
}
90+
91+
STATIC = [STATIC, ...conf.ADD_STATIC]
92+
}
8593

8694
// themes dir, files in this dir get used as themes
8795
const THEMES = path.join(ASSETS, 'themes')
@@ -146,8 +154,8 @@ export const runConfig = async (args = {}) => {
146154

147155
conf.ADD_CSS = conf.ADD_CSS
148156
? conf.ADD_CSS.map(href =>
149-
href.startsWith(conf.WEB_ROOT) ? href : replaceSlashSlash(`${conf.WEB_ROOT}/${href}`),
150-
)
157+
href.startsWith(conf.WEB_ROOT) ? href : replaceSlashSlash(`${conf.WEB_ROOT}/${href}`),
158+
)
151159
: []
152160

153161
// array of html tags that get appended after the #magic html tag

‎src/tasks/prepare/index.mjs

+18-16
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,25 @@ export const prepare = async (app, config) => {
9595

9696
app.static = await prepareMetaFiles(app, config)
9797

98-
let staticExists = false
9998
try {
100-
await fs.stat(config.DIR.STATIC)
101-
staticExists = true
99+
let staticDirs = config.DIR.STATIC
100+
if (!is.array(staticDirs)) {
101+
staticDirs = [staticDirs]
102+
}
103+
104+
await Promise.all(staticDirs.map(async dir => {
105+
const staticFiles = await fs.getFiles(dir)
106+
107+
if (!is.empty(staticFiles)) {
108+
const staticPromises = staticFiles.map(async f => {
109+
const name = f.replace(dir, '')
110+
// TODO: use streams here
111+
app.static[name] = await fs.readFile(f)
112+
})
113+
114+
await Promise.all(staticPromises)
115+
}
116+
}))
102117
} catch (e) {
103118
// it's fine if the static dir does not exist,
104119
// but all other errors will throw.
@@ -107,19 +122,6 @@ export const prepare = async (app, config) => {
107122
}
108123
}
109124

110-
if (staticExists) {
111-
const staticFiles = await fs.getFiles(config.DIR.STATIC)
112-
if (!is.empty(staticFiles)) {
113-
const staticPromises = staticFiles.map(async f => {
114-
const name = f.replace(config.DIR.STATIC, '')
115-
// TODO: use streams here
116-
app.static[name] = await fs.readFile(f)
117-
})
118-
119-
await Promise.all(staticPromises)
120-
}
121-
}
122-
123125
app.style = await prepareThemes(app, config)
124126

125127
// mutates app

0 commit comments

Comments
 (0)
Please sign in to comment.