LEFT | RIGHT |
(no file at all) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 "use strict"; |
| 19 |
| 20 const path = require("path"); |
| 21 const {exec} = require("child_process"); |
| 22 const signAddon = require("sign-addon").default; |
| 23 const {promisify} = require("util"); |
| 24 const fs = require("fs"); |
| 25 const mv = require("mv"); |
| 26 |
| 27 const readFileAsync = promisify(fs.readFile); |
| 28 const mvFileAsync = promisify(mv); |
| 29 |
| 30 exports.addArguments = function(parser) |
| 31 { |
| 32 parser.addArgument(["-p", "--package"], {required: true}); |
| 33 parser.addArgument(["-c", "--credentials"], {required: true}); |
| 34 parser.addArgument(["-t", "--target"], {defaultValue: "dist"}); |
| 35 }; |
| 36 |
| 37 exports.run = function(args) |
| 38 { |
| 39 let appIdFromPython = new Promise((resolve, reject) => |
| 40 { |
| 41 exec( |
| 42 "python -c \"" + |
| 43 "from buildtools.chainedconfigparser import ChainedConfigParser; " + |
| 44 "p = ChainedConfigParser(); " + |
| 45 "p.read('metadata.gecko'); " + |
| 46 "print p.get('general', 'app_id_devbuild')\"", |
| 47 (error, stdout, stderr) => |
| 48 { |
| 49 if (error) |
| 50 { |
| 51 console.error(stderr); |
| 52 reject(error); |
| 53 } |
| 54 else |
| 55 resolve(stdout.trim()); |
| 56 } |
| 57 ); |
| 58 }); |
| 59 |
| 60 Promise.all([ |
| 61 appIdFromPython, |
| 62 readFileAsync(path.resolve(args.credentials)) |
| 63 ]).then(([appId, fileContent]) => |
| 64 { |
| 65 let auth = JSON.parse(fileContent); |
| 66 let extension = path.extname(args.package); |
| 67 let version = args.package.replace(extension, "").split("-"); |
| 68 version = version[version.length - 1]; |
| 69 |
| 70 return signAddon({ |
| 71 xpiPath: args.package, |
| 72 version, |
| 73 apiKey: auth["AMO_KEY"], |
| 74 apiSecret: auth["AMO_SECRET"], |
| 75 channel: "unlisted", |
| 76 id: appId |
| 77 }); |
| 78 }).then(result => |
| 79 { |
| 80 // signAddon writes failure reasons directly to the shell, so we don't have |
| 81 // to take care about logging the error messages. |
| 82 if (!result.success) |
| 83 process.exit(1); |
| 84 |
| 85 let fullName = result.downloadedFiles[0]; |
| 86 let newName = path.join(args.target, path.basename(fullName)); |
| 87 |
| 88 return mvFileAsync(fullName, newName, {mkdirp: true}); |
| 89 }).catch(err => |
| 90 { |
| 91 console.error(err); |
| 92 process.exit(1); |
| 93 }); |
| 94 }; |
LEFT | RIGHT |