@qqi/check-version 0.0.2 → 0.1.0
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/README.md +56 -7
- package/bin.mjs +21 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,27 +13,76 @@ npm install --save @qqi/check-version
|
|
|
13
13
|
默认使用方式为传入 `name` 参数,代码将执行判断工作目录下的 'packages/[name]' 子 npm 包的版本号是否已存在于线上
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
+
# 写法一
|
|
16
17
|
npx @qqi/check-version name=[name]
|
|
17
|
-
|
|
18
|
+
# 写法二
|
|
18
19
|
npx @qqi/check-version n=[name]
|
|
20
|
+
# 写法三
|
|
21
|
+
npx @qqi/check-version name [name]
|
|
22
|
+
# 写法四
|
|
23
|
+
npx @qqi/check-version n [name]
|
|
19
24
|
```
|
|
20
25
|
|
|
21
26
|
也可以传入 `cwd` 参数覆盖默认的判断文件夹,默认查找 'packages' 文件夹下子 npm 包,若您习惯于其他命名方式
|
|
22
27
|
|
|
23
28
|
```bash
|
|
24
|
-
# 倘若子主包 core 在
|
|
25
|
-
npx @qqi
|
|
29
|
+
# 倘若子主包 core 在 lists 文件夹下
|
|
30
|
+
npx @qqi/check-version name=core cwd=lists # 推荐模式
|
|
31
|
+
|
|
32
|
+
npx @qqi/check-version name core cwd lists
|
|
33
|
+
|
|
34
|
+
npx @qqi/check-version name=core cwd lists
|
|
35
|
+
|
|
36
|
+
npx @qqi/check-version name core cwd=lists
|
|
37
|
+
|
|
38
|
+
npx @qqi/check-version n=core c=lists # 推荐模式
|
|
26
39
|
|
|
27
|
-
npx @qqi
|
|
40
|
+
npx @qqi/check-version n core c lists
|
|
28
41
|
```
|
|
29
42
|
|
|
43
|
+
默认的 name 值为 "." ,即以 packages 目录为项目的根(倘若 package.json 文件在这里的话)
|
|
44
|
+
|
|
30
45
|
使用 skip 参数是否跳过执行线上版本检测(因为 '0.0.0' 的版本默认为跳过检测,若初始版本非 '0.0.0' 时 ,也可以使用该参数跳过检测)
|
|
31
46
|
|
|
32
47
|
```bash
|
|
33
|
-
# 倘若子主包 core 在
|
|
34
|
-
npx @qqi
|
|
48
|
+
# 倘若子主包 core 在 lists 文件夹下
|
|
49
|
+
npx @qqi/check-version name=core cwd=lists skip # 推荐模式
|
|
50
|
+
|
|
51
|
+
npx @qqi/check-version name=core cwd lists skip
|
|
52
|
+
|
|
53
|
+
npx @qqi/check-version n=core c=lists s # 推荐模式
|
|
54
|
+
|
|
55
|
+
npx @qqi/check-version n=core c lists s
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
若想在其他非分包的项目使用,即单独的项目使用配置,使用 `npx @qqi/check-version c=.` 即可。
|
|
59
|
+
|
|
60
|
+
## 使用示例
|
|
61
|
+
|
|
62
|
+
在 `pub.sh` 文件中使用时:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# 输出的 npm 发布的 tag。也可以通过调整 cwd 和 name 的参数来适配实际的项目地址
|
|
66
|
+
output=$(npx @qqi/check-version c=. 2>&1)
|
|
67
|
+
tag=""
|
|
68
|
+
# 执行 npx 的返回值
|
|
69
|
+
exit_code=$?
|
|
70
|
+
|
|
71
|
+
# 如果执行成功,即 tag 值获取成功
|
|
72
|
+
if [ $exit_code -eq 0 ];then
|
|
73
|
+
tag="$output"
|
|
74
|
+
else
|
|
75
|
+
echo "$output"
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
echo "开始发布 npm 包"
|
|
79
|
+
|
|
80
|
+
if ! npm publish --provenance --access public --tag ${tag} ; then
|
|
81
|
+
echo "发布失败"
|
|
82
|
+
exit 0
|
|
83
|
+
fi
|
|
35
84
|
|
|
36
|
-
|
|
85
|
+
echo "🚀🚀 发布成功,完结 🎉🎉 撒花 🎉🎉"
|
|
37
86
|
```
|
|
38
87
|
|
|
39
88
|
## 文档位置
|
package/bin.mjs
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _p, pathJoin, fileExist, readFileToJsonSync, getNpmPkgInfo } from 'a-node-tools';
|
|
2
|
+
import { _p, pathJoin, getDirectoryBy, fileExist, readFileToJsonSync, getNpmPkgInfo } from 'a-node-tools';
|
|
3
3
|
import { isUndefined, isNull } from 'a-type-of-js';
|
|
4
4
|
import { Command } from 'a-command';
|
|
5
5
|
|
|
6
|
+
/** 从版本号中解析到 dist tag */
|
|
7
|
+
const getTag = (version) => {
|
|
8
|
+
const versionList = version.split('-');
|
|
9
|
+
if (versionList.length === 1) {
|
|
10
|
+
return 'latest';
|
|
11
|
+
}
|
|
12
|
+
return 'latest';
|
|
13
|
+
};
|
|
6
14
|
const command = new Command('@qqi/check-version');
|
|
7
15
|
command.bind([
|
|
8
16
|
'cwd <c> (检测的工作文件夹的位置路径,缺省值为当前跟路径的 packages)',
|
|
9
17
|
'skip <s> (跳过线上包版本检测, 默认值为 false)',
|
|
10
|
-
'name <n> (
|
|
18
|
+
'name <n> (检测的子包名,默认值为 .)',
|
|
11
19
|
]);
|
|
12
20
|
command.run().isEnd(true);
|
|
13
21
|
const args = command.args.$map;
|
|
14
22
|
/** 工作的相对路径 */
|
|
15
23
|
const cwd = args.cwd?.value?.[0].toString() ?? 'packages';
|
|
16
24
|
/** 获取输入的包名 */
|
|
17
|
-
const name = args.name?.value?.[0].toString() ?? '';
|
|
25
|
+
const name = args.name?.value?.[0].toString() ?? '.';
|
|
18
26
|
/** 是否跳过检测 */
|
|
19
27
|
const skip = args.skip?.value?.[0] !== false ? true : false;
|
|
20
28
|
/** 未检测到输入的包名,则返回 false */
|
|
@@ -23,7 +31,14 @@ if (isUndefined(name) || name === '') {
|
|
|
23
31
|
process.exit(1);
|
|
24
32
|
}
|
|
25
33
|
/** 文件路径 */
|
|
26
|
-
|
|
34
|
+
let filePath = pathJoin(process.cwd(), cwd, name);
|
|
35
|
+
/// 下面是冗余步骤,有助于在非根目录下查找 package.json 文件
|
|
36
|
+
const dirPath = getDirectoryBy('package.json', 'file', filePath);
|
|
37
|
+
if (isUndefined(dirPath)) {
|
|
38
|
+
_p(`${filePath} 文件路径不存在`, false);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
filePath = pathJoin(dirPath, 'package.json');
|
|
27
42
|
/** 文件路径 */
|
|
28
43
|
const fileIsExist = fileExist(filePath);
|
|
29
44
|
if (isUndefined(fileIsExist)) {
|
|
@@ -44,7 +59,7 @@ const pkgInfo = await getNpmPkgInfo(fileContent.name);
|
|
|
44
59
|
if (isNull(pkgInfo.data)) {
|
|
45
60
|
if (pkgInfo.status === 'notFound' &&
|
|
46
61
|
(skip || fileContent.version === '0.0.0')) {
|
|
47
|
-
_p(
|
|
62
|
+
_p(getTag(fileContent.version), false);
|
|
48
63
|
process.exit(0);
|
|
49
64
|
}
|
|
50
65
|
_p(`${fileContent.name} 包未找到`, false);
|
|
@@ -55,5 +70,5 @@ if (pkgInfo.data.time[fileContent.version]) {
|
|
|
55
70
|
_p(`${fileContent.name} 包版本号已存在`, false);
|
|
56
71
|
process.exit(1);
|
|
57
72
|
}
|
|
58
|
-
_p(
|
|
73
|
+
_p(getTag(fileContent.version), false);
|
|
59
74
|
process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qqi/check-version",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"description": "一个检测工作目录下 packages 文件夹下子 npm 包版本是否存在的模块",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"a-command": "^2.1.
|
|
7
|
+
"a-command": "^2.1.8",
|
|
8
8
|
"a-js-tools": ">=0.6.1 <1.0.0",
|
|
9
|
-
"a-node-tools": "^3.1.
|
|
9
|
+
"a-node-tools": "^3.1.4",
|
|
10
10
|
"a-type-of-js": ">=0.2.0 <1.0.0"
|
|
11
11
|
},
|
|
12
12
|
"author": {
|