зеркало из https://github.com/microsoft/jacdac-ts.git
towards a build
This commit is contained in:
Родитель
5f5f608fd0
Коммит
cb54736930
|
@ -0,0 +1,50 @@
|
|||
const gulp = require('gulp');
|
||||
const watchify = require('watchify');
|
||||
const fancy_log = require('fancy-log');
|
||||
const ts = require('gulp-typescript');
|
||||
const browserify = require('browserify');
|
||||
const source = require('vinyl-source-stream');
|
||||
const tsify = require('tsify');
|
||||
const _rimraf = require("rimraf")
|
||||
|
||||
const DIST = 'dist'
|
||||
const tsProject = ts.createProject('tsconfig.json');
|
||||
|
||||
const rimraf = (dirname) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
_rimraf(dirname, (err) => {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const clean = () => rimraf(DIST)
|
||||
|
||||
const tscNode = () => {
|
||||
return tsProject.src()
|
||||
.pipe(tsProject())
|
||||
.js.pipe(gulp.dest(DIST));
|
||||
}
|
||||
|
||||
const watchedBrowserify = watchify(browserify({
|
||||
basedir: '.',
|
||||
debug: true,
|
||||
entries: tsProject.src(),
|
||||
cache: {},
|
||||
packageCache: {}
|
||||
}).plugin(tsify));
|
||||
const tscWeb = () => watchedBrowserify
|
||||
.bundle()
|
||||
.on('error', fancy_log)
|
||||
.pipe(source('bundle.js'))
|
||||
.pipe(gulp.dest(DIST));
|
||||
watchedBrowserify.on('update', tscWeb);
|
||||
watchedBrowserify.on('log', fancy_log);
|
||||
|
||||
const buildAll = gulp.parallel(tscNode);
|
||||
|
||||
exports.clean = clean;
|
||||
exports.tscNode = tscNode;
|
||||
exports.tscWeb = tscWeb;
|
||||
exports.default = buildAll;
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
12
package.json
12
package.json
|
@ -19,7 +19,17 @@
|
|||
},
|
||||
"homepage": "https://github.com/microsoft/jacdac-ts#readme",
|
||||
"dependencies": {
|
||||
"typescript": "^3.8.3",
|
||||
"webusb": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.5.1",
|
||||
"fancy-log": "^1.3.3",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-typescript": "^5.0.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"tsify": "^4.0.2",
|
||||
"typescript": "^3.8.3",
|
||||
"vinyl-source-stream": "^2.0.0",
|
||||
"watchify": "^3.11.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
all:
|
||||
node node_modules/typescript/bin/tsc
|
|
@ -1,2 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
require("./built/main")
|
98
src/main.ts
98
src/main.ts
|
@ -1,98 +0,0 @@
|
|||
import * as U from "./pxtutils"
|
||||
import * as HF2 from "./hf2"
|
||||
import * as jd from "./jd"
|
||||
import * as jdpretty from "./jdpretty"
|
||||
import * as jdbl from "./jdbl"
|
||||
import { program as commander } from "commander"
|
||||
import * as fs from "fs"
|
||||
|
||||
const dev_ids = {
|
||||
"119c5abca9fd6070": "JDM3.0-ACC-burned",
|
||||
"ffc91289c5dc5280": "JDM3.0-ACC",
|
||||
"766ccc5755a22eb4": "JDM3.0-LIGHT",
|
||||
"259ab02e98bc2752": "F840-0",
|
||||
"69a9eaeb1a7d2bc0": "F840-1",
|
||||
"08514ae8a1995a00": "KITTEN-0",
|
||||
"XEOM": "DEMO-ACC-L",
|
||||
"OEHM": "DEMO-ACC-M",
|
||||
"MTYV": "DEMO-LIGHT",
|
||||
"ZYQT": "DEMO-MONO",
|
||||
"XMMW": "MB-BLUE",
|
||||
"CJFN": "DEMO-CPB",
|
||||
}
|
||||
|
||||
U.jsonCopyFrom(jd.deviceNames, dev_ids)
|
||||
|
||||
|
||||
interface CmdOptions {
|
||||
parseLog?: string;
|
||||
log?: string;
|
||||
all?: boolean;
|
||||
flash?: string;
|
||||
ignoreDevClass?: boolean;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
commander
|
||||
.version("0.0.0")
|
||||
.option("-p, --parse-log <logfile>", "parse log file from jdspy or Logic")
|
||||
.option("-l, --log <logfile>", "in addition to print, save data to file")
|
||||
.option("-a, --all", "print repeated commands")
|
||||
.option("-f, --flash <file.bin>", "flash binary file")
|
||||
.option("-D, --ignore-dev-class", "ignore device class when flashing")
|
||||
.parse(process.argv)
|
||||
const opts = commander as CmdOptions
|
||||
|
||||
function processFrame(frame: jdpretty.ParsedFrame) {
|
||||
if (frame.info)
|
||||
console.warn("FRM: " + frame.info)
|
||||
for (let p of jd.Packet.fromFrame(frame.data, frame.timestamp)) {
|
||||
if (opts.log)
|
||||
fs.appendFileSync(opts.log, `JD ${frame.timestamp} ${U.toHex(frame.data)}\n`)
|
||||
jd.process(p)
|
||||
const pp = jdpretty.printPkt(p, {
|
||||
skipRepeatedAnnounce: !opts.all,
|
||||
skipRepeatedReading: !opts.all
|
||||
})
|
||||
if (pp)
|
||||
console.log(pp)
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.parseLog) {
|
||||
for (const frame of jdpretty.parseLog(fs.readFileSync(opts.parseLog, "utf8")))
|
||||
processFrame(frame)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
const startTime = Date.now()
|
||||
const hf2 = new HF2.Proto(new HF2.Transport())
|
||||
try {
|
||||
await hf2.init()
|
||||
|
||||
jd.setSendPacketFn(p =>
|
||||
hf2.sendJDMessageAsync(p.toBuffer())
|
||||
.then(() => { }, err => console.log(err)))
|
||||
|
||||
if (opts.flash) {
|
||||
await jdbl.flash(hf2, {
|
||||
program: fs.readFileSync(opts.flash),
|
||||
name: opts.flash,
|
||||
ignoreDevClass: opts.ignoreDevClass
|
||||
})
|
||||
await hf2.io.disconnectAsync()
|
||||
return
|
||||
}
|
||||
|
||||
hf2.onJDMessage(buf => {
|
||||
processFrame({ data: buf, timestamp: Date.now() - startTime })
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("ERROR: ", err)
|
||||
await hf2.io.disconnectAsync()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main()
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"name": "jacdac-ts",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"main": "built/main.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"commander": "^5.0.0",
|
||||
"typescript": "^3.8.3",
|
||||
"webusb": "^2.0.1"
|
||||
}
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
{
|
||||
"include": [
|
||||
"src/**.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"target": "es6",
|
||||
"target": "ES2017",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
|
@ -10,7 +13,7 @@
|
|||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"newLine": "LF",
|
||||
"outDir": "built",
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"incremental": true
|
||||
}
|
Загрузка…
Ссылка в новой задаче