-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.js
75 lines (60 loc) · 1.4 KB
/
generator.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
'use strict';
var utils = require('./utils');
var answer;
module.exports = function plugin(app) {
if (!utils.isValid(app, 'generate-defaults')) return;
var project;
/**
* Plugins
*/
app.use(require('generate-data'));
app.use(utils.middleware());
app.use(utils.questions());
/**
* Merge package.json object onto the `project` property on the context
*/
Object.defineProperty(app.cache.data, 'project', {
set: function(val) {
project = val;
},
get: function() {
return project || (project = utils.extend({}, app.pkg.data));
}
});
/**
* Engine
*/
if (!app.getEngine('*')) {
app.engine('*', require('engine-base'), app.option('engineOpts'));
}
/**
* Helpers
*/
app.helpers(require('template-helpers')());
/**
* Tasks
*/
app.task('check-directory', function(cb) {
if (utils.isEmpty(app.cwd) || answer === true) {
cb();
return;
}
app.confirm('directory', 'The current working directory has existing files in it, are you sure you want to proceed?', {
default: false
});
app.ask('directory', function(err, answers) {
if (err) {
cb(err);
return;
}
if (answers.directory === false) {
app.log.warn(app.log.yellow('Got it, exiting process'));
process.exit();
} else {
answer = true;
cb();
}
});
});
return plugin;
};