This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
115 lines (103 loc) · 2.97 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
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
// Importing this like `import fs from "mz/fs"` was causing usage on
// npm 2.x to throw missing dependency errors. *shrug*
import {fs} from "mz";
import when from "when";
import {Client as DefaultAMOClient} from "./amo-client";
export default function signAddon(
{
// Absolute path to add-on XPI file.
xpiPath,
// The add-on ID as recognized by AMO. Example: my-addon@jetpack
id,
// The add-on version number for AMO.
version,
// The release channel on AMO (listed or unlisted).
// Defaults to most recently used channel.
channel=null,
// Your API key (JWT issuer) from AMO Devhub.
apiKey,
// Your API secret (JWT secret) from AMO Devhub.
apiSecret,
// Optional arguments:
apiUrlPrefix="https://addons.mozilla.org/api/v3",
// Number of seconds until the JWT token for the API request expires.
// This must match the expiration time that the API server accepts.
apiJwtExpiresIn,
verbose=false,
// Number of milleseconds to wait before giving up on a
// response from Mozilla's web service.
timeout,
// Absolute directory to save downloaded files in.
downloadDir,
// Optional proxy to use for all API requests,
// such as "http://yourproxy:6000"
apiProxy,
// Optional object to pass into request() for additional configuration.
// Not all properties are guaranteed to be applied.
apiRequestConfig,
AMOClient=DefaultAMOClient,
}) {
return when.promise(
(resolve) => {
function reportEmpty(name) {
throw new Error(`required argument was empty: ${name}`);
}
if (!xpiPath) {
reportEmpty("xpiPath");
}
if (!version) {
reportEmpty("version");
}
if (!apiSecret) {
reportEmpty("apiSecret");
}
if (!apiKey) {
reportEmpty("apiKey");
}
resolve();
})
.then(() => fs.stat(xpiPath))
.catch((statError) => {
throw new Error(`error with ${xpiPath}: ${statError}`);
})
.then((stats) => {
if (!stats.isFile) {
throw new Error(`not a file: ${xpiPath}`);
}
})
.then(() => {
let client = new AMOClient({
apiKey,
apiSecret,
apiUrlPrefix,
apiJwtExpiresIn,
downloadDir,
debugLogging: verbose,
signedStatusCheckTimeout: timeout,
proxyServer: apiProxy,
requestConfig: apiRequestConfig,
});
return client.sign({
xpiPath: xpiPath,
guid: id,
version: version,
channel: channel,
});
});
}
export function signAddonAndExit(
options, {systemProcess=process, throwError=false, logger=console}) {
return signAddon(options)
.then((result) => {
logger.log(result.success ? "SUCCESS" : "FAIL");
systemProcess.exit(result.success ? 0 : 1);
})
.catch((err) => {
logger.error("FAIL");
if (throwError) {
throw err;
}
logger.error(err.stack);
systemProcess.exit(1);
});
}