This repository was archived by the owner on Sep 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzcproject
More file actions
executable file
·384 lines (359 loc) · 15 KB
/
Copy pathzcproject
File metadata and controls
executable file
·384 lines (359 loc) · 15 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/usr/local/bin/node
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{ name: 'help', alias: 'v', type: Boolean },
{ name: 'folder', alias: 'f', type: String, multiple: true, defaultOption: true },
{ name: 'ip', type: String }
];
const untildify = require('untildify');
var prompt = require('prompt');
var fs = require('fs');
var http = require('http');
function errHandle(err){
console.log(err);
return 1;
};
const pfol = "./greg/";
// SAMPLE PROMPT RETURN FOR WORPDRESS PROJECT
const wp = {
projectName:'Sample Project',
baseFolder:'~/work/testResults/',
ipAddress:'192.160.0.101',
vmName:'sample-vm',
author:'ZombieCorp',
authorMail:'contato@zombiecorp.com.br',
dbRootPass:'saposapo',
domainName:'dev.testresults.com',
wordpress:{
themeName:'Sample Theme',
themeFolder:'sample-theme'
}
};
var zc = (function(){
return {
baseConfig:{
},
promptSchema:{
properties: {
baseFolder:{
description: 'baseFolder (./):',
default: './',
type: 'string'
},
projectName: {
description: 'Enter Project Name', // Prompt displayed to the user. If not supplied name will be used.
type: 'string', // Specify the type of input to expect.
//pattern: /^\w+$/, // Regular expression that input must be valid against.
//message: 'Password must be letters', // Warning message to display if validation fails.
hidden: false, // If true, characters entered will either not be output to console or will be outputed using the `replace` string.
replace: '*', // If `hidden` is set it will replace each hidden character with the specified string.
//default: 'lamepassword', // Default value to use if no value is entered.
required: true // If true, value entered must be non-empty.
//before: function(value) { return 'v' + value; } // Runs before node-prompt callbacks. It modifies user's input
},
ipAddress:{
description: 'Enter IP', // Prompt displayed to the user. If not supplied name will be used.
type: 'string', // Specify the type of input to expect.
pattern: /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/, // Regular expression that input must be valid against.
message: 'Must be an IP Address', // Warning message to display if validation fails.
// hidden: false, // If true, characters entered will either not be output to console or will be outputed using the `replace` string.
// replace: '*', // If `hidden` is set it will replace each hidden character with the specified string.
// default: 'lamepassword', // Default value to use if no value is entered.
// required: true // If true, value entered must be non-empty.
// before: function(value) { return 'v' + value; } // Runs before node-prompt callbacks. It modifies user's input
},
vmName:{
description: 'VM Name:',
type: 'string'
},
projectType:{
description: 'Scaffold: \n1) Wordpress Site',
type: 'number'
}
}
},
wpSchema:{
properties: {
themeName: {
description: 'Enter Theme Name', // Prompt displayed to the user. If not supplied name will be used.
type: 'string', // Specify the type of input to expect.
//pattern: /^\w+$/, // Regular expression that input must be valid against.
//message: 'Password must be letters', // Warning message to display if validation fails.
hidden: false, // If true, characters entered will either not be output to console or will be outputed using the `replace` string.
replace: '*', // If `hidden` is set it will replace each hidden character with the specified string.
//default: 'lamepassword', // Default value to use if no value is entered.
required: true // If true, value entered must be non-empty.
//before: function(value) { return 'v' + value; } // Runs before node-prompt callbacks. It modifies user's input
},
themeFolder:{
description: 'Enter IP', // Prompt displayed to the user. If not supplied name will be used.
type: 'string', // Specify the type of input to expect.
// pattern: /^\w+$/, // Regular expression that input must be valid against.
// message: 'Password must be letters', // Warning message to display if validation fails.
// hidden: false, // If true, characters entered will either not be output to console or will be outputed using the `replace` string.
// replace: '*', // If `hidden` is set it will replace each hidden character with the specified string.
// default: 'lamepassword', // Default value to use if no value is entered.
// required: true // If true, value entered must be non-empty.
// before: function(value) { return 'v' + value; } // Runs before node-prompt callbacks. It modifies user's input
}
}
},
// add promt stuff here later
init: (obj)=>{
// here we setup eveything
// we call prompt here
let c = zc.fixObjects(obj);
zc.getWPTemplates(c);
},
prompt: function(){
prompt.start();
var self = this;
prompt.get(this.promptSchema,function(err, result){
if (err){
errHandle(err);
}else{
console.log(result);
self.createVagrant(result);
if (result.projectType==1){
self.wordpress(result);
}
}
});
},
fixObjects: (config) => {
// here we make sure things are OK
config.baseFolder = untildify(config.baseFolder);
return config;
},
getWPTemplates:function(config){
var exec = require('child_process').exec;
function finish(error, stdout, stderr) {
console.log("Dev Files Copied");
zc.getWordpress(config);
}
let cmd = "git clone https://github.com/bugzbrown/devWPScaffold.git " + config.baseFolder + "";
console.log(cmd);
exec(cmd, finish);
},
getWordpress:function(config){
console.log('GETTING WORDPRESS FROM GITHUB')
console.log('Might take a couple of minutes')
var exec = require('child_process').exec;
function gitFinish(error, stdout, stderr) {
console.log("WP RESPONSE")
console.log("stdOut: " + stdout)
console.log("stdErr: " + stderr)
zc.createPackageForWP(config);
}
let cmd = "git clone https://github.com/WordPress/WordPress.git " + config.baseFolder + "src/main-site";
//let cmd = "mkdir -p " + config.baseFolder + "src/main-site/wp-content/themes/";
console.log(cmd);
let run = exec(cmd);
run.stdout.on('data', function(data){console.log('.')});
run.stderr.on('data', function(data){console.log(data)});
run.on('close', function(code){
if (code===0){
gitFinish();
}else{
console.log('ERROR');
return 1;
}
});
//exec("git clone https://github.com/WordPress/WordPress.git " + config.baseFolder + "src/main-site", gitFinish)
//exec("wget http://wordpress.org/latest.tar.gz", puts);
},
/*
* Create Package.json file
*/
createPackageForWP:function(config){
console.log("CREATE PACKAGE");
var fs = require('fs');
let buffer=''+
'{' + "\n" ;
' "name": "wp-DRGB",' + "\n" +
' "version": "1.0.0",' + "\n" +
' "description": "",' + "\n" +
' "author": "Gregory Brown",' + "\n" +
' "license": "MIT",' + "\n" +
' "dests": "./main-site/wp-content/themes/drgb/assets/",' + "\n" +
' "jsFileName": "js/main",' + "\n" +
' "cssFileName": "css/main",' + "\n" +
' "devDependencies": {' + "\n" +
' "grunt": "^1.0.1",' + "\n" +
' "grunt-contrib-cssmin": "^1.0.1",' + "\n" +
' "grunt-contrib-sass": "^1.0.0",' + "\n" +
' "grunt-contrib-uglify": "^1.0.1",' + "\n" +
' "grunt-contrib-watch": "^1.0.0",' + "\n" +
' "grunt-typedoc": "^0.2.4",' + "\n" +
' "grunt-ts": "^5.5.1"' + "\n" +
' }' + "\n" +
'}' + "\n" +
'' + "\n" +
'end' + "\n" ;
fs.writeFile(config.baseFolder + 'package.json', buffer, (err) => {
if (err) throw err;
console.log('package.json File Wirtten' + "\n");
zc.createVagrant(config);
});
},
/*
* Create Vagrant file
*/
createVagrant:function(result){
var fs = require('fs');
var buffer=''+
'### AUTOMATICIALLY CREATED '+ "\n" +
'### '+ result.projectName + "\n" +
'### '+ "\n" +
'Vagrant.configure("2") do |config|'+ "\n" +
' config.vm.box = "ubuntu/xenial64"'+ "\n" +
' config.vm.boot_timeout = 600'+ "\n" +
' config.vm.network :private_network, ip: "' + result.ipAddress + '"'+ "\n" +
' #config.vm.network :public_network, ip: "192.168.1.38"'+ "\n" +
' config.vm.provision "shell", path: "./provision.sh"'+ "\n" +
' config.ssh.forward_agent = true'+ "\n" +
' config.vm.provider :virtualbox do |v|'+ "\n" +
' v.name = "zcvm_' + result.vmName + '"'+ "\n" +
' v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]'+ "\n" +
' v.customize ["modifyvm", :id, "--memory", 2048]'+ "\n" +
' v.cpus = 2'+ "\n" +
' end'+ "\n" +
' config.vm.synced_folder "./src", "/var/www", id: "vagrant-root", :mount_options => [\'dmode=777\',\'fmode=777\']'+ "\n" +
'end' + "\n" ;
fs.writeFile(result.baseFolder + 'Vagrantfile', buffer, function (err) {
if (err)
return console.log(err);
console.log('Vagrant File Wirtten' + "\n");
zc.createProvision(result);
});
},
/*
* Create PROVISION file
*/
createProvision:function(config){
var fs = require('fs');
var buffer=''+
'### AUTOMATICIALLY CREATED '+ "\n" +
'### '+ config.projectName + "\n" +
'#!/usr/bin/env bash' + "\n" +
'## FIX NAMESERVER ISSUES WITH UBUNTU16' + "\n" +
'echo "nameserver 8.8.8.8"> /etc/resolvconf/resolv.conf.d/tail' + "\n" +
'echo "nameserver 8.8.4.4">> /etc/resolvconf/resolv.conf.d/tail' + "\n" +
'rm /etc/resolv.conf' + "\n" +
'ln -s /run/resolvconf/resolv.conf /etc/resolv.conf' + "\n" +
'resolvconf -u' + "\n" +
'## UPDATE APT' + "\n" +
'apt-get update' + "\n" +
'## UPGRADE APT' + "\n" +
'apt-get -y upgrade' + "\n" +
'' + "\n" +
'## INSTALL PHP + MYSQL + APACHE' + "\n" +
'DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 libapache2-mod-php mysql-server php-mysql php-gd php-curl php-soap php-xml php-xmlrpc' + "\n" +
'' + "\n" +
'## ENABLE MOD REWRITE' + "\n" +
'a2enmod rewrite' + "\n" +
'## SETUP MYSQL USER PASSWORD' + "\n" +
'mysqladmin -u root password ' + config.dbRootPass + "\n" +
'' + "\n" +
'## CREATE VHOST' + "\n" +
'echo "<VirtualHost *:80>" > /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo " ServerAdmin ' + config.authorMail + '" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo " ServerName ' + config.domainName + '" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo " DocumentRoot /var/www/main-site/" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo " <Directory /var/www/main-site/>" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo " Options Indexes FollowSymLinks MultiViews" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo " AllowOverride All" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo " </Directory>" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'echo "</VirtualHost>" >> /etc/apache2/sites-available/' + config.domainName + '.conf' + "\n" +
'' + "\n" +
'a2ensite ' + config.domainName + "\n" +
'service apache2 restart' + "\n" +
'' + "\n" +
'### END PROVISION' + "\n" ;
fs.writeFile(config.baseFolder + 'provision.sh', buffer, function (err) {
if (err)
return console.log(err);
console.log('Provision File Wirtten' + "\n");
zc.createTheme(config);
});
},
createTheme: function(config){
console.log('Creating Helpers Folder')
var exec = require('child_process').exec;
function gitFinish(error, stdout, stderr) {
zc.addGit(config);
}
exec("mkdir -p " + config.baseFolder + "src/main-site/wp-content/themes/" + config.wordpress.themeFolder + "/Helpers/", gitFinish);
},
addGit:function(config){
console.log('Adding Submodule Mobile-Detect')
var exec = require('child_process').exec;
function gitFinish(error, stdout, stderr) {
console.log("FINISHING THE INSTALL");
console.log(stdout);
console.log(stderr);
zc.addDetectMobile(config);
}
// TEMP CREATE DIRS FOR TESTING
let cmd = "git init " + config.baseFolder ;
console.log(cmd);
exec(cmd, gitFinish);
},
// we create a helpers folder.
addDetectMobile:function(config){
console.log('Adding Mobile-Detect')
var exec = require('child_process').exec;
function gitFinish(error, stdout, stderr) {
console.log("FINISHING THE INSTALL");
console.log(stdout);
console.log(stderr);
zc.createStyle(config);
}
// TEMP CREATE DIRS FOR TESTING
//let cmd = "git submodule add https://github.com/serbanghita/Mobile-Detect.git " + config.baseFolder + "src/main-site/wp-content/themes/" + config.wordpress.themeFolder + "/Helpers/Mobile-Detect";
//CLONE
let cmd = "git clone https://github.com/serbanghita/Mobile-Detect.git " + config.baseFolder + "src/main-site/wp-content/themes/" + config.wordpress.themeFolder + "/Helpers/Mobile-Detect";
console.log(cmd);
exec(cmd, gitFinish);
},
createStyle: function(config){
// here we create the basic infrastructure for a minimal wordpress theme
// we create a style.css file.
var fs = require('fs');
var buffer=''+
'{' + "\n" ;
'/*' + "\n" +
'Theme Name: ' + config.wordpress.themeName + "\n" +
'Author: ' + config.author + " <" + config.authorMail + ">" + "\n" +
'Description: New theme created with ZC_Project creator' + "\n" +
'Version: 1.0' + "\n" +
'*/' + "\n";
fs.writeFile(config.baseFolder + 'src/main-site/wp-content/themes/' + config.wordpress.themeFolder + '/styles.css', buffer, function (err) {
if (err)
return console.log(err);
console.log('Styles Wirtten' + "\n");
//zc.createHelpers(config);
});
}
// we add the submodule mobile detect
// we create a functions file with the bare bones of what we need.
};
})();
/**
* ORDER OF EVENS
1 - INIT AND PROMPT QUESTIONS
2 - GET CHOSEN REPOSITORIES
3 - CREATE VAGRANT FILE
*/
//zc.init();
/**** WORDPRESS INSTALL ****/
// get template files from github
zc.init(wp);
//zc.createTheme(wp);
// make package.json
// zc.createPackageForWP(config)
// make vagrant file
// zc.createVagrant(wp);
// get latest wordpress package
// zc.getWordpress(wp);
//zc.setupTheme();