Comparing version 0.13.2 to 0.14.0
@@ -135,16 +135,3 @@ "use strict"; | ||
info(`Using config: ${opts.configPath}`); | ||
try { | ||
prj.mkcConfig = JSON.parse(fs.readFileSync(opts.configPath, "utf8")); | ||
} | ||
catch (e) { | ||
error(`Can't read config file: '${opts.configPath}'; ` + e.message); | ||
process.exit(1); | ||
} | ||
const lnk = prj.mkcConfig.links; | ||
if (lnk) { | ||
const mkcFolder = path.resolve(".", path.dirname(opts.configPath)); | ||
for (const k of Object.keys(lnk)) { | ||
lnk[k] = path.resolve(mkcFolder, lnk[k]); | ||
} | ||
} | ||
prj.mkcConfig = readCfg(opts.configPath); | ||
} | ||
@@ -290,2 +277,57 @@ yield prj.loadEditorAsync(!!opts.update); | ||
} | ||
function isKV(v) { | ||
return !!v && typeof v === "object" && !Array.isArray(v); | ||
} | ||
function jsonMergeFrom(trg, src) { | ||
if (!src) | ||
return; | ||
Object.keys(src).forEach(k => { | ||
if (isKV(trg[k]) && isKV(src[k])) | ||
jsonMergeFrom(trg[k], src[k]); | ||
else if (Array.isArray(trg[k]) && Array.isArray(src[k])) | ||
trg[k] = trg[k].concat(src[k]); | ||
else | ||
trg[k] = src[k]; | ||
}); | ||
} | ||
function readCfg(cfgpath) { | ||
const files = []; | ||
return readCfgRec(cfgpath); | ||
function readCfgRec(cfgpath) { | ||
if (files.indexOf(cfgpath) >= 0) { | ||
error(`Config file loop: ${files.join(" -> ")} -> ${cfgpath}`); | ||
process.exit(1); | ||
} | ||
const cfg = cfgFile(cfgpath); | ||
const currCfg = {}; | ||
files.push(cfgpath); | ||
for (const fn of cfg.include || []) { | ||
const resolved = path.resolve(path.dirname(cfgpath), fn); | ||
info(` include: ${resolved}`); | ||
jsonMergeFrom(currCfg, readCfgRec(resolved)); | ||
} | ||
jsonMergeFrom(currCfg, cfg); | ||
delete currCfg.include; | ||
files.pop(); | ||
return currCfg; | ||
function cfgFile(cfgpath) { | ||
let cfg; | ||
try { | ||
cfg = JSON.parse(fs.readFileSync(cfgpath, "utf8")); | ||
} | ||
catch (e) { | ||
error(`Can't read config file: '${cfgpath}'; ` + e.message); | ||
process.exit(1); | ||
} | ||
const lnk = cfg.links; | ||
if (lnk) { | ||
const mkcFolder = path.resolve(".", path.dirname(cfgpath)); | ||
for (const k of Object.keys(lnk)) { | ||
lnk[k] = path.resolve(mkcFolder, lnk[k]); | ||
} | ||
} | ||
return cfg; | ||
} | ||
} | ||
} | ||
function mainWrapper() { | ||
@@ -292,0 +334,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -13,2 +13,3 @@ /// <reference path="../external/pxtpackage.d.ts" /> | ||
overrides?: Partial<pxt.PackageConfig>; | ||
include?: string[]; | ||
} | ||
@@ -15,0 +16,0 @@ export interface Cache { |
{ | ||
"name": "makecode", | ||
"version": "0.13.2", | ||
"version": "0.14.0", | ||
"description": "MakeCode (PXT) - web-cached build tool", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -47,3 +47,6 @@ # MKC - command line tool for MakeCode editors | ||
"testDependencies": {} | ||
} | ||
}, | ||
"include": [ | ||
"../../common-mkc.json" | ||
] | ||
} | ||
@@ -60,2 +63,4 @@ ``` | ||
* **overrides** is used to override specific keys in `pxt.json` | ||
* files listed in **include** are merged with the keys from the later ones overriding the keys from the earlier ones; | ||
the keys from the current file override all included keys | ||
@@ -62,0 +67,0 @@ You can use `--config-path` to build for a different configuration, eg. `makecode -c mkc-arcade.json`. |
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
150865
2190
112