@jag-k/rollup-plugin-scriptable
Version:
Create a Scriptable bundle from your project
41 lines (39 loc) • 1.54 kB
JavaScript
const ext = /\.[tj]sx?$/;
function scriptableBundle(config) {
return {
name: 'scriptable',
renderChunk(code, chunk) {
let bannerData = {
"always-run-in-app": config.always_run_in_app || false,
"share-sheet-inputs": config.share_sheet_inputs ? config.share_sheet_inputs.join(', ') : '',
};
if (config.icon) {
if (config.icon.color) {
bannerData["icon-color"] = config.icon.color;
}
if (config.icon.glyph) {
bannerData["icon-glyph"] = config.icon.glyph;
}
}
const banner = ("// Variables used by Scriptable.\n" +
"// These must be at the very top of the file. Do not edit.\n" +
`// ${Object
.keys(bannerData)
.filter((key) => !!bannerData[key])
.map((key) => `${key}: ${bannerData[key]};`)
.join(' ')}\n`);
const result = Object.assign(Object.assign({}, config), { script: code });
this.emitFile({
type: 'asset',
name: chunk.name.replace(ext, '.scriptable'),
fileName: chunk.fileName.replace(ext, '.scriptable'),
source: JSON.stringify(result)
});
return {
code: banner + code,
};
}
};
}
export { scriptableBundle as default };
//# sourceMappingURL=index.es.js.map