-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.js
executable file
·57 lines (45 loc) · 1.44 KB
/
clean.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
/**
* 清除缓存
* @usage:
* // 入口在根目录
* node clean.js -p '/Users/yayu.wang/hotelrn'
* // 入口在其他目录
* node clean.js -p '/Users/yayu.wang/hotelrn' -e './example/test'
* // 如果你在 hotelrn 目录下,可以不加参数 -p(-e 如有需要不可省)
* node clean.js
*/
let optimist = require('optimist');
let sysPath = require('path');
let fs = require('fs');
let crypto = require('crypto');
let os = require('os');
let projectRoots = [];
let cacheVersion = '3';
if (optimist.argv.p) {
projectRoots[0] = optimist.argv.p;
} else {
projectRoots[0] = __dirname;
}
if (optimist.argv.e) {
projectRoots[1] = sysPath.join(projectRoots[0], optimist.argv.e);
}
let rnVersion = require(sysPath.join(projectRoots[0], './node_modules/react-native/package.json')).version;
let pathKey = projectRoots.join(',').split(sysPath.sep).join('-');
let mtime;
try {
mtime = fs.statSync(sysPath.join(projectRoots[0], './node_modules/react-native/packager/transformer.js')).mtime;
mtime = String(mtime.getTime());
} catch (error) {
mtime = '';
}
let cacheKey = ['react-packager-cache', rnVersion, cacheVersion, pathKey, mtime].join('$');
let hash = crypto.createHash('md5');
hash.update(cacheKey);
let cacheFilePath = sysPath.join(os.tmpdir(), hash.digest('hex'));
console.log('try to delete cache file: ' + cacheFilePath);
try {
fs.unlinkSync(cacheFilePath);
} catch(e) {
console.log('no file')
}