Skip to content

Commit b1cd209

Browse files
committed
Merge pull request #27 from coderly/extract-command-path-option
Added optional path option to extract command
2 parents 735f15e + ef4de95 commit b1cd209

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

lib/cli/extract.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
11
#! /usr/bin/env node
22

33
var program = require('commander');
4+
var path = require('path');
45

56
var dasherize = require('../utils/string').dasherize;
6-
var Promise = require('../ext/promise');
77
var ui = require('../ui');
88

99
var options = {};
10+
var task;
1011

1112
program
12-
.usage('<addonType> <addonName>');
13+
.usage('<addonType> <addonName>')
14+
.option('-d, --destination <destination>', 'Extract destination');
1315

1416
program
1517
.command('library <addonName>')
1618
.description('Extract a library')
1719
.action(function(addonName) {
1820
options.addonName = addonName ? dasherize(addonName) : null;
19-
require('../tasks/extract-library')(options).catch(ui.error);
21+
task = require('../tasks/extract-library');
2022
});
2123

24+
2225
program
2326
.command('helper <addonName>')
2427
.description('Extract a helper')
2528
.action(function(addonName) {
2629
options.addonName = addonName ? dasherize(addonName) : null;
27-
require('../tasks/extract-helper')(options).catch(ui.error);
30+
task = require('../tasks/extract-helper');
2831
});
2932

33+
3034
program
3135
.command('component <addonName>')
3236
.description('Extract a component')
3337
.action(function(addonName) {
3438
options.addonName = addonName ? dasherize(addonName) : null;
35-
require('../tasks/extract-component')(options).catch(ui.error);
39+
task = require('../tasks/extract-component');
3640
});
3741

42+
3843
program
3944
.parse(process.argv);
4045

4146
if (process.argv.length < 3) {
4247
program.outputHelp();
43-
}
48+
} else {
49+
options.destination = program.destination || getDefaultExtractDestination(options.addonName);
50+
task(options).catch(ui.error);
51+
}
52+
53+
function getDefaultExtractDestination(addonName) {
54+
return path.resolve(path.join('..', addonName));
55+
}

lib/tasks/extract-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var fileMappings = [
2626
];
2727

2828
module.exports = function(options) {
29-
ui.write('Extracting component ' + options.addonName + ' into ../' + options.addonName);
29+
ui.write('Extracting component ' + options.addonName + ' into ' + options.destination);
3030

3131
options.blueprintName = blueprintName;
3232
options.placeholder = placeholder;

lib/tasks/extract-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var fileMappings = [
1818
];
1919

2020
module.exports = function(options) {
21-
ui.write('Extracting helper ' + options.addonName + ' into ../' + options.addonName);
21+
ui.write('Extracting helper ' + options.addonName + ' into ' + options.destination);
2222

2323
options.blueprintName = blueprintName;
2424
options.placeholder = placeholder;

lib/tasks/extract-library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var fileMappings = [
1818
];
1919

2020
module.exports = function(options) {
21-
ui.write('Extracting library ' + options.addonName + ' into ../' + options.addonName);
21+
ui.write('Extracting library ' + options.addonName + ' into ' + options.destination);
2222

2323
options.blueprintName = blueprintName;
2424
options.placeholder = placeholder;

lib/utils/extract-addon.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,16 @@ var copy = Promise.denodeify(fs.copy);
1010
var readFile = Promise.denodeify(fs.readFile);
1111
var writeFile = Promise.denodeify(fs.writeFile);
1212

13-
function getDefaultExtractDestination(addonName) {
14-
return path.resolve(path.join('..', addonName));
15-
}
16-
17-
function getExtractDestination(options) {
18-
return options.extractDestination || getDefaultExtractDestination(options.addonName);
19-
}
20-
2113
function createAddonFolder(options) {
22-
return ensureDir(getExtractDestination(options));
14+
return ensureDir(options.destination);
2315
}
2416

2517
function copyBlueprintFiles(options) {
2618
var blueprintFolderRelativePath = "../../blueprints";
2719
var blueprintPath = path.resolve(__dirname, blueprintFolderRelativePath, options.blueprintName);
2820

2921
var srcPath = path.join(blueprintPath, 'files');
30-
var destPath = getExtractDestination(options);
22+
var destPath = options.destination;
3123

3224
return copy(srcPath, destPath);
3325
}
@@ -40,7 +32,7 @@ function replaceInFile(file, placeholder, value) {
4032
}
4133

4234
function replaceInFiles(options) {
43-
var basePath = getExtractDestination(options);
35+
var basePath = options.destination;
4436
return Promise.map(options.fileList, function(relativeFilePath) {
4537
var absoluteFilePath = path.join(basePath, relativeFilePath);
4638
return replaceInFile(absoluteFilePath, options.placeholder, options.addonName);
@@ -54,7 +46,7 @@ function copyFileIfExists(oldFile, newFile) {
5446
}
5547

5648
function copyAddonFiles(options) {
57-
var destination = getExtractDestination(options);
49+
var destination = options.destination;
5850
return Promise.map(options.fileMappings, function(fileMapping) {
5951
var sourceFile = fileMapping.appFile.replace(options.placeholder, options.addonName);
6052
var destinationFile = path.join(destination, fileMapping.addonFile);

0 commit comments

Comments
 (0)