-
Notifications
You must be signed in to change notification settings - Fork 1
/
Drakefile.ts
114 lines (103 loc) · 3.14 KB
/
Drakefile.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* rimu-deno drakefile.
*/
import * as path from "https://deno.land/[email protected]/path/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import {
abort,
desc,
env,
execute,
glob,
log,
quote,
readFile,
run,
sh,
shCapture,
task,
writeFile
} from "https://raw.github.com/srackham/drake/master/mod.ts";
env("--default-task", "test");
const SRC_FILES = glob("mod.ts", "src/*.ts");
const RIMUC_TS = "src/rimuc.ts";
const RESOURCES_SRC = "src/resources.ts";
const RESOURCE_FILES = glob("src/resources/*");
desc("Format source files");
task("fmt", [], async function () {
await sh(`deno fmt ${quote(["Drakefile.ts", ...SRC_FILES])}`);
});
desc("Run tests");
task("test", ["fmt", RESOURCES_SRC], async function () {
const { output } = await shCapture(
`deno --allow-env --allow-read "${RIMUC_TS}"`,
{ input: "Hello _World_!" },
);
assertEquals(output, "<p>Hello <em>World</em>!</p>");
});
desc(
"Fetch the latest Rimu source and add .ts extension to import and export statements for Deno",
);
task("update", [], async function () {
for (const f of glob("../rimu/src/rimu/*.ts")) {
const text = readFile(f).replace(
/^((import|export).*from '.*)'/gm,
"$1.ts'",
);
writeFile(path.join("src", path.basename(f)), text);
}
await execute("fmt");
});
desc("Build resources.ts containing rimuc resource files");
task(RESOURCES_SRC, RESOURCE_FILES, async function () {
log(`Building resources ${RESOURCES_SRC}`);
let text = "// Generated automatically from resource files. Do not edit.\n";
text += "export let resources: { [name: string]: string } = {";
for (const f of RESOURCE_FILES) {
text += ` '${path.basename(f)}': `;
let data = readFile(f);
data = data.replace(/\\/g, "\\x5C"); // Escape backslash (unescaped at runtime).
data = data.replace(/`/g, "\\x60"); // Escape backticks (unescaped at runtime).
text += `String.raw\`${data}\`,\n`;
}
text += "};";
writeFile(RESOURCES_SRC, text);
await sh(`deno fmt "${RESOURCES_SRC}"`);
});
desc("Generate rimudeno executable wrapper for rimuc CLI");
task("install", ["test"], async function () {
await sh(
`deno install -f --allow-env --allow-read --allow-write rimudeno "${RIMUC_TS}"`,
);
});
desc(
"Create Git version tag e.g. 'drake tag vers=1.0.0' creates tag 'v1.0.0'",
);
task("tag", ["test"], async function () {
if (!env("vers")) {
abort("'vers' variable not set e.g. drake tag vers=1.0.0");
}
if (!/^\d+\.\d+\.\d+/.test(env("vers"))) {
abort(`illegal semantic version number: ${env("vers")}`);
}
let match = readFile(RIMUC_TS).match(/^const VERSION = "(.+)"/m);
if (!match) {
abort(`missing 'vers' declaration in ${RIMUC_TS}`);
}
match = match as RegExpMatchArray;
if (match[1] !== env("vers")) {
console.log(
`WARNING: ${env(
"vers",
)} does not match version ${match[1]} in ${RIMUC_TS}`,
);
}
const tag = `v${env("vers")}`;
console.log(`tag: ${tag}`);
await sh(`git tag -a -m ${tag} ${tag}`);
});
desc("Push changes to Github");
task("push", ["test"], async function () {
await sh(`git push -u --tags origin master`);
});
run();