From 70604f1fd172b599378982b91216b94e738144ab Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Tue, 5 Jun 2018 19:10:27 -0300 Subject: [PATCH] [Release script] Use `execa` --- scripts/release/package.json | 2 +- scripts/release/steps/bump-prettier.js | 12 ++--- scripts/release/steps/check-git-status.js | 4 +- scripts/release/steps/install-dependencies.js | 8 +-- scripts/release/steps/post-publish-steps.js | 6 +-- scripts/release/steps/publish-to-npm.js | 7 ++- scripts/release/steps/push-to-git.js | 10 ++-- scripts/release/steps/update-version.js | 4 +- scripts/release/utils.js | 6 +-- scripts/release/yarn.lock | 53 ++++++++++--------- 10 files changed, 58 insertions(+), 54 deletions(-) diff --git a/scripts/release/package.json b/scripts/release/package.json index 587e5d47..e9a1157d 100644 --- a/scripts/release/package.json +++ b/scripts/release/package.json @@ -2,8 +2,8 @@ "private": true, "dependencies": { "chalk": "2.4.1", - "child-process-promise": "2.2.1", "dedent": "0.7.0", + "execa": "0.10.0", "minimist": "1.2.0", "node-fetch": "2.1.2", "prs-merged-since": "1.0.1", diff --git a/scripts/release/steps/bump-prettier.js b/scripts/release/steps/bump-prettier.js index 1395e7fa..8b970611 100644 --- a/scripts/release/steps/bump-prettier.js +++ b/scripts/release/steps/bump-prettier.js @@ -1,20 +1,20 @@ "use strict"; -const { exec, spawn } = require("child-process-promise"); +const execa = require("execa"); const { logPromise } = require("../utils"); async function format() { - await exec("yarn lint --fix"); - await exec("yarn lint-docs --fix"); + await execa("yarn", ["lint", "--fix"]); + await execa("yarn", ["lint-docs", "--fix"]); } async function commit(version) { - await spawn("git", [ + await execa("git", [ "commit", "-am", `Bump Prettier dependency to ${version}` ]); - await exec("git push"); + await execa("git", ["push"]); } module.exports = async function({ dry, version }) { @@ -24,7 +24,7 @@ module.exports = async function({ dry, version }) { await logPromise( "Installing Prettier", - spawn("yarn", ["add", "--dev", `prettier@${version}`]) + execa("yarn", ["add", "--dev", `prettier@${version}`]) ); await logPromise("Updating files", format()); diff --git a/scripts/release/steps/check-git-status.js b/scripts/release/steps/check-git-status.js index 15e1bb71..66f40851 100644 --- a/scripts/release/steps/check-git-status.js +++ b/scripts/release/steps/check-git-status.js @@ -1,9 +1,9 @@ "use strict"; -const { exec } = require("child-process-promise"); +const execa = require("execa"); module.exports = async function() { - const status = (await exec("git status --porcelain")).stdout; + const status = await execa.stdout("git", ["status", "--porcelain"]); if (status) { throw Error( diff --git a/scripts/release/steps/install-dependencies.js b/scripts/release/steps/install-dependencies.js index e41aa207..07c5be28 100644 --- a/scripts/release/steps/install-dependencies.js +++ b/scripts/release/steps/install-dependencies.js @@ -1,13 +1,13 @@ "use strict"; -const { exec } = require("child-process-promise"); +const execa = require("execa"); const { logPromise } = require("../utils"); async function install() { - await exec("rm -rf node_modules"); - await exec("yarn install"); + await execa("rm", ["-rf", "node_modules"]); + await execa("yarn", ["install"]); - const status = (await exec("git ls-files -m")).stdout.trim(); + const status = await execa.stdout("git", ["ls-files", "-m"]); if (status) { throw Error( "The lockfile needs to be updated, commit it before making the release." diff --git a/scripts/release/steps/post-publish-steps.js b/scripts/release/steps/post-publish-steps.js index 4355e0c2..aaa30f0f 100644 --- a/scripts/release/steps/post-publish-steps.js +++ b/scripts/release/steps/post-publish-steps.js @@ -3,8 +3,8 @@ const chalk = require("chalk"); const dedent = require("dedent"); const fetch = require("node-fetch"); -const { exec } = require("child-process-promise"); -const { logPromise, waitForEnter } = require("../utils"); +const execa = require("execa"); +const { logPromise } = require("../utils"); const SCHEMA_REPO = "SchemaStore/schemastore"; const SCHEMA_PATH = "src/schemas/json/prettierrc.json"; @@ -14,7 +14,7 @@ const EDIT_URL = `https://github.com/${SCHEMA_REPO}/edit/master/${SCHEMA_PATH}`; // Any optional or manual step can be warned in this script. async function checkSchema() { - const schema = (await exec("node scripts/generate-schema.js")).stdout.trim(); + const schema = await execa.stdout("node scripts/generate-schema.js"); const remoteSchema = await logPromise( "Checking current schema in SchemaStore", fetch(RAW_URL) diff --git a/scripts/release/steps/publish-to-npm.js b/scripts/release/steps/publish-to-npm.js index 3e2e9d08..7673a65c 100644 --- a/scripts/release/steps/publish-to-npm.js +++ b/scripts/release/steps/publish-to-npm.js @@ -2,7 +2,7 @@ const chalk = require("chalk"); const dedent = require("dedent"); -const { exec } = require("child-process-promise"); +const execa = require("execa"); const { logPromise, waitForEnter } = require("../utils"); module.exports = async function({ dry, version }) { @@ -10,7 +10,10 @@ module.exports = async function({ dry, version }) { return; } - await logPromise("Publishing to npm", exec("npm publish", { cwd: "./dist" })); + await logPromise( + "Publishing to npm", + execa("npm", ["publish"], { cwd: "./dist" }) + ); console.log( dedent(chalk` diff --git a/scripts/release/steps/push-to-git.js b/scripts/release/steps/push-to-git.js index 63122917..9a3bd502 100644 --- a/scripts/release/steps/push-to-git.js +++ b/scripts/release/steps/push-to-git.js @@ -1,13 +1,13 @@ "use strict"; -const { exec, spawn } = require("child-process-promise"); +const execa = require("execa"); const { logPromise } = require("../utils"); async function pushGit({ version }) { - await spawn("git", ["commit", "-am", `Release ${version}`]); - await spawn("git", ["tag", "-a", version, "-m", `Release ${version}`]); - await exec("git push"); - await exec("git push --tags"); + await execa("git", ["commit", "-am", `Release ${version}`]); + await execa("git", ["tag", "-a", version, "-m", `Release ${version}`]); + await execa("git", ["push"]); + await execa("git", ["push", "--tags"]); } module.exports = function(params) { diff --git a/scripts/release/steps/update-version.js b/scripts/release/steps/update-version.js index c10c95b6..4777908d 100644 --- a/scripts/release/steps/update-version.js +++ b/scripts/release/steps/update-version.js @@ -1,6 +1,6 @@ "use strict"; -const { exec } = require("child-process-promise"); +const execa = require("execa"); const { readFileSync, writeFileSync } = require("fs"); const { logPromise, readJson, writeJson } = require("../utils"); @@ -22,6 +22,6 @@ module.exports = async function(params) { await logPromise("Bumping version", bump(params)); await logPromise( "Updating integration snapshots", - exec("yarn test-integration -u") + execa("yarn", ["test-integration", "-u"]) ); }; diff --git a/scripts/release/utils.js b/scripts/release/utils.js index 1c5a8a3c..e6a4ea89 100644 --- a/scripts/release/utils.js +++ b/scripts/release/utils.js @@ -4,7 +4,7 @@ require("readline").emitKeypressEvents(process.stdin); const chalk = require("chalk"); const fs = require("fs"); -const { spawn } = require("child-process-promise"); +const execa = require("execa"); const stringWidth = require("string-width"); const OK = chalk.bgGreen.black(" DONE "); @@ -34,9 +34,7 @@ function logPromise(name, promise) { } function runYarn(script) { - return spawn("yarn", ["--silent", script], { - capture: ["stdout", "stderr"] - }).catch(error => { + return execa("yarn", ["--silent", script]).catch(error => { throw Error(`\`yarn ${script}\` failed\n${error.stdout}`); }); } diff --git a/scripts/release/yarn.lock b/scripts/release/yarn.lock index c5fb117a..d309debe 100644 --- a/scripts/release/yarn.lock +++ b/scripts/release/yarn.lock @@ -55,14 +55,6 @@ chalk@2.4.1, chalk@^2.0.1, chalk@^2.3.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -child-process-promise@2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/child-process-promise/-/child-process-promise-2.2.1.tgz#4730a11ef610fad450b8f223c79d31d7bdad8074" - dependencies: - cross-spawn "^4.0.2" - node-version "^1.0.0" - promise-polyfill "^6.0.1" - cli-cursor@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" @@ -99,13 +91,6 @@ color-name@^1.1.1: version "1.1.3" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" -cross-spawn@^4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41" - dependencies: - lru-cache "^4.0.1" - which "^1.2.9" - cross-spawn@^5.0.1: version "5.1.0" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" @@ -114,6 +99,16 @@ cross-spawn@^5.0.1: shebang-command "^1.2.0" which "^1.2.9" +cross-spawn@^6.0.0: + version "6.0.5" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" + dependencies: + nice-try "^1.0.4" + path-key "^2.0.1" + semver "^5.5.0" + shebang-command "^1.2.0" + which "^1.2.9" + debug@3.1.0, debug@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" @@ -148,6 +143,18 @@ escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" +execa@0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50" + dependencies: + cross-spawn "^6.0.0" + get-stream "^3.0.0" + is-stream "^1.1.0" + npm-run-path "^2.0.0" + p-finally "^1.0.0" + signal-exit "^3.0.0" + strip-eof "^1.0.0" + execa@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777" @@ -262,14 +269,14 @@ ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" +nice-try@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.4.tgz#d93962f6c52f2c1558c0fbda6d512819f1efe1c4" + node-fetch@2.1.2, node-fetch@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5" -node-version@^1.0.0: - version "1.1.3" - resolved "https://registry.yarnpkg.com/node-version/-/node-version-1.1.3.tgz#1081c87cce6d2dbbd61d0e51e28c287782678496" - npm-run-path@^2.0.0: version "2.0.2" resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f" @@ -329,14 +336,10 @@ path-exists@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" -path-key@^2.0.0: +path-key@^2.0.0, path-key@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" -promise-polyfill@^6.0.1: - version "6.1.0" - resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-6.1.0.tgz#dfa96943ea9c121fca4de9b5868cb39d3472e057" - prs-merged-since@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/prs-merged-since/-/prs-merged-since-1.0.1.tgz#2e9905f0843ec0189c3168a6eb31087982ac47fb" @@ -364,7 +367,7 @@ restore-cursor@^2.0.0: onetime "^2.0.0" signal-exit "^3.0.2" -semver@5.5.0: +semver@5.5.0, semver@^5.5.0: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"