-
Notifications
You must be signed in to change notification settings - Fork 4
/
copy-resource.js
86 lines (77 loc) · 3.14 KB
/
copy-resource.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
const fs = require('fs-extra');
const path = require('path');
const {F_OK, COPYFILE_FICLONE} = fs.constants;
const fontAwesome = path.join(path.dirname(require.resolve('@fortawesome/fontawesome-free')), '../');
const spoqaHanSans = path.dirname(require.resolve('spoqa-han-sans/README.md'));
const notoSansKr = path.dirname(require.resolve('typeface-noto-sans-kr'));
const webfontLoader = require.resolve('webfontloader');
async function checkDirectory(name) {
let sourcePath = path.join('./source', name);
return new Promise( resolve => {
fs.access(path.join(__dirname, sourcePath), F_OK, (err) => {
if(err) {
fs.mkdirSync(path.join(__dirname, sourcePath));
}
resolve(path.join(__dirname, sourcePath))
});
})
}
checkDirectory('fonts')
.then( base => {
// copy fontawesome
fs.copy(path.join(fontAwesome, 'webfonts'), path.join(base, 'fontawesome'), err => {
if(err) console.error(err)
console.log(`Copying fontAwesome: font files copied!`)
})
fs.readFile(path.join(fontAwesome, 'css/all.min.css'), 'utf8', (err, data) => {
if(err || !data) {
console.error(`Can't read ${path.join(fontAwesome, 'css/all.min.css')}`)
return;
}
let css = data.toString().replace(/\.\.\/webfonts\//g, '') ;
fs.writeFile(path.join(base, 'fontawesome/fontawesome.css'), css, 'utf8', err => {
if(err) console.error(err);
console.log(`Copying fontAwesome: css file copied`)
})
})
// copy SpoqaHansSans
fs.copy(path.join(spoqaHanSans, './Subset/SpoqaHanSans'), path.join(base, 'spoqahansans'), err => {
if(err) console.error(err)
console.log(`Copying SpoqaHanSans: font files copied!`)
})
fs.readFile(path.join(spoqaHanSans, 'css/SpoqaHanSans-kr.css'), 'utf8', (err, data) => {
if(err || !data) {
console.error(`Can't read ${path.join(spoqaHanSans, 'css/SpoqaHanSans-kr.css')}`)
return;
}
let css = data.toString().replace(/\.\.\/Subset\/SpoqaHanSans\//g, '') ;
fs.writeFile(path.join(base, 'spoqahansans/SpoqaHanSans-kr.css'), css, 'utf8', err => {
if(err) console.error(err);
console.log(`Copying SpoqaHanSans: css file copied`)
})
})
// copy NotoSansKR
fs.copy(path.join(notoSansKr, './files'), path.join(base, 'notosanskr'), err => {
if(err) console.error(err)
console.log(`Copying NotoSansKr: font files copied!`)
})
fs.readFile(path.join(notoSansKr, 'index.css'), 'utf8', (err, data) => {
if(err || !data) {
console.error(`Can't read ${path.join(notoSansKr, 'index.css')}`)
return;
}
let css = data.toString().replace(/\.\/files\//g, '') ;
fs.writeFile(path.join(base, 'notosanskr/NotoSansKR.css'), css, 'utf8', err => {
if(err) console.error(err);
console.log(`Copying NotoSansKr: css file copied`)
})
})
})
.catch( err => console.log("An error occurred", err) )
checkDirectory('js')
.then( base => {
fs.copyFile(webfontLoader, path.join(base, 'webfontloader.js'), COPYFILE_FICLONE, err => {
if(err) console.error(err)
console.log(`Copying WebfontLoader: copied!`)
})
})