@clerc/plugin-help 0.17.0 → 0.17.2

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
2
2
  import { mustArray, gracefulFlagName } from '@clerc/utils';
3
- import * as colors from 'colorette';
3
+ import pc from 'picocolors';
4
4
  import { Table } from '@clerc/toolkit';
5
5
 
6
6
  const table = (...items) => {
@@ -27,6 +27,9 @@ const table = (...items) => {
27
27
  table2.push(...items);
28
28
  return table2;
29
29
  };
30
+ const splitTable = (...items) => {
31
+ return table(...items).toString().split("\n");
32
+ };
30
33
 
31
34
  const render = (sections) => {
32
35
  const rendered = [];
@@ -36,9 +39,9 @@ const render = (sections) => {
36
39
  const formattedBody = section.body.map((line) => indent + line);
37
40
  formattedBody.unshift("");
38
41
  const body = formattedBody.join("\n");
39
- rendered.push(table([colors.bold(section.title)], [body]).toString());
42
+ rendered.push(table([pc.bold(section.title)], [body]).toString());
40
43
  } else if (section.type === "inline") {
41
- const formattedBody = section.items.map((item) => [colors.bold(item.title), item.body]);
44
+ const formattedBody = section.items.map((item) => [pc.bold(item.title), item.body]);
42
45
  const tableGenerated = table(...formattedBody);
43
46
  rendered.push(tableGenerated.toString());
44
47
  }
@@ -47,23 +50,23 @@ const render = (sections) => {
47
50
  return rendered.join("\n");
48
51
  };
49
52
 
50
- const DELIMITER = colors.yellow("-");
53
+ const DELIMITER = pc.yellow("-");
51
54
  const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : "<Single Command>";
52
55
  const generateCliDetail = (sections, cli, subcommand) => {
53
56
  const items = [
54
57
  {
55
58
  title: "Name:",
56
- body: colors.red(cli._name)
59
+ body: pc.red(cli._name)
57
60
  },
58
61
  {
59
62
  title: "Version:",
60
- body: colors.yellow(cli._version)
63
+ body: pc.yellow(cli._version)
61
64
  }
62
65
  ];
63
66
  if (subcommand) {
64
67
  items.push({
65
68
  title: "Subcommand:",
66
- body: colors.green(formatCommandName(subcommand.name))
69
+ body: pc.green(formatCommandName(subcommand.name))
67
70
  });
68
71
  }
69
72
  sections.push({
@@ -79,7 +82,7 @@ const generateExamples = (sections, examples) => {
79
82
  const examplesFormatted = examples.map(([command, description]) => [command, DELIMITER, description]);
80
83
  sections.push({
81
84
  title: "Examples:",
82
- body: table(...examplesFormatted).toString().split("\n")
85
+ body: splitTable(...examplesFormatted)
83
86
  });
84
87
  };
85
88
  const showHelp = (ctx, notes, examples) => {
@@ -89,21 +92,21 @@ const showHelp = (ctx, notes, examples) => {
89
92
  if (ctx.isSingleCommand) {
90
93
  sections.push({
91
94
  title: "Usage:",
92
- body: [colors.magenta(`$ ${cli._name} [flags]`)]
95
+ body: [pc.magenta(`$ ${cli._name} [flags]`)]
93
96
  });
94
97
  } else {
95
98
  sections.push({
96
99
  title: "Usage:",
97
- body: [colors.magenta(`$ ${cli._name} [command] [flags]`)]
100
+ body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
98
101
  });
99
102
  }
100
103
  if (!ctx.isSingleCommand) {
101
104
  sections.push({
102
105
  title: "Commands:",
103
- body: table(...Object.values(cli._commands).map((command) => {
106
+ body: splitTable(...Object.values(cli._commands).map((command) => {
104
107
  const commandNameWithAlias = [command.name, ...mustArray(command.alias || [])].join(", ");
105
- return [colors.cyan(commandNameWithAlias), DELIMITER, command.description];
106
- })).toString().split("\n")
108
+ return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
109
+ }))
107
110
  });
108
111
  }
109
112
  if (notes) {
@@ -129,26 +132,28 @@ const showSubcommandHelp = (ctx, command) => {
129
132
  const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(" ")) || void 0;
130
133
  sections.push({
131
134
  title: "Usage:",
132
- body: [colors.magenta(`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`)]
135
+ body: [pc.magenta(`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`)]
133
136
  });
134
137
  if (subcommand.flags) {
135
138
  sections.push({
136
139
  title: "Flags:",
137
- body: Object.entries(subcommand.flags).map(([name, flag]) => {
138
- const flagNameWithAlias = [gracefulFlagName(name)];
139
- if (flag.alias) {
140
- flagNameWithAlias.push(gracefulFlagName(flag.alias));
141
- }
142
- const items = [colors.blue(flagNameWithAlias.join(", "))];
143
- if (flag.description) {
144
- items.push(DELIMITER, flag.description);
145
- }
146
- if (flag.type) {
147
- const type = Array.isArray(flag.type) ? `Array<${flag.type[0].name}>` : flag.type.name;
148
- items.push(colors.gray(`(${type})`));
149
- }
150
- return table(items).toString();
151
- })
140
+ body: splitTable(
141
+ ...Object.entries(subcommand.flags).map(([name, flag]) => {
142
+ const flagNameWithAlias = [gracefulFlagName(name)];
143
+ if (flag.alias) {
144
+ flagNameWithAlias.push(gracefulFlagName(flag.alias));
145
+ }
146
+ const items = [pc.blue(flagNameWithAlias.join(", "))];
147
+ if (flag.description) {
148
+ items.push(DELIMITER, flag.description);
149
+ }
150
+ if (flag.type) {
151
+ const type = Array.isArray(flag.type) ? `Array<${flag.type[0].name}>` : flag.type.name;
152
+ items.push(pc.gray(`(${type})`));
153
+ }
154
+ return items;
155
+ })
156
+ )
152
157
  });
153
158
  }
154
159
  if (subcommand.notes) {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
2
2
  import { mustArray, gracefulFlagName } from '@clerc/utils';
3
- import * as colors from 'colorette';
3
+ import pc from 'picocolors';
4
4
  import { Table } from '@clerc/toolkit';
5
5
 
6
6
  const table = (...items) => {
@@ -27,6 +27,9 @@ const table = (...items) => {
27
27
  table2.push(...items);
28
28
  return table2;
29
29
  };
30
+ const splitTable = (...items) => {
31
+ return table(...items).toString().split("\n");
32
+ };
30
33
 
31
34
  const render = (sections) => {
32
35
  const rendered = [];
@@ -36,9 +39,9 @@ const render = (sections) => {
36
39
  const formattedBody = section.body.map((line) => indent + line);
37
40
  formattedBody.unshift("");
38
41
  const body = formattedBody.join("\n");
39
- rendered.push(table([colors.bold(section.title)], [body]).toString());
42
+ rendered.push(table([pc.bold(section.title)], [body]).toString());
40
43
  } else if (section.type === "inline") {
41
- const formattedBody = section.items.map((item) => [colors.bold(item.title), item.body]);
44
+ const formattedBody = section.items.map((item) => [pc.bold(item.title), item.body]);
42
45
  const tableGenerated = table(...formattedBody);
43
46
  rendered.push(tableGenerated.toString());
44
47
  }
@@ -47,23 +50,23 @@ const render = (sections) => {
47
50
  return rendered.join("\n");
48
51
  };
49
52
 
50
- const DELIMITER = colors.yellow("-");
53
+ const DELIMITER = pc.yellow("-");
51
54
  const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : "<Single Command>";
52
55
  const generateCliDetail = (sections, cli, subcommand) => {
53
56
  const items = [
54
57
  {
55
58
  title: "Name:",
56
- body: colors.red(cli._name)
59
+ body: pc.red(cli._name)
57
60
  },
58
61
  {
59
62
  title: "Version:",
60
- body: colors.yellow(cli._version)
63
+ body: pc.yellow(cli._version)
61
64
  }
62
65
  ];
63
66
  if (subcommand) {
64
67
  items.push({
65
68
  title: "Subcommand:",
66
- body: colors.green(formatCommandName(subcommand.name))
69
+ body: pc.green(formatCommandName(subcommand.name))
67
70
  });
68
71
  }
69
72
  sections.push({
@@ -79,7 +82,7 @@ const generateExamples = (sections, examples) => {
79
82
  const examplesFormatted = examples.map(([command, description]) => [command, DELIMITER, description]);
80
83
  sections.push({
81
84
  title: "Examples:",
82
- body: table(...examplesFormatted).toString().split("\n")
85
+ body: splitTable(...examplesFormatted)
83
86
  });
84
87
  };
85
88
  const showHelp = (ctx, notes, examples) => {
@@ -89,21 +92,21 @@ const showHelp = (ctx, notes, examples) => {
89
92
  if (ctx.isSingleCommand) {
90
93
  sections.push({
91
94
  title: "Usage:",
92
- body: [colors.magenta(`$ ${cli._name} [flags]`)]
95
+ body: [pc.magenta(`$ ${cli._name} [flags]`)]
93
96
  });
94
97
  } else {
95
98
  sections.push({
96
99
  title: "Usage:",
97
- body: [colors.magenta(`$ ${cli._name} [command] [flags]`)]
100
+ body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
98
101
  });
99
102
  }
100
103
  if (!ctx.isSingleCommand) {
101
104
  sections.push({
102
105
  title: "Commands:",
103
- body: table(...Object.values(cli._commands).map((command) => {
106
+ body: splitTable(...Object.values(cli._commands).map((command) => {
104
107
  const commandNameWithAlias = [command.name, ...mustArray(command.alias || [])].join(", ");
105
- return [colors.cyan(commandNameWithAlias), DELIMITER, command.description];
106
- })).toString().split("\n")
108
+ return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
109
+ }))
107
110
  });
108
111
  }
109
112
  if (notes) {
@@ -129,26 +132,28 @@ const showSubcommandHelp = (ctx, command) => {
129
132
  const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(" ")) || void 0;
130
133
  sections.push({
131
134
  title: "Usage:",
132
- body: [colors.magenta(`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`)]
135
+ body: [pc.magenta(`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`)]
133
136
  });
134
137
  if (subcommand.flags) {
135
138
  sections.push({
136
139
  title: "Flags:",
137
- body: Object.entries(subcommand.flags).map(([name, flag]) => {
138
- const flagNameWithAlias = [gracefulFlagName(name)];
139
- if (flag.alias) {
140
- flagNameWithAlias.push(gracefulFlagName(flag.alias));
141
- }
142
- const items = [colors.blue(flagNameWithAlias.join(", "))];
143
- if (flag.description) {
144
- items.push(DELIMITER, flag.description);
145
- }
146
- if (flag.type) {
147
- const type = Array.isArray(flag.type) ? `Array<${flag.type[0].name}>` : flag.type.name;
148
- items.push(colors.gray(`(${type})`));
149
- }
150
- return table(items).toString();
151
- })
140
+ body: splitTable(
141
+ ...Object.entries(subcommand.flags).map(([name, flag]) => {
142
+ const flagNameWithAlias = [gracefulFlagName(name)];
143
+ if (flag.alias) {
144
+ flagNameWithAlias.push(gracefulFlagName(flag.alias));
145
+ }
146
+ const items = [pc.blue(flagNameWithAlias.join(", "))];
147
+ if (flag.description) {
148
+ items.push(DELIMITER, flag.description);
149
+ }
150
+ if (flag.type) {
151
+ const type = Array.isArray(flag.type) ? `Array<${flag.type[0].name}>` : flag.type.name;
152
+ items.push(pc.gray(`(${type})`));
153
+ }
154
+ return items;
155
+ })
156
+ )
152
157
  });
153
158
  }
154
159
  if (subcommand.notes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
5
5
  "description": "Clerc plugin help",
6
6
  "keywords": [
@@ -51,12 +51,12 @@
51
51
  "@clerc/core": "*"
52
52
  },
53
53
  "dependencies": {
54
- "colorette": "^2.0.19",
55
- "@clerc/toolkit": "0.17.0",
56
- "@clerc/utils": "0.17.0"
54
+ "picocolors": "^1.0.0",
55
+ "@clerc/toolkit": "0.17.2",
56
+ "@clerc/utils": "0.17.2"
57
57
  },
58
58
  "devDependencies": {
59
- "@clerc/core": "0.17.0"
59
+ "@clerc/core": "0.17.2"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "puild",