From 33012441bc5d99c89485772e432e7d8861f05eb2 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Apr 2017 16:26:13 -0700 Subject: [PATCH] Added extensions (#385) * inject file importers as extensions * logging * updated signature --- editor/extension.ts | 28 ++++++++++++++++++++++++++++ editor/tsconfig.json | 12 ++++++++++++ pxtarget.json | 28 +--------------------------- 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 editor/extension.ts create mode 100644 editor/tsconfig.json diff --git a/editor/extension.ts b/editor/extension.ts new file mode 100644 index 00000000..aa508dc0 --- /dev/null +++ b/editor/extension.ts @@ -0,0 +1,28 @@ +/// + +namespace pxt.editor { + initExtensionsAsync = function(opts: pxt.editor.ExtensionOptions): Promise { + pxt.debug('loading microbit target extensions...') + const res: pxt.editor.ExtensionResult = { + hexFileImporters: [{ + id: "blockly", + canImport: data => data.meta.cloudId == "microbit.co.uk" && data.meta.editor == "blockly", + importAsync: (project, data) => project.createProjectAsync({ + filesOverride: { + "main.blocks": data.source + }, name: data.meta.name + }) + }, { + id: "td", + canImport: data => data.meta.cloudId == "microbit.co.uk" && data.meta.editor == "touchdevelop", + importAsync: (project, data) => + project.createProjectAsync({ + filesOverride: { "main.blocks": "", "main.ts": " " }, + name: data.meta.name + }).then(() => project.convertTouchDevelopToTypeScriptAsync(data.source)) + .then(text => this.textEditor.overrideFile(text)) + }] + }; + return Promise.resolve(res); + } +} \ No newline at end of file diff --git a/editor/tsconfig.json b/editor/tsconfig.json new file mode 100644 index 00000000..de974d4b --- /dev/null +++ b/editor/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "es5", + "noImplicitAny": true, + "noImplicitReturns": true, + "declaration": true, + "out": "../built/editor.js", + "rootDir": ".", + "newLine": "LF", + "sourceMap": false + } +} \ No newline at end of file diff --git a/pxtarget.json b/pxtarget.json index b64e3661..51d8dabe 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -228,33 +228,7 @@ "feedbackUrl": "https://www.research.net/r/MCmicro", "appStoreID": "1092687276", "mobileSafariDownloadProtocol": "microbithex://?data", - "browserSupport": [ - { - "name": "unsupported", - "os": "*", - "path": "/browsers" - }, - { - "name": "unsupported", - "os": "mac", - "path": "/browsers/mac" - }, - { - "name": "unsupported", - "os": "linux", - "path": "browsers/linux" - }, - { - "name": "unsupported", - "os": "rpi", - "path": "/raspberry-pi" - }, - { - "name": "unsupported", - "os": "windows", - "path": "/browsers/windows" - } - ], + "extendEditor": true, "docMenu": [ { "name": "Support",