jsoneditor/tools/generateAceWorker.mjs

16 lines
661 B
JavaScript
Raw Normal View History

2020-07-30 17:42:11 +08:00
import btoa from 'btoa'
import { readFileSync, writeFileSync } from 'fs'
import path from 'path'
import mkdirp from 'mkdirp'
const workerBundleFile = './node_modules/ace-builds/src-noconflict/worker-json.js'
const outputFolder = './src/generated/ace'
const workerEmbeddedFile = path.join(outputFolder, 'jsonWorker.mjs')
// Create an embedded version of the json worker code of Ace editor: a data url
const workerScript = String(readFileSync(workerBundleFile))
const workerDataUrl = 'data:application/javascript;base64,' + btoa(workerScript)
mkdirp.sync(outputFolder)
writeFileSync(workerEmbeddedFile, 'export const jsonWorker = \'' + workerDataUrl + '\'\n')