-
Notifications
You must be signed in to change notification settings - Fork 35
/
packageNTPSuperReferrerComponent.js
73 lines (64 loc) · 2.85 KB
/
packageNTPSuperReferrerComponent.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import commander from 'commander'
import fs from 'fs-extra'
import { mkdirp } from 'mkdirp'
import path from 'path'
import util from '../lib/util.js'
import ntpUtil from '../lib/ntpUtil.js'
const stageFiles = (superReferrerName, version, outputDir) => {
util.stageDir(
path.join(path.resolve(), 'build', 'ntp-super-referrer', 'resources', superReferrerName, '/'),
getOriginalManifest(superReferrerName),
version,
outputDir)
}
const generateManifestFile = (superReferrerName, publicKey) => {
const manifestFile = getOriginalManifest(superReferrerName)
const manifestContent = {
description: 'Brave NTP Super Referrer component',
key: publicKey,
manifest_version: 2,
name: `Brave NTP Super Referrer (${superReferrerName})`,
version: '0.0.0'
}
fs.writeFileSync(manifestFile, JSON.stringify(manifestContent))
}
const getOriginalManifest = (superReferrerName) => {
return path.join(path.resolve(), 'build', 'ntp-super-referrer', `${superReferrerName}-manifest.json`)
}
const generateCRXFile = (binary, endpoint, region, superReferrerName,
componentID, privateKeyFile, publisherProofKey, publisherProofKeyAlt) => {
const rootBuildDir = path.join(path.resolve(), 'build', 'ntp-super-referrer')
const stagingDir = path.join(rootBuildDir, 'staging', superReferrerName)
const crxOutputDir = path.join(rootBuildDir, 'output')
mkdirp.sync(stagingDir)
mkdirp.sync(crxOutputDir)
util.getNextVersion(endpoint, region, componentID).then((version) => {
const crxFile = path.join(crxOutputDir, `ntp-super-referrer-${superReferrerName}.crx`)
stageFiles(superReferrerName, version, stagingDir)
util.generateCRXFile(binary, crxFile, privateKeyFile, publisherProofKey,
publisherProofKeyAlt, stagingDir)
console.log(`Generated ${crxFile} with version number ${version}`)
})
}
util.installErrorHandlers()
util.addCommonScriptOptions(
commander
.option('-n, --super-referrer-name <name>', 'super referrer name for this component')
.option('-k, --key-file <file>', 'file containing private key for signing crx file'))
.parse(process.argv)
let privateKeyFile = ''
if (fs.existsSync(commander.keyFile)) {
privateKeyFile = commander.keyFile
} else {
throw new Error('Missing or invalid private key')
}
util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
const [publicKey, componentID] = ntpUtil.generatePublicKeyAndID(privateKeyFile)
generateManifestFile(commander.superReferrerName, publicKey)
generateCRXFile(commander.binary, commander.endpoint, commander.region,
commander.superReferrerName, componentID, privateKeyFile,
commander.publisherProofKey, commander.publisherProofKeyAlt)
})