forked from thoth-org/Thoth.Json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
executable file
·157 lines (137 loc) · 3.7 KB
/
build.js
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!node
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import shell from 'shelljs';
import chalk from 'chalk';
import concurrently from 'concurrently';
import releaseNpm from './scripts/release-npm.js';
import releaseNuget from './scripts/release-nuget.js';
import { simpleSpawn } from './scripts/await-spawn.js';
const info = chalk.blueBright
const warn = chalk.yellow
const error = chalk.red
const success = chalk.green
const log = console.log
// Crash script on error
shell.config.fatal = true;
const cleanHandler = async () => {
log(info("Cleaning..."));
shell.rm("-rf", "./src/bin");
shell.rm("-rf", "./src/obj");
shell.rm("-rf", "./tests/bin");
shell.rm("-rf", "./tests/obj");
shell.rm("-rf", "./tests/fableBuild");
shell.rm("-rf", "./.nacara");
}
const testHandler = async (argv) => {
await cleanHandler();
// Make sure we have the tests/fableBuild folder so nodemon can watch it
shell.mkdir("-p", "./tests/fableBuild");
if (argv.watch) {
concurrently([
{
command: "dotnet fable --watch --outDir fableBuild",
cwd: "./tests",
name: "Fable",
prefixColor: "magenta"
},
// We use nodemon for watching the tests files
// because mocha doesn't support watching ESM files yet
{
command: `npx nodemon \
--watch fableBuild \
--delay 150ms \
--exec "npx mocha fableBuild --reporter dot"
`,
cwd: "./tests",
name: "Mocha",
prefixColor: "cyan"
}
])
} else {
await simpleSpawn(
"dotnet fable --outDir fableBuild",
"./tests"
)
await simpleSpawn(
"npx mocha fableBuild",
"./tests"
)
}
}
const documentationHandler = async (argv) => {
await cleanHandler();
await simpleSpawn("dotnet build", "./src/");
if (argv.watch) {
await simpleSpawn("npx nacara watch");
} else {
await simpleSpawn("npx nacara");
}
}
const publishDocsHandler = async () => {
await documentationHandler();
await simpleSpawn("npx gh-pages -d docs_deploy");
}
const releaseHandler = async (argv) => {
await testHandler(argv);
await releaseNuget(".", "./src/Thoth.Json.fsproj");
}
yargs(hideBin(process.argv))
.completion()
.strict()
.help()
.alias("help", "h")
.command(
"clean",
"Clean all build artifacts",
() => { },
cleanHandler
)
.command(
"test",
"Run all tests",
(argv) => {
argv
.options(
"watch",
{
alias: "w",
describe: "Watch for file changes and re-run tests",
type: "boolean",
default: false
}
)
},
testHandler
)
.command(
"docs",
"Build documentation",
(argv) => {
argv
.options(
"watch",
{
alias: "w",
describe: "Watch for file changes and re-build documentation",
type: "boolean",
default: false
}
)
},
documentationHandler
)
.command(
"publish-docs",
"Publish documentation to gh-pages",
() => { },
publishDocsHandler,
)
.command(
"release",
"Release a new version",
() => { },
releaseHandler
)
.version(false)
.argv