bajo-template 2.4.0 → 2.5.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/index.js +4 -31
- package/lib/resolve-resource.js +46 -37
- package/package.json +1 -1
- package/wiki/CHANGES.md +9 -0
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import resolveResource, {
|
|
1
|
+
import resolveResource, { checking } from './lib/resolve-resource.js'
|
|
2
2
|
import crypto from 'crypto'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
|
|
@@ -287,37 +287,10 @@ async function factory (pkgName) {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
resolveLayout = (item = '', opts = {}) => {
|
|
290
|
-
const {
|
|
291
|
-
const fallbackHandler = ({ file, exts, ns, subSubNs, type, theme }) => {
|
|
292
|
-
const dir = ''
|
|
293
|
-
const base = 'default'
|
|
290
|
+
const fallbackHandler = ({ type, ns, subSubNs, dir, exts, theme, req }) => {
|
|
294
291
|
if (!this.config.layout.fallback) return false
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${type}/_${theme}`
|
|
298
|
-
file = filecheck.call(this, { dir, base, exts, check })
|
|
299
|
-
}
|
|
300
|
-
// check main: common
|
|
301
|
-
if (!file) {
|
|
302
|
-
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${type}`
|
|
303
|
-
file = filecheck.call(this, { dir, base, exts, check })
|
|
304
|
-
}
|
|
305
|
-
if (theme && !file) {
|
|
306
|
-
const otheme = find(this.app.waibuMpa.themes, { name: theme })
|
|
307
|
-
const check = `${otheme.plugin.dir.pkg}/extend/${this.ns}/extend/${this.ns}/${type}`
|
|
308
|
-
file = filecheck.call(this, { dir, base, exts, check })
|
|
309
|
-
}
|
|
310
|
-
// check fallback: common
|
|
311
|
-
if (!file) {
|
|
312
|
-
const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${subSubNs ? (subSubNs + '/') : ''}${type}`
|
|
313
|
-
file = filecheck.call(this, { dir, base, exts, check })
|
|
314
|
-
}
|
|
315
|
-
// check general fallback
|
|
316
|
-
if (!file) {
|
|
317
|
-
const check = `${this.dir.pkg}/extend/${this.ns}/${subSubNs ? (subSubNs + '/') : ''}${type}`
|
|
318
|
-
file = filecheck.call(this, { dir, base, exts, check })
|
|
319
|
-
}
|
|
320
|
-
return file
|
|
292
|
+
const base = 'default'
|
|
293
|
+
return checking.call(this, { type, ns, subSubNs, dir, base, exts, theme, req })
|
|
321
294
|
}
|
|
322
295
|
|
|
323
296
|
return resolveResource.call(this, 'layout', item, opts, fallbackHandler)
|
package/lib/resolve-resource.js
CHANGED
|
@@ -15,52 +15,38 @@ export function filecheck ({ check, dir, base, exts }) {
|
|
|
15
15
|
return file
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function
|
|
19
|
-
const { trim, uniq, find } = this.app.lib._
|
|
20
|
-
const { fs } = this.app.lib
|
|
21
|
-
const env = this.app.bajo.config.env
|
|
22
|
-
if (env !== 'dev' && cache[item]) return cache[item]
|
|
23
|
-
|
|
24
|
-
let { ns, subSubNs, path } = this.getResource(item)
|
|
25
|
-
const ext = _path.extname(path)
|
|
26
|
-
path = trim(path, '/')
|
|
27
|
-
const dir = _path.dirname(path)
|
|
28
|
-
const base = _path.basename(path, ext)
|
|
29
|
-
const fallbackLang = this.app.bajo.config.intl.fallback
|
|
30
|
-
const exts = uniq([`.${fallbackLang}${ext}`, ext])
|
|
31
|
-
if (opts.lang) exts.unshift(`.${opts.lang}${ext}`)
|
|
32
|
-
|
|
18
|
+
export function checking ({ type, ns, subSubNs, dir, base, exts, theme, req } = {}) {
|
|
33
19
|
const extension = subSubNs ? `${subSubNs}/` : ''
|
|
34
20
|
let file
|
|
21
|
+
// check main override: domain specific
|
|
22
|
+
if (this.app.waibu && req) {
|
|
23
|
+
const hostname = this.app.waibu.getHostname(req)
|
|
24
|
+
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${hostname}/${ns}/${extension}${type}`
|
|
25
|
+
file = filecheck.call(this, { dir, base, exts, check })
|
|
26
|
+
}
|
|
35
27
|
// check main override: theme specific
|
|
36
|
-
if (
|
|
37
|
-
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${
|
|
28
|
+
if (theme && !file) {
|
|
29
|
+
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${theme.name}/${ns}/${extension}${type}`
|
|
38
30
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
39
31
|
}
|
|
40
32
|
// check main override: common
|
|
41
33
|
if (!file) {
|
|
42
|
-
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${ns}/${type}`
|
|
34
|
+
const check = `${this.app.main.dir.pkg}/extend/${this.ns}/${ns}/${extension}${type}`
|
|
43
35
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
44
36
|
}
|
|
45
37
|
// check override: theme specific
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const check = `${theme.plugin.dir.pkg}/extend/${this.ns}/${opts.theme}/${ns}/${extension}${type}`
|
|
50
|
-
file = filecheck.call(this, { dir, base, exts, check })
|
|
51
|
-
}
|
|
38
|
+
if (theme && !file) {
|
|
39
|
+
const check = `${theme.plugin.dir.pkg}/extend/${this.ns}/${theme.name}/${ns}/${extension}${type}`
|
|
40
|
+
file = filecheck.call(this, { dir, base, exts, check })
|
|
52
41
|
}
|
|
53
42
|
// check override: theme specific (common)
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const check = `${theme.plugin.dir.pkg}/extend/${this.ns}/_common/${ns}/${extension}${type}`
|
|
58
|
-
file = filecheck.call(this, { dir, base, exts, check })
|
|
59
|
-
}
|
|
43
|
+
if (theme && !file) {
|
|
44
|
+
const check = `${theme.plugin.dir.pkg}/extend/${this.ns}/_common/${ns}/${extension}${type}`
|
|
45
|
+
file = filecheck.call(this, { dir, base, exts, check })
|
|
60
46
|
}
|
|
61
47
|
// check real: theme specific
|
|
62
|
-
if (
|
|
63
|
-
const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${
|
|
48
|
+
if (theme && !file) {
|
|
49
|
+
const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${theme.name}/${extension}${type}`
|
|
64
50
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
65
51
|
}
|
|
66
52
|
// check real: common
|
|
@@ -68,12 +54,35 @@ function resolveResource (type, item = '', opts = {}, fallbackHandler) {
|
|
|
68
54
|
const check = `${this.app[ns].dir.pkg}/extend/${this.ns}/${extension}${type}`
|
|
69
55
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
70
56
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
57
|
+
return file
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resolveResource (type, item = '', opts = {}, fallbackHandler) {
|
|
61
|
+
const { trim, find, uniq } = this.app.lib._
|
|
62
|
+
const { fs } = this.app.lib
|
|
63
|
+
const env = this.app.bajo.config.env
|
|
64
|
+
if (env !== 'dev' && cache[item]) return cache[item]
|
|
65
|
+
|
|
66
|
+
let { ns, subSubNs, path } = this.getResource(item)
|
|
67
|
+
const ext = _path.extname(path)
|
|
68
|
+
path = trim(path, '/')
|
|
69
|
+
const dir = _path.dirname(path)
|
|
70
|
+
const base = _path.basename(path, ext)
|
|
71
|
+
const fallbackLang = this.app.bajo.config.intl.fallback
|
|
72
|
+
const exts = uniq([`.${fallbackLang}${ext}`, ext])
|
|
73
|
+
if (opts.lang) exts.unshift(`.${opts.lang}${ext}`)
|
|
74
|
+
let theme
|
|
75
|
+
if (opts.theme && this.app.waibuMpa && opts.req) theme = find(this.app.waibuMpa.themes, { name: opts.theme })
|
|
76
|
+
|
|
77
|
+
let file = checking.call(this, { type, ns, subSubNs, dir, base, exts, theme, req: opts.req })
|
|
78
|
+
if (!file) {
|
|
79
|
+
if (fallbackHandler) file = fallbackHandler.call(this, { dir, base, exts, ns, subSubNs, type, theme: opts.theme, req: opts.req })
|
|
80
|
+
if (opts.default) {
|
|
81
|
+
const fname = this.getResource(opts.default).fullPath
|
|
82
|
+
if (fs.existsSync(fname)) file = fname
|
|
83
|
+
}
|
|
84
|
+
if (!file) throw this.error('cantFind%s%s', type, item)
|
|
75
85
|
}
|
|
76
|
-
if (!file) throw this.error('cantFind%s%s', type, item)
|
|
77
86
|
const result = { file, ns, layout: opts.layout }
|
|
78
87
|
if (env !== 'dev') cache[item] = result
|
|
79
88
|
return result
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-02-21
|
|
4
|
+
|
|
5
|
+
- [2.5.1] Bug fix on layout fallback
|
|
6
|
+
- [2.5.1] Refactoring ```resolveResource()``` to be more modular
|
|
7
|
+
|
|
8
|
+
## 2026-02-17
|
|
9
|
+
|
|
10
|
+
- [2.5.0] Add ability to extend template by domain
|
|
11
|
+
|
|
3
12
|
## 2026-02-15
|
|
4
13
|
|
|
5
14
|
- [2.4.0] Template folder reposition
|