@todesktop/cli 0.27.2 → 0.28.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/README.md CHANGED
@@ -176,6 +176,8 @@ The following are always included if they exist:
176
176
  - `/package.json`
177
177
  - `/package-lock.json`
178
178
  - `/yarn.lock`
179
+ - `/pnpm-lock.yaml`
180
+ - `/shrinkwrap.yaml`
179
181
 
180
182
  #### Pattern syntax
181
183
 
package/build/boot.js ADDED
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+ const camelcaseKeys = require('camelcase-keys');
4
+ const decamelize = require('decamelize');
5
+ const yargs = require('yargs');
6
+
7
+ const getCommandsMessage = command => {
8
+ const usageString = [...command.usage, command.name].join(' ');
9
+ return `Commands:\n${command.subCommands.map(subCommand => ` ${usageString} ${subCommand.name}`).join('\n')}\n`;
10
+ };
11
+
12
+ module.exports = (dirname, React, Ink, originalCommands) => {
13
+ let commands = originalCommands;
14
+
15
+ // For backwards compatibility for builds made with versions prior to 1.1.0 that don't include positionalArgs
16
+ if (originalCommands.some(command => !command.positionalArgs && (command.args || []).some(arg => arg.positional))) {
17
+ commands = originalCommands.map(command => ({
18
+ ...command,
19
+ positionalArgs: (command.args || []).filter(arg => arg.positional).map(arg => arg.key)
20
+ }));
21
+ }
22
+
23
+ const addCommand = (command, yargs) => {
24
+ // Don't need to add a description as it'll be handled by the * selector in the builder
25
+ // eslint-disable-next-line no-use-before-define
26
+ yargs.command(command.name, '', builder.bind(null, command), () => yargs.showHelp());
27
+ };
28
+
29
+ const handler = (command, argv) => {
30
+ const props = {
31
+ ...camelcaseKeys(argv),
32
+ inputArgs: argv._
33
+ };
34
+
35
+ const UI = require(path.join(dirname, 'commands', command.path.replace('.tsx', '.js'))).default;
36
+ const {waitUntilExit} = Ink.render(React.createElement(UI, props));
37
+
38
+ waitUntilExit().catch(error => {
39
+ console.error(error.stack);
40
+ });
41
+ };
42
+
43
+ const builder = (command, yargs) => {
44
+ const {
45
+ positionalArgs = [],
46
+ args,
47
+ description,
48
+ name,
49
+ subCommands,
50
+ isDefaultIndex,
51
+ usage
52
+ } = command;
53
+
54
+ for (const subCommand of subCommands) {
55
+ addCommand({
56
+ ...subCommand,
57
+ usage: [...usage, name]
58
+ }, yargs);
59
+ }
60
+
61
+ // If there is no index defined, yargs will just list the sub-commands
62
+ if (isDefaultIndex) {
63
+ return;
64
+ }
65
+
66
+ const hasPositionalArgs = positionalArgs.length > 0;
67
+ const positionalArgsString = positionalArgs.map(key => {
68
+ const {isRequired, type, aliases} = args.find(arg => arg.key === key);
69
+ const [startTag, endTag] = isRequired ? ['<', '>'] : ['[', type === 'array' ? '..]' : ']'];
70
+ const argsNames = [key, ...aliases.slice(0, 1)].map(name => decamelize(name, '-')).join('|');
71
+
72
+ return `${startTag}${argsNames}${endTag}`;
73
+ }).join(' ');
74
+
75
+ const yargsName = hasPositionalArgs ? `* ${positionalArgsString}` : '*';
76
+ const commandDescription = description || `${name} command`;
77
+
78
+ yargs.command(yargsName, commandDescription, scopedYargs => {
79
+ for (const arg of command.args) {
80
+ // `inputArgs` is a reserved prop by Pastel and doesn't require a definition in yargs
81
+ if (arg.key === 'inputArgs') {
82
+ continue;
83
+ }
84
+
85
+ if (arg.positional) {
86
+ scopedYargs.positional(decamelize(arg.key, '-'), {
87
+ type: arg.type,
88
+ description: arg.description,
89
+ default: arg.defaultValue,
90
+ // This only keeps one for some reason for positional arguments
91
+ // The slice ensures we keep the same as the one we add in the command
92
+ alias: arg.aliases.slice(0, 1).map(alias => decamelize(alias, '-'))
93
+ });
94
+ } else {
95
+ scopedYargs.option(decamelize(arg.key, '-'), {
96
+ type: arg.type,
97
+ description: arg.description,
98
+ default: arg.defaultValue,
99
+ demandOption: arg.isRequired,
100
+ alias: arg.aliases.map(alias => decamelize(alias, '-'))
101
+ });
102
+ }
103
+ }
104
+
105
+ // If the index command takes no arguments and there are available sub-commands,
106
+ // list the sub-commands in the help message.
107
+ if (!hasPositionalArgs && subCommands.length > 0) {
108
+ const usageMessage = getCommandsMessage(command);
109
+ scopedYargs.demandCommand(0, 0, usageMessage, usageMessage);
110
+ }
111
+ }, handler.bind(null, command));
112
+ };
113
+
114
+ yargs.command(
115
+ '*', '',
116
+ yargs => {
117
+ const usage = [path.basename(yargs.$0)];
118
+ for (const command of commands) {
119
+ addCommand({...command, usage}, yargs);
120
+ }
121
+ },
122
+ () => yargs.showHelp()
123
+ );
124
+
125
+ yargs.parse();
126
+ };
package/build/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  'use strict';
3
3
  const React = require('react'); // eslint-disable-line import/no-unresolved
4
4
  const Ink = require('ink'); // eslint-disable-line import/no-unresolved
5
- const boot = require('pastel/boot'); // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
5
+ const boot = require('./boot'); // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
6
6
  const {commands} = require('./commands.json'); // eslint-disable-line import/no-unresolved
7
7
 
8
8
  // This file is an entrypoint of CLI applications based on Pastel
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const React = require('react'); // eslint-disable-line import/no-unresolved
4
+ const Ink = require('ink'); // eslint-disable-line import/no-unresolved
5
+ const boot = require('pastel/boot'); // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
6
+ const {commands} = require('./commands.json'); // eslint-disable-line import/no-unresolved
7
+
8
+ // This file is an entrypoint of CLI applications based on Pastel
9
+ // This file is copied to "build" directory of the CLI and "bin" field
10
+ // in package.json must point to it
11
+ boot(__dirname, React, Ink, commands);