forked from generate/generate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (93 loc) · 2.34 KB
/
index.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*!
* generate <https://github.com/generate/generate>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
var debug = require('debug')('generate');
var Assemble = require('assemble-core');
var config = require('./lib/config');
var plugins = require('./lib/plugins');
var mixins = require('./lib/mixins');
var utils = require('./lib/utils');
var setArgs;
/**
* Create an instance of `Generate` with the given `options`
*
* ```js
* var Generate = require('generate');
* var generate = new Generate();
* ```
* @param {Object} `options` Settings to initialize with.
* @api public
*/
function Generate(options) {
if (!(this instanceof Generate)) {
return new Generate(options);
}
Assemble.call(this, options);
this.is('generate');
this.initGenerate(this.options);
if (!setArgs) {
setArgs = true;
this.base.option(utils.argv);
}
}
/**
* Extend `Generate`
*/
Assemble.extend(Generate);
/**
* Initialize Stores
*/
plugins.stores(Generate.prototype);
/**
* Initialize generate config
*/
Generate.prototype.initGenerate = function(opts) {
debug('initializing from <%s>', __filename);
Generate.emit('generate.preInit', this);
// initialize config defaults
config(Generate, this);
// load listeners
Generate.initGenerateListeners(this);
// load middleware
if (!process.env.GENERATE_TEST) {
Generate.initGenerateMiddleware(this);
}
// ensure command line values are merged onto the context last
var fn = this.render;
this.render = function() {
this.data(this.cache.argv);
return fn.apply(this, arguments);
}.bind(this);
// load CLI plugins
if (utils.runnerEnabled(this)) {
this.initGenerateCLI(opts);
}
Generate.emit('generate.postInit', this);
};
/**
* Initialize CLI-specific plugins and view collections.
*/
Generate.prototype.initGenerateCLI = function(options) {
Generate.initGenerateCLI(this, options);
};
/**
* Temporary error handler method. until we implement better errors.
*
* @param {Object} `err` Object or instance of `Error`.
* @return {Object} Returns an error object, or emits `error` if a listener exists.
*/
Generate.prototype.handleErr = function(err) {
return Generate.handleErr(this, err);
};
/**
* Add static methods
*/
mixins(Generate);
/**
* Expose the `Generate` constructor
*/
module.exports = Generate;