-
Notifications
You must be signed in to change notification settings - Fork 5
/
tasks.js
executable file
·184 lines (161 loc) · 4.06 KB
/
tasks.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env node
/* eslint-disable no-sync */
const path = require('path')
const fs = require('fs')
const process = require('process')
const commander = require('commander')
const webpack = require('webpack')
const webpackConfig = require('./webpack.config')
const {
runSync,
spawnInteractive,
npmInteractive,
npxInteractive,
gcloudJson,
gcloudInteractive,
firebaseInteractive,
} = require('@kynikos/tasks/subprocess')
const {
linkDependencies,
maintainPackageDependencies,
} = require('@kynikos/tasks/dependencies')
// I can't define these constants directly in this script because they're also
// required by webpack.config.js, which in turn can't require this whole script
// because commander.js eats all the command-line arguments and the webpack-cli
// command wouldn't be able to read its own arguments
const {SRCDIR, SRCLOCAL, SRCPRODUCTION, DISTDIR, AUXDIR} =
require('./tasks-const')
commander
.command('deps')
.description('run semi-automated dependency maintenance operations')
.action(() => maintainDependencies())
commander
.command('build [VERSION]')
.description('recompile user scripts; optionally assign a version string to \
the build; if not given, only the testing script is recompiled')
.option('-n, --no-links', "do not create npm links to my dependencies \
(relies on having run the 'deps --no-links' command first)")
.action((version, {links}) => build(version, links))
commander
.command('lint')
.description('lint the source code')
.action(() => lint())
commander
.command('test [REGEX]')
.description('run the automated tests; optionally only run tests with a name \
that matches REGEX')
// eslint-disable-next-line jest/require-top-level-describe,jest/no-disabled-tests,jest/expect-expect,jest/valid-title
.action((regex) => test(regex))
commander
.command('gencert')
.description('generate the certificate to serve the user scripts from localhost')
.action(() => genCert())
commander
.command('serve')
.description('serve the user scripts on localhost')
.action(() => serve())
commander.parse(process.argv)
function maintainDependencies() {
maintainPackageDependencies(
__dirname,
{
regExpsToLink: [/^@kynikos\//u],
recursiveLinks: true,
}
)
}
function build(version, links) {
if (links) {
linkDependencies({
cwd: __dirname,
regExps: [/^@kynikos\//u],
ask: false,
recurse: true,
})
}
for (const fname of SRCLOCAL) {
const compiler = webpack(webpackConfig({entry: fname}))
compiler.run()
}
if (version) {
for (const fname of SRCPRODUCTION) {
const compiler1 = webpack(webpackConfig({
entry: fname,
production: true,
}))
compiler1.run()
const compiler2 = webpack(webpackConfig({
entry: fname,
production: true,
minified: true,
}))
compiler2.run()
}
}
if (version) {
npmInteractive({args: [
'--allow-same-version',
'--no-git-tag-version',
'version',
version,
]})
}
}
function lint() {
// See also the .eslintignore file
return npxInteractive(['eslint', __dirname])
}
function test(testNameRegex) {
npxInteractive([
'jest',
...testNameRegex ? ['--testNamePattern', testNameRegex] : [],
])
}
function genCert() {
spawnInteractive({
command: 'openssl',
args: [
'genrsa',
'-out',
'dev-key.pem',
'2048',
],
options: {cwd: AUXDIR},
})
spawnInteractive({
command: 'openssl',
args: [
'req',
'-new',
'-key',
'dev-key.pem',
'-out',
'dev.csr',
],
options: {cwd: AUXDIR},
})
spawnInteractive({
command: 'openssl',
args: [
'x509',
'-req',
'-in',
'dev.csr',
'-signkey',
'dev-key.pem',
'-out',
'dev-cert.pem',
],
options: {cwd: AUXDIR},
})
fs.unlinkSync(path.join(AUXDIR, 'dev.csr'))
}
function serve() {
npxInteractive([
'http-server',
'--cors',
'--ssl',
'--cert', path.join(AUXDIR, 'dev-cert.pem'),
'--key', path.join(AUXDIR, 'dev-key.pem'),
])
}