From bb2dcf003962470575b78fd79f286d961b9f42e6 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 30 Jul 2020 11:42:11 +0200 Subject: [PATCH] Add Ace to the project (not yet used) --- src/logic/aceJson.mjs | 14 ++++++++++++++ tools/generateAceWorker.mjs | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/logic/aceJson.mjs create mode 100644 tools/generateAceWorker.mjs diff --git a/src/logic/aceJson.mjs b/src/logic/aceJson.mjs new file mode 100644 index 0000000..a42fbea --- /dev/null +++ b/src/logic/aceJson.mjs @@ -0,0 +1,14 @@ +// load Ace editor +import ace from 'ace-builds/src-noconflict/ace' + +// load required Ace plugins +import 'ace-builds/src-noconflict/mode-json' +import 'ace-builds/src-noconflict/ext-searchbox' + +// embed Ace json worker +// generated via tools/generateWorkerJSONDataUrl.mjs +// https://github.com/ajaxorg/ace/issues/3913 +import jsonWorkerDataUrl from '../generated/worker-json-data-url' +ace.config.setModuleUrl('ace/mode/json_worker', jsonWorkerDataUrl) + +export const aceJson = ace diff --git a/tools/generateAceWorker.mjs b/tools/generateAceWorker.mjs new file mode 100644 index 0000000..b674c71 --- /dev/null +++ b/tools/generateAceWorker.mjs @@ -0,0 +1,15 @@ +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')