crabatool 1.0.282 → 1.0.284

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/tool/hash.js +20 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.282",
3
+ "version": "1.0.284",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "upload": "node run.js -upload -version master -Debug true -host http://127.0.0.1:9998 -hidejspath true -targetPath F:\\CarpaNET_NEW",
18
18
  "crabaNgp": "node run.js -mergejs -hidejspath true -targetPath F:\\CarpaNET_NEW\\src\\Carpa.Web\\js\\crabaNgp -inNames initMs.js,businessControl.js -outName F:\\CarpaMS\\src\\js\\crabaNgp.js",
19
19
  "webPath": "node ./test/test.js -checkjs -webhooks 0 -webPath F:\\crabaevery\\www -modName crabaevery",
20
- "makeHash": "node run.js -makeHash -files http://crabadoc.ca.com/js/utils/utils.js,F:/newcrabadoc/www/js/utils/utils.js,./test/test.js,./test/beefun.js,https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js?a=1 -outJson ./hash.json"
20
+ "makeHash": "node run.js -makeHash -webPath ./test/ -modName craba -files http://crabadoc.ca.com/js/utils/utils.js,F:/newcrabadoc/www/js/utils/utils.js,./test/test.js,./test/beefun.js,https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js?a=1 -outJson ./hash.json -hashName sha384"
21
21
  },
22
22
  "author": "wssf",
23
23
  "dependencies": {
package/tool/hash.js CHANGED
@@ -9,13 +9,18 @@ var requestSync = require('sync-request');
9
9
 
10
10
 
11
11
  module.exports.start = function() {
12
+ if (!config.hashName) {
13
+ config.hashName = 'sha384';
14
+ }
15
+
12
16
  var hash = {};
13
17
  var files = config.files.split(',');
14
18
  files.forEach(function(f) {
15
19
 
16
20
  console.log(f);
17
21
  var content;
18
- if (f.startsWith('http')) {
22
+ var isHttp = f.startsWith('http');
23
+ if (isHttp) {
19
24
  var res = requestSync("GET", f);
20
25
  content = res.getBody();
21
26
  } else if (fs.existsSync(f)) {
@@ -30,25 +35,29 @@ module.exports.start = function() {
30
35
  f = f.substr(0, index);
31
36
  }
32
37
 
38
+ // 转为相对webPath的路径
39
+ if (!isHttp) {
40
+ f = path.resolve(f);
41
+ f = f.replace(config.webPath, '');
42
+ if (config.modName) {
43
+ f = path.join(config.modName, f);
44
+ }
45
+ f = f.replace('\\', '/');
46
+ }
47
+
33
48
  // SRI Hash Generator
34
49
  // https://www.srihash.org/
35
50
 
36
- var hex = sha384(content); // 将文件内容进行hash计算
37
- hash[f] = 'sha384-' + hex; // 使用 base64 编码 sha384 算法计算出摘要后的 integrity 值的示例
51
+ var base64 = makeHash(content, config.hashName); // 将文件内容进行hash计算
52
+ hash[f] = config.hashName + '-' + base64; // 使用 base64 编码 sha384 算法计算出摘要后的 integrity 值的示例
38
53
  });
39
54
 
40
55
  utils.mkdirsSync(config.outJson);
41
56
  fs.writeFileSync(config.outJson, JSON.stringify(hash));
42
57
  }
43
58
 
44
- function sha256(str) {
45
- const hash = crypto.createHash('sha256');
46
- hash.update(str);
47
- return hash.digest('base64');
48
- }
49
-
50
- function sha384(str) {
51
- const hash = crypto.createHash('sha384');
59
+ function makeHash(str, name) {
60
+ const hash = crypto.createHash(name);
52
61
  hash.update(str);
53
62
  return hash.digest('base64');
54
63
  }