lack 1.3.6 → 1.3.7

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/README.md +12 -10
  2. package/bin/watch.js +19 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,15 +5,14 @@
5
5
  [![NPM count](https://img.shields.io/npm/dt/lack.svg?style=flat-square)](https://www.npmjs.com/package/lack)
6
6
  [![License](https://img.shields.io/npm/l/lack.svg?style=flat-square)](https://www.npmjs.com/package/lack)
7
7
 
8
- 生成 [whistle](https://github.com/avwo/whistle) 插件的脚手架及调试工具。
8
+ 生成 [whistle](https://github.com/avwo/whistle) 插件的脚手架。
9
9
 
10
- > 以下功能要求安装最新的 whistle 及 lack:`npm i -g whistle lack`
11
- # 安装
10
+ ### 安装
12
11
  ``` sh
13
12
  npm i -g lack
14
13
  ```
15
14
 
16
- # 生成插件
15
+ ### 使用
17
16
  严格按以下步骤操作:
18
17
  1. 新建插件目录 `whistle.xxx`(如果已存在忽略此步骤)
19
18
  > xxx 表示只包含 `a-z\d_-` 的任意字符串,具体参见帮助文档:[插件开发](https://wproxy.org/whistle/plugins.html)
@@ -22,14 +21,17 @@ npm i -g lack
22
21
  3. 选择好插件所需钩子并确定后,如果需要修改或新增钩子,可以删除已存在的钩子,并执行上面步骤2
23
22
  4. 【可选】配置eslint规则,参考:[eslint-config-imweb](https://github.com/imweb/eslint-config-imweb)
24
23
  5. 安装依赖 `npm i`
25
-
26
- # 调试插件
27
- 1. 进入插件 `whistle.xxx` 根目录,执行:
24
+ 6. 执行 `npm link` 将插件link到全局,这样可以在 whistle 界面的 Plugins 列表看到此插件
25
+ 7. 开启 whistle 调试模式
28
26
  ``` sh
27
+ w2 stop
28
+ w2 run
29
+ ```
30
+ > 这样可以在控制台里面看到插件 `console.log` 输出的内容
31
+ 8. 开启监听插件变更自动重启:
32
+ ```sh
29
33
  lack watch
30
34
  ```
31
- > 可以在该控制台看到插件 `console` 输出的日志
32
- 2. 可以通过在代码里面添加 `console.log(xxxxxx)` 调试插件
33
- 3. 更多帮助执行 `lack --help`
35
+ 9. 更多帮助执行 `lack --help`
34
36
 
35
37
  更多信息参考插件示例:[https://github.com/whistle-plugins/examples](https://github.com/whistle-plugins/examples)
package/bin/watch.js CHANGED
@@ -6,6 +6,7 @@ const fse = require('fs-extra');
6
6
  /* eslint-disable no-sync */
7
7
  const HOME_DIR_RE = /^[~~]\//;
8
8
  const PLUGIN_NAME_RE = /^(?:@[\w-]+\/)?(whistle\.[a-z\d_-]+)$/;
9
+ const REL_RE = /^(?:\.\.[\\/]+)*(?:\.\.)?$/;
9
10
 
10
11
  const getWhistlePath = () => {
11
12
  const dir = process.env.WHISTLE_PATH;
@@ -88,15 +89,31 @@ module.exports = (dirs) => {
88
89
  });
89
90
  }
90
91
  let timer;
91
- console.log(`Watching the following files and folders changes:\n${watchList.join('\n')}\n`); // eslint-disable-line
92
+ const paths = [];
93
+ const cwd = process.cwd();
94
+ const tips = watchList.map((name, i) => {
95
+ paths.push(path.resolve(cwd, name));
96
+ return `${i + 1}. ${name}`;
97
+ }).join('\n');
98
+ const len = paths.length;
99
+ const inWatchList = (filename) => {
100
+ for (let i = 0; i < len; i++) {
101
+ if (REL_RE.test(path.relative(filename, paths[i]))) {
102
+ return true;
103
+ }
104
+ }
105
+ };
106
+ console.log(`Watching the following files/folders changes:\n${tips}`); // eslint-disable-line
107
+ console.log('\n*********************************************\n'); // eslint-disable-line
92
108
  chokidar.watch(watchList, {
93
109
  ignored: /(^|[/\\])(\..|node_modules([/\\]|$))/,
94
110
  }).on('raw', (_, filename) => {
95
- if (filename.includes('package.json') || filename.includes('.console.log')) {
111
+ if (filename.includes('package.json') || filename.includes('.console.log') || !inWatchList(filename)) {
96
112
  return;
97
113
  }
98
114
  clearTimeout(timer);
99
115
  timer = setTimeout(() => {
116
+ console.log(''); // eslint-disable-line
100
117
  console.log(`${filename} is changed.`); // eslint-disable-line
101
118
  touch();
102
119
  }, 1000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lack",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "whistle extension tools",
5
5
  "author": "avenwu <avwu@qq.com>",
6
6
  "license": "MIT",