Skip to content

Commit 5cd2ea2

Browse files
Nathanael AndersonNathanWalker
authored andcommitted
Bom & fonts folder fixes (#62)
* Strip BOM on read of css and re-add BOM on save. * Check to see if source folder exists (primarily because no fonts folder yet)
1 parent 3f6167e commit 5cd2ea2

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

scripts/postinstall.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*************************************************************************************
22
* Licensed under the APACHE license
33
*
4-
* Version 0.0.1 Nathan@master-technology.com
4+
* Version 0.0.3 Nathan@master-technology.com
55
************************************************************************************/
66
"use strict";
77

@@ -39,17 +39,30 @@ copyFolder(cwd+"css", appDir+"css");
3939

4040
// Update our main app.css to import the light theme
4141
if (fs.existsSync(appDir+"app.css")) {
42+
var BOM='';
4243
var cssData = fs.readFileSync(appDir + "app.css").toString();
44+
45+
// Strip the BOM at the beginning of the file
46+
if (cssData.charCodeAt(0) === 0xFEFF) {
47+
// Newer NodeJS
48+
BOM = String.fromCharCode(0xFEFF);
49+
cssData = cssData.slice(1);
50+
} else if (cssData[0] === 0xEF && cssData[1] === 0xBB && cssData[2] === 0xBF) {
51+
// Older NodeJS
52+
BOM = String.fromCharCode(0xEF) + String.fromCharCode(0xBB) + String.fromCharCode(0xBF);
53+
cssData = cssData.slice(3);
54+
}
55+
4356
if (cssData.indexOf("@import '~/css/core.") === -1) {
44-
cssData = "@import '~/css/core.light.css'; \r\n\r\n" + cssData;
57+
cssData = BOM + "@import '~/css/core.light.css'; \r\n\r\n" + cssData;
4558
fs.writeFileSync(appDir + "app.css", cssData);
4659
}
4760
}
4861

4962
// ------------------------------------------------------
5063
// Handle the FONTS files
5164
// ------------------------------------------------------
52-
copyFolder(cwd+"fonts", appDir+"fonts");
65+
copyFolder(cwd + "fonts", appDir + "fonts");
5366

5467
// ------------------------------------------------------
5568
// Handle the SCSS files
@@ -72,19 +85,19 @@ if (hasSCSS) {
7285
* @param dest (string) - Destination folder
7386
*/
7487
function copyFolder(src, dest) {
75-
try {
88+
// No source Folder exists, can't copy it!
89+
if (!fs.existsSync(src)) { return false; }
90+
7691
var files = fs.readdirSync(src);
77-
files.forEach(function (file) {
78-
var curPath = src + "/" + file;
79-
if (fs.lstatSync(curPath).isDirectory()) { // check to see if we need to recurse
80-
copyFolder(curPath, dest + "/" + file);
81-
} else { // copy file
82-
copyFile(src, dest, file);
83-
}
92+
files.forEach(function(file){
93+
var curPath = src + "/" + file;
94+
if(fs.lstatSync(curPath).isDirectory()) { // check to see if we need to recurse
95+
copyFolder(curPath, dest + "/" + file);
96+
} else { // copy file
97+
copyFile(src, dest, file);
98+
}
8499
});
85-
} catch (err) {
86-
console.log('Skipping ' + src + ' copy.');
87-
}
100+
return true;
88101
}
89102

90103
/**

0 commit comments

Comments
 (0)