From a93d343511b9a6c9fa17251aa440c6972fc3c50d Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Fri, 28 Oct 2016 10:50:58 -0500 Subject: [PATCH] Uninstall (#100) * Created uninstall script * Updated json file to call uninstall script --- nativescript-theme-core.json | 3 +- scripts/builder.js | 3 + scripts/uninstall.js | 125 +++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 scripts/uninstall.js diff --git a/nativescript-theme-core.json b/nativescript-theme-core.json index 5e347e2..d100c44 100644 --- a/nativescript-theme-core.json +++ b/nativescript-theme-core.json @@ -10,6 +10,7 @@ "url": "https://github.com/NativeScript/theme" }, "scripts": { - "postinstall": "node scripts/postinstall.js" + "postinstall": "node scripts/postinstall.js", + "uninstall": "node scripts/uninstall.js" } } diff --git a/scripts/builder.js b/scripts/builder.js index cc097f4..c6b9b84 100644 --- a/scripts/builder.js +++ b/scripts/builder.js @@ -38,6 +38,9 @@ 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 +copyFile("./scripts/uninstall.js", "./nativescript-theme-core/scripts/uninstall.js"); + // Copy our Readme copyFile("./nativescript-theme-core.md", "./nativescript-theme-core/readme.md"); diff --git a/scripts/uninstall.js b/scripts/uninstall.js new file mode 100644 index 0000000..7241379 --- /dev/null +++ b/scripts/uninstall.js @@ -0,0 +1,125 @@ +/************************************************************************************* + * Licensed under the APACHE license + * + * Version 0.0.1 Nathan@master-technology.com + ************************************************************************************/ +"use strict"; + +// Simple require statements, built into node +var fs = require('fs'); +var path = require('path'); +var os = require('os'); + +// Do we have detect SCSS support +var hasSCSS = false; + +// Get our Paths +var cwd = process.cwd() + '/'; +var primaryDir = path.normalize(cwd+"../../"); +var appDir = primaryDir + 'app/'; + +// Test for has SCSS support +try { + var data = require(primaryDir + "package.json"); + + if (data && (data.devDependencies && data.devDependencies['nativescript-dev-sass']) || (data.dependencies && data.dependencies['nativescript-dev-sass']) ) { + hasSCSS = true; + } +} catch (err) { + hasSCSS = false; +} + + +// ------------------------------------------------------ +// Handle the CSS files +// ------------------------------------------------------ + +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';"); + } + + 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); + } + fs.writeFileSync(appDir + "app.css", cssData.trim()); + } +} + +// ------------------------------------------------------ +// Handle the font files +// ------------------------------------------------------ +deleteFolder(cwd+"fonts", appDir+"fonts"); + +// ------------------------------------------------------ +// Handle the SCSS files +// ------------------------------------------------------ + +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