@clerc/plugin-version 0.40.0 → 0.41.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 +21 -21
  2. package/README.md +25 -0
  3. package/dist/index.js +53 -1
  4. package/package.json +10 -11
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Ray <https://github.com/so1ve>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ray <https://github.com/so1ve>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @clerc/plugin-version
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@clerc/plugin-version?color=a1b858&label=)](https://www.npmjs.com/package/@clerc/plugin-version)
4
+
5
+ Clerc plugin to add version command to your cli.
6
+
7
+ ## 📦 Installation
8
+
9
+ ```bash
10
+ $ npm install @clerc/plugin-version
11
+ $ yarn add @clerc/plugin-version
12
+ $ pnpm add @clerc/plugin-version
13
+ ```
14
+
15
+ ## 🚀 Usage
16
+
17
+ ```ts
18
+ import { versionPlugin } from "@clerc/plugin-version";
19
+
20
+ cli.use(versionPlugin());
21
+ ```
22
+
23
+ ## 📝 License
24
+
25
+ [MIT](../../LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve)
package/dist/index.js CHANGED
@@ -1 +1,53 @@
1
- import{definePlugin as v}from"@clerc/core";const p=s=>s.length===0?"":s.startsWith("v")?s:`v${s}`,a={en:{"version.description":"Show CLI version","version.notes.1":'The version string begins with a "v".'},"zh-CN":{"version.description":"\u5C55\u793A CLI \u7248\u672C","version.notes.1":'\u7248\u672C\u53F7\u5F00\u5934\u5E26\u6709 "v"\u3002'}},f=({command:s=!0,flag:r=!0}={})=>v({setup:e=>{const{add:t,t:n}=e.i18n;t(a);const o=p(e._version);return s&&(e=e.command("version",n("version.description"),{help:{notes:[n("version.notes.1")]}}).on("version",()=>{process.stdout.write(o)})),r&&(e=e.flag("version",n("version.description"),{alias:"V",type:Boolean,default:!1}),e.inspector({enforce:"pre",fn:(i,u)=>{i.flags.version?process.stdout.write(o):u()}})),e}});export{f as versionPlugin};
1
+ import { definePlugin } from '@clerc/core';
2
+ import { gracefulVersion } from '@clerc/utils';
3
+
4
+ const locales = {
5
+ "en": {
6
+ "version.description": "Show CLI version",
7
+ "version.notes.1": 'The version string begins with a "v".'
8
+ },
9
+ "zh-CN": {
10
+ "version.description": "\u5C55\u793A CLI \u7248\u672C",
11
+ "version.notes.1": '\u7248\u672C\u53F7\u5F00\u5934\u5E26\u6709 "v"\u3002'
12
+ }
13
+ };
14
+
15
+ const versionPlugin = ({
16
+ command = true,
17
+ flag = true
18
+ } = {}) => definePlugin({
19
+ setup: (cli) => {
20
+ const { add, t } = cli.i18n;
21
+ add(locales);
22
+ const gracefullyVersion = gracefulVersion(cli._version);
23
+ if (command) {
24
+ cli = cli.command("version", t("version.description"), {
25
+ help: {
26
+ notes: [t("version.notes.1")]
27
+ }
28
+ }).on("version", () => {
29
+ process.stdout.write(gracefullyVersion);
30
+ });
31
+ }
32
+ if (flag) {
33
+ cli = cli.flag("version", t("version.description"), {
34
+ alias: "V",
35
+ type: Boolean,
36
+ default: false
37
+ });
38
+ cli.inspector({
39
+ enforce: "pre",
40
+ fn: (ctx, next) => {
41
+ if (ctx.flags.version) {
42
+ process.stdout.write(gracefullyVersion);
43
+ } else {
44
+ next();
45
+ }
46
+ }
47
+ });
48
+ }
49
+ return cli;
50
+ }
51
+ });
52
+
53
+ export { versionPlugin };
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@clerc/plugin-version",
3
- "version": "0.40.0",
3
+ "version": "0.41.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
+ "type": "module",
5
6
  "description": "Clerc plugin version",
6
7
  "keywords": [
7
- "cli",
8
- "clerc",
9
- "clerc-plugin",
8
+ "args",
10
9
  "arguments",
11
10
  "argv",
12
- "args",
11
+ "clerc",
12
+ "clerc-plugin",
13
+ "cli",
13
14
  "terminal"
14
15
  ],
15
- "type": "module",
16
16
  "homepage": "https://github.com/so1ve/clerc/tree/main/packages/plugin-version#readme",
17
17
  "repository": {
18
18
  "type": "git",
@@ -39,15 +39,14 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
+ "dependencies": {
43
+ "@clerc/utils": "0.41.0"
44
+ },
42
45
  "peerDependencies": {
43
46
  "@clerc/core": "*"
44
47
  },
45
- "devDependencies": {
46
- "@clerc/core": "0.40.0",
47
- "@clerc/utils": "0.40.0"
48
- },
49
48
  "scripts": {
50
- "build": "pkgroll --minify",
49
+ "build": "pkgroll",
51
50
  "watch": "pkgroll --watch"
52
51
  }
53
52
  }