Skip to content

Commit 4362385

Browse files
committed
Switched extract command to rely on commander
1 parent 113e7d4 commit 4362385

File tree

6 files changed

+66
-94
lines changed

6 files changed

+66
-94
lines changed

lib/cli/extract.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
#! /usr/bin/env node
22

3+
var program = require('commander');
4+
5+
var dasherize = require('../utils/string').dasherize;
6+
var Promise = require('../ext/promise');
37
var ui = require('../ui');
48

5-
require('../commands/extract').validateAndRun([process.argv[2], process.argv[3]])
6-
.catch(ui.error)
7-
.finally(process.exit);
9+
function validateOptions(options) {
10+
return new Promise(function(resolve, reject) {
11+
if (!options.addonType) {
12+
reject('You must provide the type of the addon you wish to extract');
13+
} else if (!options.addonName) {
14+
reject('You must provide a name of the addon you wish to extract');
15+
} else {
16+
resolve(options);
17+
}
18+
});
19+
}
20+
21+
function run(options) {
22+
if (options.addonType === 'library') {
23+
return require('../tasks/extract-library')(options);
24+
} else if (options.addonType === 'helper') {
25+
return require('../tasks/extract-helper')(options);
26+
} else if (options.addonType === 'component') {
27+
return require('../tasks/extract-component')(options);
28+
}
29+
}
30+
31+
program
32+
.arguments('<addonType> <addonName>')
33+
.action(function(addonType, addonName) {
34+
program.addonType = addonType;
35+
program.addonName = addonName;
36+
})
37+
.parse(process.argv);
38+
39+
var options = {
40+
addonType: program.addonType,
41+
addonName: dasherize(program.addonName)
42+
};
43+
44+
return validateOptions(options)
45+
.then(run)
46+
.catch(ui.error);

lib/commands/extract.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

lib/tasks/extract-component.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33

44
var path = require('path');
5-
var Promise = require('../ext/promise');
65
var ui = require('../ui');
76
var extractAddon = require('../utils/extract-addon');
87

@@ -26,19 +25,15 @@ var fileMappings = [
2625
}
2726
];
2827

29-
module.exports = function(addonName) {
30-
ui.write('Extracting component ' + addonName + ' into ../' + addonName);
28+
module.exports = function(options) {
29+
ui.write('Extracting component ' + options.addonName + ' into ../' + options.addonName);
3130

32-
var options = {
33-
addonName: addonName,
34-
blueprintName: blueprintName,
35-
placeholder: placeholder,
36-
fileList: fileList,
37-
fileMappings: fileMappings
38-
};
31+
options.blueprintName = blueprintName;
32+
options.placeholder = placeholder;
33+
options.fileList = fileList;
34+
options.fileMappings = fileMappings;
3935

4036
return extractAddon(options).then(function() {
41-
ui.write('Succesfully extracted component');
42-
return Promise.resolve();
37+
return ui.write('Component extraction successful!');
4338
});
4439
};

lib/tasks/extract-helper.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
/*jshint node:true*/
22
'use strict';
33

4-
var Promise = require('../ext/promise');
54
var path = require('path');
65
var ui = require('../ui');
76
var extractAddon = require('../utils/extract-addon');
87

98
var placeholder = '<%= helperName %>';
109
var blueprintName = 'micro-helper';
1110

12-
var fileList = ['index.js', 'package.json', 'helper.js']
11+
var fileList = ['index.js', 'package.json', 'helper.js'];
1312

1413
var fileMappings = [
1514
{
1615
appFile: path.join('app', 'helpers', placeholder + '.js'),
1716
addonFile: 'helper.js'
1817
}
19-
]
18+
];
2019

21-
module.exports = function(addonName) {
22-
ui.write('Extracting helper ' + addonName + ' into ../' + addonName);
20+
module.exports = function(options) {
21+
ui.write('Extracting helper ' + options.addonName + ' into ../' + options.addonName);
2322

24-
var options = {
25-
addonName: addonName,
26-
blueprintName: blueprintName,
27-
placeholder: placeholder,
28-
fileList: fileList,
29-
fileMappings: fileMappings
30-
};
23+
options.blueprintName = blueprintName;
24+
options.placeholder = placeholder;
25+
options.fileList = fileList;
26+
options.fileMappings = fileMappings;
3127

3228
return extractAddon(options).then(function() {
33-
ui.write('Succesfully extracted helper');
34-
return Promise.resolve();
29+
return ui.write('Helper extraction successful!');
3530
});
3631
};

lib/tasks/extract-library.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*jshint node:true*/
22
'use strict';
33

4-
var Promise = require('../ext/promise');
54
var path = require('path');
65
var ui = require('../ui');
76
var extractAddon = require('../utils/extract-addon');
@@ -18,19 +17,15 @@ var fileMappings = [
1817
}
1918
];
2019

21-
module.exports = function(addonName) {
22-
ui.write('Extracting library ' + addonName + ' into ../' + addonName);
20+
module.exports = function(options) {
21+
ui.write('Extracting library ' + options.addonName + ' into ../' + options.addonName);
2322

24-
var options = {
25-
addonName: addonName,
26-
blueprintName: blueprintName,
27-
placeholder: placeholder,
28-
fileList: fileList,
29-
fileMappings: fileMappings
30-
};
23+
options.blueprintName = blueprintName;
24+
options.placeholder = placeholder;
25+
options.fileList = fileList;
26+
options.fileMappings = fileMappings;
3127

3228
return extractAddon(options).then(function() {
33-
ui.write('Succesfully extracted library');
34-
return Promise.resolve();
29+
return ui.write('Library extraction successful!');
3530
});
3631
};

lib/utils/extract-addon.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,14 @@ function copyAddonFiles(options) {
6060
var destinationFile = path.join(destination, fileMapping.addonFile);
6161
return copyFileIfExists(sourceFile, destinationFile);
6262
});
63-
};
63+
}
6464

6565
module.exports = function(options) {
66-
console.log('creating folder');
6766
return createAddonFolder(options).then(function() {
68-
console.log('copying blueprint');
6967
return copyBlueprintFiles(options);
7068
}).then(function() {
71-
console.log('replacing');
7269
return replaceInFiles(options);
7370
}).then(function () {
74-
console.log('copying addon files');
7571
return copyAddonFiles(options);
7672
});
7773
};

0 commit comments

Comments
 (0)