-
Notifications
You must be signed in to change notification settings - Fork 4
/
fuse.ts
87 lines (76 loc) · 1.87 KB
/
fuse.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { spawn } from "child_process";
import { fusebox, sparky } from "fuse-box";
import { tsc } from "fuse-box/sparky/tsc";
import * as path from "path";
async function npmPublish(opts: { path: string; tag?: string }) {
opts.tag = opts.tag || "latest";
return new Promise((resolve, reject) => {
const publish = spawn("npm", ["publish", "--tag", opts.tag], {
cwd: path.join(__dirname, opts.path),
stdio: "inherit",
});
publish.on("close", function (code) {
if (code === 8) {
return reject("Error detected, waiting for changes...");
}
return resolve();
});
});
}
class Context {
isProduction;
runServer;
getConfig() {
return fusebox({
cache: false,
entry: "src/_development/index.ts",
target: "server",
watcher: true,
});
}
}
const { exec, rm, src, task } = sparky<Context>(Context);
task("default", async (ctx) => {
rm("./dist");
const fuse = ctx.getConfig();
const { onComplete } = await fuse.runDev();
onComplete(({ server }) => {
server.start();
});
});
task("dist", async (ctx) => {
rm("./dist");
await exec("bump-version");
await exec("transpile");
});
task("publish", async (ctx) => {
await exec("dist");
await npmPublish({ path: "dist/" });
});
task("transpile", async (c) => {
await tsc(
{
declaration: true,
module: "CommonJS",
skipLibCheck: true,
moduleResolution : "Node",
target: "ES2017",
outDir: "dist",
},
["src/index.ts"]
);
});
task("bump-version", async (ctx) => {
await src("package.json")
.bumpVersion("package.json", { type: "patch" })
.write()
.dest("dist/", __dirname)
.exec();
});
task("preview", async (ctx) => {
rm("./dist");
ctx.isProduction = true;
const fuse = ctx.getConfig();
const { onComplete } = await fuse.runProd();
onComplete(({ server }) => server.start());
});