crabatool 1.0.300 → 1.0.301

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.
package/index.js CHANGED
@@ -52,6 +52,16 @@ function checkFast(args) {
52
52
  return false;
53
53
  }
54
54
 
55
+ if (args.includes('-iconfont')) {
56
+ start.bindAndCheckConfig('-zipPath');
57
+ start.bindAndCheckConfig('-fontPath');
58
+ start.bindConfigByArgv('-prefix');
59
+ start.bindConfigByArgv('-fontName');
60
+
61
+ start.iconfont();
62
+ return false;
63
+ }
64
+
55
65
  // crabatool -update -webPath 项目路径 -version可选参数
56
66
  if (args.includes('-update')) {
57
67
  start.bindAndCheckConfig('-webPath');
package/lib/utils.js CHANGED
@@ -287,7 +287,7 @@ class Utils {
287
287
  next(); // 继续处理
288
288
  }
289
289
 
290
- // 清空整个目录,包括子目录和文件
290
+ // 删除文件夹,清空文件夹,删除目录,清空目录,清空整个目录,包括子目录和文件
291
291
  cleardirsSync(dirname) {
292
292
  if (!fs.existsSync(dirname)) return;
293
293
 
@@ -539,7 +539,9 @@ class Utils {
539
539
  unzip(zipPath, targetPath, cb, opts) {
540
540
  compressing.zip.uncompress(zipPath, targetPath, opts)
541
541
  .then(function done() {
542
- if (cb) cb(); // 解压完成
542
+ if (cb) {
543
+ cb(zipPath); // 解压完成
544
+ }
543
545
  })
544
546
  .catch(function err() {
545
547
  console.log(arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.300",
3
+ "version": "1.0.301",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,6 +17,8 @@
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
+ "biconfont": "node ./test/test.js -iconfont -zipPath F:\\crabaevery\\www\\biconfont -fontPath F:\\crabaevery\\www\\skins\\bicon -prefix .bicon- -fontName biconfont",
21
+ "aiconfont": "node ./test/test.js -iconfont -zipPath F:\\crabaevery\\www\\iconfont -fontPath F:\\CarpaNET_NEW\\src\\Carpa.Web\\skins -prefix .aicon- -fontName iconfont",
20
22
  "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
23
  "makeHash2": "node run.js -makeHash -webPath ./test/ -modName craba -files ./test/ -exts .js -outJson ./hash2.json -hashName sha384"
22
24
  },
@@ -0,0 +1,130 @@
1
+ var utils = require('../lib/utils.js');
2
+ var config = require('../lib/config.js');
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+
6
+ module.exports.start = async function() {
7
+ if (!config.zipPath) {
8
+ console.log('缺少zipPath路径')
9
+ return;
10
+ }
11
+
12
+ var zipName = "";
13
+ var files = fs.readdirSync(config.zipPath);
14
+ for (var i = 0; i < files.length; i++) {
15
+ var fname = files[i];
16
+ var ext = path.extname(fname);
17
+ if (ext == '.zip') {
18
+ zipName = fname;
19
+ break;
20
+ }
21
+ }
22
+ if (!zipName) {
23
+ console.log('字体库文件不存在,操作无效。');
24
+ return;
25
+ }
26
+ var zipUrl = path.join(config.zipPath, zipName);
27
+
28
+ if (!fs.existsSync(zipUrl)) {
29
+ console.log(zipUrl + '文件不存在,操作无效。');
30
+ return;
31
+ }
32
+
33
+ if (!config.prefix) {
34
+ config.prefix = '.bicon-';
35
+ }
36
+ if (!config.fontName) {
37
+ config.fontName = 'biconfont';
38
+ }
39
+
40
+ zipLoaded(zipUrl);
41
+ }
42
+
43
+ function zipLoaded(zipUrl) {
44
+ if (!fs.existsSync(zipUrl)) {// 检查文件
45
+ console.log(":::服务不可用,拉取字体文件失败:::");
46
+ return;
47
+ }
48
+
49
+ utils.unzip(zipUrl, config.zipPath, zipOk);
50
+ }
51
+
52
+ function zipOk(zipUrl) {
53
+ var zipFolder = "";
54
+ var files = fs.readdirSync(config.zipPath);
55
+ for (var i = 0; i < files.length; i++) {
56
+ var fname = files[i];
57
+ var fname2 = path.join(config.zipPath, fname);
58
+ var stat = fs.statSync(fname2);
59
+ if (stat.isDirectory()) {
60
+ zipFolder = fname;
61
+ break;
62
+ }
63
+ }
64
+ var target = path.join(config.zipPath, zipFolder);
65
+
66
+
67
+ // 拷贝到bicon目录
68
+ utils.copyFiles(target, config.zipPath, null, utils.createDelegate(this, function(fileName) {
69
+ utils.debug('拷贝文件', fileName);
70
+ }));
71
+
72
+ // 删除解压后的文件夹
73
+ utils.cleardirsSync(target);
74
+ fs.unlinkSync(zipUrl);
75
+
76
+ var ignores = ["读我.txt", "font.zip", "iconfont.css", "demo_index.html", "demo.css", "iconfont.json", "iconfont.woff2", "iconfont.js"];
77
+ // 从bicon下面拷贝文件到skins\bicon下面
78
+ utils.copyFiles(config.zipPath, config.fontPath, ignores, utils.createDelegate(this, function(fileName) {
79
+ utils.debug('拷贝文件', fileName);
80
+ }));
81
+
82
+ // 读取zip里面的css
83
+ var cssPath = path.join(config.zipPath, 'iconfont.css');
84
+ var css = fs.readFileSync(cssPath).toString();
85
+
86
+ // 读取模板css
87
+ var css2 = `
88
+ @font-face {
89
+ font-family: "{fontName}";
90
+ src: url("iconfont.eot?t={t}");
91
+ src: url("iconfont.eot?t={t}#iefix") format('embedded-opentype'),
92
+ {url},
93
+ url("iconfont.woff?t={t}") format('woff'),
94
+ url("iconfont.ttf?t={t}") format('truetype'),
95
+ url("iconfont.svg?t={t}#{fontName}") format('svg');
96
+ }
97
+
98
+ .{fontName} {
99
+ font-family: "{fontName}" !important;
100
+ font-size: 16px;
101
+ font-style: normal;
102
+ -webkit-font-smoothing: antialiased;
103
+ -moz-osx-font-smoothing: grayscale;
104
+ }
105
+
106
+ {css}`;
107
+
108
+ // 替换图标css集合
109
+ var index = css.indexOf(config.prefix);
110
+ if (index > -1) {
111
+ var content = css.substring(index);
112
+ css2 = css2.replace('{css}', content);
113
+ }
114
+
115
+ // 替换woff2的二进制流
116
+ var r = new RegExp(/url\('data:.*'\)/);
117
+ var r0 = css.match(r);
118
+ if (r0 && r0.length > 0) {
119
+ css2 = css2.replace('{url}', r0[0]);
120
+ }
121
+
122
+ // 替换时间戳
123
+ css2 = css2.replace(/\{t\}/ig, new Date().getTime());
124
+
125
+ // 替换时间戳
126
+ css2 = css2.replace(/\{fontName\}/ig, config.fontName);
127
+
128
+ // 将新内容写到bion/iconfont.css下面
129
+ fs.writeFileSync(path.join(config.fontPath, 'iconfont.css'), css2);
130
+ }
package/tool/start.js CHANGED
@@ -233,6 +233,11 @@ class Start {
233
233
  }
234
234
  }
235
235
 
236
+ // 校验项目js语法
237
+ iconfont() {
238
+ require('./iconfont.js').start();
239
+ }
240
+
236
241
  // 校验项目js语法
237
242
  checkAllJs() {
238
243
  start.checkWebPath(); // 兼容老平台