Comparing version 0.27.0 to 0.28.0
@@ -15,2 +15,3 @@ "use strict"; | ||
const util = require("util"); | ||
const http_1 = require("http"); | ||
const mkc = require("./mkc"); | ||
@@ -111,3 +112,3 @@ const files = require("./files"); | ||
const port = parseInt(opts.port) || 7000; | ||
msg(`listening on http://localhost:${port}`); | ||
msg(`simulator web server at http://localhost:${port}`); | ||
(0, simserver_1.startSimServer)(prj.editor, port); | ||
@@ -188,2 +189,10 @@ }); | ||
} | ||
if (opts.serve && !opts.watch) { | ||
error("--serve must be used with --watch"); | ||
process.exit(1); | ||
} | ||
if (opts.serve && opts.monoRepo) { | ||
error("--serve and --mono-repo cannot be used together"); | ||
process.exit(1); | ||
} | ||
if (opts.watch) { | ||
@@ -200,2 +209,47 @@ startWatch(opts); | ||
function startWatch(opts) { | ||
const binaries = {}; | ||
if (opts.serve) { | ||
const port = opts.servePort || 7001; | ||
(0, http_1.createServer)((req, res) => __awaiter(this, void 0, void 0, function* () { | ||
// find file | ||
const k = req.url.toLowerCase().replace(/^\//, '').replace(/\/$/i, ''); | ||
const data = binaries[k]; | ||
if (data) { | ||
info(`found firmware file ${k}`); | ||
res.writeHead(200, { | ||
"Cache-Control": "no-cache", | ||
"Content-Type": typeof data === "string" ? "text/plain" : "application/octet-stream" | ||
}); | ||
res.end(data); | ||
} | ||
else if (k === 'favicon.ico') { | ||
res.writeHead(404); | ||
res.end(); | ||
} | ||
else { | ||
// display default path | ||
res.writeHead(200, { | ||
"Cache-Control": "no-cache" | ||
}); | ||
const entries = Object.entries(binaries); | ||
res.end(` | ||
<html> | ||
<head> | ||
${entries.length === 0 ? `<meta http-equiv="refresh" content="1">` : ''} | ||
<style> | ||
body { font-family: monospace; font-size: 14pt; } | ||
</style> | ||
</head> | ||
<body> | ||
<h1>MakeCode firmware files</h1> | ||
${entries.length === 0 ? `<p>Waiting for first build...</p>` : ''} | ||
<table> | ||
${entries.map(([key, value]) => `<tr><td><a download="${key}" href="/${key}">${key}</a></td><td>${Math.ceil(value.length / 1e3)}Kb</td></tr>`).join('\n')} | ||
</table> | ||
</body> | ||
</html>`); | ||
} | ||
})).listen(port); | ||
msg(`firmware file server at http://localhost:${port}/`); | ||
} | ||
const watcher = (0, node_watch_1.default)('./', { | ||
@@ -232,3 +286,10 @@ recursive: true, | ||
opts0.update = false; | ||
yield buildCommandOnce(opts0); | ||
const files = yield buildCommandOnce(opts0); | ||
if (files) | ||
Object.entries(files).forEach(([key, value]) => { | ||
if (/\.(hex|json|asm)$/.test(key)) | ||
binaries[key] = value; | ||
else | ||
binaries[key] = Buffer.from(value, 'base64'); | ||
}); | ||
} | ||
@@ -244,3 +305,3 @@ } | ||
watcher.on('change', build); | ||
info(`start watching for file changes`); | ||
msg(`start watching for file changes`); | ||
build(undefined, undefined); | ||
@@ -341,3 +402,3 @@ } | ||
if (opts.watch) | ||
return; | ||
return compileRes === null || compileRes === void 0 ? void 0 : compileRes.outfiles; | ||
else | ||
@@ -349,3 +410,3 @@ process.exit(0); | ||
if (opts.watch) | ||
return; | ||
return compileRes === null || compileRes === void 0 ? void 0 : compileRes.outfiles; | ||
else | ||
@@ -670,2 +731,4 @@ process.exit(1); | ||
.option("-d, --deploy", "copy resulting binary to UF2 or HEX drive") | ||
.option("-s, --serve", "start firmware files web server") | ||
.option("-p", "--serve-port", "specify the port for firmware file web server") | ||
.option("-h, --hw <id,...>", "set hardware(s) for which to compile (implies -n)") | ||
@@ -679,3 +742,3 @@ .option("-j, --java-script", "compile to JavaScript") | ||
createCommand("serve") | ||
.description("start simulator server") | ||
.description("start local simulator web server") | ||
.option("--no-watch", "do not watch source files") | ||
@@ -682,0 +745,0 @@ .option("-p, --port <number>", "port to listen at, default to 7000") |
{ | ||
"name": "makecode", | ||
"version": "0.27.0", | ||
"version": "0.28.0", | ||
"description": "MakeCode (PXT) - web-cached build tool", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -85,2 +85,11 @@ # MKC - command line tool for MakeCode editors | ||
### mkc build --watch --serve | ||
When building within a virtual machine without USB access, like in GitHub Codespaces or Windows Subsytem for Linux, the `--serve`, or `-s` option starts a local web server | ||
that serves the compiled binaries by the build process. | ||
``` | ||
mkc -w -s | ||
``` | ||
### Built files in codespace | ||
@@ -140,3 +149,3 @@ | ||
Adding ``--version-file`` will make `mkc` write a TypeScript file with the version number. | ||
Adding `--version-file` will make `mkc` write a TypeScript file with the version number. | ||
@@ -147,3 +156,3 @@ ``` | ||
Add ``--stage`` to test the bump without pushing to git. | ||
Add `--stage` to test the bump without pushing to git. | ||
@@ -150,0 +159,0 @@ ``` |
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
206501
3095
244
9