@qqi/check-version 0.0.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.
Files changed (4) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +41 -0
  3. package/bin.mjs +59 -0
  4. package/package.json +41 -0
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) <2025> <earthnut.dev@outlook.com>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # qqi check-version
2
+
3
+ 一个简单的本地版本检测工具
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install --save @qqi/check-version
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ 默认使用方式为传入 `name` 参数,代码将执行判断工作目录下的 'packages/[name]' 子 npm 包的版本号是否已存在于线上
14
+
15
+ ```bash
16
+ npx @qqi/check-version name=[name]
17
+
18
+ npx @qqi/check-version n=[name]
19
+ ```
20
+
21
+ 也可以传入 `cwd` 参数覆盖默认的判断文件夹,默认查找 'packages' 文件夹下子 npm 包,若您习惯于其他命名方式
22
+
23
+ ```bash
24
+ # 倘若子主包 core 在 pkgs 文件夹下
25
+ npx @qqi/.check-version name=core cwd=pkgs
26
+
27
+ npx @qqi/.check-version n=core c=pkgs
28
+ ```
29
+
30
+ 使用 skip 参数是否跳过执行线上版本检测(因为 '0.0.0' 的版本默认为跳过检测,若初始版本非 '0.0.0' 时 ,也可以使用该参数跳过检测)
31
+
32
+ ```bash
33
+ # 倘若子主包 core 在 pkgs 文件夹下
34
+ npx @qqi/.check-version name=core cwd=pkgs skip
35
+
36
+ npx @qqi/.check-version n=core c=pkgs s
37
+ ```
38
+
39
+ ## 文档位置
40
+
41
+ [@qqi/check-version](https://earthnut.dev/qqi/check-version)
package/bin.mjs ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ import { _p, pathJoin, fileExist, readFileToJsonSync, getNpmPkgInfo } from 'a-node-tools';
3
+ import { isUndefined, isNull } from 'a-type-of-js';
4
+ import { Command } from 'a-command';
5
+
6
+ const command = new Command('@qqi/check-version');
7
+ command.bind([
8
+ 'cwd <c> (检测的工作文件夹的位置路径,缺省值为当前跟路径的 packages)',
9
+ 'skip <s> (跳过线上包版本检测, 默认值为 false)',
10
+ 'name <n> (检测的子包名)',
11
+ ]);
12
+ command.run().isEnd(true);
13
+ const args = command.args.$map;
14
+ /** 工作的相对路径 */
15
+ const cwd = args.cwd?.value?.[0].toString() ?? 'packages';
16
+ /** 获取输入的包名 */
17
+ const name = args.name?.value?.[0].toString() ?? '';
18
+ /** 是否跳过检测 */
19
+ const skip = args.skip?.value?.[0] !== false ? true : false;
20
+ /** 未检测到输入的包名,则返回 false */
21
+ if (isUndefined(name) || name === '') {
22
+ _p('为检测到输入的包名', false);
23
+ process.exit(1);
24
+ }
25
+ /** 文件路径 */
26
+ const filePath = pathJoin(process.cwd(), cwd, name, 'package.json');
27
+ /** 文件路径 */
28
+ const fileIsExist = fileExist(filePath);
29
+ if (isUndefined(fileIsExist)) {
30
+ _p(`${filePath} 文件路径不存在`, false);
31
+ process.exit(1);
32
+ }
33
+ const fileContent = readFileToJsonSync(filePath);
34
+ if (isNull(fileContent)) {
35
+ _p(`读取 ${filePath} 出错`, false);
36
+ process.exit(1);
37
+ }
38
+ if (!fileContent.name || !fileContent.version) {
39
+ _p(`读取 ${filePath} 出错,未找到包名或版本号`, false);
40
+ process.exit(1);
41
+ }
42
+ const pkgInfo = await getNpmPkgInfo(fileContent.name);
43
+ // 包数据未找到或是版本号已存在则返回
44
+ if (isNull(pkgInfo.data)) {
45
+ if (pkgInfo.status === 'notFound' &&
46
+ (skip || fileContent.version === '0.0.0')) {
47
+ _p(true, false);
48
+ process.exit(0);
49
+ }
50
+ _p(`${fileContent.name} 包未找到`, false);
51
+ process.exit(1);
52
+ }
53
+ // 包数据未找到或是版本号已存在则返回
54
+ if (pkgInfo.data.time[fileContent.version]) {
55
+ _p(`${fileContent.name} 包版本号已存在`, false);
56
+ process.exit(1);
57
+ }
58
+ _p(true, false);
59
+ process.exit(0);
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@qqi/check-version",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "description": "一个检测工作目录下 packages 文件夹下子 npm 包版本是否存在的模块",
6
+ "dependencies": {
7
+ "a-command": ">=2.1.7 <3.0.0",
8
+ "a-js-tools": ">=0.6.1 <1.0.0",
9
+ "a-node-tools": ">=3.0.1 <4.0.0",
10
+ "a-type-of-js": ">=0.2.0 <1.0.0"
11
+ },
12
+ "author": {
13
+ "name": "earthnut",
14
+ "email": "earthnut.dev@outlook.com",
15
+ "url": "https://earthnut.dev"
16
+ },
17
+ "files": [
18
+ "bin.mjs"
19
+ ],
20
+ "keywords": [
21
+ "qqi",
22
+ "@qqi/check-version",
23
+ "@qqi"
24
+ ],
25
+ "homepage": "https://earthnut.dev/qqi",
26
+ "bugs": {
27
+ "url": "https://github.com/earthnutDev/qqi/issues",
28
+ "email": "earthnut.dev@outlook.com"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/earthnutDev/qqi.git"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "bin": {
39
+ "@qqi/check-version": "./bin.mjs"
40
+ }
41
+ }