Skip to content

Commit

Permalink
Some npm scripts for maintainance.
Browse files Browse the repository at this point in the history
* `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 OpenUserJS#249
  • Loading branch information
Martii committed Jun 16, 2018
1 parent 4697ab5 commit eabd000
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
39 changes: 39 additions & 0 deletions dev/clean.js
Original file line number Diff line number Diff line change
@@ -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/');


File renamed without changes.
2 changes: 1 addition & 1 deletion dev/preinit.js → dev/preinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit eabd000

Please sign in to comment.