Socket
Socket
Sign inDemoInstall

makecode

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

makecode - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

2

built/bump.js

@@ -146,3 +146,3 @@ "use strict";

mkc.log(`Github slug ${slug}; refreshing makecode.com cache`);
const res = yield downloader_1.httpGetJsonAsync("https://makecode.com/api/gh/" + slug + "/refs?nocache=1");
const res = yield (0, downloader_1.httpGetJsonAsync)("https://makecode.com/api/gh/" + slug + "/refs?nocache=1");
const sha = (_b = res === null || res === void 0 ? void 0 : res.refs) === null || _b === void 0 ? void 0 : _b["refs/tags/v" + newV];

@@ -149,0 +149,0 @@ mkc.log(`refreshed ${newV} -> ${sha}`);

@@ -22,2 +22,4 @@ "use strict";

const deploy_1 = require("./deploy");
const loader_1 = require("./loader");
const node_watch_1 = require("node-watch");
function downloadProjectAsync(id) {

@@ -79,46 +81,37 @@ return __awaiter(this, void 0, void 0, function* () {

}
function mainCli() {
function createCommand(name, opts) {
const cmd = commander_1.program.command(name, opts)
.option("--colors", "force color output")
.option("--no-colors", "disable color output")
.option("--debug", "enable debug output from PXT");
return cmd;
}
function applyGlobalOptions(opts) {
if (opts.noColors)
chalk.level = 0;
else if (opts.colors && !chalk.level)
chalk.level = 1;
else if (process.env["GITHUB_WORKFLOW"])
chalk.level = 1;
}
function downloadCommand(URL, opts) {
return __awaiter(this, void 0, void 0, function* () {
commander_1.program
.version(require("../package.json").version)
.option("-n, --native", "compile native (default)")
.option("-d, --deploy", "copy resulting binary to UF2 or HEX drive")
.option("-h, --hw <id,...>", "set hardware(s) for which to compile (implies -n)")
.option("-j, --java-script", "compile to JavaScript")
.option("-d, --download <URL>", "download project from share URL")
.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 (default: \"mkc.json\")")
.option("-r, --mono-repo", "also build all subfolders with 'pxt.json' in them")
.option("-m, --pxt-modules", "write pxt_modules/*")
.option("--symlink-pxt-modules", "symlink files in pxt_modules/* for auto-completion")
.option("--link-pxt-modules", "write pxt_modules/* adhering to 'links' field in mkc.json (for pxt cli build)")
.option("--always-built", "always generate files in built/ folder (and not built/hw-variant/)")
.option("--colors", "force color output")
.option("--no-colors", "disable color output")
.option("--debug", "enable debug output from PXT")
.parse(process.argv);
const opts = commander_1.program.opts();
if (opts.noColors)
chalk.level = 0;
else if (opts.colors && !chalk.level)
chalk.level = 1;
else if (process.env["GITHUB_WORKFLOW"])
chalk.level = 1;
if (opts.deploy && opts.monoRepo) {
error("--deploy and --mono-repo cannot be used together");
process.exit(1);
}
if (opts.deploy && opts.javaScript) {
error("--deploy and --java-script cannot be used together");
process.exit(1);
}
mkc.setLogging({
log: info,
error: error,
debug: s => console.log(chalk.gray(s))
applyGlobalOptions(opts);
yield downloadProjectAsync(URL);
});
}
function cleanCommand(opts) {
return __awaiter(this, void 0, void 0, function* () {
applyGlobalOptions(opts);
["built", "pxt_modules"]
.filter(d => fs.existsSync(d))
.forEach(d => {
msg(`deleting ${d} folder`);
fs.rmdirSync(d, { recursive: true, force: true });
});
if (opts.download)
return downloadProjectAsync(opts.download);
msg("run `mkc init` again to setup your project");
});
}
function resolveProject(opts) {
return __awaiter(this, void 0, void 0, function* () {
const prjdir = files.findProjectDir();

@@ -134,6 +127,6 @@ if (!prjdir) {

}
info(`Using project: ${prjdir}/pxt.json`);
info(`using project: ${prjdir}/pxt.json`);
const prj = new mkc.Project(prjdir);
if (opts.configPath) {
info(`Using config: ${opts.configPath}`);
info(`using config: ${opts.configPath}`);
prj.mkcConfig = readCfg(opts.configPath);

@@ -147,9 +140,78 @@ }

catch (_a) { }
info(`Using editor: ${prj.mkcConfig.targetWebsite} v${version}`);
info(`using editor: ${prj.mkcConfig.targetWebsite} v${version}`);
if (opts.debug)
prj.service.runSync("(() => { pxt.options.debug = 1 })()");
if (opts.bump) {
yield bump.bumpAsync(prj);
process.exit(0);
prj.writePxtModules = !!opts.pxtModules;
if (opts.linkPxtModules) {
prj.writePxtModules = true;
prj.linkPxtModules = true;
}
else if (opts.symlinkPxtModules) {
prj.writePxtModules = true;
prj.symlinkPxtModules = true;
}
return prj;
});
}
function buildCommand(opts) {
return __awaiter(this, void 0, void 0, function* () {
applyGlobalOptions(opts);
if (opts.deploy && opts.monoRepo) {
error("--deploy and --mono-repo cannot be used together");
process.exit(1);
}
if (opts.deploy && opts.javaScript) {
error("--deploy and --java-script cannot be used together");
process.exit(1);
}
if (opts.watch) {
startWatch(opts);
}
else
yield buildCommandOnce(opts);
});
}
function startWatch(opts) {
const watcher = (0, node_watch_1.default)('./', {
recursive: true,
delay: 3000,
filter(f, skip) {
// skip node_modules, pxt_modules, built, .git
if (/\/?((node|pxt)_modules|built|\.git)/i.test(f))
return skip;
// only watch for js files
return /\.(json|ts|asm|cpp|c|h|hpp)$/i.test(f);
}
});
let building = false;
let buildPending = false;
const build = (ev, filename) => __awaiter(this, void 0, void 0, function* () {
if (ev)
msg(`detected ${ev} ${filename}`);
// don't trigger 2 build, wait and do it again
if (building) {
msg(` build in progress, waiting...`);
buildPending = true;
return;
}
// start a build
try {
building = true;
buildPending = false;
yield buildCommandOnce(JSON.parse(JSON.stringify(opts)));
}
catch (e) {
error(e);
}
finally {
building = false;
}
});
watcher.on('change', build);
info(`start watching for file changes`);
build(undefined, undefined);
}
function buildCommandOnce(opts) {
return __awaiter(this, void 0, void 0, function* () {
const prj = yield resolveProject(opts);
prj.service.runSync("(() => { pxt.savedAppTheme().experimentalHw = true; pxt.reloadAppTargetVariant() })()");

@@ -165,15 +227,2 @@ const hwVariants = prj.service.hwVariants;

}
if (opts.initMkc) {
msg("saving mkc.json");
fs.writeFileSync("mkc.json", mkc.stringifyConfig(prj.mainPkg.mkcConfig));
}
prj.writePxtModules = !!opts.pxtModules;
if (opts.linkPxtModules) {
prj.writePxtModules = true;
prj.linkPxtModules = true;
}
else if (opts.symlinkPxtModules) {
prj.writePxtModules = true;
prj.symlinkPxtModules = true;
}
if (!opts.javaScript || opts.hw)

@@ -196,3 +245,3 @@ opts.native = true;

const compileInfo = prj.service.runSync("pxt.appTarget.compile");
const drives = yield deploy_1.getDeployDrives(compileInfo);
const drives = yield (0, deploy_1.getDeployDrives)(compileInfo);
if (drives.length == 0) {

@@ -248,3 +297,3 @@ msg("cannot find any drives to deploy to");

}
catch (_b) { }
catch (_a) { }
}

@@ -260,7 +309,13 @@ if (uf2s.length > 1) {

msg("Build OK");
process.exit(0);
if (opts.watch)
return;
else
process.exit(0);
}
else {
error("Build failed");
process.exit(1);
if (opts.watch)
return;
else
process.exit(1);
}

@@ -294,2 +349,56 @@ function hwid(cfg) {

}
function bumpCommand(opts) {
return __awaiter(this, void 0, void 0, function* () {
applyGlobalOptions(opts);
const prj = yield resolveProject(opts);
yield bump.bumpAsync(prj);
});
}
function initCommand(template, opts) {
return __awaiter(this, void 0, void 0, function* () {
applyGlobalOptions(opts);
if (!fs.existsSync("pxt.json")) {
const target = loader_1.descriptors.find(t => t.id === template);
if (!target) {
error(`template not found`);
process.exit(1);
}
msg(`initializing project for ${target.name}`);
msg("saving main.ts");
fs.writeFileSync("main.ts", "// add code here", { encoding: "utf-8" });
msg("saving pxt.json");
fs.writeFileSync("pxt.json", JSON.stringify({
"name": "my-project",
"version": "0.0.0",
"files": ["main.ts"],
"supportedTargets": [target.targetId],
"dependencies": target.dependencies || (target.corepkg && { [target.corepkg]: "*" }) || {},
"testDependencies": target.testDependencies || {}
}, null, 4));
fs.writeFileSync("mkc.json", JSON.stringify({
targetWebsite: target.website
}, null, 4), { encoding: "utf-8" });
}
if (!fs.existsSync("tsconfig.json")) {
msg("saving tsconfig.json");
fs.writeFileSync("tsconfig.json", JSON.stringify({
"compilerOptions": {
"target": "ES5",
"noImplicitAny": true,
"outDir": "built",
"rootDir": "."
},
"exclude": ["pxt_modules/**/*test.ts"]
}, null, 4), { encoding: "utf-8" });
}
opts.pxtModules = true;
const prj = yield resolveProject(opts);
if (!fs.existsSync("mkc.json")) {
msg("saving mkc.json");
fs.writeFileSync("mkc.json", mkc.stringifyConfig(prj.mainPkg.mkcConfig), { encoding: "utf-8" });
}
yield prj.maybeWritePxtModulesAsync();
msg(`project ready, run "mkc -d" to build and deploy`);
});
}
function isKV(v) {

@@ -350,2 +459,41 @@ return !!v && typeof v === "object" && !Array.isArray(v);

}
function mainCli() {
return __awaiter(this, void 0, void 0, function* () {
mkc.setLogging({
log: info,
error: error,
debug: s => console.log(chalk.gray(s))
});
commander_1.program
.version(require("../package.json").version);
createCommand("build", { isDefault: true })
.description("build project")
.option("-w, --watch", "watch source files and rebuild on changes")
.option("-n, --native", "compile native (default)")
.option("-d, --deploy", "copy resulting binary to UF2 or HEX drive")
.option("-h, --hw <id,...>", "set hardware(s) for which to compile (implies -n)")
.option("-j, --java-script", "compile to JavaScript")
.option("-u, --update", "check for web-app updates")
.option("-c, --config-path <file>", "set configuration file path (default: \"mkc.json\")")
.option("-r, --mono-repo", "also build all subfolders with 'pxt.json' in them")
.option("--always-built", "always generate files in built/ folder (and not built/hw-variant/)")
.action(buildCommand);
createCommand("download <URL>")
.description("download project from share URL")
.action(downloadCommand);
createCommand("bump")
.description("bump version in pxt.json and git")
.action(bumpCommand);
createCommand("init")
.addArgument(new commander_1.Argument("<template>", "project template name").choices(loader_1.descriptors.map(d => d.id)))
.description("initializes the project, optionally for a particular editor")
.option("--symlink-pxt-modules", "symlink files in pxt_modules/* for auto-completion")
.option("--link-pxt-modules", "write pxt_modules/* adhering to 'links' field in mkc.json (for pxt cli build)")
.action(initCommand);
createCommand("clean")
.description("deletes built artifacts")
.action(cleanCommand);
yield commander_1.program.parseAsync(process.argv);
});
}
function mainWrapper() {

@@ -352,0 +500,0 @@ return __awaiter(this, void 0, void 0, function* () {

import * as mkc from "./mkc";
export interface TargetDescriptor {
id: string;
targetId: string;
name: string;
description: string;
website: string;
corepkg: string;
corepkg?: string;
label?: string;
dependencies?: Record<string, string>;
testDependencies?: Record<string, string>;
}

@@ -10,0 +13,0 @@ export declare const descriptors: TargetDescriptor[];

@@ -17,2 +17,3 @@ "use strict";

id: "arcade",
targetId: "arcade",
name: "MakeCode Arcade",

@@ -24,2 +25,3 @@ description: "Old school games",

id: "microbit",
targetId: "microbit",
name: "micro:bit",

@@ -29,4 +31,38 @@ description: "Get creative, get connected, get coding",

corepkg: "core",
dependencies: {
"core": "*",
"radio": "*",
"microphone": "*"
}
}, {
id: "maker-jacdac-brain-esp32",
targetId: "maker",
name: "Maker ESP32-S2",
description: "Jacdac ESP32-S2 brain",
website: "https://maker.makecode.com/",
corepkg: "jacdac-iot-s2",
}, {
id: "maker-jacdac-brain-f4",
targetId: "maker",
name: "Maker Jacdac Brain F4",
description: "Jacdac STM32 F4 brain",
website: "https://maker.makecode.com/",
corepkg: "jacdac-brain-f4",
}, {
id: "maker-jacdac-brain-rp2040",
targetId: "maker",
name: "Maker Jacdac Brain RP2040",
description: "Jacdac STM32 RP2040 brain",
website: "https://maker.makecode.com/",
corepkg: "jacdac-brain-rp2040",
}, {
id: "maker-jacdac-brain-nrf52",
targetId: "maker",
name: "Maker Jacdac Brain NRF52",
description: "Jacdac STM32 NRF52 brain",
website: "https://maker.makecode.com/",
corepkg: "jacdac-nrfbrain",
}, {
id: "adafruit",
targetId: "adafruit",
name: "Circuit Playground Express",

@@ -40,5 +76,7 @@ description: "An educational board from Adafruit",

const ver = prj.config.targetVersions || { target: "" };
const theTarget = exports.descriptors.filter(d => d.id == ver.targetId)[0]
|| exports.descriptors.filter(d => d.website == ver.targetWebsite)[0]
|| exports.descriptors.filter(d => { var _a, _b; return !!((_b = (_a = prj.config) === null || _a === void 0 ? void 0 : _a.testDependencies) === null || _b === void 0 ? void 0 : _b[d.corepkg]) || !!prj.config.dependencies[d.corepkg]; })[0];
const vers = prj.config.supportedTargets || [];
const theTarget = exports.descriptors.find(d => d.targetId == ver.targetId)
|| exports.descriptors.find(d => d.website == ver.targetWebsite)
|| exports.descriptors.find(d => vers.indexOf(d.targetId) > -1)
|| exports.descriptors.find(d => { var _a, _b; return d.corepkg && !!((_b = (_a = prj.config) === null || _a === void 0 ? void 0 : _a.testDependencies) === null || _b === void 0 ? void 0 : _b[d.corepkg]) || !!prj.config.dependencies[d.corepkg]; });
if (!mkc.targetWebsite) {

@@ -45,0 +83,0 @@ if (ver.targetWebsite) {

@@ -53,3 +53,3 @@ "use strict";

if (cfg.dependencies[v.name] || ((_a = cfg.testDependencies) === null || _a === void 0 ? void 0 : _a[v.name])) {
exports.log("guessing hw-variant: " + hwid(v));
(0, exports.log)("guessing hw-variant: " + hwid(v));
this.hwVariant = hwid(v);

@@ -59,3 +59,3 @@ return;

}
exports.log("selecting first hw-variant: " + hwid(variants[0]));
(0, exports.log)("selecting first hw-variant: " + hwid(variants[0]));
this.hwVariant = hwid(variants[0]);

@@ -103,3 +103,3 @@ function hwid(cfg) {

delete filesmap[fn];
exports.log(`link ${id} -> ${lnk}`);
(0, exports.log)(`link ${id} -> ${lnk}`);
const pxtJson = JSON.stringify({

@@ -121,3 +121,3 @@ additionalFilePath: rel

else {
exports.log(`not link ${fn}`);
(0, exports.log)(`not link ${fn}`);
}

@@ -207,3 +207,3 @@ }

if (this.writePxtModules && !wasThis) {
exports.log("writing pxt_modules/*");
(0, exports.log)("writing pxt_modules/*");
yield this.savePxtModulesAsync(this.mainPkg.files);

@@ -210,0 +210,0 @@ }

{
"name": "makecode",
"version": "0.15.0",
"version": "0.16.0",
"description": "MakeCode (PXT) - web-cached build tool",

@@ -40,15 +40,16 @@ "keywords": [

"devDependencies": {
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.2.1",
"@semantic-release/npm": "^7.1.1",
"@semantic-release/release-notes-generator": "^9.0.2",
"@types/node": "^14.14.37",
"semantic-release": "^17.4.2",
"typescript": "^4.2.4"
"@semantic-release/git": "^10.0.0",
"@semantic-release/github": "^8.0.1",
"@semantic-release/npm": "^8.0.0",
"@semantic-release/release-notes-generator": "^10.0.2",
"@types/node": "^16.10.3",
"semantic-release": "^18.0.0",
"typescript": "^4.4.3"
},
"dependencies": {
"@types/glob": "^7.1.3",
"chalk": "^4.1.0",
"commander": "^7.2.0",
"glob": "^7.1.6"
"@types/glob": "^7.1.4",
"chalk": "^4.1.2",
"commander": "^8.2.0",
"glob": "^7.2.0",
"node-watch": "^0.7.2"
},

@@ -55,0 +56,0 @@ "release": {

@@ -13,3 +13,3 @@ # MKC - command line tool for MakeCode editors

To install globally, run
To install mkc globally, run

@@ -20,3 +20,3 @@ ```

To update the client,
To update mkc,

@@ -29,26 +29,94 @@ ```

In a folder with `pxt.json` file, run:
The command line tool can be invoked as ``makecode`` or ``mkc`` for short.
### mkc init
To start a new [micro:bit](https://makecode.microbit.org) project in an empty folder:
```
> makecode
mkc init microbit
```
where `microbit` is the template name. To get the list of supported templates, do `mkc help init`.
Your project is ready to be edited. If you are a Visual Studio Code user, type `code .` and you're ready to go!
### mkc build
In a folder with `pxt.json` file, run the build command.
```
mkc build
```
Build is also the default command, so you can just leave it out.
```
mkc
```
You can also pass `--hw f4`, `--hw d5` etc. Try `--hw help` to get a list.
Use `makecode -j` to build JavaScript (it defaults to native).
Use `mkc -j` to build JavaScript (it defaults to native).
The tool is configured with optional `mkc.json` file. Example:
To build and deploy to a device add `-d`.
```
mkc -d
```
The tool checks once a day if the MakeCode editor has been updated. However, you can force an update by using ``--update``
during a build.
```
mkc --update
```
### mkc build --watch
Use ``--watch``, or ``-w``, with ``mkc build`` to automatically watch changes in source files and rebuild automatically.
```
mkc -w
```
### mkc clean
Run the clean command to erase build artifacts and cached packages.
```
mkc clean
```
### mkc bump
Interactive update of the version number of the current project
and nested projects in a mono-repo.
```
mkc bump
```
### mkc download
Downloads a shared MakeCode project to files and initializes the project.
```
mkc download https://.....
```
## Configuration
The `init` commands creates a `mkc.json` file that you can also use for additional configurations.
```json
{
"targetWebsite": "https://arcade.makecode.com/beta",
"hwVariant": "samd51",
"links": {
"jacdac": "../../pxt-jacdac"
},
"overrides": {
"testDependencies": {}
},
"include": [
"../../common-mkc.json"
]
"targetWebsite": "https://arcade.makecode.com/beta",
"hwVariant": "samd51",
"links": {
"jacdac": "../../pxt-jacdac"
},
"overrides": {
"testDependencies": {}
},
"include": ["../../common-mkc.json"]
}

@@ -59,13 +127,17 @@ ```

* **targetWebsite** says where to take the compiler from; if you omit it, it will be guessed based on packages used by `pxt.json`;
- **targetWebsite** says where to take the compiler from; if you omit it, it will be guessed based on packages used by `pxt.json`;
you can point this to a live or beta version of the editor, as well as to a specific version (including SHA-indexed uploads
generated during PXT target builds)
* **hwVariant** specifies default hardware variant (currently only used in Arcade); try `--hw help` command line option to list variants
* **links** overrides specific packages; these can be github packages or built-in packages
* **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;
- **hwVariant** specifies default hardware variant (currently only used in Arcade); try `--hw help` command line option to list variants
- **links** overrides specific packages; these can be github packages or built-in packages
- **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
You can use `--config-path` to build for a different configuration, eg. `makecode -c mkc-arcade.json`.
You can use `--config-path` to build for a different configuration
```
mkc -c mkc-arcade.json
```
## Local development

@@ -75,13 +147,13 @@

* install node.js
* run `yarn install`
* start the build: `yarn watch`
* run `node path/to/pxt-mkc/makecode` in your project folder
- install node.js
- run `yarn install`
- start the build: `yarn watch`
- run `node path/to/pxt-mkc/makecode` in your project folder
If you want to test out changes in pxt, first run the build as usual, and then replace
`$HOME/.pxt/mkc-cache/https_58__47__47_<your-editor>-pxtworker.js`
`$HOME/.pxt/mkc-cache/https_58__47__47_<your-editor>-pxtworker.js`
with `pxt/built/web/pxtworker.js`.
Make sure to run `makecode` tool without the `-u` option.
## Releases
### Releases

@@ -91,18 +163,14 @@ A new release will be automatically generated by the build system based on these

* **feat:** A new feature
* **fix:** A bug fix
* **docs:** Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
* **refactor:** A code change that neither fixes a bug nor adds a feature
* **perf:** A code change that improves performance
* **test:** Adding missing or correcting existing tests
* **chore:** Changes to the build process or auxiliary tools and libraries such as documentation generation
- **feat:** A new feature
- **fix:** A bug fix
- **docs:** Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- **refactor:** A code change that neither fixes a bug nor adds a feature
- **perf:** A code change that improves performance
- **test:** Adding missing or correcting existing tests
- **chore:** Changes to the build process or auxiliary tools and libraries such as documentation generation
## TODO
### Contributing
* [ ] allow updating `shims.d.ts`/`enums.d.ts`
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us

@@ -109,0 +177,0 @@ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc