Comparing version 0.4.1 to 0.4.2
@@ -39,6 +39,7 @@ "use strict"; | ||
.option("-d, --download <URL>", "download project from share URL") | ||
.option("-m, --pxt-modules", "write pxt_modules/*") | ||
.option("-i, --init-mkc", "initialize mkc.json") | ||
.option("-u, --update", "check for web-app updates") | ||
.option("-b, --bump", "bump version in pxt.json and git") | ||
.option("-c, --config-path <file>", "set configuration file path", "mkc.json") | ||
.option("--pxt-modules", "write pxt_modules/*") | ||
.option("--always-built", "always generate files in built/ folder (and not built/hw-variant/)") | ||
@@ -51,2 +52,3 @@ .option("--debug", "enable debug output from PXT") | ||
const prj = new mkc.Project(files.findProjectDir()); | ||
prj.mkcConfigPath = opts.configPath; | ||
yield prj.loadEditorAsync(!!opts.update); | ||
@@ -53,0 +55,0 @@ if (opts.debug) |
import * as mkc from "./mkc"; | ||
export declare function findProjectDir(): string; | ||
export declare function readPrjFileAsync(dir: string, filename: string): Promise<string>; | ||
export declare function readProjectAsync(dir: string): Promise<mkc.Package>; | ||
export declare function readProjectAsync(dir: string): Promise<pxt.Map<string>>; | ||
export declare function mkHomeCache(dir?: string): mkc.Cache; | ||
@@ -6,0 +6,0 @@ export declare function writeFilesAsync(built: string, outfiles: pxt.Map<string>, log?: boolean): Promise<void>; |
@@ -41,3 +41,3 @@ "use strict"; | ||
config: JSON.parse(pxtJson), | ||
mkcConfig: JSON.parse(yield readAsync(path.join(dir, "mkc.json"), "utf8").then(s => s, err => "{}")), | ||
mkcConfig: null, | ||
files: { | ||
@@ -52,3 +52,3 @@ "pxt.json": pxtJson | ||
} | ||
return res; | ||
return res.files; | ||
}); | ||
@@ -55,0 +55,0 @@ } |
@@ -79,3 +79,3 @@ "use strict"; | ||
if (mkcJson.links && mkcJson.links[pkgid]) { | ||
text = (yield mkc.files.readProjectAsync(mkcJson.links[pkgid])).files; | ||
text = yield mkc.files.readProjectAsync(mkcJson.links[pkgid]); | ||
} | ||
@@ -82,0 +82,0 @@ else if (ver == "*" || /^file:/.test(ver)) { |
@@ -12,2 +12,3 @@ /// <reference path="../external/pxtpackage.d.ts" /> | ||
links?: pxt.Map<string>; | ||
overrides?: Partial<pxt.PackageConfig>; | ||
} | ||
@@ -49,2 +50,3 @@ export interface Cache { | ||
outputPrefix: string; | ||
mkcConfigPath: string; | ||
constructor(directory: string, cache?: Cache); | ||
@@ -51,0 +53,0 @@ get hwVariant(): string; |
@@ -20,2 +20,8 @@ "use strict"; | ||
exports.cloudRoot = "https://makecode.com/api/"; | ||
function jsonCopyFrom(trg, src) { | ||
let v = JSON.parse(JSON.stringify(src)); | ||
for (let k of Object.keys(src)) { | ||
trg[k] = v[k]; | ||
} | ||
} | ||
class Project { | ||
@@ -27,2 +33,3 @@ constructor(directory, cache = null) { | ||
this.outputPrefix = "built"; | ||
this.mkcConfigPath = "mkc.json"; | ||
if (!this.cache) | ||
@@ -72,3 +79,3 @@ this.cache = exports.files.mkHomeCache(); | ||
config: JSON.parse(pxtJson), | ||
mkcConfig: JSON.parse(yield this.readFileAsync("mkc.json").then(s => s, err => "{}")), | ||
mkcConfig: JSON.parse(yield this.readFileAsync(this.mkcConfigPath).then(s => s, err => "{}")), | ||
files: { | ||
@@ -78,2 +85,6 @@ "pxt.json": pxtJson | ||
}; | ||
if (res.mkcConfig.overrides) { | ||
jsonCopyFrom(res.config, res.mkcConfig.overrides); | ||
res.files["pxt.json"] = JSON.stringify(res.config, null, 4); | ||
} | ||
for (let f of res.config.files.concat(res.config.testFiles || [])) { | ||
@@ -80,0 +91,0 @@ if (f.indexOf("/") >= 0) |
@@ -0,2 +1,17 @@ | ||
/// <reference types="node" /> | ||
import vm = require("vm"); | ||
import mkc = require("./mkc"); | ||
export interface HexInfo { | ||
hex: string[]; | ||
} | ||
export interface ExtensionInfo { | ||
sha: string; | ||
compileData: string; | ||
skipCloudBuild?: boolean; | ||
hexinfo?: HexInfo; | ||
appVariant?: string; | ||
} | ||
export interface ExtensionTarget { | ||
extinfo: ExtensionInfo; | ||
} | ||
export interface CompileOptions { | ||
@@ -22,2 +37,4 @@ fileSystem: pxt.Map<string>; | ||
embedBlob?: string; | ||
extinfo?: ExtensionInfo; | ||
otherMultiVariants?: ExtensionTarget[]; | ||
} | ||
@@ -58,3 +75,3 @@ export declare enum DiagnosticCategory { | ||
editor: mkc.DownloadedEditor; | ||
sandbox: any; | ||
sandbox: vm.Context; | ||
lastUser: unknown; | ||
@@ -68,2 +85,3 @@ private makerHw; | ||
setUserAsync(user: unknown): Promise<void>; | ||
private compileExtInfo; | ||
simpleCompileAsync(prj: mkc.Package, simpleOpts?: any): Promise<CompileResult>; | ||
@@ -70,0 +88,0 @@ getOptions(prj: mkc.Package, simpleOpts?: any): Promise<CompileOptions>; |
@@ -29,3 +29,5 @@ "use strict"; | ||
this.sandbox = { | ||
eval: undefined, | ||
eval: (str) => vm.runInContext(str, this.sandbox, { | ||
filename: "eval" | ||
}), | ||
Function: undefined, | ||
@@ -98,51 +100,58 @@ setTimeout: setTimeout, | ||
} | ||
simpleCompileAsync(prj, simpleOpts = {}) { | ||
compileExtInfo(extinfo) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const opts = yield this.getOptions(prj, simpleOpts); | ||
const cppsha = opts.extinfo ? opts.extinfo.sha : null; | ||
if (simpleOpts.native && cppsha) { | ||
let existing = yield this.editor.cache.getAsync("cpp-" + cppsha); | ||
if (!existing) { | ||
const url = this.editor.cdnUrl + "/compile/" + opts.extinfo.sha + ".hex"; | ||
const resp = yield downloader.requestAsync({ url }).then(r => r, err => null); | ||
if (resp == null) { | ||
console.log(`compiling C++; this can take a while`); | ||
const cdata = opts.extinfo.compileData; | ||
const cdataObj = JSON.parse(Buffer.from(cdata, "base64").toString()); | ||
if (!cdataObj.config) | ||
throw new Error(`Compile config missing in C++; compile variant likely misconfigured`); | ||
// writeFileSync("compilereq.json", JSON.stringify(JSON.parse(Buffer.from(cdata, "base64").toString()), null, 4)) | ||
const cresp = yield downloader.requestAsync({ | ||
url: "https://www.makecode.com/api/compile/extension", | ||
data: { data: cdata }, | ||
allowGzipPost: true | ||
}); | ||
const hexurl = cresp.json.hex; | ||
const jsonUrl = hexurl.replace(/\.hex/, ".json"); | ||
for (let i = 0; i < 100; ++i) { | ||
const jresp = yield downloader.requestAsync({ url: jsonUrl }).then(r => r, e => null); | ||
if (jresp) { | ||
const json = jresp.json; | ||
console.log(`build log ${jsonUrl.replace(/\.json$/, ".log")}`); | ||
if (!json.success) { | ||
console.log(`C++ build failed`); | ||
if (json.mbedresponse && json.mbedresponse.result && json.mbedresponse.result.exception) | ||
console.log(json.mbedresponse.result.exception); | ||
throw new Error("C++ build failed"); | ||
} | ||
else { | ||
const hexresp = yield downloader.requestAsync({ url: hexurl }); | ||
existing = hexresp.buffer; | ||
break; | ||
} | ||
let existing = yield this.editor.cache.getAsync("cpp-" + extinfo.sha); | ||
if (!existing) { | ||
const url = this.editor.cdnUrl + "/compile/" + extinfo.sha + ".hex"; | ||
const resp = yield downloader.requestAsync({ url }).then(r => r, err => null); | ||
if (resp == null) { | ||
console.log(`compiling C++; this can take a while`); | ||
const cdata = extinfo.compileData; | ||
const cdataObj = JSON.parse(Buffer.from(cdata, "base64").toString()); | ||
if (!cdataObj.config) | ||
throw new Error(`Compile config missing in C++; compile variant likely misconfigured`); | ||
// writeFileSync("compilereq.json", JSON.stringify(JSON.parse(Buffer.from(cdata, "base64").toString()), null, 4)) | ||
const cresp = yield downloader.requestAsync({ | ||
url: "https://www.makecode.com/api/compile/extension", | ||
data: { data: cdata }, | ||
allowGzipPost: true | ||
}); | ||
const hexurl = cresp.json.hex; | ||
const jsonUrl = hexurl.replace(/\.hex/, ".json"); | ||
for (let i = 0; i < 100; ++i) { | ||
const jresp = yield downloader.requestAsync({ url: jsonUrl }).then(r => r, e => null); | ||
if (jresp) { | ||
const json = jresp.json; | ||
console.log(`build log ${jsonUrl.replace(/\.json$/, ".log")}`); | ||
if (!json.success) { | ||
console.log(`C++ build failed`); | ||
if (json.mbedresponse && json.mbedresponse.result && json.mbedresponse.result.exception) | ||
console.log(json.mbedresponse.result.exception); | ||
throw new Error("C++ build failed"); | ||
} | ||
else { | ||
const hexresp = yield downloader.requestAsync({ url: hexurl }); | ||
existing = hexresp.buffer; | ||
break; | ||
} | ||
} | ||
} | ||
else { | ||
existing = resp.buffer; | ||
} | ||
yield this.editor.cache.setAsync("cpp-" + cppsha, existing); | ||
} | ||
opts.extinfo.hexinfo = { hex: existing.toString("utf8").split(/\r?\n/) }; | ||
else { | ||
existing = resp.buffer; | ||
} | ||
yield this.editor.cache.setAsync("cpp-" + extinfo.sha, existing); | ||
} | ||
extinfo.hexinfo = { hex: existing.toString("utf8").split(/\r?\n/) }; | ||
}); | ||
} | ||
simpleCompileAsync(prj, simpleOpts = {}) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const opts = yield this.getOptions(prj, simpleOpts); | ||
if (simpleOpts.native && ((_a = opts === null || opts === void 0 ? void 0 : opts.extinfo) === null || _a === void 0 ? void 0 : _a.sha)) { | ||
const infos = [opts.extinfo].concat((opts.otherMultiVariants || []).map(x => x.extinfo)); | ||
for (const info of infos) | ||
yield this.compileExtInfo(info); | ||
} | ||
// opts.breakpoints = true | ||
@@ -149,0 +158,0 @@ return this.serviceOp("compile", { options: opts }); |
{ | ||
"name": "makecode", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "MakeCode (PXT) - web-cached build tool", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -28,2 +28,5 @@ # MKC - command line tool for MakeCode editors | ||
"jacdac-services": "../../pxt-jacdac-services" | ||
}, | ||
"overrides": { | ||
"testDependencies": {} | ||
} | ||
@@ -40,3 +43,6 @@ } | ||
* **links** overrides specific packages; these can be github packages or built-in packages | ||
* **overrides** is used to override specific keys in `pxt.json` | ||
You can use `--config-path` to build for a different configuration, eg. `makecode -c mkc-arcade.json`. | ||
## TODO | ||
@@ -43,0 +49,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106491
1600
64