-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp_starter.js
74 lines (64 loc) · 2.31 KB
/
wp_starter.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
// TODO: init theme
// TODO: init frontend
//
var fs = require('fs');
var request = require('request');
var unzip = require('unzip');
const WORDPRESS_ZIP_URL = "https://wordpress.org/latest.zip";
const WORDPRESS_ZIP_LOCALE = "wordpress.zip";
const MINIMAL_CSS_URL = "https://github.com/KrzywdaKrystian/minimal-css/archive/master.zip";
const MINIMAL_CSS_LOCALE = "front.zip";
downloadWordpress();
function downloadWordpress() {
var body = null;
var contentLength;
request({url: WORDPRESS_ZIP_URL, encoding: null}, function (err, resp, body) {
if (err) throw err;
fs.writeFile(WORDPRESS_ZIP_LOCALE, body, function (err) {
console.log('\033c');
console.log("Wordpress downloaded!");
unzipWordpress();
});
}).on('response', function (response) {
contentLength = response.headers['content-length'];
}).on('data', function (data) {
body += data;
console.log('\033c');
console.log('Download Wordpress: ' + parseInt(body.length / contentLength * 100) + '%');
})
}
function unzipWordpress() {
console.log('Wordpress unpacking...');
fs.createReadStream(WORDPRESS_ZIP_LOCALE).pipe(unzip.Extract(
{
path: __dirname
}
)).on('finish', function () {
console.log('Wordpress unpacked!');
fs.unlink(WORDPRESS_ZIP_LOCALE, function () {
console.log(WORDPRESS_ZIP_LOCALE + ' deleted');
});
fs.rename('wordpress', 'www', function () {
console.log('rename "wordpress" to "www"');
});
//downloadMinimalCss();
});
}
function downloadMinimalCss() {
var body = null;
var contentLength;
request({url: MINIMAL_CSS_URL, encoding: null}, function (err, resp, body) {
if (err) throw err;
fs.writeFile(MINIMAL_CSS_LOCALE, body, function (err) {
console.log('\033c');
console.log("minimal-css downloaded!");
//unzipWordpress();
});
}).on('response', function (response) {
contentLength = response.headers['content-length'];
}).on('data', function (data) {
body += data;
console.log('\033c');
console.log('Download minimal-css (https://github.com/KrzywdaKrystian/minimal-css): ' + parseInt(body.length / contentLength * 100) + '%');
})
}