-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
91 lines (78 loc) · 2.72 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
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var MuiGenerator = module.exports = function MuiGenerator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);
this.on('end', function () {
//this.installDependencies({ skipInstall: options['skip-install'] });
});
this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
};
util.inherits(MuiGenerator, yeoman.generators.Base);
MuiGenerator.prototype.askFor = function askFor() {
var cb = this.async();
var logo =
' _ \n' +
' _ __ ___ _ _(_) \n' +
' | \'_ ` _ \\| | | | |\n' +
' | | | | | | |_| | | \n' +
' |_| |_| |_|\\__,_|_| \n' +
'Welcome to Yeoman. Start your component with mui!\n';
console.log(logo);
var defaultConfig = {
name: 'Component',
style: 'css',
author: '',
email: ''
};
var prompts = [
{
name: 'name',
message: 'Component\'s name:',
default: defaultConfig.name
},
{
type: 'list',
name: 'style',
message: 'Choice style engine:',
choices: ['css', 'less']
},
{
name: 'author',
message: 'Author\'s name:',
default: defaultConfig.author
},
{
name: 'email',
message: 'Author\'s email:',
default: defaultConfig.email
}
];
this.prompt(prompts, function (props) {
this.name = props.name;
this.author = props.author;
this.email = props.email;
this.style = props.style.toLowerCase();
this.enableLess = (/less/i).test(this.style);
if (!this.enableLess) {
this.style = defaultConfig.style;
}
cb();
}.bind(this));
};
MuiGenerator.prototype.app = function app() {
var src = path.join(this.name, 'src');
var templates = path.join(this.name, 'templates');
this.mkdir(this.name);
this.mkdir(src);
this.mkdir(templates);
this.template('example/src/index.js', path.join(src, 'index.js'));
this.template('example/src/init.js', path.join(src, 'init.js'));
this.copy('example/src/style.css', path.join(src, 'style.' + this.style));
this.copy('example/templates/index.html', path.join(templates, 'index.html'));
this.copy('example/templates/index.php', path.join(templates, 'index.php'));
this.copy('example/templates/index.vm', path.join(templates, 'index.vm'));
this.template('_README.md', path.join(this.name, 'README.md'));
this.template('_package.json', path.join(this.name, 'package.json'));
};