This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
67 lines (61 loc) · 1.69 KB
/
build.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
var scraper = require('website-scraper');
var spawn = require('child_process').spawn;
var replace = require("replace");
var glob = require("glob");
function scrapeIt(process) {
scraper.scrape({
urls: [
'http://localhost:8765/',
],
directory: __dirname + '/build',
subdirectories: [
{directory: 'img', extensions: ['.jpg', '.png', '.svg']},
{directory: 'js', extensions: ['.js']},
{directory: 'css', extensions: ['.css']}
],
sources: [
{selector: 'img', attr: 'src'},
{selector: 'link[rel="stylesheet"]', attr: 'href'},
{selector: 'script', attr: 'src'}
],
request: {
headers: {
'User-Agent': 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'
}
}
}).then(function (result) {
glob(__dirname + '/build/**/*.js', {}, function (er, files) {
replace({
regex: /[\u200B-\u200D\uFEFF ]/g,
replacement: ' ',
paths: files,
recursive: true,
silent: true,
});
});
if (process) {
process.kill();
}
}).catch(function(err){
console.log(err);
if (process) {
process.kill();
}
});
}
if (/^win/.test(process.platform)) {
console.log('You will need to manually run `meteor run -p 8765`');
scrapeIt();
} else {
// launch meteor
var start = spawn('meteor', ['run', '-p', '8765'], {
cwd: __dirname + '/src'
});
start.stdout.pipe(process.stdout);
start.stdout.on('data', function (data) {
if (data.indexOf('localhost:8765') !== -1) {
// Then crawl the website for all the assets
scrapeIt(start);
}
});
}