From 0990849136b76603f73890fdc4500bc89ce614b9 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Sun, 27 Mar 2016 21:22:06 -0700 Subject: [PATCH] adding deploy command --- cmds/cmds.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ cmds/tsconfig.json | 13 +++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 cmds/cmds.ts create mode 100644 cmds/tsconfig.json diff --git a/cmds/cmds.ts b/cmds/cmds.ts new file mode 100644 index 00000000..fdb46850 --- /dev/null +++ b/cmds/cmds.ts @@ -0,0 +1,43 @@ +/// + +import * as fs from 'fs'; +import * as path from 'path'; +import * as child_process from 'child_process'; + +let writeFileAsync: any = Promise.promisify(fs.writeFile) +let execAsync: (cmd: string, options?: { cwd?: string }) => Promise = Promise.promisify(child_process.exec) + +export function deployCoreAsync(res: ts.ks.CompileResult) { + return getBitDrivesAsync() + .then(drives => { + if (drives.length == 0) { + console.log("cannot find any drives to deploy to") + } else { + console.log("copy microbit.hex to " + drives.join(", ")) + } + return Promise.map(drives, d => + writeFileAsync(d + "microbit.hex", res.outfiles["microbit.hex"]) + .then(() => { + console.log("wrote hex file to " + d) + })) + }) + .then(() => { }) +} + +function getBitDrivesAsync(): Promise { + if (process.platform == "win32") { + return execAsync("wmic PATH Win32_LogicalDisk get Device ID, VolumeName, FileSystem") + .then(buf => { + let res: string[] = [] + buf.toString("utf8").split(/\n/).forEach(ln => { + let m = /^([A-Z]:).* MICROBIT/.exec(ln) + if (m) { + res.push(m[1] + "/") + } + }) + return res + }) + } else { + return Promise.resolve([]) + } +} \ No newline at end of file diff --git a/cmds/tsconfig.json b/cmds/tsconfig.json new file mode 100644 index 00000000..d439cadb --- /dev/null +++ b/cmds/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es5", + "noImplicitAny": true, + "noImplicitReturns": true, + "declaration": true, + "outDir": "../built", + "module": "commonjs", + "rootDir": ".", + "newLine": "LF", + "sourceMap": true + } +}