From eabd00021675eeb51765fdbb93322adc5a8eb81b Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 16 Jun 2018 03:28:46 -0600 Subject: [PATCH] Some npm scripts for maintainance. * `npm run clean` ... clears the caches. This is usually done when *uglify-* *(at some point terser)* needs a refreshing after a dep update *(and what I usually get to do by hand for the last few years)* * Renamed existing scripts to match their counterpart names e.g. * `npm run preinstall` ... will get rid of that pesky `package-lock.json` when needed and is run on `npm install` always * `npm run postinstall`... well probably shouldn't run this directly at all but it's there none-the-less NOTE: * Most of these are meant to be very simple scripts. I'd use direct commands but then Windows users would be left out of the mix... so utilizing *node* native APIs Applies to #249 --- dev/clean.js | 39 +++++++++++++++++++++++++++++ dev/{postinit.js => postinstall.js} | 0 dev/{preinit.js => preinstall.js} | 2 +- package.json | 5 ++-- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 dev/clean.js rename dev/{postinit.js => postinstall.js} (100%) rename dev/{preinit.js => preinstall.js} (90%) diff --git a/dev/clean.js b/dev/clean.js new file mode 100644 index 000000000..224e09d75 --- /dev/null +++ b/dev/clean.js @@ -0,0 +1,39 @@ +'use strict'; + +// Define some pseudo module globals +var isPro = require('../libs/debug').isPro; +var isDev = require('../libs/debug').isDev; +var isDbg = require('../libs/debug').isDbg; + +// +// NOTE: Only use native *node* `require`s in this file +// since dependencies may not be installed yet +// +var fs = require('fs'); + +var rmFilesExceptHidden = function (dirPath) { + var files = null; + var filePath = null; + var i = null; + + try { + files = fs.readdirSync(dirPath); + } catch (aE) { + console.warn(dirPath, 'path not found'); + return; + } + + if (files.length > 0) { + for (i = 0; i < files.length; i++) { + filePath = dirPath + '/' + files[i]; + if (fs.statSync(filePath).isFile() && files[i].indexOf('.') !== 0) { + fs.unlinkSync(filePath); + } + } + } +}; + +console.log('Attempting to clean caches'); +rmFilesExceptHidden('./dev/cache/express-minify/release/'); + + diff --git a/dev/postinit.js b/dev/postinstall.js similarity index 100% rename from dev/postinit.js rename to dev/postinstall.js diff --git a/dev/preinit.js b/dev/preinstall.js similarity index 90% rename from dev/preinit.js rename to dev/preinstall.js index 0aac40f29..2f73abefd 100644 --- a/dev/preinit.js +++ b/dev/preinstall.js @@ -15,5 +15,5 @@ console.log('Attempting to delete `package-lock.json`'); try { fs.unlinkSync('./package-lock.json'); } catch (aE) { - console.log('Nothing to delete'); + console.warn('`package-lock.json` not found'); } diff --git a/package.json b/package.json index 00960e318..93015d569 100644 --- a/package.json +++ b/package.json @@ -83,8 +83,9 @@ "license": "(GPL-3.0 AND GFDL-1.3)", "scripts": { "start": "node app.js", - "preinstall": "node dev/preinit.js", - "postinstall": "node dev/postinit.js" + "preinstall": "node dev/preinstall.js", + "postinstall": "node dev/postinstall.js", + "clean": "node dev/clean.js" }, "engines": { "node": ">=8.9.0 <9.0.0",