Skip to content

Commit eabd000

Browse files
committed
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 OpenUserJS#249
1 parent 4697ab5 commit eabd000

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

dev/clean.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
// Define some pseudo module globals
4+
var isPro = require('../libs/debug').isPro;
5+
var isDev = require('../libs/debug').isDev;
6+
var isDbg = require('../libs/debug').isDbg;
7+
8+
//
9+
// NOTE: Only use native *node* `require`s in this file
10+
// since dependencies may not be installed yet
11+
//
12+
var fs = require('fs');
13+
14+
var rmFilesExceptHidden = function (dirPath) {
15+
var files = null;
16+
var filePath = null;
17+
var i = null;
18+
19+
try {
20+
files = fs.readdirSync(dirPath);
21+
} catch (aE) {
22+
console.warn(dirPath, 'path not found');
23+
return;
24+
}
25+
26+
if (files.length > 0) {
27+
for (i = 0; i < files.length; i++) {
28+
filePath = dirPath + '/' + files[i];
29+
if (fs.statSync(filePath).isFile() && files[i].indexOf('.') !== 0) {
30+
fs.unlinkSync(filePath);
31+
}
32+
}
33+
}
34+
};
35+
36+
console.log('Attempting to clean caches');
37+
rmFilesExceptHidden('./dev/cache/express-minify/release/');
38+
39+
File renamed without changes.

dev/preinit.js renamed to dev/preinstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ console.log('Attempting to delete `package-lock.json`');
1515
try {
1616
fs.unlinkSync('./package-lock.json');
1717
} catch (aE) {
18-
console.log('Nothing to delete');
18+
console.warn('`package-lock.json` not found');
1919
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383
"license": "(GPL-3.0 AND GFDL-1.3)",
8484
"scripts": {
8585
"start": "node app.js",
86-
"preinstall": "node dev/preinit.js",
87-
"postinstall": "node dev/postinit.js"
86+
"preinstall": "node dev/preinstall.js",
87+
"postinstall": "node dev/postinstall.js",
88+
"clean": "node dev/clean.js"
8889
},
8990
"engines": {
9091
"node": ">=8.9.0 <9.0.0",

0 commit comments

Comments
 (0)