UNPKG

makecode-core

Version:

MakeCode (PXT) - web-cached build tool

76 lines 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shareProjectAsync = void 0; const path = require("path"); const host_1 = require("./host"); const commands_1 = require("./commands"); const apiRoot = "https://www.makecode.com"; async function shareProjectAsync(opts) { const prj = await (0, commands_1.resolveProject)(opts); const req = await createShareLinkRequestAsync(prj); let siteRoot = new URL(prj.editor.website).origin; if (!siteRoot.endsWith("/")) { siteRoot += "/"; } const res = await (0, host_1.host)().requestAsync({ url: apiRoot + "/api/scripts", data: req }); if (res.statusCode === 200) { const resJSON = JSON.parse(res.text); return siteRoot + resJSON.shortid; } return undefined; } exports.shareProjectAsync = shareProjectAsync; async function createShareLinkRequestAsync(prj) { var _a; const theHost = (0, host_1.host)(); const config = await prj.readPxtConfig(); const files = { "pxt.json": JSON.stringify(config) }; for (const file of config.files) { const content = await theHost.readFileAsync(path.join(prj.directory, file), "utf8"); files[file] = content; } if (config.testFiles) { for (const file of config.testFiles) { const content = await theHost.readFileAsync(path.join(prj.directory, file), "utf8"); files[file] = content; } } const target = await prj.service.languageService.getAppTargetAsync(); const header = { "name": config.name, "meta": { "versions": target.versions }, "editor": "tsprj", "pubId": undefined, "pubCurrent": false, "target": target.id, "targetVersion": target.versions.target, "id": ((_a = theHost.guidGen) === null || _a === void 0 ? void 0 : _a.call(theHost)) || "", "recentUse": Date.now(), "modificationTime": Date.now(), "path": config.name, "saveId": {}, "githubCurrent": false, "pubVersions": [] }; return { id: header.id, name: config.name, target: target.id, targetVersion: target.versions.target, description: config.description || `Made with ❤️ in MakeCode.`, editor: "tsprj", header: JSON.stringify(header), text: JSON.stringify(files), meta: { versions: target.versions } }; } //# sourceMappingURL=share.js.map