@kawaijs/vite-plugin 0.1.3

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 ADDED
@@ -0,0 +1,36 @@
1
+ # @kawaijs/vite-plugin
2
+
3
+ **Official Vite plugin for Kawaijs visual novel projects.**
4
+
5
+ Part of the [Kawaijs](https://github.com/biagio-scaglia/KawaiJS) visual novel engine.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -D @kawaijs/vite-plugin
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ In your `vite.config.ts`:
16
+
17
+ ```typescript
18
+ import { defineConfig } from 'vite';
19
+ import kawaijsPlugin from '@kawaijs/vite-plugin';
20
+
21
+ export default defineConfig({
22
+ plugins: [kawaijsPlugin()]
23
+ });
24
+ ```
25
+
26
+ Now you can import `.kawa` scripts directly in TypeScript/JavaScript with instant HMR:
27
+
28
+ ```typescript
29
+ import story from './game/script.kawa';
30
+ import { mountKawaApp } from '@kawaijs/renderer-dom';
31
+
32
+ mountKawaApp(story, document.getElementById('app')!);
33
+ ```
34
+
35
+ ## License
36
+ MIT © Biagio Scaglia
@@ -0,0 +1,14 @@
1
+ export interface KawaijsPluginOptions {
2
+ include?: string | RegExp | (string | RegExp)[];
3
+ }
4
+ export declare function kawaijsPlugin(_options?: KawaijsPluginOptions): {
5
+ name: string;
6
+ transform(code: string, id: string): {
7
+ code: string;
8
+ map: {
9
+ mappings: string;
10
+ };
11
+ } | null;
12
+ };
13
+ export default kawaijsPlugin;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACjD;AAED,wBAAgB,aAAa,CAAC,QAAQ,GAAE,oBAAyB;;oBAG7C,MAAM,MAAM,MAAM;;;;;;EA8BrC;AAED,eAAe,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ import { compileScript } from '@kawaijs/parser';
2
+ export function kawaijsPlugin(_options = {}) {
3
+ return {
4
+ name: 'vite-plugin-kawaijs',
5
+ transform(code, id) {
6
+ if (!id.endsWith('.kawa')) {
7
+ return null;
8
+ }
9
+ try {
10
+ const storyPackage = compileScript(code, id);
11
+ const jsonStr = JSON.stringify(storyPackage);
12
+ return {
13
+ code: `
14
+ export const story = ${jsonStr};
15
+ export default story;
16
+
17
+ if (import.meta.hot) {
18
+ import.meta.hot.accept((newModule) => {
19
+ if (newModule) {
20
+ window.location.reload();
21
+ }
22
+ });
23
+ }
24
+ `,
25
+ map: { mappings: '' }
26
+ };
27
+ }
28
+ catch (err) {
29
+ const error = err;
30
+ throw new Error(`[vite-plugin-kawaijs] Failed to compile ${id}: ${error.message}`);
31
+ }
32
+ }
33
+ };
34
+ }
35
+ export default kawaijsPlugin;
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMhD,MAAM,UAAU,aAAa,CAAC,WAAiC,EAAE;IAC/D,OAAO;QACL,IAAI,EAAE,qBAAqB;QAC3B,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,YAAY,GAAG,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;gBAE7C,OAAO;oBACL,IAAI,EAAE;uBACO,OAAO;;;;;;;;;;CAU7B;oBACS,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;iBACtB,CAAC;YACJ,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACtB,MAAM,KAAK,GAAG,GAAY,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,2CAA2C,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,eAAe,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@kawaijs/vite-plugin",
3
+ "version": "0.1.3",
4
+ "description": "Official Vite/Rollup plugin to import and hot-reload .kawa visual novel scripts directly",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/biagio-scaglia/KawaiJS.git",
18
+ "directory": "packages/vite-plugin"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/biagio-scaglia/KawaiJS/issues"
22
+ },
23
+ "homepage": "https://github.com/biagio-scaglia/KawaiJS#readme",
24
+ "scripts": {
25
+ "build": "tsc",
26
+ "typecheck": "tsc --noEmit"
27
+ },
28
+ "dependencies": {
29
+ "@kawaijs/ast": "^0.1.3",
30
+ "@kawaijs/parser": "^0.1.3"
31
+ },
32
+ "peerDependencies": {
33
+ "vite": ">=4.0.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "vite": {
37
+ "optional": true
38
+ }
39
+ },
40
+ "keywords": [
41
+ "kawaijs",
42
+ "vite-plugin",
43
+ "vite",
44
+ "rollup",
45
+ "visual-novel"
46
+ ],
47
+ "author": "Biagio Scaglia",
48
+ "license": "MIT"
49
+ }