-
Notifications
You must be signed in to change notification settings - Fork 0
/
.firefoxdeploy.js
66 lines (49 loc) · 1.97 KB
/
.firefoxdeploy.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
// Built upon https://github.com/LinusU/wext-shipit
// Refer the github link above for using wext-shipit package
// I just needed the firefox deploy from that package
const execa = require('execa')
const ora = require('ora')
const StreamSearch = require('text-stream-search')
const UserError = require('./.user-error')
const webextBinPath = require.resolve('.bin/web-ext')
module.exports = async function (source) {
let errors = []
if (!process.env.WEXT_SHIPIT_FIREFOX_JWT_ISSUER) errors.push(`WEXT_SHIPIT_FIREFOX_JWT_ISSUER`)
if (!process.env.WEXT_SHIPIT_FIREFOX_JWT_SECRET) errors.push(`WEXT_SHIPIT_FIREFOX_JWT_SECRET`)
if (errors.length) {
throw new UserError(`Missing ${errors.join(', ')} from environemnt`)
}
const args = [
'sign',
'--source-dir', source,
'--ignore-files', 'package.json package-lock.json yarn.lock .npmrc .yarnc',
'--api-key', process.env.WEXT_SHIPIT_FIREFOX_JWT_ISSUER,
'--api-secret', process.env.WEXT_SHIPIT_FIREFOX_JWT_SECRET
]
const spinner = ora('Loading web-ext tool...').start()
try {
const child = execa(webextBinPath, args, { stdio: ['ignore', 'pipe', 'inherit'] })
const searcher = new StreamSearch(child.stdout)
let wasSubmitted = false
searcher.waitForText('Building web extension')
.then(() => { spinner.text = 'Building extension...' })
searcher.waitForText('Validating add-on')
.then(() => { spinner.text = 'Validating extension...' })
searcher.waitForText('Validation results:')
.then(() => { spinner.text = 'Submitting extension...' })
searcher.waitForText('Your add-on has been submitted for review.')
.then(() => { wasSubmitted = true })
try {
await child
} catch (err) {
if (err.code !== 1 || !wasSubmitted) throw err
}
if (!wasSubmitted) {
throw new Error('Failed to submit extension to addons.mozilla.org')
}
spinner.succeed('Extension submitted 🎉')
} catch (err) {
spinner.fail(String(err))
throw err
}
}