@vituum/vite-plugin-latte 0.1.11 → 0.1.12
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 +7 -4
- package/index.js +13 -3
- package/index.php +6 -6
- package/latte/AssetFilter.php +1 -1
- package/package.json +3 -2
package/handler.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { resolve } from 'path'
|
|
2
2
|
|
|
3
3
|
const vite = (await import(resolve(process.cwd(), 'vite.config.js'))).default
|
|
4
|
-
|
|
5
|
-
const name =
|
|
4
|
+
let params = JSON.parse(process.argv[4])
|
|
5
|
+
const name = process.argv[2]
|
|
6
|
+
const type = process.argv[3]
|
|
6
7
|
|
|
7
|
-
params.
|
|
8
|
+
params = params.map(value => Buffer.from(value, 'base64').toString('utf-8'))
|
|
8
9
|
|
|
9
|
-
vite.plugins.filter(({ name }) => name === '@vituum/vite-plugin-latte')[0]._params
|
|
10
|
+
const output = await vite.plugins.filter(({ name }) => name === '@vituum/vite-plugin-latte')[0]._params[type][name](...params)
|
|
11
|
+
|
|
12
|
+
console.log(Buffer.from(output.toString(), 'utf-8').toString('base64'))
|
package/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolve, dirname } from 'path'
|
|
2
2
|
import { fileURLToPath } from 'url'
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import process from 'node:process'
|
|
5
5
|
import * as childProcess from 'child_process'
|
|
6
6
|
import FastGlob from 'fast-glob'
|
|
7
7
|
import lodash from 'lodash'
|
|
8
|
+
import chalk from 'chalk'
|
|
8
9
|
|
|
9
10
|
const defaultParams = {
|
|
10
11
|
reload: true,
|
|
@@ -96,6 +97,8 @@ const latte = (params = {}) => {
|
|
|
96
97
|
path = path.replace('?raw', '')
|
|
97
98
|
filename = filename.replace('?raw', '')
|
|
98
99
|
|
|
100
|
+
const start = new Date()
|
|
101
|
+
|
|
99
102
|
if (
|
|
100
103
|
!params.filetypes.html.test(path) &&
|
|
101
104
|
!params.filetypes.json.test(path) &&
|
|
@@ -111,20 +114,27 @@ const latte = (params = {}) => {
|
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
const renderLatte = renderTemplate(path, params, content)
|
|
117
|
+
const warningLog = renderLatte.output.includes('Warning: Undefined')
|
|
118
|
+
|
|
119
|
+
console.info(`${chalk.cyan('@vituum/vite-plugin-latte')} ${chalk.green(`finished in ${chalk.grey(new Date() - start + 'ms')}`)}`)
|
|
114
120
|
|
|
115
|
-
if (renderLatte.error) {
|
|
121
|
+
if (renderLatte.error || warningLog) {
|
|
116
122
|
if (!server) {
|
|
117
123
|
console.error(renderLatte.output)
|
|
118
124
|
return
|
|
119
125
|
}
|
|
120
126
|
|
|
127
|
+
const message = warningLog ? 'Warning: Undefined' + renderLatte.output.split('Warning: Undefined').pop() : renderLatte.output
|
|
128
|
+
|
|
121
129
|
server.ws.send({
|
|
122
130
|
type: 'error',
|
|
123
131
|
err: {
|
|
124
|
-
message
|
|
132
|
+
message,
|
|
125
133
|
plugin: '@vituum/vite-plugin-latte'
|
|
126
134
|
}
|
|
127
135
|
})
|
|
136
|
+
|
|
137
|
+
return
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
return renderLatte.output
|
package/index.php
CHANGED
|
@@ -32,12 +32,12 @@ define("PACKAGE_DIR", str_replace($config->cwd, ROOT_DIR, $config->packageRoot))
|
|
|
32
32
|
/**
|
|
33
33
|
* @throws JsonException
|
|
34
34
|
*/
|
|
35
|
-
function NodeHandler($name, ...$params) : string {
|
|
36
|
-
|
|
35
|
+
function NodeHandler($name, $type, ...$params) : string {
|
|
36
|
+
$params = array_map(static function($value) { return base64_encode((string)$value); }, $params);
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
exec('node '. PACKAGE_DIR .'/handler.js ' . $name . ' ' . $type .' ' . json_encode(json_encode($params, JSON_HEX_QUOT | JSON_HEX_TAG), JSON_THROW_ON_ERROR), $output);
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
return base64_decode($output[0] ?? '') ?? $params[1];
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (!file_exists(__DIR__ . '/temp') && !mkdir($concurrentDirectory = __DIR__ . '/temp') && !is_dir($concurrentDirectory)) {
|
|
@@ -127,7 +127,7 @@ foreach ($config->filters as $filter => $path) {
|
|
|
127
127
|
$latte->addFilter($filter, 'App\Latte\\' . ucfirst($filter) . 'Filter::execute');
|
|
128
128
|
} elseif (!$isDocker) {
|
|
129
129
|
$latte->addFilter($filter, function (...$params) use ($filter) : string {
|
|
130
|
-
return NodeHandler($filter, ...$params);
|
|
130
|
+
return NodeHandler($filter, 'filters', ...$params);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -138,7 +138,7 @@ foreach ($config->functions as $function => $path) {
|
|
|
138
138
|
$latte->addFunction($function, 'App\Latte\\' . ucfirst($function) . 'Function::execute');
|
|
139
139
|
} elseif (!$isDocker) {
|
|
140
140
|
$latte->addFunction($function, function (...$params) use ($function) : string {
|
|
141
|
-
return NodeHandler($function, ...$params);
|
|
141
|
+
return NodeHandler($function, 'functions', ...$params);
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
}
|
package/latte/AssetFilter.php
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vituum/vite-plugin-latte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"fast-glob": "^3.2.11",
|
|
13
|
-
"lodash": "^4.17.21"
|
|
13
|
+
"lodash": "^4.17.21",
|
|
14
|
+
"chalk": "^5.0.1"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"vite": "^3.0.9",
|