@vituum/vite-plugin-latte 1.0.0-alpha.9 → 1.0.0

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/README.md CHANGED
@@ -7,50 +7,30 @@
7
7
  import latte from '@vituum/vite-plugin-latte'
8
8
 
9
9
  export default {
10
- plugins: [
11
- latte({
12
- bin: 'php', // php or docker or your own binary path
13
- filters: {
14
- icon: 'latte/IconFilter.php',
15
- nbsp: () => {}
16
- },
17
- functions: {},
18
- tags: {},
19
- globals: {
20
- template: 'playground/templates/Layout/Main.latte'
21
- },
22
- data: '*.json',
23
- isStringFilter: undefined,
24
- filetypes: {
25
- html: /.(json.html|latte.json.html|latte.html)$/,
26
- json: /.(json.latte.html)$/
27
- }
28
- })
29
- ]
10
+ plugins: [
11
+ latte()
12
+ ],
13
+ build: {
14
+ rollupOptions: {
15
+ input: ['index.latte.html']
16
+ }
17
+ }
30
18
  }
31
19
  ```
32
20
 
33
- Read the [docs](https://vituum.dev/config/integrations-options.html#vituum-latte) to learn more about the plugin options.
21
+ * Read the [docs](https://vituum.dev/plugins/latte.html) to learn more about the plugin options.
22
+ * Use with [Vituum](https://vituum.dev) to get multi-page support.
34
23
 
35
24
  ## Basic usage
36
25
 
37
26
  ```html
38
- <!-- index.html -->
39
- <script type="application/json">
40
- {
41
- "template": "path/to/template.latte",
42
- "title": "Hello world"
43
- }
44
- </script>
45
- ```
46
- or
47
27
  ```html
48
- <!-- index.latte.html with index.latte.json -->
28
+ <!-- index.latte with index.latte.json -->
49
29
  {$title}
50
30
  ```
51
31
  or
52
32
  ```html
53
- <!-- index.latte.html or index.latte.json.html -->
33
+ <!-- index.json -->
54
34
  {
55
35
  "template": "path/to/template.latte",
56
36
  "title": "Hello world"
@@ -61,4 +41,4 @@ or
61
41
 
62
42
  - [Node.js LTS (16.x)](https://nodejs.org/en/download/)
63
43
  - [PHP (8.x)](https://www.php.net/) or [Docker PHP (8.x)](https://hub.docker.com/_/php)
64
- - [Vite](https://vitejs.dev/) or [Vituum](https://vituum.dev/)
44
+ - [Vite](https://vitejs.dev/)
package/handler-single.js CHANGED
@@ -3,7 +3,7 @@ const path = process.argv[2]
3
3
 
4
4
  params = params.map(value => Buffer.from(value, 'base64').toString('utf-8'))
5
5
 
6
- const output = (await import([path])).default(...params)
6
+ const output = await (await import([path])).default(...params)
7
7
 
8
8
  if (output) {
9
9
  console.log(Buffer.from(output.toString(), 'utf-8').toString('base64'))
package/index.js CHANGED
@@ -5,7 +5,15 @@ import process from 'node:process'
5
5
  import * as childProcess from 'node:child_process'
6
6
  import FastGlob from 'fast-glob'
7
7
  import { minimatch } from 'minimatch'
8
- import { getPackageInfo, pluginError, pluginReload, merge, pluginBundle } from 'vituum/utils/common.js'
8
+ import {
9
+ getPackageInfo,
10
+ pluginError,
11
+ pluginReload,
12
+ merge,
13
+ pluginBundle,
14
+ normalizePath,
15
+ pluginMiddleware
16
+ } from 'vituum/utils/common.js'
9
17
  import { renameBuildEnd, renameBuildStart } from 'vituum/utils/build.js'
10
18
 
11
19
  const { name } = getPackageInfo(import.meta.url)
@@ -46,9 +54,9 @@ const renderTemplate = ({ server, path, filename, cwd, packageRoot }, options, c
46
54
  const renderTransformedHtml = options.renderTransformedHtml(server ? filename.replace('.html', '') : filename)
47
55
 
48
56
  if (options.data) {
49
- const normalizePaths = Array.isArray(options.data) ? options.data.map(path => path.replace(/\\/g, '/')) : options.data.replace(/\\/g, '/')
57
+ const normalizePaths = Array.isArray(options.data) ? options.data.map(path => normalizePath(path)) : normalizePath(options.data)
50
58
 
51
- options.data = FastGlob.sync(normalizePaths).map(entry => resolve(process.cwd(), entry))
59
+ options.data = FastGlob.sync(normalizePaths).map(entry => resolve(cwd, entry))
52
60
  }
53
61
 
54
62
  Object.keys(options.filters).forEach(key => {
@@ -112,17 +120,19 @@ const plugin = (options = {}) => {
112
120
 
113
121
  if (!options.root) {
114
122
  options.root = config.root
123
+ } else {
124
+ options.root = normalizePath(options.root)
115
125
  }
116
126
  },
117
127
  buildStart: async () => {
118
- if (userEnv.command !== 'build') {
128
+ if (userEnv.command !== 'build' || !resolvedConfig.build.rollupOptions.input) {
119
129
  return
120
130
  }
121
131
 
122
132
  await renameBuildStart(resolvedConfig.build.rollupOptions.input, options.formats)
123
133
  },
124
134
  buildEnd: async () => {
125
- if (userEnv.command !== 'build') {
135
+ if (userEnv.command !== 'build' || !resolvedConfig.build.rollupOptions.input) {
126
136
  return
127
137
  }
128
138
 
@@ -167,7 +177,7 @@ const plugin = (options = {}) => {
167
177
  }
168
178
  },
169
179
  handleHotUpdate: ({ file, server }) => pluginReload({ file, server }, options)
170
- }, pluginBundle(options.formats)]
180
+ }, pluginBundle(options.formats), pluginMiddleware(name, options.formats)]
171
181
  }
172
182
 
173
183
  export default plugin
package/package.json CHANGED
@@ -1,23 +1,26 @@
1
1
  {
2
2
  "name": "@vituum/vite-plugin-latte",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
+ "types": "types/index.d.ts",
6
7
  "scripts": {
8
+ "tsc": "tsc",
9
+ "eslint": "eslint '**/*.js' --fix",
7
10
  "dev": "vite dev",
8
11
  "build": "vite build",
9
12
  "preview": "vite preview"
10
13
  },
11
14
  "dependencies": {
12
- "vituum": "^1.0.0-alpha.16",
15
+ "vituum": "^1.0.0",
13
16
  "fast-glob": "^3.2.12",
14
17
  "lodash": "^4.17.21",
15
- "minimatch": "^9.0.1"
18
+ "minimatch": "^9.0.2"
16
19
  },
17
20
  "devDependencies": {
18
- "@types/node": "^20.3.1",
21
+ "@types/node": "^20.3.2",
19
22
  "vite": "^4.3.9",
20
- "eslint": "^8.42.0",
23
+ "eslint": "^8.43.0",
21
24
  "eslint-config-standard": "^17.1.0",
22
25
  "typescript": "^5.1.3"
23
26
  },
package/types/index.d.ts CHANGED
@@ -11,3 +11,5 @@ export interface PluginUserConfig {
11
11
  renderTransformedHtml?: (filename: string) => boolean
12
12
  ignoredPaths?: string[]
13
13
  }
14
+
15
+ export default function plugin(options?: PluginUserConfig) : import('vite').Plugin