-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerator.js
133 lines (110 loc) · 2.81 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
var path = require('path');
var extend = require('extend-shallow');
var isValid = require('is-valid-app');
module.exports = function(app) {
if (!isValid(app, 'generate-breakdance')) return;
/**
* Plugins
*/
app.use(require('generate-project'));
/**
* Helpers
*/
app.helper('pluginName', function(name) {
return name.replace(/^breakdance\W*/, '');
});
/**
* Run the generator's default task to scaffold out a new breakdance plugin project.
*
* ```sh
* $ gen breakdance
* ```
* @name default task
* @api public
*/
app.task('default', ['files', 'plugin-only', 'install']);
/**
* Generate only the `index.js` file for a breakdance plugin.
* Use `--stem` to change the file name.
*
* ```sh
* $ gen breakdance:plugin-only
* $ gen breakdance:plugin-only --stem foo.js
* ```
* @name plugin-only
* @api public
*/
task(app, 'plugin-only', 'plugin.js');
/**
* Scaffold out a complete project for a breakdance **compiler** plugin.
*
* ```sh
* $ gen breakdance:compiler
* ```
* @name compiler
* @api public
*/
app.task('compiler', ['files', 'compiler-only', 'install']);
/**
* Generate only the `index.js` file for a compiler plugin.
* Use `--stem` to change the file name.
*
* ```sh
* $ gen breakdance:compiler-only
* $ gen breakdance:compiler-only --stem foo.js
* ```
* @name compiler-only
* @api public
*/
task(app, 'compiler-only', 'compiler.js');
/**
* Scaffold out a complete project for a breakdance parser plugin.
*
* ```sh
* $ gen breakdance:parser
* ```
* @name parser
* @api public
*/
app.task('parser', ['files', 'parser-only', 'install']);
/**
* Generate only the `index.js` file for a breakdance parser plugin.
* Use `--stem` to change the file name.
*
* ```sh
* $ gen breakdance:parser-only
* $ gen breakdance:parser-only --stem foo.js
* ```
* @name parser-only
* @api public
*/
task(app, 'parser-only', 'parser.js');
/**
* For unit tests, to ensure this works as a sub-generator
*/
app.task('unit-test', function(cb) {
app.base.set('cache.unit-test', true);
cb();
});
};
/**
* Create a task with the given `name` and glob `pattern`
*/
function task(app, name, pattern, dependencies) {
app.task(name, dependencies || [], function(cb) {
return file(app, pattern);
});
}
function file(app, pattern) {
var opts = extend({}, app.base.options, app.options);
var templates = opts.srcBase || path.join(__dirname, 'templates');
return app.src(pattern, {cwd: templates})
.pipe(app.renderFile('*'))
.pipe(app.conflicts(app.cwd))
.pipe(app.dest(function(file) {
if (opts.stem) file.stem = opts.stem;
if (opts.name) file.stem = opts.name;
return app.cwd;
}));
}