Skip to content

Commit

Permalink
style: update scripts/ to follow the coding conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
sis0k0 committed Nov 3, 2016
1 parent 8c5dd0f commit 41a1097
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 58 deletions.
8 changes: 4 additions & 4 deletions scripts/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ copyFile("./nativescript-theme-core.json", "./nativescript-theme-core/package.js
// Copy our Post Install Script
copyFile("./scripts/postinstall.js", "./nativescript-theme-core/scripts/postinstall.js");

// Copy our Un-install
// Copy our Un-install
copyFile("./scripts/uninstall.js", "./nativescript-theme-core/scripts/uninstall.js");

// Copy our Readme
Expand Down Expand Up @@ -113,7 +113,7 @@ function copySCSS() {
fs.writeFileSync(out, scss, 'utf8');
} else {
fs.writeFileSync(out, fs.readFileSync(sassFiles[i]));
}
}
}
}

Expand All @@ -123,7 +123,7 @@ function copySCSS() {
* Create all the CSS from SCSS files
*/
function createCSSFromSCSS() {

var sassFilesPath = './app/**/*.scss';
var sassImportPaths = [
'./app/',
Expand Down Expand Up @@ -179,7 +179,7 @@ function parseSass(sassFile, importPaths) {
// console.log(css);
fs.writeFileSync(cssFilePath, css, 'utf8');

// if build stats are ever desired
// if build stats are ever desired
// console.log(result.stats);
}
});
Expand Down
18 changes: 8 additions & 10 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ if (hasSCSS) {
// -------------------------------------------------------

/**
* Checks whether a style sheet is imported in another sheet
* Checks whether a theme sheet is imported in another sheet
* @param sheetPath (string) - The main sheet
* @param themePath (string) - The sheet to check whether imported
* @param themeBasePath (string) - The base name of the theme
*/
function themeImported(sheetPath, themePath) {
function themeImported(sheetPath, themeBasePath) {
if (!fs.existsSync(sheetPath)) {
return false;
}

var cssData = fs.readFileSync(sheetPath).toString();
return cssData.indexOf(`@import '${themePath}`) !== -1 ||
cssData.indexOf(`@import "${themePath}`) !== -1;
return cssData.indexOf(`@import '${themeBasePath}`) !== -1 ||
cssData.indexOf(`@import "${themeBasePath}`) !== -1;
}

/**
Expand Down Expand Up @@ -152,20 +152,18 @@ function checkIfTNSBug() {
// Windows & Linux
var env = process.env["TMP"];
if (env && process.argv[1].indexOf(env) === 0) {
process.exit(0);
process.exit(0);
}

// Windows & Linux
env = process.env["TEMP"];
if (env && process.argv[1].indexOf(env) === 0) {
process.exit(0);
process.exit(0);
}

// Mac Directory
env = process.env["TMPDIR"];
if (env && (process.argv[1].indexOf(env) === 0 || process.argv[1].indexOf("/private"+env) === 0)) {
process.exit(0);
}


}
87 changes: 43 additions & 44 deletions scripts/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,22 @@ deleteFolder(cwd+"css", appDir+"css");

// Update our main app.css to delete the import the theme
if (fs.existsSync(appDir+"app.css")) {
var BOM='';
var cssData = fs.readFileSync(appDir + "app.css").toString();

// Search for only our themes
var idx = cssData.indexOf("@import '~/css/core.light.css';");
if (idx === -1) {
idx = cssData.indexOf("@import '~/css/core.dark.css';");
}


// Search for only our themes
var idx = cssData.indexOf("@import '~/css/core.light.css';");
if (idx === -1) {
idx = cssData.indexOf("@import '~/css/core.dark.css';");
}

if (idx !== -1) {
var idxOffset = cssData.indexOf(";", idx)+1;
if (idx === 0) {
cssData = cssData.substring(idxOffset, cssData.length);
} else {
cssData = cssData.substring(0, idx)+cssData.substring(idxOffset, cssData.length);
}
var idxOffset = cssData.indexOf(";", idx)+1;
if (idx === 0) {
cssData = cssData.substring(idxOffset, cssData.length);
} else {
cssData = cssData.substring(0, idx)+cssData.substring(idxOffset, cssData.length);
}
fs.writeFileSync(appDir + "app.css", cssData.trim());
}
}
Expand All @@ -69,19 +68,19 @@ deleteFolder(cwd+"fonts", appDir+"fonts");
// ------------------------------------------------------

if (hasSCSS) {
var extraFiles=["_bootstrap-map.scss", "core.dark.android.scss", "core.dark.ios.scss", "core.light.android.scss", "core.light.ios.scss"];
deleteFolder(cwd+"theme-core-scss", appDir+"theme-core-scss");
for (var i=0;i<extraFiles.length;i++) {
if (fs.existsSync(appDir+extraFiles[i])) {
try {
fs.unlinkSync(appDir+extraFiles[i]);
} catch (err) {
console.log("Unable to uninstall ", appDir + extraFiles[i]);
}
}
}
var extraFiles=["_bootstrap-map.scss", "core.dark.android.scss", "core.dark.ios.scss", "core.light.android.scss", "core.light.ios.scss"];
deleteFolder(cwd+"theme-core-scss", appDir+"theme-core-scss");

for (var i=0;i<extraFiles.length;i++) {
if (fs.existsSync(appDir+extraFiles[i])) {
try {
fs.unlinkSync(appDir+extraFiles[i]);
} catch (err) {
console.log("Unable to uninstall ", appDir + extraFiles[i]);
}
}
}

}


Expand All @@ -95,31 +94,31 @@ if (hasSCSS) {
* @param dest (string) - Destination folder
*/
function deleteFolder(src, dest) {

// No source/dest Folder exists, don't delete it!
if (!fs.existsSync(src)) { return false; }
if (!fs.existsSync(dest)) { return false; }
if (!fs.existsSync(dest)) { return false; }

var files = fs.readdirSync(src);
files.forEach(function(file){
var curPath = src + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // check to see if we need to recurse
deleteFolder(curPath, dest + "/" + file);
} else if (fs.existsSync(dest +"/"+file)) {
try {
fs.unlinkSync(dest+"/"+file);
} catch (err) {
console.log("Unable to uninstall ", dest+"/"+file);
}
}
try {
fs.unlinkSync(dest+"/"+file);
} catch (err) {
console.log("Unable to uninstall ", dest+"/"+file);
}
}
});
// Clear the folder, will fail if not empty
try {
fs.rmdirSync(dest);
} catch (err) {
console.log("Unable to delete: ", dest);
}

// Clear the folder, will fail if not empty
try {
fs.rmdirSync(dest);
} catch (err) {
console.log("Unable to delete: ", dest);
}

return true;
}

0 comments on commit 41a1097

Please sign in to comment.