@vituum/vite-plugin-latte 1.0.0-alpha.6 → 1.0.0-alpha.7
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 +22 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -19,7 +19,9 @@ const defaultOptions = {
|
|
|
19
19
|
filters: {},
|
|
20
20
|
functions: {},
|
|
21
21
|
tags: {},
|
|
22
|
-
globals: {
|
|
22
|
+
globals: {
|
|
23
|
+
format: 'latte'
|
|
24
|
+
},
|
|
23
25
|
data: ['src/data/**/*.json'],
|
|
24
26
|
formats: ['latte', 'json.latte', 'json'],
|
|
25
27
|
bin: 'php',
|
|
@@ -40,31 +42,31 @@ const execSync = (cmd) => {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
const renderTemplate = ({ server, path, filename, cwd, packageRoot },
|
|
44
|
-
const renderTransformedHtml =
|
|
45
|
+
const renderTemplate = ({ server, path, filename, cwd, packageRoot }, options, content) => {
|
|
46
|
+
const renderTransformedHtml = options.renderTransformedHtml(server ? filename.replace('.html', '') : filename)
|
|
45
47
|
|
|
46
|
-
if (
|
|
47
|
-
const normalizePaths = Array.isArray(
|
|
48
|
+
if (options.data) {
|
|
49
|
+
const normalizePaths = Array.isArray(options.data) ? options.data.map(path => path.replace(/\\/g, '/')) : options.data.replace(/\\/g, '/')
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
options.data = FastGlob.sync(normalizePaths).map(entry => resolve(process.cwd(), entry))
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
Object.keys(
|
|
53
|
-
if (typeof
|
|
54
|
-
|
|
54
|
+
Object.keys(options.filters).forEach(key => {
|
|
55
|
+
if (typeof options.filters[key] === 'function') {
|
|
56
|
+
options.filters[key] = options.filters[key].toString().match(/\(\s*([^)]+?)\s*\)/)[1].replace(/\s/g, '').split(',')
|
|
55
57
|
}
|
|
56
58
|
})
|
|
57
59
|
|
|
58
|
-
Object.keys(
|
|
59
|
-
if (typeof
|
|
60
|
-
|
|
60
|
+
Object.keys(options.functions).forEach(key => {
|
|
61
|
+
if (typeof options.functions[key] === 'function') {
|
|
62
|
+
options.functions[key] = options.functions[key].toString().match(/\(\s*([^)]+?)\s*\)/)[1].replace(/\s/g, '').split(',')
|
|
61
63
|
}
|
|
62
64
|
})
|
|
63
65
|
|
|
64
66
|
if (renderTransformedHtml) {
|
|
65
67
|
const timestamp = Math.floor(Date.now() * Math.random())
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
options.contentTimestamp = timestamp
|
|
68
70
|
|
|
69
71
|
if (!fs.existsSync(resolve(packageRoot, 'temp'))) {
|
|
70
72
|
fs.mkdirSync(resolve(packageRoot, 'temp'))
|
|
@@ -73,9 +75,9 @@ const renderTemplate = ({ server, path, filename, cwd, packageRoot }, params, co
|
|
|
73
75
|
fs.writeFileSync(resolve(packageRoot, `temp/${timestamp}.html`), content)
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
const data = Object.assign({ packageRoot, cwd, isRenderTransformedHtml: renderTransformedHtml },
|
|
78
|
+
const data = Object.assign({ packageRoot, cwd, isRenderTransformedHtml: renderTransformedHtml }, options)
|
|
77
79
|
|
|
78
|
-
return execSync(`${
|
|
80
|
+
return execSync(`${options.bin} ${packageRoot}/index.php ${join(options.root, server ? path.replace('.html', '') : path)} ${JSON.stringify(JSON.stringify(data))}`)
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
/**
|
|
@@ -137,6 +139,11 @@ const plugin = (options = {}) => {
|
|
|
137
139
|
return content
|
|
138
140
|
}
|
|
139
141
|
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
if (!options.formats.includes(options.globals.format)) {
|
|
144
|
+
return content
|
|
145
|
+
}
|
|
146
|
+
|
|
140
147
|
const render = renderTemplate({ server, path, filename, cwd, packageRoot }, options, content)
|
|
141
148
|
const warningLog = render.output.includes('Warning: Undefined')
|
|
142
149
|
|