-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.js
executable file
·237 lines (205 loc) · 5.94 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env node
/* eslint-disable no-sync,no-await-in-loop,no-use-before-define,no-console */
const fs = require('fs')
const process = require('process')
const {oneLine: L} = require('common-tags')
const {
eslint,
webpackInteractive,
} = require('@kynikos/tasks/subprocess')
const {
linkSelf,
maintainPackageDependencies,
} = require('@kynikos/tasks/dependencies')
const {jest} = require('@kynikos/tasks/testing')
const {
writePkgbuildNodeJs,
makePkgbuild,
installPkgbuild,
} = require('@kynikos/tasks/packaging')
const {
releaseProcedure,
npmPublish,
submitToAur,
} = require('@kynikos/tasks/releasing')
const {wrapCommander} = require('@kynikos/tasks/commander')
const {makeReadme} = require('./aux/README')
const {reportTodo: reportTodoSrc} = require('./src/index')
const packageJson = require('./package.json')
// TODO[setup]: The @kynikos dependencies should only provide peerDependencies
function init() {
// Technically also 'npm install' is required, but this very script can't be
// executed until that command is run a first time directly in the console
linkSelf({cwd: __dirname, ask: false})
}
function maintainDependencies() {
maintainPackageDependencies(
__dirname,
[/^@kynikos\//u],
true,
)
// The report-todo bin script requires (at least for testing) this very
// library to be npm-linked
// Having run the 'init' task should be enough
linkSelf({cwd: __dirname, ask: true})
}
function lint() {
// See also the .eslintignore file
return eslint([__dirname])
}
function build({production}) {
return webpackInteractive([production ? '--env.production' : '--env'])
}
function runTests({
// TODO[setup]: Optionally require the compiled library from dist/ to test it
// Especially do it when testing a release
testNameRegex,
verbose,
printConsole,
printReceived,
updateExpected,
}) {
// The report-todo bin script requires (at least for testing) this very
// library to be npm-linked
// Having run the 'init' task should be enough
// linkSelf({cwd: __dirname, ask: true})
jest({
testNamePattern: testNameRegex,
verbose,
printConsole,
printReceived: printReceived ? 'JEST_PRINT_RECEIVED_VALUES' : false,
updateExpected: updateExpected ? 'JEST_UPDATE_EXPECTED_VALUES' : false,
})
}
async function todo({labelOnly}) {
fs.writeFileSync(
'./TODO.md', // report-todo-ignore-line
await reportTodoSrc(
[
'.',
'!./.git',
'!./aux/DEMO.js',
'!./build',
'!./dist',
'!./node_modules',
'!./README.md',
'!./test/expected',
'!./test/fixtures',
'!./TODO.md', // report-todo-ignore-line
],
{
labels: labelOnly ? [null] : null,
labelsIsBlacklist: Boolean(labelOnly),
reportMode: 'markdown',
},
),
)
}
async function docs() {
return fs.writeFileSync(
'./README.md',
await makeReadme(),
)
}
function setupPkg() {
return writePkgbuildNodeJs(
{
pkgbuildPath: './aux/PKGBUILD',
buildDir: './build/',
},
{
Maintainers: [
`${packageJson.author.name} <${packageJson.author.email}>`,
],
pkgname: packageJson.name,
pkgver: packageJson.version,
pkgrel: 1,
pkgdesc: packageJson.description,
url: packageJson.homepage,
license: [packageJson.license],
packageInstallLicense: './LICENSE',
},
)
}
function makePkg() {
return makePkgbuild({buildDir: './build/', pkgbuildPath: './aux/PKGBUILD'})
}
function installPkg({pkgrel}) {
const tarballPath =
`${packageJson.name}-${packageJson.version}-${pkgrel}-any.pkg.tar.xz`
return installPkgbuild({buildDir: './build/', tarballPath})
}
function publishToNpm() {
// Don't recreate the tarball, or its checksum will change
return npmPublish({
tarball: `./build/${packageJson.name}-${packageJson.version}.tgz`,
public: true,
})
}
function publishToAur() {
return submitToAur({
buildDir: './build/',
pkgbase: packageJson.name,
pkgver: packageJson.version,
})
}
function release() {
releaseProcedure({
// updateMetafiles,
// checkNodeJsWebpackConfiguration,
// releaseDependencies,
// checkoutProductionBranch,
updateVersion: L`Did you update the version number in package.json?
Do it manually, don't use npm-version`,
updateDependencies: () => maintainDependencies(),
recompileApplication: () => build({production: true}),
// TODO[setup]: Require the compiled library from dist/ to test it when
// testing a release
runTests: () => runTests({}),
checkRelatedFunctionality: false,
lintCode: () => lint(),
updateTodo: () => todo({}),
updateDatabaseDiagram: false,
// updateChangelog,
// updateDocumentation,
buildDocumentation: () => docs(),
setupDistributionPackages: () => setupPkg(),
// TODO[setup]: Create a separate package with normal package.json
// dependencies installed in node_modules
// For example restore the normal separation between 'dependencies' and
// 'devDependencies' in package.json, but, when building the
// compiled/bundled version, temporarily merge 'dependencies' into
// 'devDependencies'
testBuildDistributionPackages: () => makePkg(),
// TODO[setup]: Allow changing pkgrel
testInstallDistributionPackages: () => installPkg({pkgrel: 1}),
// testInstalledDistributionPackages,
// commitReleaseChanges,
deployApplication: false,
deployOtherServices: false,
publishDocumentation: false,
// pushToRemoteGitRepository,
publishToPackageIndex: () => publishToNpm(),
publishToSoftwareDistributions: () => publishToAur(),
// updateBugTracker,
// announceRelease,
// advertiseRelease,
// restoreDevelopmentEnvironment,
})
}
const commander = wrapCommander({
init,
maintainDependencies,
lint,
build,
runTests,
todo,
docs,
setupPkg,
makePkg,
installPkg,
publishToNpm,
publishToAur,
release,
})
commander.parse(process.argv)