-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathindex.js
83 lines (72 loc) · 1.78 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
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var validatePackageName = require('validate-npm-package-name');
module.exports = yeoman.Base.extend({
prompting: function () {
this.log(yosay(
'Welcome to the shining ' + chalk.red('generator-react-server') + ' generator!'
));
var prompts = [{
type: 'input',
name: 'name',
message: 'What would you like to call your app?',
default: this.appname.trim().replace(/\s+/g, '-'),
validate: function (name) {
var validation = validatePackageName(name);
var warnings = validation.warnings || [];
var errors = validation.errors || [];
if (validation.validForNewPackages) {
return true;
}
return warnings.concat(errors).join('\n');
},
}, {
type: 'confirm',
name: 'dockerCfg',
message: 'Do you want to generate a Docker file and Docker Compose file?',
default: false,
}];
return this.prompt(prompts).then(function (props) {
this.props = props;
}.bind(this));
},
writing: function () {
var _this = this;
[
'_eslintrc',
'_gitignore',
'_reactserverrc',
].forEach(function (filename) {
var fn = filename.replace('_', '.');
_this.fs.copyTpl(
_this.templatePath(filename),
_this.destinationPath(fn),
_this.props
);
});
var files = [
'pages/hello-world.js',
'components/hello-world.js',
'babel.config.js',
'package.json',
'README.md',
'routes.json',
'test.js',
];
if (this.props.dockerCfg) {
files.push('Dockerfile');
files.push('docker-compose.yml');
}
files.forEach(function (filename) {
_this.fs.copyTpl(
_this.templatePath(filename),
_this.destinationPath(filename),
_this.props
);
});
},
install: function () {
this.npmInstall();
},
});