-
Notifications
You must be signed in to change notification settings - Fork 6
/
fuse.ts
82 lines (71 loc) · 1.73 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
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;
getDevConfig() {
return fusebox({
cache: true,
devServer: !this.isProduction,
entry: "src/dev/index.tsx",
target: "browser",
watcher: { include: ["src"] },
webIndex: { template: "src/index.html" },
});
}
}
const { exec, rm, src, task } = sparky<Context>(Context);
task("default", async (ctx) => {
rm("./dist");
const fuse = ctx.getDevConfig();
await fuse.runDev();
});
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",
jsx: "React",
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 = false;
const fuse = ctx.getDevConfig();
await fuse.runProd();
});