pjj 0.0.0 → 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/LICENSE +13 -0
- package/README.md +76 -2
- package/bin/pjj.js +4 -0
- package/mjs/index.mjs +3 -0
- package/mjs/src/cn.mjs +3 -0
- package/mjs/src/colorText.mjs +25 -0
- package/mjs/src/command.mjs +31 -0
- package/mjs/src/line.mjs +18 -0
- package/mjs/src/main.mjs +40 -0
- package/package.json +36 -13
- package/index.js +0 -1
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
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pjj
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [&label=月下载量&labelColor=rgb(194,112,210)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj)
|
|
4
|
+
|
|
5
|
+
[&label=最后推码&labelColor=rgb(255,165,0)&color=rgb(0,0,0)>)](https://github.com/earthnutDev/pjj) [&color=rgb(0,0,0)>)](https://github.com/earthnutDev/pjj) [&color=rgb(0,0,0)>)](https://coveralls.io/github/earthnutDev/pjj?branch=main) [&color=rgb(0,0,0)>)](https://codecov.io/gh/earthnutDev/pjj)
|
|
6
|
+
|
|
7
|
+
[>)](https://github.com/earthnutDev/pjj/blob/main/CHANGELOG.md) [>)](https://github.com/earthnutDev/pjj/issues)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_发现个更简单的方法,直接在 `package.json` 中添加 `private: true` 更简单粗暴_
|
|
12
|
+
|
|
13
|
+
禁止在项目的根目录执行 npm publish,防止意外发布。该脚本命令仅允许在 `prepublishOnly` ` 钩子中执行。
|
|
14
|
+
|
|
15
|
+
因为我的项目都是打包到 `dist` 目录下,然后再 `cd dist` 在 dist 目录下执行 `npm publish`,所以需要禁止在根目录执行 `npm publish`。
|
|
16
|
+
|
|
17
|
+
因为偶尔会忘记在 `dist` 目录下执行 `npm publish`,所以需要该脚本命令。
|
|
18
|
+
|
|
19
|
+
_我构建后的 `package.json` 🀄️不包含 `scripts` 字段,所以仅考虑根目录禁止执行 `npm publish`_
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install pjj --save-dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 使用
|
|
28
|
+
|
|
29
|
+
### 常规使用
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"scripts": {
|
|
34
|
+
"prepublishOnly": "pjj"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 替换掉默认文本
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"scripts": {
|
|
44
|
+
"prepublishOnly": "pjj -m '请在 dist 目录下执行 npm publish'"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 替换掉默认文本并使用黑色(默认)文本颜色
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"scripts": {
|
|
54
|
+
"prepublishOnly": "pjj -m '请在 dist 目录下执行 npm publish' -b"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
需要注意
|
|
60
|
+
|
|
61
|
+
- 添加了 `-s` 命令用于替换默认 prepublishOnly,但是还不知道怎么用,慎用
|
|
62
|
+
- 在使用命令 `pjj` 时,需保证在项目中进行了安装
|
|
63
|
+
- 只要将该命令配置到 `"prepublishOnly": "pjj"` 时,总会在执行 `npm publish` 时阻止执行 `npm publish`
|
|
64
|
+
- 该命令仅适用于 `npm publish`
|
|
65
|
+
- 使用该命令请不要使用 `npx` 调用,除非配置 `-s npx` 命令
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"scripts": {
|
|
70
|
+
"prepublishOnly": "npx pjj -s npx"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 文档地址
|
|
76
|
+
|
|
77
|
+
参看 [https://earthnut.dev/pjj/](https://earthnut.dev/pjj/)
|
package/bin/pjj.js
ADDED
package/mjs/index.mjs
ADDED
package/mjs/src/cn.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { pen } from 'color-pen';
|
|
2
|
+
import { noColor } from './command.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @description 生成随机颜色文本
|
|
7
|
+
* @param str 字符串
|
|
8
|
+
* @param text 是否不使用颜色
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
function colorText(str, text = true) {
|
|
13
|
+
return `${' '.repeat(7)}${str}${' '.repeat(7)}`
|
|
14
|
+
.split('')
|
|
15
|
+
.map(char => noColor
|
|
16
|
+
? text
|
|
17
|
+
? char
|
|
18
|
+
: pen.hide(char)
|
|
19
|
+
: text
|
|
20
|
+
? pen.random.bgBlack(char)
|
|
21
|
+
: pen.random.bgBlack.hide(char))
|
|
22
|
+
.join('');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { colorText };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Command } from 'a-command';
|
|
2
|
+
import { cn } from './cn.mjs';
|
|
3
|
+
|
|
4
|
+
/** 创建一个命令 */
|
|
5
|
+
const command = new Command('pjj');
|
|
6
|
+
command
|
|
7
|
+
.bind({
|
|
8
|
+
'message <-m> (添加自定义的命令消息)': [],
|
|
9
|
+
'black <-b> (显示为黑色(默认)文本)': [],
|
|
10
|
+
'script <-s> (触发的勾子,默认为 prepublishOnly)': [],
|
|
11
|
+
})
|
|
12
|
+
.run().isEnd.end;
|
|
13
|
+
/**
|
|
14
|
+
* 命令参数映射
|
|
15
|
+
*/
|
|
16
|
+
const argMap = command.args.$map;
|
|
17
|
+
/**
|
|
18
|
+
* 命令参数值
|
|
19
|
+
*/
|
|
20
|
+
const message = argMap.message && argMap.message.value && argMap.message.value.length > 0
|
|
21
|
+
? argMap.message.value.join('\n')
|
|
22
|
+
: cn
|
|
23
|
+
? '禁止在项目的根目录下执行 npm publish 命令'
|
|
24
|
+
: 'It is forbidden to execute the npm publish command in the root directory of the project';
|
|
25
|
+
/// 没有颜色
|
|
26
|
+
const noColor = argMap.black !== undefined;
|
|
27
|
+
const script = argMap.script && argMap.script.value && argMap.script.value.length > 0
|
|
28
|
+
? argMap.script.value[0]
|
|
29
|
+
: 'prepublishOnly';
|
|
30
|
+
|
|
31
|
+
export { command, message, noColor, script };
|
package/mjs/src/line.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import pen from 'color-pen';
|
|
2
|
+
import { cn } from './cn.mjs';
|
|
3
|
+
import { noColor } from './command.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @description 生成分割线
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
function line() {
|
|
11
|
+
let str = '';
|
|
12
|
+
for (let i = 0; i < (cn ? 54 : 101); i++) {
|
|
13
|
+
str += noColor ? '=' : pen.random('=');
|
|
14
|
+
}
|
|
15
|
+
return str;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { line };
|
package/mjs/src/main.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import pen from 'color-pen';
|
|
2
|
+
import { colorText } from './colorText.mjs';
|
|
3
|
+
import { script, message } from './command.mjs';
|
|
4
|
+
import { line } from './line.mjs';
|
|
5
|
+
import { _p } from 'a-node-tools';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 空行
|
|
9
|
+
*/
|
|
10
|
+
const space = '\n'.repeat(3);
|
|
11
|
+
/**
|
|
12
|
+
* 主程序入口
|
|
13
|
+
*/
|
|
14
|
+
function main() {
|
|
15
|
+
if (process && process.env && process.env.npm_lifecycle_event === script) {
|
|
16
|
+
_p(space);
|
|
17
|
+
_p(line());
|
|
18
|
+
_p(colorText(message, false));
|
|
19
|
+
_p(colorText(message, false));
|
|
20
|
+
_p(colorText(message));
|
|
21
|
+
_p(colorText(message, false));
|
|
22
|
+
_p(colorText(message, false));
|
|
23
|
+
_p(line());
|
|
24
|
+
_p(space);
|
|
25
|
+
end();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const m = ' 所以,看见这段文本,说明你哪里 ❌ 了 ';
|
|
29
|
+
_p('====================================');
|
|
30
|
+
_p('跳过了禁止发布,而且该命令可能不会显示在终端\n');
|
|
31
|
+
_p(pen.hide.brightRed.bgBlack(m));
|
|
32
|
+
_p(pen.bold.blink.brightRed.bgBlack(m));
|
|
33
|
+
_p(pen.hide.brightRed.bgBlack(m));
|
|
34
|
+
_p('\n====================================');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** 命令结束回调 */
|
|
38
|
+
const end = () => process.exit(1);
|
|
39
|
+
|
|
40
|
+
export { end, main };
|
package/package.json
CHANGED
|
@@ -1,26 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pjj",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"module": "./mjs/index.mjs",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "earthnut",
|
|
8
|
+
"email": "earthnut.dev@outlook.com",
|
|
9
|
+
"url": "https://earthnut.dev"
|
|
10
|
+
},
|
|
11
|
+
"description": "禁止在项目的根目录执行 npm publish,防止意外发布。该脚本命令仅允许在 `prepublishOnly` ` 钩子中执行。",
|
|
9
12
|
"files": [
|
|
10
|
-
"
|
|
13
|
+
"mjs",
|
|
14
|
+
"bin"
|
|
11
15
|
],
|
|
12
|
-
"
|
|
13
|
-
"
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"default": "./mjs/index.mjs",
|
|
20
|
+
"types": "./types/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
14
23
|
},
|
|
15
24
|
"keywords": [
|
|
16
|
-
"
|
|
25
|
+
"pjj"
|
|
17
26
|
],
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"homepage": "https://earthnut.dev/pjj",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/earthnutDev/gtu/issues",
|
|
31
|
+
"email": "earthnut.dev@outlook.com"
|
|
32
|
+
},
|
|
18
33
|
"repository": {
|
|
19
34
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/
|
|
35
|
+
"url": "git+https://github.com/earthnutDev/pjj.git"
|
|
21
36
|
},
|
|
22
37
|
"publishConfig": {
|
|
23
38
|
"access": "public",
|
|
24
|
-
"registry": "https://registry.npmjs.org"
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"a-command": "^0.0.8",
|
|
43
|
+
"a-node-tools": "^0.1.0",
|
|
44
|
+
"color-pen": "^0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"bin": {
|
|
47
|
+
"pjj": "bin/pjj.js"
|
|
25
48
|
}
|
|
26
|
-
}
|
|
49
|
+
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log("hello ,iggg!");
|