Skip to content

Commit

Permalink
Merge branch 'hotfix/preinstall'
Browse files Browse the repository at this point in the history
  • Loading branch information
mulder21c committed Apr 3, 2019
2 parents f377725 + 3dfe6da commit c3ce35e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 19 deletions.
83 changes: 83 additions & 0 deletions copy-resource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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);

await fs.access(path.join(__dirname, sourcePath), F_OK, (err) => {
if(err) fs.mkdirSync(path.join(__dirname, sourcePath));
});

return 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!`)
})
})
18 changes: 0 additions & 18 deletions copy-resource.sh

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"preinstall": "cd ../../ && npm install --save-dev hexo-renderer-jade",
"test": "echo \"Error: no test specified\" && exit 1",
"copyresource": "copy-resource.sh",
"copyresource": "node copy-resource.js",
"postinstall": "npm run copyresource"
},
"keywords": [],
Expand All @@ -25,6 +25,7 @@
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"autoprefixer": "^9.4.4",
"fs-extra": "^7.0.1",
"node-sass": "^4.11.0",
"postcss": "^7.0.7",
"uglify-js": "^3.4.9"
Expand Down

0 comments on commit c3ce35e

Please sign in to comment.