This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
201 lines (193 loc) · 7.17 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
var fs = require('fs');
var path = require('path');
var nyg = require('nyg');
var spawn = require('cross-spawn');
var createSections = require('./lib/createSections');
var Favicon = require('./templates/scripts/favicons/favicons.js');
var addPasswordProtection = require('./lib/addPasswordProtection.js');
var prompts = [{
type: "input",
name: "author",
message: "What is your name? (Author)",
default: ""
}, {
type: "input",
name: "email",
message: "What is your email? (Author Email)",
default: ""
}, {
type: "input",
name: "description",
message: "Describe the project:",
default: ""
}, {
type: "input",
name: "repo",
message: "What is your git repository? (GitHub Repository)",
default: ""
}, {
type: "list",
message: "What framework will your project use?",
name: "framework",
choices: [{
name: "React",
value: "react"
},{
name: "Bigwheel / Handlebars",
value: "bigwheel",
checked: true
},
{
name: "None",
value: "none"
}]
},{
type: "confirm",
name: "sectionNames",
message: "Would you prefer ComponentName/ComponentName.js over ComponentName/index.js?",
default: false,
when: function(answers) { return answers.framework!=='none'; }
},{
type: "confirm",
name: "useES6",
message: "Would you like to use ES6?",
default: true,
when: function(answers) { return answers.framework==='bigwheel' || answers.framework==='none'; }
},{
type: "list",
message: "What css preprocessor will your project use?",
name: "css",
choices: [{
name: "SCSS",
value: "scss",
checked: true
},{
name: "LESS",
value: "less"
}]
},{
type: "confirm",
name: "vendor",
message: "Separate common npm modules into vendor.js?",
default: true
},{
type: "list",
message: "What backend language would you like to use?",
name: "backend",
choices: [{
name: "PHP",
value: "php"
}, {
name: "None",
value: "none"
}]
},{
type: "confirm",
name: "unsupported",
message: "Would you like to include an unsupported page?",
default: true
},{
type: "input",
name: "password",
message: "Choose the password to use for password protection. (leave blank to disable)",
default: ""
},{
type: "input",
name: "passLocation",
message: "Where on the server will your .htpasswd be located?",
default: "/var/www",
when: function(answers) { return answers.password!==''; }
}];
var globs = [
{ base: 'templates/{{framework}}/' },
{ base: 'templates/', glob: 'scripts/*' },
{ base: 'templates/base/' },
{ base: 'templates/style/', output: 'src/style/' },
{ base: 'templates/scripts/{{css}}/', glob: '*', output: 'scripts/' },
{ base: 'templates/scripts/favicons/', glob: '*', output: 'scripts/favicons/' },
{ base: 'templates/backend/{{backend}}/'},
{ base: 'templates/unsupported/default/', when: function(answers) { return answers.unsupported; }},
{ base: 'templates/unsupported/{{backend}}/', when: function(answers) { return answers.unsupported; } }
];
var gen = nyg(prompts,globs,{ignore:[".phar"]})
.on('postprompt', onPostPrompt)
.on('postcopy', onPostCopy)
.on('postinstall', onPostInstall)
.run();
//*************************** Event Handlers ***************************
function onPostPrompt() {
var repo = gen.config.get('repo').split('/');
repo = repo[repo.length-1].toLowerCase().replace('.git','');
gen.config.set('repoName', repo || '');
if (gen.config.get('framework')!=='none' && gen.config.get('framework')!=='bigwheel') gen.config.set('useES6',true);
}
function onPostCopy() {
var done = gen.async();
fs.rename(path.join(gen.cwd,'gitignore'),path.join(gen.cwd,'.gitignore'),function() {
if (gen.config.get('framework')!=='none') {
if (gen.config.get('useES6')) {
gen.copy('templates/.babelrc','.babelrc',function() {
if (gen.config.get('sectionNames') && gen.config.get('framework')==='react') {
var style = gen.config.get('css');
var files = [
[path.join(gen.cwd,'src/components/Preloader/style.'+style),path.join(gen.cwd,'src/components/Preloader/Preloader.'+style)],
[path.join(gen.cwd,'src/components/Rotate/index.js'),path.join(gen.cwd,'src/components/Rotate/Rotate.js')],
[path.join(gen.cwd,'src/components/Rotate/style.'+style),path.join(gen.cwd,'src/components/Rotate/Rotate.'+style)],
[path.join(gen.cwd,'src/components/MobileFullscreenVideo/index.js'),path.join(gen.cwd,'src/components/MobileFullscreenVideo/MobileFullscreenVideo.js')],
[path.join(gen.cwd,'src/components/MobileFullscreenVideo/style.'+style),path.join(gen.cwd,'src/components/MobileFullscreenVideo/MobileFullscreenVideo.'+style)],
[path.join(gen.cwd,'src/components/VideoPlayer/index.js'),path.join(gen.cwd,'src/components/VideoPlayer/VideoPlayer.js')],
[path.join(gen.cwd,'src/components/VideoPlayer/style.'+style),path.join(gen.cwd,'src/components/VideoPlayer/VideoPlayer.'+style)],
[path.join(gen.cwd,'src/components/VideoPlayer/VideoPoster/index.js'),path.join(gen.cwd,'src/components/VideoPlayer/VideoPoster/VideoPoster.js')],
[path.join(gen.cwd,'src/components/VideoPlayer/VideoPoster/style.'+style),path.join(gen.cwd,'src/components/VideoPlayer/VideoPoster/VideoPoster.'+style)],
[path.join(gen.cwd,'src/components/VideoPlayer/VideoTimeline/index.js'),path.join(gen.cwd,'src/components/VideoPlayer/VideoTimeline/VideoTimeline.js')],
[path.join(gen.cwd,'src/components/VideoPlayer/VideoTimeline/style.'+style),path.join(gen.cwd,'src/components/VideoPlayer/VideoTimeline/VideoTimeline.'+style)],
[path.join(gen.cwd,'src/sections/App/style.'+style),path.join(gen.cwd,'src/sections/App/App.'+style)],
[path.join(gen.cwd,'src/components/HamburgerButton/index.js'),path.join(gen.cwd,'src/components/HamburgerButton/HamburgerButton.js')],
[path.join(gen.cwd,'src/components/HamburgerButton/style.'+style),path.join(gen.cwd,'src/components/HamburgerButton/HamburgerButton.'+style)]
];
renameFiles(files,function() {
createSections(gen,done);
});
} else {
createSections(gen,done);
}
});
} else {
createSections(gen,done);
}
} else {
fs.writeFile(path.join(gen.cwd,'src/index.js'),'',function() {
if (gen.config.get('useES6')) {
gen.copy('templates/.babelrc','.babelrc',done);
} else {
done();
}
});
}
if (gen.config.get('password') !== '') {
addPasswordProtection(gen.cwd, gen.config.get('password'));
}
});
}
function renameFiles(arr,cb) {
var total = arr.length;
var count = 0;
var done = function() {
count++;
if (count>=total) cb();
};
arr.forEach(function(cur) {
fs.rename(cur[0],cur[1],done);
});
}
function onPostInstall() {
var done = gen.async();
var npm = spawn('npm', ['run','favicons'], {cwd: gen.cwd, stdio: 'inherit'});
npm.on('error',function() {
console.log(arguments);
});
npm.on('close',function(code) {
if (code!==0) console.log(new Error('npm run favicons exited with non-zero code ' + code + '. Please try running "npm run favicons" again as administrator.'));
done();
});
}