crabatool 1.0.52 → 1.0.55

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
@@ -74,7 +74,7 @@ function checkConfig() {
74
74
 
75
75
  // 支持相对路径
76
76
  if (!path.isAbsolute(config.webPath)) {
77
- config.webPath = path.join(process.cwd(), config.webPath);
77
+ config.webPath = utils.join(process.cwd(), config.webPath);
78
78
  console.log('webPath转换为绝对路径:', config.webPath);
79
79
  }
80
80
 
@@ -82,7 +82,7 @@ function checkConfig() {
82
82
  throw new Error(`请检查craba.js,配置的webPath路径不存在,请检查拼写是否正确:${config.webPath}`);;
83
83
  }
84
84
 
85
- var crabaJs = path.join(config.webPath, 'js/craba.min.js');
85
+ var crabaJs = utils.join(config.webPath, 'js/craba.min.js');
86
86
  if (!fs.existsSync(crabaJs)) {
87
87
  throw new Error('请检查craba.js,平台前端组件不存在,请检查指定的webPath路径是否为craba前端框架的根目录。' + crabaJs);
88
88
  }
package/lib/utils.js CHANGED
@@ -242,7 +242,7 @@ class Utils {
242
242
  if (!fs.existsSync(dirname)) return;
243
243
 
244
244
  fs.readdirSync(dirname).forEach(function(file) {
245
- var filePath = path.join(dirname, file);
245
+ var filePath = utils.join(dirname, file);
246
246
  if (fs.statSync(filePath).isDirectory()) {
247
247
  //递归读取文件
248
248
  utils.cleardirsSync(filePath);
@@ -340,12 +340,12 @@ class Utils {
340
340
  return next();
341
341
  }
342
342
 
343
- var crabaJs = path.join(config.webPath, 'js/craba.min.js');
343
+ var crabaJs = utils.join(config.webPath, 'js/craba.min.js');
344
344
  if (!fs.existsSync(crabaJs)) {
345
345
  throw new Error('平台前端组件不存在,请检查:' + crabaJs);
346
346
  }
347
347
 
348
- var clientSocketJs = path.join(__dirname, '../tool/client.js');
348
+ var clientSocketJs = utils.join(__dirname, '../tool/client.js');
349
349
  var content = fs.readFileSync(crabaJs).toString();
350
350
 
351
351
  var clientContent = fs.readFileSync(clientSocketJs).toString();
@@ -363,15 +363,14 @@ class Utils {
363
363
  var source = options.source;
364
364
  if (options.ignores && !fileList) {
365
365
  options.ignores = options.ignores.map((item) => {
366
- item = item.replace(/\\/g, path.sep).replace(/\//g, path.sep);
367
- return path.join(source, item);
366
+ return utils.join(source, item);
368
367
  });
369
368
  }
370
369
 
371
370
  if (!fileList) fileList = [];
372
371
  var files = fs.readdirSync(source);
373
372
  files.forEach(function(fileName) {
374
- var filePath = path.join(source, fileName);
373
+ var filePath = utils.join(source, fileName);
375
374
  if (options.ignores && options.ignores.includes(filePath)) {
376
375
  return;
377
376
  }
@@ -393,11 +392,9 @@ class Utils {
393
392
 
394
393
  copyFiles(source, dest, ignores, cb) {
395
394
  var files = utils.getFiles({ source: source, ignores: ignores });
396
- files.forEach(function(fileName) {
397
- fileName = fileName.replace(source, ''); // 去掉根路径
398
-
399
- var filePath = path.join(source, fileName);
400
- var destPath = path.join(dest, fileName);
395
+ files.forEach(function(filePath) {
396
+ var fileName = filePath.replace(source.source, ''); // 去掉根路径
397
+ var destPath = utils.join(dest, fileName);
401
398
 
402
399
  utils.mkdirsSync(destPath);
403
400
 
@@ -425,6 +422,12 @@ class Utils {
425
422
  require('child_process').exec(cmd);
426
423
  }
427
424
  }
425
+
426
+ join() {
427
+ var p = path.join.apply(path, arguments);
428
+ p = p.replace(/\\/g, path.sep).replace(/\//g, path.sep); // 兼容windows和linux,当前操作系统
429
+ return p;
430
+ }
428
431
  }
429
432
  var utils = new Utils();
430
433
  module = module.exports = utils;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.52",
3
+ "version": "1.0.55",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/test.js CHANGED
@@ -9,7 +9,7 @@ var crabaTool = require('../index.js'); // 引入craba脚手架工具包
9
9
  var config = {
10
10
  //【必填】
11
11
  // 告诉工具当前项目的端路径地址,填绝对路径哦
12
- webPath: "../web/src/main/resources/static/shell",
12
+ webPath: "F:/shell_master/web/src/main/resources/static/shell",
13
13
 
14
14
  //【必填】
15
15
  // 告诉工具当前项目前端服务器端口地址
package/tool/merge.js CHANGED
@@ -38,7 +38,7 @@ function readFileList(folder, filesList) {
38
38
 
39
39
  var files = fs.readdirSync(folder);
40
40
  files.forEach(function(itm, index) {
41
- var file = path.join(folder, itm);
41
+ var file = utils.join(folder, itm);
42
42
  var stat = fs.statSync(file);
43
43
  if (stat.isDirectory()) {
44
44
  //递归读取文件
@@ -91,7 +91,7 @@ function getAbsPath(filePath) {
91
91
  if (npath.isAbsolute(filePath)) return filePath;
92
92
 
93
93
  filePath = npath.relative(__dirname, filePath);
94
- return npath.join(__dirname, filePath);
94
+ return nutils.join(__dirname, filePath);
95
95
  }
96
96
 
97
97
  function replaceBlackFunction(content) {
package/tool/ngptool.js CHANGED
@@ -5,12 +5,12 @@ var fs = require('fs');
5
5
  var fork = require('child_process').fork;
6
6
  var utils = require('../lib/utils.js');
7
7
 
8
- var mergeJs = path.join(__dirname, 'merge.js');
8
+ var mergeJs = utils.join(__dirname, 'merge.js');
9
9
  var compressArgs = config.ignoreCompress ? ['-ignorecompress'] : []; // 是否压缩
10
10
 
11
11
  // 打包biz.js
12
12
  function mergeBiz() {
13
- var bizPath = path.join(config.webPath, '/js/biz');
13
+ var bizPath = utils.join(config.webPath, '/js/biz');
14
14
  if (!fs.existsSync(bizPath)) {
15
15
  return utils.error('error biz.js关联打包的路径不存在,已经取消打包功能。如需打包请先创建目录:' + bizPath);
16
16
  }
@@ -23,7 +23,7 @@ function mergeBiz() {
23
23
  var watchAction = function() {
24
24
  utils.debug('打包中');
25
25
  // 这里进行文件更改后的操作
26
- var p = fork(mergeJs, [`${[bizPath]}`, `${[path.join(config.webPath, '/js/biz.js')]}`, compressArgs])
26
+ var p = fork(mergeJs, [`${[bizPath]}`, `${[utils.join(config.webPath, '/js/biz.js')]}`, compressArgs])
27
27
  p.on('exit', code => {
28
28
  utils.debug('打包完成');
29
29
  });
@@ -42,7 +42,7 @@ function mergeBiz() {
42
42
 
43
43
  // 打包生成jxc/js/init.js
44
44
  function mergeInit() {
45
- var modJs = path.join(config.webPath, '/js/' + config.modName + '.js'); // jxc/js/jxc.js
45
+ var modJs = utils.join(config.webPath, '/js/' + config.modName + '.js'); // jxc/js/jxc.js
46
46
  if (!fs.existsSync(modJs)) {
47
47
  return utils.error(`error 模块对应的资源不存在:${modJs},已经取消打包功能。如需打包,请先将${config.modName}/js/init.js修改为:${config.modName}/js/${config.modName}.js`);
48
48
  }
@@ -53,7 +53,7 @@ function mergeInit() {
53
53
  var watchAction = function() {
54
54
  utils.debug('打包中');
55
55
  // 这里进行文件更改后的操作
56
- var p = fork(mergeJs, [`${[inits]}`, `${[path.join(config.webPath, '/js/init.js')]}`, compressArgs])
56
+ var p = fork(mergeJs, [`${[inits]}`, `${[utils.join(config.webPath, '/js/init.js')]}`, compressArgs])
57
57
  p.on('exit', code => {
58
58
  utils.debug('打包完成');
59
59
  });
@@ -78,7 +78,7 @@ function mergeInit() {
78
78
  watchJs(modJs);
79
79
 
80
80
  config.childModList.forEach(childName => {
81
- var childInitPath = path.join(config.webPath, childName, 'js/init.js');
81
+ var childInitPath = utils.join(config.webPath, childName, 'js/init.js');
82
82
  inits.push(childInitPath);
83
83
  //utils.mkdirsSync(childInitPath);
84
84
  if (!fs.existsSync(childInitPath)) {
package/tool/upgrade.js CHANGED
@@ -28,7 +28,7 @@ class Upgrade {
28
28
 
29
29
  getLocalVersion() {
30
30
  // 获取本地craba平台版本
31
- var crabaJs = path.join(config.webPath, 'js/craba.min.js');
31
+ var crabaJs = utils.join(config.webPath, 'js/craba.min.js');
32
32
  var content = fs.readFileSync(crabaJs).toString();
33
33
 
34
34
  var m = content.match(new RegExp("crabaVersion = \\S*;"));
@@ -83,10 +83,10 @@ class Upgrade {
83
83
 
84
84
  var projectPath = "";
85
85
  if (options.type == 1) {
86
- projectPath = path.join(options.projectPath, 'www');
86
+ projectPath = utils.join(options.projectPath, 'www');
87
87
  } else if (options.type == 2) {
88
88
  projectPath = `${options.modName}/web/src/main/resources/static/${options.modName}`;
89
- projectPath = path.join(options.projectPath, projectPath);
89
+ projectPath = utils.join(options.projectPath, projectPath);
90
90
  projectPath = projectPath;
91
91
  }
92
92
 
@@ -113,7 +113,7 @@ class Upgrade {
113
113
 
114
114
  _createDone() {
115
115
  // 拷贝server文件
116
- utils.copyFiles(config.ServerPath, path.join(this.options.projectPath, this.serverFolder), null, utils.createDelegate(this, function(fileName) {
116
+ utils.copyFiles(config.ServerPath, utils.join(this.options.projectPath, this.serverFolder), null, utils.createDelegate(this, function(fileName) {
117
117
  this.pb.render({ value: ++this.pb.value, text: fileName });
118
118
  }));
119
119
 
@@ -124,7 +124,7 @@ class Upgrade {
124
124
  }));
125
125
  } else {
126
126
  var that = this;
127
- utils.copyFiles(path.join(config.WebPath, 'ngp'), this.projectPath, null, utils.createDelegate(this, function(fileName, bytes) {
127
+ utils.copyFiles(utils.join(config.WebPath, 'ngp'), this.projectPath, null, utils.createDelegate(this, function(fileName, bytes) {
128
128
  this.pb.render({ value: ++this.pb.value, text: fileName });
129
129
  return bytes.toString().replaceAll('${modName}', that.options.modName);
130
130
  }));
@@ -135,11 +135,11 @@ class Upgrade {
135
135
 
136
136
  this._updateDone();
137
137
 
138
- console.log('项目创建完成,请切换到新项目下继续操作。' + path.join(this.options.projectPath, this.serverFolder));
138
+ console.log('项目创建完成,请切换到新项目下继续操作。' + utils.join(this.options.projectPath, this.serverFolder));
139
139
  }
140
140
 
141
141
  _rewriteNode() {
142
- var nodeJs = path.join(path.join(this.options.projectPath, this.serverFolder), 'craba.js');
142
+ var nodeJs = utils.join(utils.join(this.options.projectPath, this.serverFolder), 'craba.js');
143
143
  var content = fs.readFileSync(nodeJs).toString();
144
144
  content = content.replace('${webPath}', this.projectPath.replaceAll('\\', '/'));
145
145
  content = content.replace('${port}', (10000 + parseInt(Math.random() * 1000)));