Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You may then need to run `npm install` again to register the local copies of the
| `runtime` | `squiffy-runtime` | Package | Squiffy runtime, which provides the JavaScript library for running Squiffy scripts |
| `site` | `site` | Web app | Squiffy website, `squiffystory.com` |
| `types` | `@textadventures/squiffy-types` | Package | Type definitions used by the Vite plugin |
| `vite-plugin` | `@textadventures/vite-plugin-squiffy` | Package | Vite plugin, allowing you to build Squiffy scripts as part of a web app |

There is also an `examples` folder which contains some sample Squiffy scripts.

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"packager",
"runtime",
"site",
"types"
"types",
"vite-plugin"
],
"scripts": {
"build": "lerna run build",
Expand Down
41 changes: 41 additions & 0 deletions vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@textadventures/vite-plugin-squiffy",
"version": "6.0.0-alpha.16",
"description": "Vite plugin to compile .squiffy files",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"files": [
"dist",
"LICENSE",
"README.md"
],
"scripts": {
"build": "tsc -p tsconfig.json",
"dev": "tsc -w -p tsconfig.json",
"prepublishOnly": "npm run build"
},
"author": "Alex Warren",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"@textadventures/squiffy-types": "^6.0.0-alpha.15",
"squiffy-packager": "^6.0.0-alpha.16"
},
"peerDependencies": {
"vite": "^7.1.2"
},
"devDependencies": {
"shx": "^0.4.0",
"typescript": "^5.9.2"
}
}
40 changes: 40 additions & 0 deletions vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export type __squiffy_types_ref = typeof import('@textadventures/squiffy-types');
import { type Plugin } from 'vite';
import { compileFile } from 'squiffy-packager';

export interface SquiffyPluginOptions {
/** Log transformed file paths (defaults to false). */
verbose?: boolean;
}

export default function squiffyPlugin(options: SquiffyPluginOptions = {}): Plugin {
const { verbose = false } = options;

return {
name: 'vite-plugin-squiffy',
enforce: 'pre', // run before other transforms that might depend on output

async transform(code, id) {
if (!id.endsWith('.squiffy')) return null;

if (verbose) {
this.warn(`vite-plugin-squiffy: transforming ${id}`);
}

const result = await compileFile(id);
if (result == null) return null;

return {
code: result,
map: null,
};
},

// Optional: so users can import *.squiffy without adding `assetsInclude` themselves
config() {
return {
assetsInclude: ['**/*.squiffy'],
};
},
};
}
14 changes: 14 additions & 0 deletions vite-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "Bundler",
"declaration": true,
"declarationMap": false,
"outDir": "dist",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true
},
"include": ["src"]
}