Skip to content

Commit

Permalink
Change how we ask questions (#75)
Browse files Browse the repository at this point in the history
* change how we ask questions
  • Loading branch information
emmatown authored and Noviny committed Jun 6, 2019
1 parent 3d2f023 commit 16fde2e
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 241 deletions.
4 changes: 4 additions & 0 deletions .changeset/fast-chicken-beam/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"releases": [{ "name": "@changesets/cli", "type": "minor" }],
"dependents": []
}
4 changes: 4 additions & 0 deletions .changeset/fast-chicken-beam/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Use [enquirer](https://github.com/enquirer/enquirer) instead of inquirer for asking questions because it's smaller, faster and prettier.
Change bump type questions from asking for each bump type individually per package to asking users to two questions where the user selects what packages should have major and minor bumps and the packages left are assumed to be patch bumps. This dramatically cuts down the amount of time it takes to create a changeset with a large number of packages.

![example of using the CLI with the new questions](https://user-images.githubusercontent.com/11481355/58873398-a1c4de80-8709-11e9-80e8-16061e395b15.gif)
49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,59 @@
"author": "Atlassian Pty Ltd",
"license": "MIT",
"dependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.4",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@babel/runtime": "^7.4.4",
"@types/fs-extra": "^5.1.0",
"@types/jest": "^24.0.12",
"@types/meow": "^5.0.0",
"@types/semver": "^6.0.0",
"@types/uuid": "^3.4.4",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"bolt": "^0.22.1",
"boxen": "^1.3.0",
"chalk": "^2.1.0",
"cli-table": "^0.3.1",
"codecov": "^3.5.0",
"dataloader": "^1.4.0",
"detect-indent": "^6.0.0",
"dotenv": "^8.0.0",
"enquirer": "^2.3.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.2.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-node": "^9.0.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"fs-extra": "^7.0.1",
"fuzzy": "^0.1.3",
"globby": "^9.2.0",
"human-id": "^1.0.2",
"inquirer": "^3.3.0",
"inquirer-checkbox-plus-prompt": "^1.0.1",
"jest": "^24.7.1",
"jest-fixtures": "^0.5.0",
"jest-junit": "^6.4.0",
"lodash.startcase": "^4.4.0",
"meow": "^5.0.0",
"node-fetch": "^2.5.0",
"outdent": "^0.5.0",
"pkg-dir": "^4.1.0",
"preconstruct": "^0.0.79",
"prettier": "^1.14.3",
"projector-spawn": "^1.0.1",
"semver": "^5.4.1",
"tty-table": "^2.7.0",
"typescript": "^3.4.5",
"uuid": "^3.3.2",
"@types/inquirer": "^6.0.3",
"@types/uuid": "^3.4.4",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.0.0-0",
"@babel/preset-env": "^7.4.4",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"codecov": "^3.5.0",
"dotenv": "^8.0.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.2.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-node": "^9.0.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.7.1",
"jest-fixtures": "^0.5.0",
"jest-junit": "^6.4.0",
"preconstruct": "^0.0.76"
"strip-ansi": "^5.2.0"
},
"preconstruct": {
"packages": [
Expand Down
1 change: 1 addition & 0 deletions packages/bolt-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"bin.js"
],
"dependencies": {
"@babel/runtime": "^7.4.4",
"chalk": "^2.1.0",
"detect-indent": "^6.0.0",
"fs-extra": "^7.0.1",
Expand Down
11 changes: 5 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"bin": {
"changeset": "bin.js"
},
"repository":"https://github.com/changesets/changesets/tree/master/packages/cli",
"repository": "https://github.com/changesets/changesets/tree/master/packages/cli",
"files": [
"default-files",
"dist",
Expand All @@ -17,21 +17,19 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.4.4",
"@types/inquirer": "^6.0.3",
"@types/semver": "^6.0.0",
"@types/uuid": "^3.4.4",
"bolt": "^0.22.1",
"boxen": "^1.3.0",
"chalk": "^2.1.0",
"cli-table": "^0.3.1",
"detect-indent": "^6.0.0",
"enquirer": "^2.3.0",
"fs-extra": "^7.0.1",
"fuzzy": "^0.1.3",
"get-workspaces": "^0.3.0",
"globby": "^9.2.0",
"human-id": "^1.0.2",
"inquirer": "^3.3.0",
"inquirer-checkbox-plus-prompt": "^1.0.1",
"lodash.startcase": "^4.4.0",
"meow": "^5.0.0",
"outdent": "^0.5.0",
Expand All @@ -43,6 +41,7 @@
"uuid": "^3.3.2"
},
"devDependencies": {
"jest-fixtures": "^0.5.0"
"jest-fixtures": "^0.5.0",
"strip-ansi": "^5.2.0"
}
}
}
49 changes: 36 additions & 13 deletions packages/cli/src/commands/add/__tests__/add.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// @flow
import { copyFixtureIntoTempDir } from "jest-fixtures";
import {
askCheckboxPlus,
askList,
askConfirm,
askQuestion
} from "../../../utils/cli";
import stripAnsi from "strip-ansi";
import { askCheckboxPlus, askConfirm, askQuestion } from "../../../utils/cli";
import * as git from "../../../utils/git";

import addChangeset from "..";
Expand All @@ -14,7 +10,7 @@ import writeChangeset from "../writeChangeset";
jest.mock("../../../utils/logger");
jest.mock("../../../utils/cli");
jest.mock("../../../utils/git");
jest.mock("../../../commands/add/writeChangeset");
jest.mock("../writeChangeset");
writeChangeset.mockImplementation(() => Promise.resolve("abcdefg"));
git.commit.mockImplementation(() => Promise.resolve(true));

Expand All @@ -39,13 +35,40 @@ unsafeGetChangedPackagesSinceMaster.mockReturnValue([]);

const mockUserResponses = mockResponses => {
const summary = mockResponses.summary || "summary message mock";
const shouldCommit = mockResponses.shouldCommit || "n";
askCheckboxPlus.mockReturnValueOnce(Object.keys(mockResponses.releases));
Object.entries(mockResponses.releases).forEach(([_pkg, type]) =>
askList.mockReturnValueOnce(type)
);
let majorReleases = [];
let minorReleases = [];
Object.entries(mockResponses.releases).forEach(([pkgName, type]) => {
if (type === "major") {
majorReleases.push(pkgName);
} else if (type === "minor") {
minorReleases.push(pkgName);
}
});
let callCount = 0;
let returnValues = [
Object.keys(mockResponses.releases),
majorReleases,
minorReleases
];
askCheckboxPlus.mockImplementation(() => {
if (callCount === returnValues.length) {
throw new Error(`There was an unexpected call to askCheckboxPlus`);
}
return returnValues[callCount++];
});

let confirmAnswers = {
"Is this your desired changeset?": true
};

askQuestion.mockReturnValueOnce(summary);
askConfirm.mockReturnValueOnce(shouldCommit);
askConfirm.mockImplementation(question => {
question = stripAnsi(question);
if (confirmAnswers[question]) {
return confirmAnswers[question];
}
throw new Error(`An answer could not be found for ${question}`);
});
};

describe("Changesets", () => {
Expand Down
47 changes: 35 additions & 12 deletions packages/cli/src/commands/add/__tests__/changesetsPeerDeps.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// @flow
import { copyFixtureIntoTempDir } from "jest-fixtures";
import {
askCheckboxPlus,
askList,
askConfirm,
askQuestion
} from "../../../utils/cli";
import stripAnsi from "strip-ansi";
import { askCheckboxPlus, askConfirm, askQuestion } from "../../../utils/cli";
import * as git from "../../../utils/git";
import addChangeset from "..";
import writeChangeset from "../writeChangeset";
Expand Down Expand Up @@ -45,13 +41,40 @@ unsafeGetChangedPackagesSinceMaster.mockReturnValue([]);

const mockUserResponses = mockResponses => {
const summary = mockResponses.summary || "summary message mock";
const shouldCommit = mockResponses.shouldCommit || "n";
askCheckboxPlus.mockReturnValueOnce(Object.keys(mockResponses.releases));
Object.entries(mockResponses.releases).forEach(([_pkg, type]) =>
askList.mockReturnValueOnce(type)
);
let majorReleases = [];
let minorReleases = [];
Object.entries(mockResponses.releases).forEach(([pkgName, type]) => {
if (type === "major") {
majorReleases.push(pkgName);
} else if (type === "minor") {
minorReleases.push(pkgName);
}
});
let callCount = 0;
let returnValues = [
Object.keys(mockResponses.releases),
majorReleases,
minorReleases
];
askCheckboxPlus.mockImplementation(() => {
if (callCount === returnValues.length) {
throw new Error(`There was an unexpected call to askCheckboxPlus`);
}
return returnValues[callCount++];
});

let confirmAnswers = {
"Is this your desired changeset?": true
};

askQuestion.mockReturnValueOnce(summary);
askConfirm.mockReturnValueOnce(shouldCommit);
askConfirm.mockImplementation(question => {
question = stripAnsi(question);
if (confirmAnswers[question]) {
return confirmAnswers[question];
}
throw new Error(`An answer could not be found for ${question}`);
});
};

describe("Changesets - bumping peerDeps", () => {
Expand Down
Loading

0 comments on commit 16fde2e

Please sign in to comment.