Skip to content

Commit 8f02b0b

Browse files
committed
feature: mkc install + prettier
1 parent 258105b commit 8f02b0b

File tree

14 files changed

+1096
-761
lines changed

14 files changed

+1096
-761
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ tmp
22
built
33
.DS_Store
44
node_modules
5+
pxt_modules
56
*.vsix
67
src/simloaderfiles.ts

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"arrowParens": "avoid",
3+
"semi": false,
4+
"tabWidth": 4
5+
}

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"dbaeumer.vscode-eslint"
5+
]
6+
}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ mkc init microbit jacdac jacdac-button jacdac-led
4444

4545
Your project is ready to be edited. If you are a Visual Studio Code user, type `code .` and you're ready to go!
4646

47+
### mkc install
48+
49+
This command downloads the sources of extensions to the file system so that your TypeScript
50+
IDE can use them
51+
52+
```
53+
mkc install
54+
```
55+
4756
### mkc build
4857

4958
In a folder with `pxt.json` file, run the build command.

src/bump.ts

Lines changed: 87 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import * as child_process from 'child_process';
2-
import * as fs from 'fs';
3-
import * as path from 'path';
1+
import * as child_process from "child_process"
2+
import * as fs from "fs"
3+
import * as path from "path"
44
import * as mkc from "./mkc"
55
import * as files from "./files"
6-
import { httpGetJsonAsync } from './downloader';
7-
import { glob } from 'glob';
6+
import { httpGetJsonAsync } from "./downloader"
7+
import { glob } from "glob"
88

99
export interface SpawnOptions {
10-
cmd: string;
11-
args: string[];
12-
cwd?: string;
13-
shell?: boolean;
14-
pipe?: boolean;
15-
input?: string;
16-
silent?: boolean;
17-
allowNonZeroExit?: boolean;
10+
cmd: string
11+
args: string[]
12+
cwd?: string
13+
shell?: boolean
14+
pipe?: boolean
15+
input?: string
16+
silent?: boolean
17+
allowNonZeroExit?: boolean
1818
}
1919

2020
export function spawnAsync(opts: SpawnOptions) {
2121
opts.pipe = false
22-
return spawnWithPipeAsync(opts)
23-
.then(() => { })
22+
return spawnWithPipeAsync(opts).then(() => {})
2423
}
2524

2625
export function spawnWithPipeAsync(opts: SpawnOptions) {
@@ -32,81 +31,95 @@ export function spawnWithPipeAsync(opts: SpawnOptions) {
3231
let ch = child_process.spawn(opts.cmd, opts.args, {
3332
cwd: opts.cwd,
3433
env: process.env,
35-
stdio: opts.pipe ? [opts.input == null ? process.stdin : "pipe", "pipe", process.stderr] : "inherit",
36-
shell: opts.shell || false
34+
stdio: opts.pipe
35+
? [
36+
opts.input == null ? process.stdin : "pipe",
37+
"pipe",
38+
process.stderr,
39+
]
40+
: "inherit",
41+
shell: opts.shell || false,
3742
} as any)
3843
let bufs: Buffer[] = []
3944
if (opts.pipe)
40-
ch.stdout.on('data', (buf: Buffer) => {
45+
ch.stdout.on("data", (buf: Buffer) => {
4146
bufs.push(buf)
4247
if (!opts.silent) {
4348
process.stdout.write(buf)
4449
}
4550
})
46-
ch.on('close', (code: number) => {
51+
ch.on("close", (code: number) => {
4752
if (code != 0 && !opts.allowNonZeroExit)
4853
reject(new Error("Exit code: " + code + " from " + info))
4954
resolve(Buffer.concat(bufs))
50-
});
51-
if (opts.input != null)
52-
ch.stdin.end(opts.input, "utf8")
55+
})
56+
if (opts.input != null) ch.stdin.end(opts.input, "utf8")
5357
})
5458
}
5559

56-
5760
let readlineCount = 0
5861
function readlineAsync() {
59-
process.stdin.resume();
60-
process.stdin.setEncoding('utf8');
62+
process.stdin.resume()
63+
process.stdin.setEncoding("utf8")
6164
readlineCount++
6265
return new Promise<string>((resolve, reject) => {
63-
process.stdin.once('data', (text: string) => {
66+
process.stdin.once("data", (text: string) => {
6467
resolve(text)
6568
})
6669
})
6770
}
6871

6972
export function queryAsync(msg: string, defl: string) {
7073
process.stdout.write(`${msg} [${defl}]: `)
71-
return readlineAsync()
72-
.then(text => {
73-
text = text.trim()
74-
if (!text) return defl
75-
else return text
76-
})
74+
return readlineAsync().then(text => {
75+
text = text.trim()
76+
if (!text) return defl
77+
else return text
78+
})
7779
}
7880

7981
export function needsGitCleanAsync() {
8082
return Promise.resolve()
81-
.then(() => spawnWithPipeAsync({
82-
cmd: "git",
83-
args: ["status", "--porcelain", "--untracked-files=no"]
84-
}))
83+
.then(() =>
84+
spawnWithPipeAsync({
85+
cmd: "git",
86+
args: ["status", "--porcelain", "--untracked-files=no"],
87+
})
88+
)
8589
.then(buf => {
8690
if (buf.length)
87-
throw new Error("Please commit all files to git before running 'makecode --bump'")
91+
throw new Error(
92+
"Please commit all files to git before running 'makecode --bump'"
93+
)
8894
})
8995
}
9096

9197
export function runGitAsync(...args: string[]) {
9298
return spawnAsync({
9399
cmd: "git",
94100
args: args,
95-
cwd: "."
101+
cwd: ".",
96102
})
97103
}
98104

99105
export function monoRepoConfigs(folder: string, includingSelf = true) {
100-
return glob.sync(folder + "/**/pxt.json")
101-
.filter(e =>
102-
e.indexOf("pxt_modules") < 0 &&
103-
e.indexOf("node_modules") < 0 &&
104-
(includingSelf || path.resolve(folder, "pxt.json") != path.resolve(e)))
106+
return glob
107+
.sync(folder + "/**/pxt.json")
108+
.filter(
109+
e =>
110+
e.indexOf("pxt_modules") < 0 &&
111+
e.indexOf("node_modules") < 0 &&
112+
(includingSelf ||
113+
path.resolve(folder, "pxt.json") != path.resolve(e))
114+
)
105115
}
106116

107-
export async function bumpAsync(prj: mkc.Project, versionFile: string, stage: boolean) {
108-
if (stage)
109-
mkc.log(`operation staged, skipping git commit/push`)
117+
export async function bumpAsync(
118+
prj: mkc.Project,
119+
versionFile: string,
120+
stage: boolean
121+
) {
122+
if (stage) mkc.log(`operation staged, skipping git commit/push`)
110123

111124
if (!stage) {
112125
await needsGitCleanAsync()
@@ -121,10 +134,13 @@ export async function bumpAsync(prj: mkc.Project, versionFile: string, stage: bo
121134

122135
if (versionFile) {
123136
mkc.log(`writing version ${newV} in ${versionFile}`)
124-
const versionSrc =
125-
`
137+
const versionSrc = `
126138
// Auto-generated file: do not edit.
127-
namespace ${cfg.name.replace(/^pxt-/, '').split(/-/g).map((p, i) => i == 0 ? p : (p[0].toUpperCase() + p.slice(1))).join("")} {
139+
namespace ${cfg.name
140+
.replace(/^pxt-/, "")
141+
.split(/-/g)
142+
.map((p, i) => (i == 0 ? p : p[0].toUpperCase() + p.slice(1)))
143+
.join("")} {
128144
/**
129145
* Version of the library
130146
*/
@@ -135,7 +151,12 @@ namespace ${cfg.name.replace(/^pxt-/, '').split(/-/g).map((p, i) => i == 0 ? p :
135151

136152
const configs = monoRepoConfigs(prj.directory, false)
137153
if (configs.length > 0) {
138-
if (await queryAsync(`Also update sub-packages (${configs.length}) in this repo?`, "y") == "y") {
154+
if (
155+
(await queryAsync(
156+
`Also update sub-packages (${configs.length}) in this repo?`,
157+
"y"
158+
)) == "y"
159+
) {
139160
for (const fn of configs) {
140161
const cfg0 = JSON.parse(fs.readFileSync(fn, "utf8"))
141162
cfg0.version = newV
@@ -144,7 +165,11 @@ namespace ${cfg.name.replace(/^pxt-/, '').split(/-/g).map((p, i) => i == 0 ? p :
144165
}
145166
}
146167

147-
await files.writeFilesAsync(prj.directory, { "pxt.json": mkc.stringifyConfig(cfg) }, true)
168+
await files.writeFilesAsync(
169+
prj.directory,
170+
{ "pxt.json": mkc.stringifyConfig(cfg) },
171+
true
172+
)
148173

149174
if (!stage) {
150175
await runGitAsync("commit", "-a", "-m", newV)
@@ -155,17 +180,22 @@ namespace ${cfg.name.replace(/^pxt-/, '').split(/-/g).map((p, i) => i == 0 ? p :
155180
const urlinfo = await spawnWithPipeAsync({
156181
cmd: "git",
157182
args: ["remote", "get-url", "origin"],
158-
pipe: true
159-
}).then(v => v, err => {
160-
mkc.error(err)
161-
return null as Buffer
162-
})
183+
pipe: true,
184+
}).then(
185+
v => v,
186+
err => {
187+
mkc.error(err)
188+
return null as Buffer
189+
}
190+
)
163191
const url = urlinfo?.toString("utf8")?.trim()
164192
if (url) {
165193
const slug = url.replace(/.*github\.com\//i, "")
166194
if (slug != url) {
167195
mkc.log(`Github slug ${slug}; refreshing makecode.com cache`)
168-
const res = await httpGetJsonAsync("https://makecode.com/api/gh/" + slug + "/refs?nocache=1")
196+
const res = await httpGetJsonAsync(
197+
"https://makecode.com/api/gh/" + slug + "/refs?nocache=1"
198+
)
169199
const sha = res?.refs?.["refs/tags/" + newTag]
170200
mkc.log(`refreshed ${newV} -> ${sha}`)
171201
}

0 commit comments

Comments
 (0)