-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.js
executable file
·148 lines (137 loc) · 3.89 KB
/
init.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env node
var program = require('commander');
var fs = require('graceful-fs');
var rm = require('rimraf');
var inquirer = require('inquirer');
var glob = require('glob');
var package = require('./package.json');
var bower = require('./bower.json');
var project = {};
program
.version(package.version)
.parse(process.argv);
// Initialisation prompt questions
var questions = [{
name: 'name',
message: 'Project unique name:',
validate: function(input) {
return input !== '' ? true : 'You must enter a valid name.';
}
}, {
name: 'displayedName',
message: 'Project displayed name:',
validate: function(input) {
return input !== '' ? true : 'You must enter a valid name.';
}
}, {
name: 'version',
message: 'Project version:',
default: '0.0.1',
validate: function(input) {
return input !== '' ? true : 'You must enter a valid version.';
}
}, {
name: 'description',
message: 'Project description:'
}, {
name: 'keywords',
message: 'Project keywords:'
}, {
name: 'url',
message: 'Project url:',
default: 'http://localhost:3000'
}, {
name: 'repository',
message: 'Project git repository:'
}, {
name: 'browsers',
type: 'checkbox',
message: 'Browser support:',
choices: [{
value: 'Internet Explorer 8',
checked: false
}, {
value: 'Internet Explorer 9',
checked: true
}, {
value: 'Internet Explorer 10',
checked: true
}, {
value: 'Internet Explorer 11',
checked: true
}, {
value: 'Microsoft Edge',
checked: true
}, {
value: 'Google Chrome (dernière version)',
checked: true
}, {
value: 'Firefox (dernière version)',
checked: true
}, {
value: 'Safari (dernière version)',
checked: true
}]
}, {
name: 'responsive',
type: 'confirm',
message: 'Responsive?'
}, {
name: 'accessible',
type: 'confirm',
message: 'Accessible?'
}, {
name: 'retina',
type: 'confirm',
message: 'Retina?'
}, {
name: 'templates',
type: 'confirm',
message: 'Include VTT templates?'
}];
// Prompt user for project informations
inquirer.prompt(questions).then(function (answers) {
// Update package.json values
package.name = answers.name;
package.version = answers.version;
package.description = answers.description;
package.keywords = answers.keywords;
package.url = answers.url;
package.repository = answers.repository;
// Update bower.json values
bower.name = answers.name;
bower.version = answers.version;
bower.description = answers.description;
bower.homepage = answers.url;
// Update project.json values
project.name = answers.name;
project.displayedName = answers.displayedName;
project.description = answers.description;
project.repository = answers.repository;
project.templates = answers.templates;
project.browsers = answers.browsers;
project.responsive = answers.responsive;
project.accessible = answers.accessible;
project.retina = answers.retina;
// Save new package.json values
fs.writeFile('./package.json', JSON.stringify(package, null, 2), function(error) {
if (error) return console.log(error);
});
// Save new project values
fs.writeFile('./bower.json', JSON.stringify(bower, null, 2), function(error) {
if (error) return console.log(error);
});
// Save new project values
fs.writeFile('./project.json', JSON.stringify(project, null, 2), function(error) {
if (error) return console.log(error);
});
// Remove templates files
if (!answers.templates) {
rm('./templates/', function(error) {
if (error) return console.log(error);
});
rm('./src/sass/styles.json', function(error) {
if (error) return console.log(error);
});
}
});