diff --git a/docs/cli.html b/docs/cli.html index 3b0085bc7..197bb6348 100644 --- a/docs/cli.html +++ b/docs/cli.html @@ -255,7 +255,6 @@

Developer Platform

  • env:get
  • env:set
  • env:unset
  • -
  • help
  • history
  • init
  • integrations
  • @@ -596,67 +595,6 @@

    env:unset

    -
    -
    -

    help

    -
    -
    - -
    -
    -
    -
    -
    -
    -

    Lists all the commands you can use.

    -

    Usage: zapier help [command]

    Prints documentation to the terminal screen.

    Generally - the zapier command works off of two files:

      -
    • ~/.zapierrc (home directory identifies the deploy key & user)
    • -
    • ./.zapierapprc (current directory identifies the app)
    • -

    The zapier login and zapier register "Example" or zapier link commands will help manage those files. All commands listed below.

    Arguments

      -
    • none -- print all commands
    • -
    • cmd [value] -- optional, the command to view docs for
    • -
    • --format={plain,json,raw,row,table} -- optional, display format. Default is table
    • -
    • --help -- optional, prints this help text
    • -
    • --debug -- optional, print debug API calls and tracebacks
    • -
    -
    -
    -
    $ zapier help apps
    -$ zapier help scaffold
    -$ zapier help
    -# Usage: zapier COMMAND [command-specific-arguments] [--command-specific-options]
    -#
    -# ┌─────────────┬───────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────┐
    -# │ Command     │ Example                               │ Help                                                                       │
    -# ├─────────────┼───────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤
    -# │ apps        │ zapier apps                           │ Lists all the apps you can access.                                         │
    -# │ build       │ zapier build                          │ Builds a uploadable zip from the current directory.                        │
    -# │ collaborate │ zapier collaborate [user@example.com] │ Manage the admins on your project. Can optionally --remove.         │
    -# │ push        │ zapier push                           │ Build and upload the current app - does not promote.                       │
    -# │ deprecate   │ zapier deprecate 1.0.0 2017-01-20     │ Mark a non-production version of your app as deprecated by a certain date. │
    -# │ describe    │ zapier describe                       │ Describes the current app.                                                 │
    -# │ env         │ zapier env 1.0.0 CLIENT_SECRET 12345  │ Read and write environment variables.                                      │
    -# │ help        │ zapier help [command]                 │ Lists all the commands you can use.                                        │
    -# │ history     │ zapier history                        │ Prints all recent history for your app.                                    │
    -# │ init        │ zapier init path                      │ Initializes a new zapier app in a directory.                               │
    -# │ invite      │ zapier invite [user@example.com]      │ Manage the invitees/testers on your project. Can optionally --remove.      │
    -# │ link        │ zapier link                           │ Link the current directory to an app you have access to.                   │
    -# │ login       │ zapier login                          │ Configure your `~/.zapierrc` with a deploy key.                            │
    -$ │ logout      │ zapier logout                         │ Deactivates all your personal deploy keys and resets `~/.zapierrc`.        │
    -# │ logs        │ zapier logs                           │ Prints recent logs. See help for filter arguments.                         │
    -# │ migrate     │ zapier migrate 1.0.0 1.0.1 [10%]      │ Migrate users from one version to another.                                 │
    -# │ promote     │ zapier promote 1.0.0                  │ Promotes a specific version to public access.                              │
    -# │ register    │ zapier register "Example"             │ Registers a new app in your account.                                       │
    -# │ scaffold    │ zapier scaffold resource "Contact"    │ Adds a starting resource, trigger, action or search to your app.           │
    -# │ test        │ zapier test                           │ Tests your app via `npm test`.                                             │
    -# │ upload      │ zapier upload                         │ Upload the last build as a version.                                        │
    -# │ validate    │ zapier validate                       │ Validates the current project.                                             │
    -# │ versions    │ zapier versions                       │ Lists all the versions of the current app.                                 │
    -# └─────────────┴───────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
    -
    -
    -
    -

    history

    diff --git a/docs/cli.md b/docs/cli.md index f916a2780..a1b065a06 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -203,66 +203,6 @@ Prints a human readable enumeration of your integrations's triggers, searches, a * `zapier env:unset 1.2.3 SECRET OTHER` -## help - - > Lists all the commands you can use. - - **Usage:** `zapier help [command]` - - -Prints documentation to the terminal screen. - -Generally - the `zapier` command works off of two files: - - * ~/.zapierrc (home directory identifies the deploy key & user) - * ./.zapierapprc (current directory identifies the app) - -The `zapier login` and `zapier register "Example"` or `zapier link` commands will help manage those files. All commands listed below. - -**Arguments** - -* _none_ -- print all commands -* `cmd [value]` -- _optional_, the command to view docs for -* `--format={plain,json,raw,row,table}` -- _optional_, display format. Default is `table` -* `--help` -- _optional_, prints this help text -* `--debug` -- _optional_, print debug API calls and tracebacks - -```bash -$ zapier help apps -$ zapier help scaffold -$ zapier help -# Usage: zapier COMMAND [command-specific-arguments] [--command-specific-options] -# -# ┌─────────────┬───────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────┐ -# │ Command │ Example │ Help │ -# ├─────────────┼───────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ -# │ apps │ zapier apps │ Lists all the apps you can access. │ -# │ build │ zapier build │ Builds a uploadable zip from the current directory. │ -# │ collaborate │ zapier collaborate [user@example.com] │ Manage the admins on your project. Can optionally --remove. │ -# │ push │ zapier push │ Build and upload the current app - does not promote. │ -# │ deprecate │ zapier deprecate 1.0.0 2017-01-20 │ Mark a non-production version of your app as deprecated by a certain date. │ -# │ describe │ zapier describe │ Describes the current app. │ -# │ env │ zapier env 1.0.0 CLIENT_SECRET 12345 │ Read and write environment variables. │ -# │ help │ zapier help [command] │ Lists all the commands you can use. │ -# │ history │ zapier history │ Prints all recent history for your app. │ -# │ init │ zapier init path │ Initializes a new zapier app in a directory. │ -# │ invite │ zapier invite [user@example.com] │ Manage the invitees/testers on your project. Can optionally --remove. │ -# │ link │ zapier link │ Link the current directory to an app you have access to. │ -# │ login │ zapier login │ Configure your `~/.zapierrc` with a deploy key. │ -$ │ logout │ zapier logout │ Deactivates all your personal deploy keys and resets `~/.zapierrc`. │ -# │ logs │ zapier logs │ Prints recent logs. See help for filter arguments. │ -# │ migrate │ zapier migrate 1.0.0 1.0.1 [10%] │ Migrate users from one version to another. │ -# │ promote │ zapier promote 1.0.0 │ Promotes a specific version to public access. │ -# │ register │ zapier register "Example" │ Registers a new app in your account. │ -# │ scaffold │ zapier scaffold resource "Contact" │ Adds a starting resource, trigger, action or search to your app. │ -# │ test │ zapier test │ Tests your app via `npm test`. │ -# │ upload │ zapier upload │ Upload the last build as a version. │ -# │ validate │ zapier validate │ Validates the current project. │ -# │ versions │ zapier versions │ Lists all the versions of the current app. │ -# └─────────────┴───────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘ -``` - - ## history > Gets the history of your integration. diff --git a/packages/cli/docs/cli.html b/packages/cli/docs/cli.html index 3b0085bc7..197bb6348 100644 --- a/packages/cli/docs/cli.html +++ b/packages/cli/docs/cli.html @@ -255,7 +255,6 @@

    Developer Platform

  • env:get
  • env:set
  • env:unset
  • -
  • help
  • history
  • init
  • integrations
  • @@ -596,67 +595,6 @@

    env:unset

    -
    -
    -

    help

    -
    -
    - -
    -
    -
    -
    -
    -
    -

    Lists all the commands you can use.

    -

    Usage: zapier help [command]

    Prints documentation to the terminal screen.

    Generally - the zapier command works off of two files:

      -
    • ~/.zapierrc (home directory identifies the deploy key & user)
    • -
    • ./.zapierapprc (current directory identifies the app)
    • -

    The zapier login and zapier register "Example" or zapier link commands will help manage those files. All commands listed below.

    Arguments

      -
    • none -- print all commands
    • -
    • cmd [value] -- optional, the command to view docs for
    • -
    • --format={plain,json,raw,row,table} -- optional, display format. Default is table
    • -
    • --help -- optional, prints this help text
    • -
    • --debug -- optional, print debug API calls and tracebacks
    • -
    -
    -
    -
    $ zapier help apps
    -$ zapier help scaffold
    -$ zapier help
    -# Usage: zapier COMMAND [command-specific-arguments] [--command-specific-options]
    -#
    -# ┌─────────────┬───────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────┐
    -# │ Command     │ Example                               │ Help                                                                       │
    -# ├─────────────┼───────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤
    -# │ apps        │ zapier apps                           │ Lists all the apps you can access.                                         │
    -# │ build       │ zapier build                          │ Builds a uploadable zip from the current directory.                        │
    -# │ collaborate │ zapier collaborate [user@example.com] │ Manage the admins on your project. Can optionally --remove.         │
    -# │ push        │ zapier push                           │ Build and upload the current app - does not promote.                       │
    -# │ deprecate   │ zapier deprecate 1.0.0 2017-01-20     │ Mark a non-production version of your app as deprecated by a certain date. │
    -# │ describe    │ zapier describe                       │ Describes the current app.                                                 │
    -# │ env         │ zapier env 1.0.0 CLIENT_SECRET 12345  │ Read and write environment variables.                                      │
    -# │ help        │ zapier help [command]                 │ Lists all the commands you can use.                                        │
    -# │ history     │ zapier history                        │ Prints all recent history for your app.                                    │
    -# │ init        │ zapier init path                      │ Initializes a new zapier app in a directory.                               │
    -# │ invite      │ zapier invite [user@example.com]      │ Manage the invitees/testers on your project. Can optionally --remove.      │
    -# │ link        │ zapier link                           │ Link the current directory to an app you have access to.                   │
    -# │ login       │ zapier login                          │ Configure your `~/.zapierrc` with a deploy key.                            │
    -$ │ logout      │ zapier logout                         │ Deactivates all your personal deploy keys and resets `~/.zapierrc`.        │
    -# │ logs        │ zapier logs                           │ Prints recent logs. See help for filter arguments.                         │
    -# │ migrate     │ zapier migrate 1.0.0 1.0.1 [10%]      │ Migrate users from one version to another.                                 │
    -# │ promote     │ zapier promote 1.0.0                  │ Promotes a specific version to public access.                              │
    -# │ register    │ zapier register "Example"             │ Registers a new app in your account.                                       │
    -# │ scaffold    │ zapier scaffold resource "Contact"    │ Adds a starting resource, trigger, action or search to your app.           │
    -# │ test        │ zapier test                           │ Tests your app via `npm test`.                                             │
    -# │ upload      │ zapier upload                         │ Upload the last build as a version.                                        │
    -# │ validate    │ zapier validate                       │ Validates the current project.                                             │
    -# │ versions    │ zapier versions                       │ Lists all the versions of the current app.                                 │
    -# └─────────────┴───────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
    -
    -
    -
    -

    history

    diff --git a/packages/cli/docs/cli.md b/packages/cli/docs/cli.md index f916a2780..a1b065a06 100644 --- a/packages/cli/docs/cli.md +++ b/packages/cli/docs/cli.md @@ -203,66 +203,6 @@ Prints a human readable enumeration of your integrations's triggers, searches, a * `zapier env:unset 1.2.3 SECRET OTHER` -## help - - > Lists all the commands you can use. - - **Usage:** `zapier help [command]` - - -Prints documentation to the terminal screen. - -Generally - the `zapier` command works off of two files: - - * ~/.zapierrc (home directory identifies the deploy key & user) - * ./.zapierapprc (current directory identifies the app) - -The `zapier login` and `zapier register "Example"` or `zapier link` commands will help manage those files. All commands listed below. - -**Arguments** - -* _none_ -- print all commands -* `cmd [value]` -- _optional_, the command to view docs for -* `--format={plain,json,raw,row,table}` -- _optional_, display format. Default is `table` -* `--help` -- _optional_, prints this help text -* `--debug` -- _optional_, print debug API calls and tracebacks - -```bash -$ zapier help apps -$ zapier help scaffold -$ zapier help -# Usage: zapier COMMAND [command-specific-arguments] [--command-specific-options] -# -# ┌─────────────┬───────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────┐ -# │ Command │ Example │ Help │ -# ├─────────────┼───────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ -# │ apps │ zapier apps │ Lists all the apps you can access. │ -# │ build │ zapier build │ Builds a uploadable zip from the current directory. │ -# │ collaborate │ zapier collaborate [user@example.com] │ Manage the admins on your project. Can optionally --remove. │ -# │ push │ zapier push │ Build and upload the current app - does not promote. │ -# │ deprecate │ zapier deprecate 1.0.0 2017-01-20 │ Mark a non-production version of your app as deprecated by a certain date. │ -# │ describe │ zapier describe │ Describes the current app. │ -# │ env │ zapier env 1.0.0 CLIENT_SECRET 12345 │ Read and write environment variables. │ -# │ help │ zapier help [command] │ Lists all the commands you can use. │ -# │ history │ zapier history │ Prints all recent history for your app. │ -# │ init │ zapier init path │ Initializes a new zapier app in a directory. │ -# │ invite │ zapier invite [user@example.com] │ Manage the invitees/testers on your project. Can optionally --remove. │ -# │ link │ zapier link │ Link the current directory to an app you have access to. │ -# │ login │ zapier login │ Configure your `~/.zapierrc` with a deploy key. │ -$ │ logout │ zapier logout │ Deactivates all your personal deploy keys and resets `~/.zapierrc`. │ -# │ logs │ zapier logs │ Prints recent logs. See help for filter arguments. │ -# │ migrate │ zapier migrate 1.0.0 1.0.1 [10%] │ Migrate users from one version to another. │ -# │ promote │ zapier promote 1.0.0 │ Promotes a specific version to public access. │ -# │ register │ zapier register "Example" │ Registers a new app in your account. │ -# │ scaffold │ zapier scaffold resource "Contact" │ Adds a starting resource, trigger, action or search to your app. │ -# │ test │ zapier test │ Tests your app via `npm test`. │ -# │ upload │ zapier upload │ Upload the last build as a version. │ -# │ validate │ zapier validate │ Validates the current project. │ -# │ versions │ zapier versions │ Lists all the versions of the current app. │ -# └─────────────┴───────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘ -``` - - ## history > Gets the history of your integration. diff --git a/packages/cli/package.json b/packages/cli/package.json index 161890feb..8689ba552 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -6,20 +6,19 @@ "homepage": "https://zapier.com/", "author": "Bryan Helmig ", "license": "UNLICENSED", - "main": "zapier.js", + "main": "./src/index.js", "files": [ "/src/*.js", "/src/commands/", "/src/oclif/", - "/src/bin/run", + "/src/bin/", "/src/bin/run.cmd", "/src/utils/", "/scaffold/", - "/zapier.js", "/oclif.manifest.json" ], "engines": { - "node": ">=8.10.0" + "node": ">=10" }, "scripts": { "docs": "ZAPIER_BASE_ENDPOINT='' node src/bin/docs.js && cp -r docs ../..", @@ -29,10 +28,9 @@ "precommit": "yarn docs && git add docs README.md ../../docs", "version": "yarn docs && yarn gen-completions && git add docs/* goodies/* README.md", "postversion": "git push && git push --tags", - "lint": "eslint zapier.js src snippets --fix", + "lint": "eslint src snippets --fix", "test": "NODE_ENV=test mocha -t 50000 --recursive src/tests", "smoke-test": "NODE_ENV=test mocha -t 120000 --recursive src/smoke-tests", - "zapier": "zapier.js", "validate-templates": "./scripts/validate-app-templates.js", "set-template-versions": "./scripts/set-app-template-versions.js", "gen-completions": "./scripts/gen-zsh-completions.js > ./goodies/zsh/_zapier && ./scripts/gen-bash-completions.js > ./goodies/bash/_zapier", @@ -43,6 +41,7 @@ "@oclif/command": "1.5.18", "@oclif/config": "1.13.3", "@oclif/plugin-help": "2.2.1", + "@oclif/plugin-not-found": "1.2.3", "adm-zip": "0.4.13", "archiver": "3.1.1", "browserify": "16.5.0", @@ -53,7 +52,6 @@ "ignore": "5.1.3", "inquirer": "6.5.0", "klaw": "3.0.0", - "leven": "2.1.0", "lodash": "4.17.15", "node-fetch": "2.6.0", "ora": "3.4.0", @@ -77,18 +75,28 @@ "yamljs": "0.3.0" }, "bin": { - "zapier": "zapier.js" + "zapier": "./src/bin/run" }, "oclif": { "commands": "src/oclif/commands", "bin": "zapier", - "plugins": [], + "plugins": [ + "@oclif/plugin-not-found" + ], "hooks": { - "init": "./src/oclif/hooks/deprecated" + "init": [ + "./src/oclif/hooks/deprecated", + "./src/oclif/hooks/updateNotifier", + "./src/oclif/hooks/checkValidNodeVersion" + ] }, "topics": { - "delete": { "description": "Delete your entire integration or a specific integration version" }, - "env": {"description": "Interact with your integration's environment"} + "delete": { + "description": "Delete your entire integration or a specific integration version" + }, + "env": { + "description": "Interact with your integration's environment" + } } } } diff --git a/packages/cli/scripts/set-app-template-versions.js b/packages/cli/scripts/set-app-template-versions.js index 37cabe5f5..90328bd7a 100755 --- a/packages/cli/scripts/set-app-template-versions.js +++ b/packages/cli/scripts/set-app-template-versions.js @@ -3,14 +3,14 @@ const _ = require('lodash'); const path = require('path'); const tmp = require('tmp'); -const utils = require('../src/utils'); +const { promisifyAll } = require('../src/utils/promisify'); const appTemplates = require('../src/app-templates'); const versionStore = require('../src/version-store'); const fse = require('fs-extra'); const semver = require('semver'); const yaml = require('yamljs'); -const childProcess = utils.promisifyAll(require('child_process')); +const childProcess = promisifyAll(require('child_process')); const CLONE_URL_PREFIX = 'git@github.com:zapier/zapier-platform-example-app'; const PACKAGES_NAMES = 'node, npm, and zapier-platform-core'; diff --git a/packages/cli/scripts/test-convert.js b/packages/cli/scripts/test-convert.js index 555e49b1a..76b4675a3 100755 --- a/packages/cli/scripts/test-convert.js +++ b/packages/cli/scripts/test-convert.js @@ -3,10 +3,10 @@ const _ = require('lodash'); const path = require('path'); const tmp = require('tmp'); -const utils = require('../src/utils'); +const { promisifyAll } = require('../src/utils/promisify'); const fse = require('fs-extra'); -const childProcess = utils.promisifyAll(require('child_process')); +const childProcess = promisifyAll(require('child_process')); const appsToConvert = [ { id: 80082, name: 'simple-basic-auth' }, @@ -26,7 +26,7 @@ const appsToConvert = [ ]; const testConvertedApp = (appToConvert, rootTmpDir) => { - const zapierCmd = path.resolve(__dirname, '../zapier.js'); + const zapierCmd = path.resolve(__dirname, '../src/bin/run'); // Prepare all env variables the apps might need const exportCmd = 'export CLIENT_ID=1234 CLIENT_SECRET=asdf USERNAME=user PASSWORD=secret API_KEY=secret SESSION_KEY=secret ACCESS_TOKEN=a_token REFRESH_TOKEN=a_refresh_token'; @@ -41,11 +41,7 @@ const testConvertedApp = (appToConvert, rootTmpDir) => { .ensureFile(logFile) .then(() => { return new Promise((resolve, reject) => { - const cmd = `${zapierCmd} convert ${appToConvert.id} ${ - appToConvert.name - } --debug && cd ${ - appToConvert.name - } && npm install && ${zapierCmd} validate && ${exportCmd} && ${zapierCmd} test --timeout=10000`; + const cmd = `${zapierCmd} convert ${appToConvert.id} ${appToConvert.name} --debug && cd ${appToConvert.name} && npm install && ${zapierCmd} validate && ${exportCmd} && ${zapierCmd} test --timeout=10000`; const child = childProcess.exec(cmd, { cwd: rootTmpDir }, err => { if (err) { console.log('error starting child process:', err); diff --git a/packages/cli/scripts/validate-app-templates.js b/packages/cli/scripts/validate-app-templates.js index d3eb4b86b..289a855d9 100755 --- a/packages/cli/scripts/validate-app-templates.js +++ b/packages/cli/scripts/validate-app-templates.js @@ -3,16 +3,16 @@ const _ = require('lodash'); const path = require('path'); const tmp = require('tmp'); -const utils = require('../src/utils'); +const { promisifyAll } = require('../src/utils/promisify'); const fse = require('fs-extra'); -const childProcess = utils.promisifyAll(require('child_process')); +const childProcess = promisifyAll(require('child_process')); const appTemplates = require('../src/app-templates'); const validateAppTemplate = (template, rootTmpDir) => { - //const appDir = path.resolve(rootTmpDir, template); - const zapierCmd = path.resolve(__dirname, '../zapier.js'); + // const appDir = path.resolve(rootTmpDir, template); + const zapierCmd = path.resolve(__dirname, '../src/bin/run'); const extraCmd = template === 'babel' ? ' && npm run zapier-build' : ''; const logFile = path.resolve(__dirname, '..', `${template}.log`); diff --git a/packages/cli/src/bin/docs.js b/packages/cli/src/bin/docs.js index c4fea4f59..6a037b50f 100644 --- a/packages/cli/src/bin/docs.js +++ b/packages/cli/src/bin/docs.js @@ -8,44 +8,17 @@ const _ = require('lodash'); const toc = require('markdown-toc'); const litdoc = require('litdoc'); -const oCommands = require('../oclif/oCommands'); -const oclifCommands = new Set(Object.keys(oCommands)); - -const commands = { - ...require('../commands'), - ...oCommands -}; - -const block = str => '> ' + str.split('\n').join('\n> '); +const commands = require('../oclif/oCommands'); const { LAMBDA_VERSION, PACKAGE_VERSION } = require('../constants'); -const _oldCommandMarkdown = (name, command) => - `\ - ## ${name} - - ${block(command.help)} - - **Usage:** \`${command.usage || command.example}\` - - ${command.docs} -`.trim(); - -// for oclif commands -const _commandMarkdown = (name, command) => command.markdownHelp(name); - -const commandMarkdown = (name, command) => - oclifCommands.has(name) - ? _commandMarkdown(name, command) - : _oldCommandMarkdown(name, command); - // Takes all the cmd.docs and puts them into a big md file. const generateCliMarkdown = () => { return _.orderBy(Object.keys(commands)) .filter(name => !_.isBoolean(commands[name])) .filter(name => !commands[name].hide) .map(name => { - return commandMarkdown(name, commands[name]); + return commands[name].markdownHelp(name); }) .join('\n\n\n'); }; diff --git a/packages/cli/src/commands/help.js b/packages/cli/src/commands/help.js deleted file mode 100644 index 6f020b2c6..000000000 --- a/packages/cli/src/commands/help.js +++ /dev/null @@ -1,105 +0,0 @@ -const _ = require('lodash'); - -const constants = require('../constants'); -const utils = require('../utils'); - -const help = (context, cmd) => { - const commands = require('./index'); - const oCommands = require('../oclif/oCommands'); - const oclifCommands = new Set(Object.keys(oCommands)); - - const allCommands = { ...commands, ...oCommands }; - - if (commands[cmd] && commands[cmd].docs) { - // this only shows help for old commands, since `help newcommand` goes to oclif - context.line(commands[cmd].help); - context.line(); - context.line(`Usage: \`${commands[cmd].example}\``); - context.line(); - utils.markdownLog(commands[cmd].docs.trim()); - return Promise.resolve(); - } - context.line( - 'Usage: zapier COMMAND [command-specific-arguments] [--command-specific-options]'.trim() - ); - return Promise.resolve().then(() => { - context.line(); - const commandList = _.orderBy(Object.keys(allCommands)) - .filter(name => !_.isBoolean(allCommands[name])) - .filter(name => !allCommands[name].hide) - .map(name => { - const c = allCommands[name]; - return { - name, - help: c.help || c.description.split('\n')[0], - example: oclifCommands.has(name) - ? c.zUsage(name) // new - : c.example // old - }; - }); - utils.printData(commandList, [ - ['Command', 'name'], - ['Example', 'example'], - ['Help', 'help'] - ]); - }); -}; -help.argsSpec = [{ name: 'cmd', help: 'the command to view docs for' }]; -help.argOptsSpec = {}; -help.help = 'Lists all the commands you can use.'; -help.example = 'zapier help [command]'; -help.docs = ` -Prints documentation to the terminal screen. - -Generally - the \`zapier\` command works off of two files: - - * ${ - constants.AUTH_LOCATION_RAW - } (home directory identifies the deploy key & user) - * ./${constants.CURRENT_APP_FILE} (current directory identifies the app) - -The \`zapier login\` and \`zapier register "Example"\` or \`zapier link\` commands will help manage those files. All commands listed below. - -**Arguments** - -* _none_ -- print all commands -${utils.argsFragment(help.argsSpec)} -${utils.defaultArgOptsFragment()} - -${'```'}bash -$ zapier help apps -$ zapier help scaffold -$ zapier help -# Usage: zapier COMMAND [command-specific-arguments] [--command-specific-options] -# -# ┌─────────────┬───────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────┐ -# │ Command │ Example │ Help │ -# ├─────────────┼───────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ -# │ apps │ zapier apps │ Lists all the apps you can access. │ -# │ build │ zapier build │ Builds a uploadable zip from the current directory. │ -# │ collaborate │ zapier collaborate [user@example.com] │ Manage the admins on your project. Can optionally --remove. │ -# │ push │ zapier push │ Build and upload the current app - does not promote. │ -# │ deprecate │ zapier deprecate 1.0.0 2017-01-20 │ Mark a non-production version of your app as deprecated by a certain date. │ -# │ describe │ zapier describe │ Describes the current app. │ -# │ env │ zapier env 1.0.0 CLIENT_SECRET 12345 │ Read and write environment variables. │ -# │ help │ zapier help [command] │ Lists all the commands you can use. │ -# │ history │ zapier history │ Prints all recent history for your app. │ -# │ init │ zapier init path │ Initializes a new zapier app in a directory. │ -# │ invite │ zapier invite [user@example.com] │ Manage the invitees/testers on your project. Can optionally --remove. │ -# │ link │ zapier link │ Link the current directory to an app you have access to. │ -# │ login │ zapier login │ Configure your \`~/.zapierrc\` with a deploy key. │ -$ │ logout │ zapier logout │ Deactivates all your personal deploy keys and resets \`~/.zapierrc\`. │ -# │ logs │ zapier logs │ Prints recent logs. See help for filter arguments. │ -# │ migrate │ zapier migrate 1.0.0 1.0.1 [10%] │ Migrate users from one version to another. │ -# │ promote │ zapier promote 1.0.0 │ Promotes a specific version to public access. │ -# │ register │ zapier register "Example" │ Registers a new app in your account. │ -# │ scaffold │ zapier scaffold resource "Contact" │ Adds a starting resource, trigger, action or search to your app. │ -# │ test │ zapier test │ Tests your app via \`npm test\`. │ -# │ upload │ zapier upload │ Upload the last build as a version. │ -# │ validate │ zapier validate │ Validates the current project. │ -# │ versions │ zapier versions │ Lists all the versions of the current app. │ -# └─────────────┴───────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘ -${'```'} -`; - -module.exports = help; diff --git a/packages/cli/src/commands/index.js b/packages/cli/src/commands/index.js deleted file mode 100644 index 6b237c21b..000000000 --- a/packages/cli/src/commands/index.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - help: require('./help') -}; diff --git a/packages/cli/src/entry.js b/packages/cli/src/entry.js deleted file mode 100644 index 1887d04cf..000000000 --- a/packages/cli/src/entry.js +++ /dev/null @@ -1,165 +0,0 @@ -/* eslint no-process-exit: 0 */ -const _ = require('lodash'); -const colors = require('colors/safe'); -const updateNotifier = require('update-notifier'); - -const pkg = require('../package.json'); - -const { LAMBDA_VERSION, UPDATE_NOTIFICATION_INTERVAL } = require('./constants'); -const commands = require('./commands'); -const oCommands = require('./oclif/oCommands'); -const utils = require('./utils'); -const { recordAnalytics } = require('./utils/analytics'); -const leven = require('leven'); - -const oclifCommands = new Set(Object.keys(oCommands)); - -const commandSuggestion = command => { - const availableCommands = Object.keys(commands); - // the lower the score, the more identical the words - const suggestion = _.sortBy( - availableCommands.map(c => { - return { command: c, score: leven(command, c) }; - }), - 'score' - )[0]; - - // after some brief testing, ~3 is a reasonable threshold for a typo vs an unrelated word - if (suggestion.score <= 3) { - return suggestion.command; - } else { - return null; - } -}; - -module.exports = argv => { - if (!utils.isValidNodeVersion()) { - console.error( - colors.red( - `Requires node version >= ${LAMBDA_VERSION}, found ${process.versions.node}. Please upgrade Node.js.` - ) - ); - process.exitCode = 1; - return; - } - - const notifier = updateNotifier({ - pkg, - updateCheckInterval: UPDATE_NOTIFICATION_INTERVAL - }); - if (notifier.update && notifier.update.latest !== pkg.version) { - notifier.notify({ isGlobal: true }); - } - - argv = argv.slice(2); // strip path, zapier.js - - let [args, argOpts] = utils.argParse(argv); - global.argOpts = argOpts; - - // when `zapier invitees --help`, swap to `zapier help invitees` - if (argOpts.help || args.length === 0) { - args = ['help'].concat(args); - } - - const rootCommand = c => (c || '').split(':')[0]; // accounts for subcommands - const command = rootCommand(args[0]); - args = args.slice(1); - - if ( - oclifCommands.has(command) || // zapier blah - (command === 'help' && oclifCommands.has(rootCommand(args[0]))) // zapier help blah - ) { - global.argOpts = undefined; // prevent mixing the new and the old - require('./bin/run'); // requiring shouldn't have side effects, but this one is temporary and special - return; - } - - const analyticsPromise = recordAnalytics( - command, - Boolean(oclifCommands.has(command) || commands[command]), - args, - argOpts - ); - - // create the context, logs thread through this - const context = utils.createContext({ command, args, argOpts }); - - if (command === 'help' && (argOpts.version || argOpts.v)) { - utils.printVersionInfo(context); - return; - } - - const commandFunc = commands[command]; - if (!commandFunc) { - const message = [`\`zapier ${command}\` is not a command!`]; - const suggestion = commandSuggestion(command); - if (suggestion) { - message.push(`Did you mean \`zapier ${suggestion}\`?`); - } else { - message.push( - 'Run `zapier help` to see a full list of available commands.' - ); - } - - context.line(message.join(' ')); - process.exitCode = 1; - return; - } - - const { valid, reason } = utils.isValidAppInstall(command); - if (!valid) { - // wait here, because it looks weird to print the "missing install" message and then wait another second - analyticsPromise.then(() => { - console.error(colors.red(reason)); - process.exitCode = 1; - }); - return; - } - - const spec = { - argsSpec: commandFunc.argsSpec, - argOptsSpec: _.extend({}, utils.globalArgOptsSpec, commandFunc.argOptsSpec) - }; - const errors = utils.enforceArgSpec(spec, args, argOpts); - if (errors.length) { - // wait here, because it looks weird to print the "wrong flag" message and then wait another second - analyticsPromise.then(() => { - context.line(); - context.line( - colors.red( - 'Errors running command `' + ['zapier'].concat(argv).join(' ') + '`:' - ) - ); - context.line(); - errors.forEach(error => context.line(colors.red(`!!! ${error}`))); - context.line(); - context.line(`For more information, run \`zapier help ${command}\`.`); - context.line(); - process.exitCode = 1; - }); - return; - } - - commandFunc(context, ...args).catch(err => { - analyticsPromise.then(() => { - utils.endSpinner(false); - - if (global.argOpts.debug) { - context.line(); - context.line(err.stack); - context.line(); - context.line(colors.red('Error!')); - } else { - context.line(); - context.line(); - context.line(colors.red('Error!') + ' ' + colors.red(err.message)); - context.line( - colors.grey( - '(Use --debug flag and run this command again to get more details.)' - ) - ); - } - process.exitCode = 1; - }); - }); -}; diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js new file mode 100644 index 000000000..a99fe5b0c --- /dev/null +++ b/packages/cli/src/index.js @@ -0,0 +1,3 @@ +// for now, requiring this file has no real effect + +module.exports = require('@oclif/command'); diff --git a/packages/cli/src/oclif/README.md b/packages/cli/src/oclif/README.md deleted file mode 100644 index a5d6ed6c9..000000000 --- a/packages/cli/src/oclif/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# oclif migration - -Some notes to help an ongoing project - -## helpful links - -- the docs are fairly useful: https://oclif.io/docs/commands -- base command source is great for seeing what's available: https://github.com/oclif/command/blob/master/src/command.ts - -## migrating a command - -1. add a new command file in `src/oclif/commands` -2. add a require line in `src/oclif/oCommands.js` -3. remove the old command from `src/commands` -4. remove the import from `src/commands/index.js`. smoke test will fail if you don't do this - -## relative command difficulty - -### easy - -- [x] apps -- [ ] delete -- [ ] describe -- [x] deprecate -- [ ] help -- [x] history -- [ ] invitees -- [ ] link -- [x] logout -- [x] login -- [ ] logs -- [x] migrate -- [ ] register -- [x] test - -## hard - -- [x] build -- [ ] collaborate -- [ ] convert -- [ ] env -- [ ] invite -- [x] promote -- [x] push -- [ ] scaffold -- [x] upload -- [x] watch - remove? -- [x] validate diff --git a/packages/cli/src/oclif/hooks/checkValidNodeVersion.js b/packages/cli/src/oclif/hooks/checkValidNodeVersion.js new file mode 100644 index 000000000..8ad05bdef --- /dev/null +++ b/packages/cli/src/oclif/hooks/checkValidNodeVersion.js @@ -0,0 +1,11 @@ +const { isValidNodeVersion } = require('../../utils/misc'); +const { LAMBDA_VERSION } = require('../../constants'); + +// can't be fat arrow because it inherits `this` from commands +module.exports = function() { + if (!isValidNodeVersion()) { + this.error( + `Requires node version >= ${LAMBDA_VERSION}, found ${process.versions.node}. Please upgrade Node.js.` + ); + } +}; diff --git a/packages/cli/src/oclif/hooks/deprecated.js b/packages/cli/src/oclif/hooks/deprecated.js index 6a46bb64d..2dc4cf895 100644 --- a/packages/cli/src/oclif/hooks/deprecated.js +++ b/packages/cli/src/oclif/hooks/deprecated.js @@ -1,14 +1,18 @@ -// current => new +// this is an init hook because the info about which command is clobbered by the time we get to the pre_run hook + +// deprecated => recommended const deprecatedCommands = { apps: 'integrations' }; -module.exports = async function(options) { +// can't be fat arrow because it inherits `this` from commands +module.exports = function(options) { if (deprecatedCommands[options.id]) { - console.warn( - `\nWARNING: The \`${options.id}\` command is deprecated. Use the \`${ + this.warn( + `The \`${options.id}\` command is deprecated. Use the \`${ deprecatedCommands[options.id] - }\` command instead\n` + }\` command instead.` ); + console.log(); } }; diff --git a/packages/cli/src/oclif/hooks/updateNotifier.js b/packages/cli/src/oclif/hooks/updateNotifier.js new file mode 100644 index 000000000..462948c3d --- /dev/null +++ b/packages/cli/src/oclif/hooks/updateNotifier.js @@ -0,0 +1,13 @@ +const updateNotifier = require('update-notifier'); +const pkg = require('../../../package.json'); +const { UPDATE_NOTIFICATION_INTERVAL } = require('../../constants'); + +// can't be fat arrow because it inherits `this` from commands +module.exports = function(options) { + const notifier = updateNotifier({ + pkg, + updateCheckInterval: UPDATE_NOTIFICATION_INTERVAL + }); + + notifier.notify({ isGlobal: true }); +}; diff --git a/packages/cli/src/smoke-tests/smoke-tests.js b/packages/cli/src/smoke-tests/smoke-tests.js index 01b81061b..cb238be21 100644 --- a/packages/cli/src/smoke-tests/smoke-tests.js +++ b/packages/cli/src/smoke-tests/smoke-tests.js @@ -95,10 +95,10 @@ describe('smoke tests - setup will take some time', () => { }); it('zapier --version', () => { - const firstLine = runCommand(context.cliBin, ['--version']) - .split('\n')[0] - .trim(); - firstLine.should.be.eql(`zapier-platform-cli/${context.package.version}`); + const firstLine = runCommand(context.cliBin, ['--version']); + firstLine + .includes(`zapier-platform-cli/${context.package.version}`) + .should.be.true(); }); it('zapier init', () => { diff --git a/packages/cli/src/tests/utils/args.js b/packages/cli/src/tests/utils/args.js deleted file mode 100644 index ff9254b61..000000000 --- a/packages/cli/src/tests/utils/args.js +++ /dev/null @@ -1,133 +0,0 @@ -require('should'); - -const argUtils = require('../../utils/args'); - -describe('args', () => { - it('should parse some args', () => { - const [args, argOpts] = argUtils.argParse([ - 'hello', - 'world', - '--cat', - '--lolz=hahaha' - ]); - args.should.eql(['hello', 'world']); - argOpts.should.eql({ cat: true, lolz: 'hahaha' }); - }); - - it('should enforce some args', () => { - let args, argOpts, errors; - const spec = { - argsSpec: [ - { name: 'firstGreeting', required: true }, - { name: 'secondGreeting' }, - { rest: true } - ], - argOptsSpec: { - cat: { help: 'Is this a cat?', flag: true }, - lolz: { help: 'What kind of lolz do you have?', required: true } - } - }; - - [args, argOpts] = argUtils.argParse([]); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([ - 'Missing required positional argument 1/firstGreeting', - 'Missing required keyword argument --lolz=value' - ]); - - [args, argOpts] = argUtils.argParse(['hello']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql(['Missing required keyword argument --lolz=value']); - - [args, argOpts] = argUtils.argParse(['hello', '--lolz=hahaha']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([]); - - [args, argOpts] = argUtils.argParse([ - 'hello', - 'world', - 'lots', - 'more', - '--lolz=hahaha' - ]); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([]); - }); - - it('should enforce requiredWith args', () => { - let args, argOpts, errors; - const spec = { - argsSpec: [ - { name: 'version', required: true }, - { name: 'key' }, - { name: 'value', requiredWith: ['key'] } - ] - }; - - [args, argOpts] = argUtils.argParse([]); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql(['Missing required positional argument 1/version']); - - [args, argOpts] = argUtils.argParse(['1.0.0']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([]); - - [args, argOpts] = argUtils.argParse(['1.0.0', 'some_key']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql(['Missing required positional argument 3/value']); - - [args, argOpts] = argUtils.argParse(['1.0.0', 'some_key', 'some_value']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([]); - }); - - it('should enforce no args', () => { - let args, argOpts, errors; - const spec = {}; - - [args, argOpts] = argUtils.argParse(['something']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql(['Unexpected positional argument 1 of something']); - - [args, argOpts] = argUtils.argParse(['something', 'other']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([ - 'Unexpected positional argument 1 of something', - 'Unexpected positional argument 2 of other' - ]); - - [args, argOpts] = argUtils.argParse(['--color=blue']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql(['Unexpected keyword argument --color=blue']); - - [args, argOpts] = argUtils.argParse(['--flaggy']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql(['Unexpected keyword argument --flaggy']); - }); - - it('should enforce args choices', () => { - let args, argOpts, errors; - const spec = { - argsSpec: [{ name: 'color', choices: ['blue', 'red'] }], - argOptsSpec: { - color: { choices: ['blue', 'red'] } - } - }; - - [args, argOpts] = argUtils.argParse(['blue']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([]); - - [args, argOpts] = argUtils.argParse(['urple']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([ - 'Unexpected positional argument 1/color of urple, must be one of {blue,red}' - ]); - - [args, argOpts] = argUtils.argParse(['--color=urple']); - errors = argUtils.enforceArgSpec(spec, args, argOpts); - errors.should.eql([ - 'Unexpected keyword argument --color=urple, must be one of {blue,red}' - ]); - }); -}); diff --git a/packages/cli/src/tests/utils/display.js b/packages/cli/src/tests/utils/display.js index d7044784e..59a3a0444 100644 --- a/packages/cli/src/tests/utils/display.js +++ b/packages/cli/src/tests/utils/display.js @@ -1,6 +1,6 @@ require('should'); -const utils = require('../../utils'); +const { makeTable } = require('../../utils/display'); describe('display', () => { describe('table', () => { @@ -8,7 +8,7 @@ describe('display', () => { const originalWidth = process.stdout.columns; try { process.stdout.columns = 50; - const table = utils.makeTable( + const table = makeTable( [{ id: 123, title: 'hello' }, { id: 456, title: 'world' }], [['ID', 'id'], ['Title', 'title'], ['Missing', 'missing']] ); @@ -38,7 +38,7 @@ describe('display', () => { const originalWidth = process.stdout.columns; try { process.stdout.columns = 15; - const table = utils.makeTable( + const table = makeTable( [{ id: 123, title: 'hello' }, { id: 456, title: 'world' }], [['ID', 'id'], ['Title', 'title'], ['Missing', 'missing']] ); diff --git a/packages/cli/src/utils/args.js b/packages/cli/src/utils/args.js deleted file mode 100644 index da9c7e791..000000000 --- a/packages/cli/src/utils/args.js +++ /dev/null @@ -1,181 +0,0 @@ -const _ = require('lodash'); -const display = require('./display'); - -const globalArgOptsSpec = { - format: { - help: 'display format', - choices: Object.keys(display.formatStyles), - default: 'table' - }, - help: { help: 'prints this help text', flag: true }, - debug: { help: 'print debug API calls and tracebacks', flag: true } -}; - -const quoteStr = s => (String(s || '').indexOf(' ') === -1 ? s : `"${s}"`); -const choicesStr = choices => `{${choices.map(String).join(',')}}`; - -// Turn process.argv into args/opts. -const argParse = argv => { - const args = []; - const opts = {}; - argv.forEach(arg => { - if (arg.startsWith('--')) { - const key = arg.split('=', 1)[0].replace('--', ''); - let val = arg - .split('=') - .slice(1) - .join('='); - if (val === '') { - val = true; - } else if (val.toLowerCase() === 'false') { - val = false; - } - opts[key] = val; - } else if (arg.startsWith('-') && arg.length === 2) { - // single letter - opts[arg[1]] = true; - } else { - args.push(arg); - } - }); - return [args, opts]; -}; - -// Given a spec and args/opts - return an array of errors. -const enforceArgSpec = (fullSpec, args, argOpts) => { - const argsSpec = fullSpec.argsSpec || []; - const argOptsSpec = fullSpec.argOptsSpec || {}; - - const errors = []; - let restAfter = -1; - - const _argLookback = {}; - - // Make sure the spec has the provided args. - _.forEach(argsSpec, (spec, i) => { - const arg = args[i]; - - _argLookback[spec.name] = arg; - - const missingCurrent = spec.required && !arg; - const missingLookback = - !arg && // is absent (but that could be fine)! - (spec.requiredWith || []).length && // has required friends! - _.every(spec.requiredWith, name => _argLookback[name]); // friends are missing! - if (missingCurrent || missingLookback) { - errors.push(`Missing required positional argument ${i + 1}/${spec.name}`); - } - if ( - arg && - spec.choices && - spec.choices.length && - spec.choices.indexOf(arg) === -1 - ) { - const choices = choicesStr(spec.choices); - errors.push( - `Unexpected positional argument ${i + 1}/${spec.name} of ${quoteStr( - arg - )}, must be one of ${choices}` - ); - } - - restAfter = i; - if (spec.rest) { - restAfter = 1000; - } - }); - - // Make sure any leftover provided args are expected. - _.forEach(args, (arg, i) => { - if (i > restAfter) { - errors.push( - `Unexpected positional argument ${i + 1} of ${quoteStr(arg)}` - ); - } - }); - - // Make sure the spec has the provided args opts/keywords. - _.forEach(argOptsSpec, (spec, name) => { - const arg = argOpts[name]; - - if (spec.flag && arg && arg !== true) { - errors.push(`Unexpected keyword argument with value --${name}`); - return; - } - - if (spec.required && !arg) { - errors.push( - `Missing required keyword argument --${name}=${quoteStr( - arg || spec.example || 'value' - )}` - ); - } - - if ( - arg && - spec.choices && - spec.choices.length && - spec.choices.indexOf(arg) === -1 - ) { - const choices = choicesStr(spec.choices); - errors.push( - `Unexpected keyword argument --${name}=${quoteStr( - arg - )}, must be one of ${choices}` - ); - } - }); - - // Make sure any leftover provided args opts/keywords are expected. - _.forEach(argOpts, (arg, name) => { - if (!argOptsSpec[name]) { - if (arg === true) { - errors.push(`Unexpected keyword argument --${name}`); - } else { - errors.push(`Unexpected keyword argument --${name}=${quoteStr(arg)}`); - } - } - }); - - return errors; -}; - -// Make a markdown list for args. -const argsFragment = argsSpec => { - return _.map(argsSpec, spec => { - let val = spec.example || 'value'; - val = spec.choices && spec.choices.length ? choicesStr(spec.choices) : val; - const def = spec.default ? `. Default is \`${spec.default}\`` : ''; - return `* \`${spec.name} [${quoteStr(val)}]\` -- ${ - spec.required ? '**required**' : '_optional_' - }, ${spec.help || ''}${def}`; - }) - .join('\n') - .trim(); -}; - -// Make a markdown list for args opts/keywords. -const argOptsFragment = argOptsSpec => { - return _.map(argOptsSpec, (spec, name) => { - let val = spec.example || spec.default || 'value'; - val = spec.choices && spec.choices.length ? choicesStr(spec.choices) : val; - val = spec.flag ? '' : `=${quoteStr(val)}`; - const def = spec.default ? `. Default is \`${spec.default}\`` : ''; - return `* \`--${name}${val}\` -- ${ - spec.required ? '**required**' : '_optional_' - }, ${spec.help || ''}${def}`; - }) - .join('\n') - .trim(); -}; - -const defaultArgOptsFragment = () => argOptsFragment(globalArgOptsSpec); - -module.exports = { - argOptsFragment, - argParse, - argsFragment, - defaultArgOptsFragment, - enforceArgSpec, - globalArgOptsSpec -}; diff --git a/packages/cli/src/utils/context.js b/packages/cli/src/utils/context.js deleted file mode 100644 index 7836f3d73..000000000 --- a/packages/cli/src/utils/context.js +++ /dev/null @@ -1,17 +0,0 @@ -const createContext = ({ command, args, argOpts } = {}) => { - return { - command, - args, - argOpts, - line: _line => { - // json-like formats should only print json output, not text - if (!['json', 'raw'].includes(argOpts.format)) { - console.log(_line || ''); - } - } - }; -}; - -module.exports = { - createContext -}; diff --git a/packages/cli/src/utils/display.js b/packages/cli/src/utils/display.js index 218bb3833..51e143956 100644 --- a/packages/cli/src/utils/display.js +++ b/packages/cli/src/utils/display.js @@ -4,23 +4,14 @@ const Table = require('cli-table3'); const colors = require('colors/safe'); const stringLength = require('string-length'); const _ = require('lodash'); -const read = require('read'); const ora = require('ora'); const { CHECK_REF_DOC_LINK } = require('../constants'); const notUndef = s => String(s === undefined ? '' : s).trim(); -const unBacktick = s => s.replace(/\n?`+(bash)?/g, ''); - const prettyJSONstringify = obj => JSON.stringify(obj, null, ' '); -const markdownLog = str => { - // turn markdown into something with styles and stuff - // https://blog.mariusschulz.com/content/images/sublime_markdown_with_syntax_highlighting.png - console.log(unBacktick(str)); -}; - // Convert rows from keys to column labels. const rewriteLabels = (rows, columnDefs) => { return rows.map(row => { @@ -186,7 +177,6 @@ const makeJSON = (rows, columnDefs) => prettyJSONstringify(rewriteLabels(rows, columnDefs)); const makeRawJSON = rows => prettyJSONstringify(rows); -const DEFAULT_STYLE = 'table'; const formatStyles = { plain: makePlain, json: makeJSON, @@ -195,27 +185,6 @@ const formatStyles = { table: makeTable }; -// DEPRECATED, use this.logTable instead -const printData = ( - rows, - columnDefs, - ifEmptyMessage = '', - useRowBasedTable = false -) => { - const formatStyle = - (global.argOpts || {}).format || (useRowBasedTable ? 'row' : DEFAULT_STYLE); - const formatter = formatStyles[formatStyle] || formatStyles[DEFAULT_STYLE]; - if (rows && !rows.length) { - if (['json', 'raw'].includes(formatStyle)) { - console.log([]); - } else { - console.log(ifEmptyMessage); - } - } else { - console.log(formatter(rows, columnDefs)); - } -}; - // single global instance of the spinner const spinner = ora(); @@ -236,46 +205,6 @@ const endSpinner = (success = true, message) => { } }; -// Get input from a user. -const getInput = (question, { secret = false } = {}) => { - return new Promise((resolve, reject) => { - read( - { - prompt: question, - silent: secret, - replace: secret ? '*' : undefined - }, - (err, result) => { - if (err) { - reject(err); - } - resolve(result); - } - ); - }); -}; - -const hasAccepted = answer => - answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes'; - -const hasRejected = answer => - answer.toLowerCase() === 'n' || answer.toLowerCase() === 'no'; - -const getYesNoInput = (question, showCtrlC = true) => { - let message = question + ' (y/n) '; - if (showCtrlC) { - message += '(Ctrl-C to cancel) '; - } - return getInput(message).then(answer => { - const yes = hasAccepted(answer); - const no = hasRejected(answer); - if (!yes && !no) { - throw new Error('That answer is not valid. Please try "y" or "n".'); - } - return yes; - }); -}; - const flattenCheckResult = checkResult => { const res = []; for (const severity in checkResult) { @@ -315,12 +244,7 @@ module.exports = { endSpinner, flattenCheckResult, formatStyles, - getInput, - getYesNoInput, - makeRowBasedTable, - makeTable, - markdownLog, + makeTable, // exported for tests prettyJSONstringify, - printData, startSpinner }; diff --git a/packages/cli/src/utils/files.js b/packages/cli/src/utils/files.js index c7345c974..fe62bf129 100644 --- a/packages/cli/src/utils/files.js +++ b/packages/cli/src/utils/files.js @@ -4,7 +4,6 @@ const os = require('os'); const path = require('path'); const fse = require('fs-extra'); -const { getYesNoInput } = require('./display'); const fixHome = dir => { const home = process.env.HOME || process.env.USERPROFILE; @@ -140,19 +139,6 @@ const isEmptyDir = dir => fse.readdir(dir).then(items => _.isEmpty(items)); const isExistingEmptyDir = async dir => fse.existsSync(dir) && !(await isEmptyDir(dir)); -const confirmNonEmptyDir = async location => { - if (fse.existsSync(location) && !(await isEmptyDir(location))) { - const yes = await getYesNoInput( - 'Current directory not empty, continue anyway?', - false - ); - if (!yes) { - /* eslint no-process-exit: 0 */ - process.exit(0); - } - } -}; - const makeTempDir = () => { let workdir; const tmpBaseDir = os.tmpdir(); @@ -170,7 +156,6 @@ module.exports = { fileExistsSync, isEmptyDir, isExistingEmptyDir, - confirmNonEmptyDir, readFile, removeDir, validateFileExists, diff --git a/packages/cli/src/utils/index.js b/packages/cli/src/utils/index.js deleted file mode 100644 index 25e46cd4f..000000000 --- a/packages/cli/src/utils/index.js +++ /dev/null @@ -1,17 +0,0 @@ -const _ = require('lodash'); - -module.exports = _.extend( - {}, - require('./api'), - require('./args'), - require('./build'), - require('./changelog'), - require('./context'), - require('./convert'), - require('./display'), - require('./files'), - require('./init'), - require('./local'), - require('./misc'), - require('./promisify') -); diff --git a/packages/cli/zapier.js b/packages/cli/zapier.js deleted file mode 100755 index b8180a440..000000000 --- a/packages/cli/zapier.js +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -var entry = require('./src/entry'); -entry(process.argv); diff --git a/packages/core/package.json b/packages/core/package.json index 5a8233ed1..7ce053d54 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -33,7 +33,7 @@ "validate": "yarn test && yarn smoke-test && yarn lint" }, "engines": { - "node": ">=8.10.0", + "node": ">=10", "npm": ">=5.6.0" }, "engineStrict": true, diff --git a/yarn.lock b/yarn.lock index 75070b311..18e6d371b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -889,6 +889,15 @@ "@nodelib/fs.scandir" "2.1.3" fastq "^1.6.0" +"@oclif/color@^0.0.0": + version "0.0.0" + resolved "https://registry.yarnpkg.com/@oclif/color/-/color-0.0.0.tgz#54939bbd16d1387511bf1a48ccda1a417248e6a9" + integrity sha512-KKd3W7eNwfNF061tr663oUNdt8EMnfuyf5Xv55SGWA1a0rjhWqS/32P7OeB7CbXcJUBdfVrPyR//1afaW12AWw== + dependencies: + ansi-styles "^3.2.1" + supports-color "^5.4.0" + tslib "^1" + "@oclif/command@1.5.18": version "1.5.18" resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.5.18.tgz#57125b501fafa155ad280bf8dc9f36a911c44f11" @@ -901,7 +910,7 @@ debug "^4.1.1" semver "^5.6.0" -"@oclif/command@^1.5.1", "@oclif/command@^1.5.13": +"@oclif/command@^1.5.1", "@oclif/command@^1.5.13", "@oclif/command@^1.5.3": version "1.5.19" resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.5.19.tgz#13f472450eb83bd6c6871a164c03eadb5e1a07ed" integrity sha512-6+iaCMh/JXJaB2QWikqvGE9//wLEVYYwZd5sud8aLoLKog1Q75naZh2vlGVtg5Mq/NqpqGQvdIjJb3Bm+64AUQ== @@ -979,6 +988,17 @@ widest-line "^2.0.1" wrap-ansi "^4.0.0" +"@oclif/plugin-not-found@1.2.3": + version "1.2.3" + resolved "https://registry.yarnpkg.com/@oclif/plugin-not-found/-/plugin-not-found-1.2.3.tgz#00f9e7a0a793a5e2f616d8280075f4592de8f079" + integrity sha512-Igbw2T4gLrb/f28Llr730FeMXBSI2PXdky2YvQfsZeQGDsyBZmC4gprJJtmrMWQcjz0B51IInRBnZYERvwfIpw== + dependencies: + "@oclif/color" "^0.0.0" + "@oclif/command" "^1.5.3" + cli-ux "^4.9.0" + fast-levenshtein "^2.0.6" + lodash "^4.17.13" + "@oclif/screen@^1.0.3": version "1.0.4" resolved "https://registry.yarnpkg.com/@oclif/screen/-/screen-1.0.4.tgz#b740f68609dfae8aa71c3a6cab15d816407ba493" @@ -2909,6 +2929,33 @@ cli-truncate@^0.2.1: slice-ansi "0.0.4" string-width "^1.0.1" +cli-ux@^4.9.0: + version "4.9.3" + resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-4.9.3.tgz#4c3e070c1ea23eef010bbdb041192e0661be84ce" + integrity sha512-/1owvF0SZ5Gn54cgrikJ0QskgTzeg30HGjkmjFoaHDJzAqFpuX1DBpFR8aLvsE1J5s9MgeYRENQK4BFwOag5VA== + dependencies: + "@oclif/errors" "^1.2.2" + "@oclif/linewrap" "^1.0.0" + "@oclif/screen" "^1.0.3" + ansi-escapes "^3.1.0" + ansi-styles "^3.2.1" + cardinal "^2.1.1" + chalk "^2.4.1" + clean-stack "^2.0.0" + extract-stack "^1.0.0" + fs-extra "^7.0.0" + hyperlinker "^1.0.0" + indent-string "^3.2.0" + is-wsl "^1.1.0" + lodash "^4.17.11" + password-prompt "^1.0.7" + semver "^5.6.0" + strip-ansi "^5.0.0" + supports-color "^5.5.0" + supports-hyperlinks "^1.0.1" + treeify "^1.1.0" + tslib "^1.9.3" + cli-ux@^5.2.1: version "5.3.3" resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-5.3.3.tgz#6459e180da29f2850473b9bf2f1ae097e5257d31" @@ -4645,7 +4692,7 @@ fast-json-stable-stringify@^2.0.0: resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I= -fast-levenshtein@~2.0.4: +fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.4: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= @@ -6571,11 +6618,6 @@ lerna@3.16.4: import-local "^2.0.0" npmlog "^4.1.2" -leven@2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580" - integrity sha1-wuep93IJTe6dNCAq6KzORoeHVYA= - levn@^0.3.0, levn@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" @@ -6948,7 +6990,7 @@ lodash@4.17.11: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== -lodash@4.17.15, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0: +lodash@4.17.15, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0: version "4.17.15" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== @@ -8306,7 +8348,7 @@ pascalcase@^0.1.1: resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= -password-prompt@^1.1.2: +password-prompt@^1.0.7, password-prompt@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/password-prompt/-/password-prompt-1.1.2.tgz#85b2f93896c5bd9e9f2d6ff0627fa5af3dc00923" integrity sha512-bpuBhROdrhuN3E7G/koAju0WjVw9/uQOG5Co5mokNj0MiOSBVZS1JTwM4zl55hu0WFmIEFvO9cU9sJQiBIYeIA== @@ -10035,7 +10077,7 @@ supports-color@^3.1.0: dependencies: has-flag "^1.0.0" -supports-color@^5.0.0, supports-color@^5.3.0, supports-color@^5.5.0: +supports-color@^5.0.0, supports-color@^5.3.0, supports-color@^5.4.0, supports-color@^5.5.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== @@ -10324,7 +10366,7 @@ trim-right@^1.0.1: resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= -tslib@^1.9.0, tslib@^1.9.3: +tslib@^1, tslib@^1.9.0, tslib@^1.9.3: version "1.10.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==