crabatool 1.0.40 → 1.0.43

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 (3) hide show
  1. package/index.js +26 -23
  2. package/package.json +1 -1
  3. package/tool/ngptool.js +12 -5
package/index.js CHANGED
@@ -81,21 +81,36 @@ function checkConfig() {
81
81
  }
82
82
 
83
83
 
84
+ async function waitFolder(question) {
85
+ const projectPath = await question('请输入项目生成路径(必须为空路径):');
86
+ if (!path.isAbsolute(projectPath)) {
87
+ console.log('路径不合法,请输入绝对路径,如:f:\\craba_web');
88
+ return waitFolder(question);
89
+ }
90
+ if (fs.existsSync(projectPath)) {
91
+ if (fs.readdirSync(projectPath).length > 0) {
92
+ console.log(':::输入的项目路径不为空,避免文件覆盖或冲突,请重新输入一个空路径或不存在的路径:::');
93
+ return waitFolder(question);
94
+ }
95
+ }
96
+ return projectPath;
97
+ }
98
+
99
+ function rlPromisify(fn) {
100
+ return async function(t) {
101
+ return new Promise(function(resolve) { fn(t, resolve) });
102
+ };
103
+ }
104
+
84
105
  function waitInput() {
85
106
  const rl = readline.createInterface({
86
107
  input: process.stdin,
87
108
  output: process.stdout
88
109
  });
89
110
 
90
- function rlPromisify(fn) {
91
- return async (t) => {
92
- return new Promise(resolve => fn(t, resolve));
93
- };
94
- }
95
-
96
111
  const question = rlPromisify(rl.question.bind(rl));
97
112
 
98
- (async () => {
113
+ (async function() {
99
114
  var ques = [
100
115
  "1. 启动服务。\t\t\t\t主要包含:自动合并打包init.js和biz.js,查看本地平台的版本",
101
116
  "2. 更新当前项目的平台,然后启动服务。\t主要包含:从<内网>拉取环境相关资源,再拷贝到webPath路径下覆盖老文件,替代手工操作,同时解决npm不稳定问题",
@@ -133,7 +148,7 @@ function waitInput() {
133
148
  installvscode();
134
149
  } else if (num == 8) {
135
150
  var options = {};
136
- options.projectPath = await waitFolder();
151
+ options.projectPath = await waitFolder(question);
137
152
  options.type = await question('选择项目类型:1. 普通craba项目; 2. ngp微前端项目; 输入编号:');
138
153
  if (options.type != 1 && options.type != 2) options.type = 1;
139
154
  if (options.type == 2) {
@@ -146,21 +161,6 @@ function waitInput() {
146
161
  console.error('无效输入,请继续。\r\n\r\n');
147
162
  waitInput(); // 重复
148
163
  }
149
-
150
- async function waitFolder() {
151
- const projectPath = await question('请输入项目生成路径(必须为空路径):');
152
- if (!path.isAbsolute(projectPath)) {
153
- console.log('路径不合法,请输入绝对路径,如:f:\\craba_web');
154
- return waitFolder();
155
- }
156
- if (fs.existsSync(projectPath)) {
157
- if (fs.readdirSync(projectPath).length > 0) {
158
- console.log(':::输入的项目路径不为空,避免文件覆盖或冲突,请重新输入一个空路径或不存在的路径:::');
159
- return waitFolder();
160
- }
161
- }
162
- return projectPath;
163
- }
164
164
  })();
165
165
  }
166
166
 
@@ -200,7 +200,10 @@ function installvscode() {
200
200
 
201
201
  function mergeInit() {
202
202
  if (config.modName && config.childModList && config.childModList.length > 0) {
203
+ config.mergeinitjs = true; // 标记仅打包,不监视文件变动
203
204
  require('../tool/ngptool.js');
205
+ } else {
206
+ console.log('mergeinitjs缺少其他相关参数配置,因此不会执行打包init.js操作')
204
207
  }
205
208
  }
206
209
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.40",
3
+ "version": "1.0.43",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tool/ngptool.js CHANGED
@@ -28,12 +28,15 @@ function mergeBiz() {
28
28
  utils.debug('打包完成');
29
29
  });
30
30
  }
31
- watcher
32
- .on('ready', () => utils.debug(`${bizPath},Initial scan complete. Ready for changes.`))
33
- //.on('add', path => log(`File ${path} has been added`))
34
- .on('change', path => watchAction({ event: 'change', eventPath: path }))
35
- .on('unlink', path => watchAction({ event: 'remove', eventPath: path }));
36
31
 
32
+ // 只打包的情况就不监视文件
33
+ if (!config.mergeinitjs) {
34
+ watcher
35
+ .on('ready', () => utils.debug(`${bizPath},Initial scan complete. Ready for changes.`))
36
+ //.on('add', path => log(`File ${path} has been added`))
37
+ .on('change', path => watchAction({ event: 'change', eventPath: path }))
38
+ .on('unlink', path => watchAction({ event: 'remove', eventPath: path }));
39
+ }
37
40
  watchAction();// 启动就打包一次
38
41
  }
39
42
 
@@ -57,10 +60,14 @@ function mergeInit() {
57
60
  }
58
61
 
59
62
  var watchJs = function(jsPath) {
63
+ // 只打包的情况就不监视文件
64
+ if (config.mergeinitjs) return;
65
+
60
66
  var watcher = chokidar.watch([jsPath], {
61
67
  persistent: true,
62
68
  usePolling: true
63
69
  });
70
+
64
71
  watcher
65
72
  .on('ready', () => utils.debug(`${jsPath},Initial scan complete. Ready for changes.`))
66
73
  //.on('add', path => log(`File ${path} has been added`))