-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare-zip.js
More file actions
90 lines (68 loc) · 2.35 KB
/
Copy pathprepare-zip.js
File metadata and controls
90 lines (68 loc) · 2.35 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
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
const fs = require('fs-extra');
const path = require('path');
const OUTPUT_DIRECTORY = path.resolve(__dirname, '../zip');
const getFontDirectories = () => {
const files = fs.readdirSync(path.resolve('./packages/'));
// Don't build Variable fonts for now
return files.filter(
name => name.includes('plex-') && !name.includes('variable')
);
};
const globDirectory = type => {
const folders = [];
const files = getFontDirectories();
files.forEach(name => {
const list = [];
let p = `packages/${name}/fonts/complete/${type}`;
if (!fs.pathExistsSync(p)) {
p = `packages/${name}/fonts/${type}`;
}
if (!fs.pathExistsSync(p)) {
console.log(`No path exists at ${p}`);
return;
}
const fonts = fs.readdirSync(path.resolve(p));
fonts.forEach(f =>
list.push({
name: f,
path: `${p}/${f}`,
})
);
folders.push({
name,
files: list,
});
});
return folders;
}
const writeZip = (typeName, folders) => {
fs.ensureDirSync(OUTPUT_DIRECTORY);
fs.removeSync(`${OUTPUT_DIRECTORY}/${typeName}`);
fs.ensureDirSync(`${OUTPUT_DIRECTORY}/${typeName}`);
folders.forEach(folder => {
fs.ensureDirSync(`${OUTPUT_DIRECTORY}/${typeName}/${folder.name}`);
folder.files.forEach(f => {
const source = f.path;
const dest = `${OUTPUT_DIRECTORY}/${typeName}/${folder.name}/${f.name}`;
fs.copySync(source, dest);
});
});
};
const writeWebFiles = () => {
fs.ensureDirSync(`${OUTPUT_DIRECTORY}/Web`);
const files = getFontDirectories();
files.forEach(name => {
fs.ensureDirSync(`${OUTPUT_DIRECTORY}/Web/${name}`);
fs.copySync(`packages/${name}/fonts`, `${OUTPUT_DIRECTORY}/Web/${name}/fonts`);
fs.copySync(`packages/${name}/css`, `${OUTPUT_DIRECTORY}/Web/${name}/css`);
fs.copySync(`packages/${name}/scss`, `${OUTPUT_DIRECTORY}/Web/${name}/scss`);
fs.copySync('LICENSE.txt', `${OUTPUT_DIRECTORY}/Web/${name}/LICENSE.txt`);
fs.copySync('CHANGELOG.md', `${OUTPUT_DIRECTORY}/Web/${name}/CHANGELOG.md`);
fs.ensureDirSync(`${OUTPUT_DIRECTORY}/ibm-${name}`);
fs.copySync(`packages/${name}/fonts`, `${OUTPUT_DIRECTORY}/ibm-${name}/fonts`);
fs.copySync('LICENSE.txt', `${OUTPUT_DIRECTORY}/ibm-${name}/LICENSE.txt`);
});
}
writeZip('OpenType', globDirectory('otf'));
writeZip('TrueType', globDirectory('ttf'));
writeWebFiles();