-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·32 lines (30 loc) · 942 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// @ts-check
import { extname } from "path";
import { createFilter } from "@rollup/pluginutils";
import { archieml as amlParser } from "archieml";
/**
* @typedef {import('@rollup/pluginutils').FilterPattern} FilterPattern
* @typedef {import('vite').Plugin} Plugin
* @typedef {{ include?: FilterPattern; exclude?: FilterPattern }} RollupArchieMLOptions
*/
/**
* Convert `.aml` files into JavaScript modules.
* @param {RollupArchieMLOptions} [options]
* @returns {Plugin}
*/
export default function archieml(options = {}) {
const filter = createFilter(options.include, options.exclude);
return {
name: "archieml",
transform(code, id) {
if (!filter(id)) return null;
const ext = extname(id);
if (ext !== `.aml`) return null;
const parsed = amlParser.load(code);
return {
code: `export default ${JSON.stringify(parsed, null, 2)};`,
map: { mappings: "" },
};
},
};
}