pjj 0.1.0 → 0.2.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 CHANGED
@@ -1,12 +1,6 @@
1
1
  # pjj
2
2
 
3
- [![version](<https://img.shields.io/npm/v/pjj.svg?logo=npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [![NPM Last Update](<https://img.shields.io/npm/last-update/pjj?logo=npm&label=版本最后更新&labelColor=rgb(255,36,63)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [![📦 size](<https://img.shields.io/bundlephobia/minzip/pjj.svg?logo=npm&label=压缩包大小&labelColor=rgb(201,158,140)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [![downloads](<https://img.shields.io/npm/dm/pjj.svg?logo=npm&logoColor=rgb(0,0,0)&label=月下载量&labelColor=rgb(194,112,210)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [![downloads](<https://img.shields.io/npm/dt/pjj.svg?logo=npm&label=总下载量&labelColor=rgb(107,187,124)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj)
4
-
5
- [![last commit](<https://img.shields.io/github/last-commit/earthnutDev/pjj.svg?logo=github&logoColor=rgb(0,0,0)&label=最后推码&labelColor=rgb(255,165,0)&color=rgb(0,0,0)>)](https://github.com/earthnutDev/pjj) [![GitHub commit activity](<https://img.shields.io/github/commit-activity/y/earthnutDev/pjj.svg?logo=github&label=推码数&labelColor=rgb(128,0,128)&color=rgb(0,0,0)>)](https://github.com/earthnutDev/pjj) [![Coverage Status](<https://img.shields.io/coverallsCoverage/github/earthnutDev/pjj?logo=coveralls&label=coveralls&labelColor=rgb(12, 244, 39)&color=rgb(0,0,0)>)](https://coveralls.io/github/earthnutDev/pjj?branch=main) [![codecov](<https://img.shields.io/codecov/c/github/earthnutDev/pjj/main?logo=codecov&label=codecov&labelColor=rgb(7, 245, 245)&color=rgb(0,0,0)>)](https://codecov.io/gh/earthnutDev/pjj)
6
-
7
- [![查看 📔 日志](<https://img.shields.io/badge/👀-日_%20_志-rgb(0,125,206)>)](https://github.com/earthnutDev/pjj/blob/main/CHANGELOG.md) [![bug 🙋‍♂️ 提交](<https://img.shields.io/badge/☣️-bug_%20_提交-rgb(255,0,63)>)](https://github.com/earthnutDev/pjj/issues)
8
-
9
- ---
3
+ ## [![version](<https://img.shields.io/npm/v/pjj.svg?logo=npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/pjj) [![issues 提交](<https://img.shields.io/badge/issues-提交-rgb(255,0,63)?logo=github>)](https://github.com/earthnutDev/pjj/issues)
10
4
 
11
5
  _发现个更简单的方法,直接在 `package.json` 中添加 `private: true` 更简单粗暴_
12
6
 
@@ -21,7 +15,7 @@ _我构建后的 `package.json` 🀄️不包含 `scripts` 字段,所以仅考
21
15
  ## 安装
22
16
 
23
17
  ```bash
24
- npm install pjj --save-dev
18
+ npm install --save-dev pjj
25
19
  ```
26
20
 
27
21
  ## 使用
package/bin.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ import './index.mjs';
4
+
package/package.json CHANGED
@@ -1,49 +1,43 @@
1
1
  {
2
2
  "name": "pjj",
3
3
  "type": "module",
4
- "version": "0.1.0",
5
- "module": "./mjs/index.mjs",
4
+ "version": "0.2.0",
5
+ "description": "禁止在项目的根目录执行 npm publish,防止意外发布。该脚本命令需在 `prepublishOnly` ` 钩子中配置",
6
+ "license": "ISC",
7
+ "dependencies": {
8
+ "@qqi/dev-log": ">=0.1.0 <1.0.0",
9
+ "a-command": ">=2.1.2 <3.0.0",
10
+ "a-js-tools": ">=0.5.4 <1.0.0",
11
+ "a-node-tools": ">=2.2.0 <3.0.0",
12
+ "color-pen": "^1.2.2"
13
+ },
6
14
  "author": {
7
- "name": "earthnut",
15
+ "name": "🥜",
8
16
  "email": "earthnut.dev@outlook.com",
9
17
  "url": "https://earthnut.dev"
10
18
  },
11
- "description": "禁止在项目的根目录执行 npm publish,防止意外发布。该脚本命令仅允许在 `prepublishOnly` ` 钩子中执行。",
12
19
  "files": [
13
- "mjs",
14
- "bin"
20
+ "bin.js",
21
+ "src",
22
+ "index.mjs"
15
23
  ],
16
- "exports": {
17
- ".": {
18
- "import": {
19
- "default": "./mjs/index.mjs",
20
- "types": "./types/index.d.ts"
21
- }
22
- }
23
- },
24
24
  "keywords": [
25
25
  "pjj"
26
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
- },
33
27
  "repository": {
34
28
  "type": "git",
35
29
  "url": "git+https://github.com/earthnutDev/pjj.git"
36
30
  },
31
+ "homepage": "https://earthnut.dev/pjj",
32
+ "bugs": {
33
+ "url": "https://github.com/earthnutDev/pjj/issues",
34
+ "email": "earthnut.dev@outlook.com"
35
+ },
37
36
  "publishConfig": {
38
37
  "access": "public",
39
38
  "registry": "https://registry.npmjs.org/"
40
39
  },
41
- "dependencies": {
42
- "a-command": "^0.0.8",
43
- "a-node-tools": "^0.1.0",
44
- "color-pen": "^0.1.0"
45
- },
46
40
  "bin": {
47
- "pjj": "bin/pjj.js"
41
+ "pjj": "bin.js"
48
42
  }
49
43
  }
@@ -0,0 +1,21 @@
1
+ import { _p } from 'a-node-tools';
2
+ import pen from 'color-pen';
3
+ import { dataStore } from './data-store.mjs';
4
+ import { noColor } from './command.mjs';
5
+
6
+ /**
7
+ *
8
+ * 打印一个空白的黑色背景
9
+ *
10
+ */
11
+ function blackSpace() {
12
+ if (noColor) {
13
+ _p();
14
+ }
15
+ else {
16
+ const str = ' '.repeat(dataStore.screenWith);
17
+ _p(pen.bgBlack(str));
18
+ }
19
+ }
20
+
21
+ export { blackSpace };
@@ -0,0 +1,26 @@
1
+ import { truncateStringWithChar, strInTerminalLength, pen } from 'color-pen';
2
+ import { noColor } from './command.mjs';
3
+ import { dataStore } from './data-store.mjs';
4
+ import { getRandomInt } from 'a-js-tools';
5
+
6
+ /**
7
+ *
8
+ * @description 生成随机颜色文本
9
+ *
10
+ * @param str 字符串
11
+ *
12
+ *
13
+ */
14
+ function colorText(str) {
15
+ const { screenWith, safeWidth } = dataStore;
16
+ /** 安全区空白 */
17
+ const blankSpace = ' '.repeat(safeWidth);
18
+ const computerStr = `${blankSpace}${truncateStringWithChar(str, screenWith)}${blankSpace}`;
19
+ strInTerminalLength(computerStr);
20
+ return computerStr
21
+ .split('')
22
+ .map(char => noColor ? char : pen.number(getRandomInt(1, 225)).bgBlack(char))
23
+ .join('');
24
+ }
25
+
26
+ export { colorText };
@@ -3,13 +3,13 @@ import { cn } from './cn.mjs';
3
3
 
4
4
  /** 创建一个命令 */
5
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;
6
+ command.bind([
7
+ 'message <-m> (添加自定义的命令消息)',
8
+ 'black <-b> (显示为黑色(默认)文本)',
9
+ 'script <-s> (触发的勾子,默认为 `prepublishOnly`)',
10
+ ]);
11
+ command.run();
12
+ command.isEnd(true);
13
13
  /**
14
14
  * 命令参数映射
15
15
  */
@@ -0,0 +1,14 @@
1
+ import { strInTerminalLength } from 'color-pen';
2
+ import { message } from './command.mjs';
3
+
4
+ const screenWith = process.stdout.columns;
5
+ const messageLength = strInTerminalLength(message);
6
+ const safeWidth = screenWith - messageLength;
7
+ const dataStore = {
8
+ /** 终端的宽度(可显示字符数) */
9
+ screenWith,
10
+ /** 安全区长度 */
11
+ safeWidth: safeWidth > 0 ? Math.floor(safeWidth / 2) : 0,
12
+ };
13
+
14
+ export { dataStore };
package/src/dog.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import Dog from '@qqi/dev-log';
2
+
3
+ const dog = new Dog({
4
+ name: 'pjj',
5
+ type: 'error',
6
+ });
7
+
8
+ export { dog };
@@ -1,6 +1,6 @@
1
1
  import pen from 'color-pen';
2
- import { cn } from './cn.mjs';
3
2
  import { noColor } from './command.mjs';
3
+ import { dataStore } from './data-store.mjs';
4
4
 
5
5
  /**
6
6
  *
@@ -9,7 +9,7 @@ import { noColor } from './command.mjs';
9
9
  */
10
10
  function line() {
11
11
  let str = '';
12
- for (let i = 0; i < (cn ? 54 : 101); i++) {
12
+ for (let i = 0; i < dataStore.screenWith; i++) {
13
13
  str += noColor ? '=' : pen.random('=');
14
14
  }
15
15
  return str;
@@ -1,8 +1,10 @@
1
1
  import pen from 'color-pen';
2
2
  import { colorText } from './colorText.mjs';
3
- import { script, message } from './command.mjs';
3
+ import { script, command, message } from './command.mjs';
4
4
  import { line } from './line.mjs';
5
5
  import { _p } from 'a-node-tools';
6
+ import { dog } from './dog.mjs';
7
+ import { blackSpace } from './blackSpace.mjs';
6
8
 
7
9
  /**
8
10
  * 空行
@@ -15,16 +17,19 @@ function main() {
15
17
  if (process && process.env && process.env.npm_lifecycle_event === script) {
16
18
  _p(space);
17
19
  _p(line());
18
- _p(colorText(message, false));
19
- _p(colorText(message, false));
20
+ _p();
21
+ blackSpace();
22
+ blackSpace();
20
23
  _p(colorText(message));
21
- _p(colorText(message, false));
22
- _p(colorText(message, false));
24
+ blackSpace();
25
+ blackSpace();
26
+ _p();
23
27
  _p(line());
24
28
  _p(space);
25
- end();
29
+ command.error();
26
30
  }
27
31
  else {
32
+ dog.error(process && process.env && process.env.npm_lifecycle_event);
28
33
  const m = ' 所以,看见这段文本,说明你哪里 ❌ 了 ';
29
34
  _p('====================================');
30
35
  _p('跳过了禁止发布,而且该命令可能不会显示在终端\n');
@@ -34,7 +39,5 @@ function main() {
34
39
  _p('\n====================================');
35
40
  }
36
41
  }
37
- /** 命令结束回调 */
38
- const end = () => process.exit(1);
39
42
 
40
- export { end, main };
43
+ export { main };
package/bin/pjj.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- import '../mjs/index.mjs';
@@ -1,25 +0,0 @@
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 };
File without changes
File without changes