@todesktop/cli 0.26.0 → 0.28.0-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
@@ -333,7 +333,15 @@ Default: Electron is downloaded from the main official source.
333
333
 
334
334
  Example: `https://cdn.npm.taobao.org/dist/electron/`
335
335
 
336
- The base URL of the mirror to download Electron from. This may be a mirror geographically closer to you or even your own mirror which contains custom Electron builds. The version downloaded is the Electron version specified in `devDependencies` in your app's `package.json`.
336
+ The base URL of the mirror to download Electron from. This may be a mirror geographically closer to you or even your own mirror which contains custom Electron builds. The version downloaded is the Electron version specified in `devDependencies` in your app's `package.json`. Alternatively you can explicitly specify an `electronVersion` in `todesktop.json` as described below.
337
+
338
+ ### `electronVersion` - (optional) string
339
+
340
+ Default: Electron version specified in `devDependencies` in your app's `package.json`
341
+
342
+ Example: `12.0.7-beta.17`
343
+
344
+ The version of Electron to use. In most cases you should not specify an `electronVersion` property. Only specify this option if you wish to override the version that is specified in `package.json`.
337
345
 
338
346
  ### `extraResources` - (optional) array of objects
339
347
 
@@ -645,3 +653,22 @@ The path to your application's Windows desktop icon. It must be an ICO, ICNS, or
645
653
  ### Recommendations for app package.json
646
654
 
647
655
  - You should set the `productName` property. Otherwise, your app name will default to the value of the `name` property.
656
+
657
+ ## FAQs
658
+
659
+ ### One of my dependencies is a private package. How do I safely using it with ToDesktop CLI
660
+
661
+ ToDesktop CLI is similar to Continuous Integration service so you can use the guide from here: https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow/
662
+
663
+ To summarize:
664
+
665
+ 1. Create a token using npm: `npm token create --read-only`.
666
+ 2. In ToDesktop's web UI go to Settings -> Build and Deploy.
667
+ 3. Enter an environment variable key of `NPM_TOKEN` and value should be the token entered above.
668
+ 4. Create an `.npmrc` file in the root of your project with the following contents:
669
+
670
+ ```
671
+ //registry.npmjs.org/:_authToken=${NPM_TOKEN}
672
+ ```
673
+
674
+ Note: **Do not put a token in this file**. You are specifying a literal value of `${NPM_TOKEN}`. NPM will replace the value for you. 5. Add `.npmrc` to your `appFiles` array `[".npmrc"]` in `todesktop.json`.
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);