forked from KhronosGroup/WebGL
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.js
100 lines (90 loc) · 2.38 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
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
var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var fs = require('fs')
var path = require('path')
var BLACKLIST = require('./lib/blacklist.json')
var VERSION = '1.0.3'
var TEST_DIR = path.join(__dirname, 'node-test')
var SUITE_DIR = path.join(
__dirname,
'conformance-suites',
VERSION,
'conformance')
// We build shims ASAP because some scripts scan in shims immediately.
var buildShims = require('./lib/build-shims')
buildShims(SUITE_DIR)
// Build conformance test suite
var scanFiles = require('./lib/scan-files')
var parseCase = require('./lib/parse-case')
var genCase = require('./lib/compile-case')
var getResources = require('./lib/load-resources')
function fail (err) {
console.error('crashing', err)
process.exit(-1)
}
function basePath (file) {
return path.relative(SUITE_DIR, file).replace(/\\/g, '/')
}
function writeManifest (fileList) {
console.log('writing manifest...')
fileList.sort()
var code = [ 'module.exports=[' ]
for (var i = 0; i < fileList.length; ++i) {
if (i > 0) {
code.push(',')
}
code.push('["', fileList[i], '",require("./', fileList[i], '")]')
}
code.push(']')
var codeStr = code.join('')
fs.writeFileSync('./node-test/index.js', codeStr)
console.log('done!')
}
function build () {
scanFiles(VERSION, function (err, files) {
if (err) {
fail(err)
}
var count = files.length
var fileList = []
function decCount () {
if (--count === 0) {
writeManifest(fileList)
}
}
files.forEach(function (file) {
if (BLACKLIST.indexOf(basePath(file)) >= 0) {
console.log('skip ', file, 'blacklisted')
decCount()
return
}
parseCase(VERSION, file, function (err, result) {
if (err) {
fail(err)
} else {
var str = genCase(SUITE_DIR, result)
if (str) {
var fileName = result.caseName
fileList.push(fileName)
fs.writeFileSync(path.join(TEST_DIR, fileName) + '.js', str)
}
decCount()
}
})
})
})
getResources(SUITE_DIR, function (err, resources) {
if (err) {
fail(err)
}
fs.writeFile(path.join(TEST_DIR, 'resources.json'), JSON.stringify(resources), function (err) {
if (err) {
fail(err)
}
})
})
}
// Clear directory and run build
rimraf(TEST_DIR, function () {
mkdirp(TEST_DIR, build)
})