forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-from-blueprint.js
95 lines (76 loc) · 2.93 KB
/
generate-from-blueprint.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*jshint quotmark: false*/
'use strict';
var Promise = require('../ext/promise');
var Blueprint = require('../models/blueprint');
var Task = require('../models/task');
var parseOptions = require('../utilities/parse-options');
var merge = require('lodash/merge');
module.exports = Task.extend({
blueprintFunction: 'install',
run: function(options) {
var self = this;
var name = options.args[0];
var noAddonBlueprint = ['mixin', 'blueprint-test'];
var mainBlueprint = this.lookupBlueprint(name, options.ignoreMissingMain);
var testBlueprint = this.lookupBlueprint(name + '-test', true);
// lookup custom addon blueprint
var addonBlueprint = this.lookupBlueprint(name + '-addon', true);
// otherwise, use default addon-import
if (noAddonBlueprint.indexOf(name) < 0 && !addonBlueprint && (mainBlueprint && mainBlueprint.supportsAddon()) && options.args[1]) {
addonBlueprint = this.lookupBlueprint('addon-import', true);
}
if (options.ignoreMissingMain && !mainBlueprint) {
return Promise.resolve();
}
if (options.dummy) {
// don't install test or addon reexport for dummy
if (this.project.isEmberCLIAddon()) {
testBlueprint = null;
addonBlueprint = null;
}
}
var entity = {
name: options.args[1],
options: parseOptions(options.args.slice(2))
};
var blueprintOptions = {
target: this.project.root,
entity: entity,
ui: this.ui,
project: this.project,
settings: this.settings,
testing: this.testing,
taskOptions: options,
originBlueprintName: name
};
blueprintOptions = merge(blueprintOptions, options || {});
return mainBlueprint[this.blueprintFunction](blueprintOptions)
.then(function() {
if (!testBlueprint) { return; }
if (testBlueprint.locals === Blueprint.prototype.locals) {
testBlueprint.locals = function(options) {
return mainBlueprint.locals(options);
};
}
var testBlueprintOptions = merge({} , blueprintOptions, { installingTest: true });
return testBlueprint[self.blueprintFunction](testBlueprintOptions);
})
.then(function() {
if (!addonBlueprint || name.match(/-addon/)) { return; }
if (!this.project.isEmberCLIAddon() && blueprintOptions.inRepoAddon === null) { return; }
if (addonBlueprint.locals === Blueprint.prototype.locals) {
addonBlueprint.locals = function(options) {
return mainBlueprint.locals(options);
};
}
var addonBlueprintOptions = merge({}, blueprintOptions, { installingAddon: true });
return addonBlueprint[self.blueprintFunction](addonBlueprintOptions);
}.bind(this));
},
lookupBlueprint: function(name, ignoreMissing) {
return Blueprint.lookup(name, {
paths: this.project.blueprintLookupPaths(),
ignoreMissing: ignoreMissing
});
}
});