UNPKG

@jag-k/rollup-plugin-scriptable

Version:
43 lines (40 loc) 1.55 kB
'use strict'; 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, }; } }; } module.exports = scriptableBundle; //# sourceMappingURL=index.js.map