-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautofile.js
52 lines (45 loc) · 1.28 KB
/
autofile.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
'use strict';
var fs = require('fs');
var path = require('path');
module.exports = function (task) {
task
.id('init')
.name('Init')
.description('Init an empty autofile.')
.author('Indigo United')
.option('name', 'The task name.', 'autofile')
.option('dst', 'Directory in which the task will be created.', process.cwd())
.setup(function (opt, ctx, next) {
var error;
if (path.extname(opt.name) === '.js') {
opt.name = opt.name.slice(0, -3);
}
opt.filename = path.join(opt.dst, opt.name + '.js');
opt.__dirname = __dirname;
fs.stat(opt.filename, function (err) {
if (!err || err.code !== 'ENOENT') {
error = new Error('EEXIST, file already exists \'' + opt.filename + '\'');
error.code = 'EXISTS';
return next(error);
}
next();
});
})
.do('cp', {
description: null,
options: {
files: {
'{{__dirname}}/base_autofile.js': '{{filename}}'
}
}
})
.do('scaffolding-replace', {
description: null,
options: {
files: '{{filename}}',
data: {
name: '{{name}}'
}
}
});
};