forked from bem/bem-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-fixtures.js
More file actions
59 lines (51 loc) · 1.58 KB
/
Copy pathbuild-fixtures.js
File metadata and controls
59 lines (51 loc) · 1.58 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
var fs = require('fs'),
path = require('path'),
walk = require('bem-walk'),
borschik = require('borschik').api,
sets = require('./config').sets,
platforms = Object.keys(sets),
fixturesDir = path.join(__dirname, 'fixtures'),
blocksDir = path.resolve('libs/bem-pr/spec.blocks'),
asset = fs.readFileSync(path.join(__dirname, 'assets', 'test.html'), 'utf-8');
if(!fs.existsSync(fixturesDir)) {
fs.mkdirSync(fixturesDir);
}
[
'mocha.css',
'mocha.js',
'chai.js',
'sinon.js',
'sinon-chai.js'
].map(function (basename) {
var name = basename.split('.')[0];
borschik({
input : path.join(blocksDir, name, basename),
output : path.join(fixturesDir, basename)
});
});
platforms.forEach(function (platform) {
var levels = sets[platform].filter(fs.existsSync),
config = {
levels : levels.map(function (levelname) {
return { path : levelname };
})
},
walker = walk(levels, config),
specs = [];
walker.on('data', function (data) {
if(data.tech === 'spec.js') {
specs.push(data.path);
}
});
walker.on('end', function () {
html = buildHTML(platform, specs);
fs.writeFileSync(path.join(fixturesDir, platform + '.html'), html, 'utf-8');
});
});
function buildHTML(platform, specs) {
return asset
.replace(/\${ platform }/g, platform)
.replace(/\${ scripts }/g, specs.map(function (url) {
return ' <script src="../../../' + url + '"></script>';
}).join('\n'));
}