@vituum/vite-plugin-latte 1.0.0-alpha.4 → 1.0.0-alpha.5
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/handler.js +41 -3
- package/index.php +1 -1
- package/package.json +1 -1
package/handler.js
CHANGED
|
@@ -1,13 +1,51 @@
|
|
|
1
|
-
import { resolve } from 'path'
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
function find (obj) {
|
|
5
|
+
if (typeof obj === 'object') {
|
|
6
|
+
if (obj.name === '@vituum/vite-plugin-latte') {
|
|
7
|
+
return obj
|
|
8
|
+
} else {
|
|
9
|
+
for (const key in obj) {
|
|
10
|
+
const result = find(obj[key])
|
|
11
|
+
|
|
12
|
+
if (result !== null) {
|
|
13
|
+
return result
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEFAULT_CONFIG_FILES = [
|
|
23
|
+
'vite.config.js',
|
|
24
|
+
'vite.config.mjs',
|
|
25
|
+
'vite.config.ts',
|
|
26
|
+
'vite.config.cjs',
|
|
27
|
+
'vite.config.mts',
|
|
28
|
+
'vite.config.cts'
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
let resolvedPath
|
|
32
|
+
|
|
33
|
+
for (const filename of DEFAULT_CONFIG_FILES) {
|
|
34
|
+
const filePath = resolve(process.cwd(), filename)
|
|
35
|
+
if (!fs.existsSync(filePath)) continue
|
|
36
|
+
|
|
37
|
+
resolvedPath = filePath
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const vite = (await import(resolvedPath)).default
|
|
4
42
|
let params = JSON.parse(process.argv[4])
|
|
5
43
|
const name = process.argv[2]
|
|
6
44
|
const type = process.argv[3]
|
|
7
45
|
|
|
8
46
|
params = params.map(value => Buffer.from(value, 'base64').toString('utf-8'))
|
|
9
47
|
|
|
10
|
-
const output = await vite.plugins
|
|
48
|
+
const output = await find(vite.plugins)._options[type][name](...params)
|
|
11
49
|
|
|
12
50
|
if (output) {
|
|
13
51
|
console.log(Buffer.from(output.toString(), 'utf-8').toString('base64'))
|
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->contentTimestamp) && $config->contentTimestamp) {
|
|
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');
|