-
Notifications
You must be signed in to change notification settings - Fork 15
/
create-manifest.js
59 lines (51 loc) · 1.51 KB
/
create-manifest.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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { versionDir, majorVersionDir } = require('./webpack.config');
const buildDate = new Date();
const manifest = {
name: process.env.APP_NAME,
version: process.env.VERSION,
build: process.env.BUILD_ID,
buildDate: buildDate.toISOString(),
indexFiles: []
};
/* add demo */
try {
const files = fs.readdirSync('dist/demo/');
files.forEach(file => {
if (fs.lstatSync('dist/demo/' + file).isDirectory()) {
const dirFiles = fs.readdirSync('dist/demo/' + file);
dirFiles.forEach(dirFile => {
if (fs.lstatSync('dist/demo/' + file + '/' + dirFile).isDirectory()) {
return;
}
manifest.indexFiles.push({
file: 'demo/' + file + '/' + dirFile
});
});
return;
}
manifest.indexFiles.push({
file: 'demo/' + file
});
});
} catch (e) {
// demo dir (examples don't exist)
}
/* add versioned bundles for CDN */
function dirWalk (dir) {
const files = [];
function walk (dir) {
fs.readdirSync(dir).forEach(file => {
const absolute = path.join(dir, file);
if (fs.statSync(absolute).isDirectory()) return walk(absolute);
else files.push(absolute);
});
return files;
}
return walk(dir);
}
[...dirWalk(versionDir), ...dirWalk(majorVersionDir)]
.forEach(filename => manifest.indexFiles.push({ file: filename.replace('dist/', '') }));
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifest, null, 2), { encoding: 'utf8' });