Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

Commit

Permalink
feat: Added option to specify output directory for XPI file (#544)
Browse files Browse the repository at this point in the history
* feat: #315 - xpi output directory command line option

New command line option for the 'xpi' action (build the package):
--dest-dir <outputDir> allows to specify the directory where the package
will be written

* feat: #315 - xpi output directory command line option

Refactoring according to @kumar303's proposal, and adding a unit test

* feat: #315 - xpi output directory command line option

Fixing unit test

* feat: #315 - xpi output directory command line option

Cleaning up unit test

* feat: #315 - xpi output directory command line option

Fixing default behaviour
  • Loading branch information
alexduch authored and kumar303 committed Aug 31, 2016
1 parent e1f9f52 commit 8059d86
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
10 changes: 8 additions & 2 deletions bin/jpm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

var VERSION = require("../package.json").version;
var assign = require("object-assign");
var program = require("commander");
var console = require("../lib/utils").console;
var run = require("../lib/run");
Expand Down Expand Up @@ -69,9 +70,14 @@ program
program
.command("xpi")
.description("Bundle the addon into an .xpi file")
.action(cmd.prepare("xpi", program, function(manifest) {
.option("--dest-dir <output_dir>", "Where to write the generated xpi",
// turn into an absolute path
function(dir) {
return path.resolve(dir);
})
.action(cmd.prepare("xpi", program, function(manifest, options) {
var start = Date.now();
xpi(manifest, program).then(function(xpiPath) {
xpi(manifest, assign({}, program, options)).then(function(xpiPath) {
var diff = Date.now() - start;
console.log("Successfully created XPI at " +
xpiPath + " (" + diff + "ms)");
Expand Down
10 changes: 6 additions & 4 deletions lib/xpi.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ var _ = require("lodash");
*
* @param {Object} manifest
* @param {Object} options
* - `xpiPath` Path where xpi should be saved. Used by `run`, `test` to indicate
* that the xpi saved in a temp directory.
* - `destDir` Directory path where xpi should be saved.
* - `xpiPath` Legacy alias for `destDir`. Used by `run` and `test` to
* save the xpi to a temp directory.
* @return {Promise}
*/

Expand All @@ -48,8 +49,9 @@ function xpi(manifest, options) {
}
xpiName += ".xpi";
var updateRdfName = getID(manifest) + xpiVersion + ".update.rdf";
var xpiPath = join(options.xpiPath || addonDir, xpiName);
var updateRdfPath = join(options.xpiPath || addonDir, updateRdfName);
var outputPath = options.xpiPath || options.destDir || addonDir;
var xpiPath = join(outputPath, xpiName);
var updateRdfPath = join(outputPath, updateRdfName);
var useFallbacks = !(options.forceAOM || hasAOMSupport(manifest));

options = _.merge(options, {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"mozilla-toolkit-versioning": "0.0.2",
"mozilla-version-comparator": "1.0.2",
"node-watch": "0.3.4",
"object-assign": "4.1.0",
"open": "0.0.5",
"promzard": "0.3.0",
"read": "1.0.7",
Expand Down
17 changes: 17 additions & 0 deletions test/unit/test.xpi.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var jpmignoreLFPath = path.join(__dirname, "..", "addons", "jpmignore-lf");
var jpmignoreCRLFPath = path.join(__dirname, "..", "addons", "jpmignore-crlf");
var jpmignoreMixedPath = path.join(__dirname, "..", "addons", "jpmignore-mixed");
var tmpOutputDir = path.join(__dirname, "../", "tmp");
var targetDir = path.join(__dirname, "../", "target");
var updateRDFPath = path.join(__dirname, "..", "fixtures", "updateRDF");
var updateRDFFailPath = path.join(__dirname, "..", "fixtures", "updateRDF-fail");
var webextensionManifestExcludedPath = path.join(
Expand Down Expand Up @@ -52,6 +53,22 @@ describe("lib/xpi", function() {
})
.catch(done);
});

it("Zips up cwd's addon in the specified directory", function() {
process.chdir(simpleAddonPath);
var manifest = require(path.join(simpleAddonPath, "package.json"));
fs.mkdirs(targetDir);
return xpi(manifest, {destDir: targetDir}).then(function(filePath) {
expect(filePath).to.be.equal(path.join(targetDir, "simple-addon.xpi"));
return utils.unzipTo(filePath, tmpOutputDir).then(function() {
utils.compareDirs(simpleAddonPath, tmpOutputDir);
});
})
.then(function() {
fs.remove(targetDir);
});
});

it("Check file name with id", function(done) {
process.chdir(simpleAddonWithIdPath);
var manifest = require(path.join(simpleAddonWithIdPath, "package.json"));
Expand Down

0 comments on commit 8059d86

Please sign in to comment.