diff --git a/packages/gatsby-cli/package.json b/packages/gatsby-cli/package.json index bda073ca8f1c6..2a56e9915fc77 100644 --- a/packages/gatsby-cli/package.json +++ b/packages/gatsby-cli/package.json @@ -13,6 +13,7 @@ "@babel/code-frame": "^7.0.0", "@babel/runtime": "^7.0.0", "bluebird": "^3.5.0", + "clipboardy": "^1.2.3", "ci-info": "^2.0.0", "common-tags": "^1.4.0", "configstore": "^4.0.0", diff --git a/packages/gatsby-cli/src/create-cli.js b/packages/gatsby-cli/src/create-cli.js index 38c2dac3aac15..f12f6c41179f6 100644 --- a/packages/gatsby-cli/src/create-cli.js +++ b/packages/gatsby-cli/src/create-cli.js @@ -5,6 +5,7 @@ const report = require(`./reporter`) const didYouMean = require(`./did-you-mean`) const envinfo = require(`envinfo`) const existsSync = require(`fs-exists-cached`).sync +const clipboardy = require(`clipboardy`) const { trackCli, setDefaultTags, @@ -240,26 +241,30 @@ function buildLocalCommands(cli, isLocalSite) { }), handler: args => { try { - envinfo.run( - { + const copyToClipboard = + // Clipboard is not accessible when on a linux tty + process.platform === `linux` && !process.env.DISPLAY + ? false + : args.clipboard + + envinfo + .run({ System: [`OS`, `CPU`, `Shell`], Binaries: [`Node`, `npm`, `Yarn`], Browsers: [`Chrome`, `Edge`, `Firefox`, `Safari`], Languages: [`Python`], npmPackages: `gatsby*`, npmGlobalPackages: `gatsby*`, - }, - { - console: true, - // Clipboard is not accessible when on a linux tty - clipboard: - process.platform === `linux` && !process.env.DISPLAY - ? false - : args.clipboard, - } - ) + }) + .then(envinfoOutput => { + console.log(envinfoOutput) + + if (copyToClipboard) { + clipboardy.writeSync(envinfoOutput) + } + }) } catch (err) { - console.log(`Error: unable to print environment info`) + console.log(`Error: Unable to print environment info`) console.log(err) } }, diff --git a/yarn.lock b/yarn.lock index 1b0b33954a03a..ea09124ca26f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5934,6 +5934,14 @@ clipboard@^2.0.0: select "^1.1.2" tiny-emitter "^2.0.0" +clipboardy@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/clipboardy/-/clipboardy-1.2.3.tgz#0526361bf78724c1f20be248d428e365433c07ef" + integrity sha512-2WNImOvCRe6r63Gk9pShfkwXsVtKCroMAevIbiae021mS850UkWPbevxsBz3tnvjZIEGvlwaqCPsw+4ulzNgJA== + dependencies: + arch "^2.1.0" + execa "^0.8.0" + cliui@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1"