-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
108 lines (89 loc) · 2.68 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
const fs = require('fs');
const puppeteer = require('puppeteer');
const { fork, execSync } = require('child_process');
//const getCapture = require('./getCapture.js');
const { PATH_LIST, HOSTS } = require('./config.js');
const dirlist = ['./results/production', './results/development', './results/cli', './results/diff'];
for (let i = 0; i < dirlist.length; ++i) {
let path = dirlist[i];
if (!fs.existsSync(path)) {
fs.mkdirSync(path, { recursive: true });
}
}
const SUBROUTINE_SCRIPT_PATH = './getCapture.js';
function createQuery() {
const queries = [];
for (let i = 0; i < PATH_LIST.length; ++i) {
let url = PATH_LIST[i];
queries.push({
url: `${HOSTS.production}${url}`,
output: `results/production/${url
.replace(/:/g, '')
.replace(/\/$/g, '_index.html')
.replace(/\//g, '_')
.replace(/^_/g, '')}.png`
});
queries.push({
url: `${HOSTS.development}${url}`,
output: `results/development/${url
.replace(/:/g, '')
.replace(/\/$/g, '_index.html')
.replace(/\//g, '_')
.replace(/^_/g, '')}.png`
});
}
return queries;
}
function setup(threadNumber) {
childs[threadNumber].send({ query: 'setup', threadNumber: threadNumber });
}
function close(threadNumber) {
childs[threadNumber].send({ query: 'close', threadNumber: threadNumber });
}
function getCapture(threadNumber) {
const query = queries.length > 0 ? queries.shift() : undefined;
const processExit = queries.length < childs.length;
childs[threadNumber].send({ query: query, processExit: processExit, threadNumber: threadNumber });
}
// 他プロセスの作成
const CPUs = require('os').cpus().length;
let usingThreadNumber = CPUs;
const childs = [];
for (let i = 0; i < CPUs; ++i) {
let child = fork(SUBROUTINE_SCRIPT_PATH);
child.on('message', function(data) {
if (data.message === 'exit') usingThreadNumber--;
if (data.message === 'close') usingThreadNumber--;
if ((data.message === 'fix' || data.message === 'setup-fix') && queries.length > 0) {
getCapture(data.threadNumber);
} else {
close(data.threadNumber);
}
if (usingThreadNumber === 0) {
console.log('thread exit');
exec_reg();
process.exit();
return;
}
});
childs.push(child);
}
// クエリの生成
const queries = createQuery();
// 実行
for (let i = 0; i < childs.length; ++i) {
//getCapture(i);
setup(i);
}
function exec_reg() {
try {
//reg
execSync('node ./node_modules/reg-cli/dist/cli.js ./results/development/ ./results/production/ ./results/diff/ -R ./results/report.html');
} catch (err) {
err.stdout;
err.stderr;
err.pid;
err.signal;
err.status;
}
}