@gjsify/vite-plugin-blueprint 0.2.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 +88 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/package.json +27 -0
- package/src/index.ts +42 -0
- package/src/type.d.ts +4 -0
- package/tsconfig.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# vite-plugin-blueprint
|
|
2
|
+
|
|
3
|
+
A Vite plugin for compiling Blueprint UI files (`.blp`) to XML and importing them as strings in your JavaScript/TypeScript code.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Automatically compiles `.blp` files to XML when imported
|
|
8
|
+
- Optionally minifies the generated XML
|
|
9
|
+
- Seamlessly integrates with your Vite build process
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @gjsify/vite-plugin-blueprint --save-dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or if you use Yarn:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn add @gjsify/vite-plugin-blueprint -D
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Add the plugin to your Vite configuration:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
// vite.config.js / vite.config.ts
|
|
29
|
+
import { defineConfig } from "vite";
|
|
30
|
+
import blueprintPlugin from "@gjsify/vite-plugin-blueprint";
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
plugins: [
|
|
34
|
+
blueprintPlugin({
|
|
35
|
+
minify: true, // optional, defaults to false
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
// ... other configurations
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then, you can import `.blp` files directly in your code:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import myUIXML from "./path/to/my-ui.blp";
|
|
46
|
+
console.log(myUIXML); // This will log the compiled XML content as a string
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### TypeScript
|
|
50
|
+
|
|
51
|
+
To use the plugin with TypeScript, you need to declare the module for `.blp` files in a `.d.ts` file:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
declare module "*.blp" {
|
|
55
|
+
const content: string;
|
|
56
|
+
export default content;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then, you can import `.blp` files in your TypeScript code:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import myUIXML from "./path/to/my-ui.blp";
|
|
64
|
+
console.log(myUIXML); // This will log the compiled XML content as a string
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Options
|
|
68
|
+
|
|
69
|
+
The plugin accepts an options object with the following properties:
|
|
70
|
+
|
|
71
|
+
- `minify` (boolean, optional): If set to `true`, the plugin will minify the generated XML. Default is `false`.
|
|
72
|
+
|
|
73
|
+
## Requirements
|
|
74
|
+
|
|
75
|
+
- Vite 2.x or higher
|
|
76
|
+
- Node.js 12.x or higher
|
|
77
|
+
- `blueprint-compiler` must be installed and available in your system's PATH
|
|
78
|
+
|
|
79
|
+
## How it Works
|
|
80
|
+
|
|
81
|
+
1. When a `.blp` file is imported, the plugin intercepts the import.
|
|
82
|
+
2. It runs the `blueprint-compiler` to compile the `.blp` file to XML.
|
|
83
|
+
3. If minification is enabled, the XML is minified.
|
|
84
|
+
4. The resulting XML is returned as a string, which can be used in your JavaScript/TypeScript code.
|
|
85
|
+
|
|
86
|
+
## Contributing
|
|
87
|
+
|
|
88
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {} from "vite";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import minifyXML from "minify-xml";
|
|
4
|
+
export default function blueprintPlugin(options = {}) {
|
|
5
|
+
const { minify = false, verbose = false } = options;
|
|
6
|
+
return {
|
|
7
|
+
name: "vite-plugin-blueprint",
|
|
8
|
+
async load(id) {
|
|
9
|
+
if (id.endsWith(".blp")) {
|
|
10
|
+
try {
|
|
11
|
+
// Compile .blp file and get XML output directly
|
|
12
|
+
const { stdout } = await execa("blueprint-compiler", ["compile", id]);
|
|
13
|
+
if (verbose)
|
|
14
|
+
console.log(`Compiled ${id}`);
|
|
15
|
+
let xmlContent = stdout;
|
|
16
|
+
// Minify XML if option is enabled
|
|
17
|
+
if (minify) {
|
|
18
|
+
xmlContent = minifyXML(xmlContent);
|
|
19
|
+
if (verbose)
|
|
20
|
+
console.log(`Minified XML for ${id}`);
|
|
21
|
+
}
|
|
22
|
+
// Return the XML content as a string
|
|
23
|
+
return `export default ${JSON.stringify(xmlContent)};`;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error(`Error processing ${id}:`, error);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,SAAS,MAAM,YAAY,CAAC;AAOnC,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,UAAkC,EAAE;IAEpC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAEpD,OAAO;QACL,IAAI,EAAE,uBAAuB;QAE7B,KAAK,CAAC,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBACxB,IAAI,CAAC;oBACH,gDAAgD;oBAChD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;oBACtE,IAAI,OAAO;wBAAE,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;oBAE3C,IAAI,UAAU,GAAG,MAAM,CAAC;oBAExB,kCAAkC;oBAClC,IAAI,MAAM,EAAE,CAAC;wBACX,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;wBACnC,IAAI,OAAO;4BAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;oBACrD,CAAC;oBAED,qCAAqC;oBACrC,OAAO,kBAAkB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC;gBACzD,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;oBAChD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gjsify/vite-plugin-blueprint",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Vite plugin for compiling Gnome Blueprint files",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Warning: no test specified\" && exit 0",
|
|
9
|
+
"clear": "rm -rf dist",
|
|
10
|
+
"check": "tsc --noEmit",
|
|
11
|
+
"build": "tsc --declaration"
|
|
12
|
+
},
|
|
13
|
+
"author": "Pascal Garber <pascal@mailfreun.de>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^24.3.0",
|
|
17
|
+
"typescript": "^5.9.2",
|
|
18
|
+
"vite": "^7.1.2"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"vite": "*"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"execa": "^9.6.0",
|
|
25
|
+
"minify-xml": "^4.5.2"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Plugin } from "vite";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import minifyXML from "minify-xml";
|
|
4
|
+
|
|
5
|
+
export interface BlueprintPluginOptions {
|
|
6
|
+
minify?: boolean;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function blueprintPlugin(
|
|
11
|
+
options: BlueprintPluginOptions = {}
|
|
12
|
+
): Plugin {
|
|
13
|
+
const { minify = false, verbose = false } = options;
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
name: "vite-plugin-blueprint",
|
|
17
|
+
|
|
18
|
+
async load(id) {
|
|
19
|
+
if (id.endsWith(".blp")) {
|
|
20
|
+
try {
|
|
21
|
+
// Compile .blp file and get XML output directly
|
|
22
|
+
const { stdout } = await execa("blueprint-compiler", ["compile", id]);
|
|
23
|
+
if (verbose) console.log(`Compiled ${id}`);
|
|
24
|
+
|
|
25
|
+
let xmlContent = stdout;
|
|
26
|
+
|
|
27
|
+
// Minify XML if option is enabled
|
|
28
|
+
if (minify) {
|
|
29
|
+
xmlContent = minifyXML(xmlContent);
|
|
30
|
+
if (verbose) console.log(`Minified XML for ${id}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Return the XML content as a string
|
|
34
|
+
return `export default ${JSON.stringify(xmlContent)};`;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(`Error processing ${id}:`, error);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
package/src/type.d.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"preserveWatchOutput": true,
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"types": ["node"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"module": "NodeNext",
|
|
8
|
+
"target": "ESNext",
|
|
9
|
+
"moduleResolution": "NodeNext",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"diagnostics": true,
|
|
17
|
+
"verbatimModuleSyntax": true,
|
|
18
|
+
"isolatedModules": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*.ts"],
|
|
21
|
+
"exclude": ["node_modules", "dist"]
|
|
22
|
+
}
|