-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
74 lines (57 loc) · 2.04 KB
/
index.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
/* semantic-release lifecycles used:
* `verifyConditions`: check mod portal token, ...
* `prepare`: update changelog.txt and info.json + package mod in zip
* `publish`: push update to mod portal
*/
const { promisify } = require('node:util');
const exec = promisify(require('node:child_process').exec);
const AggregateError = require('aggregate-error');
const { updateChangelog } = require('./lib/changelog');
const { verifyToken, uploadMod } = require('./lib/mod-portal.js');
const { isInfoValid, readInfoFile, updateInfo } = require('./lib/mod-info.js');
async function verifyConditions(config, context) {
const { logger } = context;
const errors = [];
try {
const info = await readInfoFile(config, context);
isInfoValid(config, context, info);
await verifyToken(config, context, info.name);
} catch (error) {
errors.push(error);
}
if (errors.length > 0) {
logger.log("verification failed!");
throw new AggregateError(errors);
}
}
async function prepare(config, context) {
const errors = [];
try {
await updateInfo(config, context);
await updateChangelog(config, context);
} catch (error) {
errors.push(error);
}
if (errors.length > 0) {
throw new AggregateError(errors);
}
}
async function publish(config, context) {
const errors = [];
const { logger } = context;
try {
const info = await readInfoFile(config, context);
const archiveFile = [info.name, "_", info.version, ".zip"].join("");
const archiveCommand = "git archive --format zip --prefix " + info.name +
"/ --worktree-attributes --output " + archiveFile + " HEAD";
logger.log("packaging mod for release");
const { stdout0, stderr0 } = await exec(archiveCommand);
await uploadMod(config, context, info, archiveFile);
} catch (error) {
errors.push(error);
}
if (errors.length > 0) {
throw new AggregateError(errors);
}
}
module.exports = { verifyConditions, prepare, publish };