@vituum/vite-plugin-latte 1.0.0-alpha.5 → 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 +23 -14
- package/index.php +1 -1
- 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,7 +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
|
-
|
|
78
|
+
const data = Object.assign({ packageRoot, cwd, isRenderTransformedHtml: renderTransformedHtml }, options)
|
|
79
|
+
|
|
80
|
+
return execSync(`${options.bin} ${packageRoot}/index.php ${join(options.root, server ? path.replace('.html', '') : path)} ${JSON.stringify(JSON.stringify(data))}`)
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
/**
|
|
@@ -135,6 +139,11 @@ const plugin = (options = {}) => {
|
|
|
135
139
|
return content
|
|
136
140
|
}
|
|
137
141
|
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
if (!options.formats.includes(options.globals.format)) {
|
|
144
|
+
return content
|
|
145
|
+
}
|
|
146
|
+
|
|
138
147
|
const render = renderTemplate({ server, path, filename, cwd, packageRoot }, options, content)
|
|
139
148
|
const warningLog = render.output.includes('Warning: Undefined')
|
|
140
149
|
|
package/index.php
CHANGED
|
@@ -164,7 +164,7 @@ if (!file_exists(str_replace($config->cwd, ROOT_DIR, $params->template))) {
|
|
|
164
164
|
throw new Error('File not found ' . str_replace($config->cwd, ROOT_DIR, $params->template));
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
if (isset($config->
|
|
167
|
+
if (isset($config->isRenderTransformedHtml) && $config->isRenderTransformedHtml) {
|
|
168
168
|
if (isset($config->contentTimestamp)) {
|
|
169
169
|
$content = file_get_contents(__DIR__ . '/temp/' . $config->contentTimestamp . '.html');
|
|
170
170
|
unlink(__DIR__ . '/temp/' . $config->contentTimestamp . '.html');
|