Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove bin/ directory #948

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions bin/cli.js

This file was deleted.

9 changes: 7 additions & 2 deletions lib/cli.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
const yargs = require("yargs");

module.exports = function cli() {
function cli() {
// eslint-disable-next-line no-unused-expressions
yargs
.usage("$0 <command>")
Expand All @@ -9,4 +10,8 @@ module.exports = function cli() {
.strict()
.alias("help", "h")
.alias("version", "v").argv;
};
}

cli();

module.exports = cli;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"tool"
],
"main": "lib/index.js",
"bin": "bin/cli.js",
"bin": "lib/cli.js",
"types": "types/ybiq.d.ts",
"files": [
"bin",
"lib",
"types",
".editorconfig",
Expand Down
12 changes: 6 additions & 6 deletions test/__snapshots__/help.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Options:
`;

exports[`with arguments [] 1`] = `
"Command failed: bin/cli.js
"Command failed: lib/cli.js
cli.js <command>

Commands:
Expand All @@ -52,7 +52,7 @@ Not enough non-option arguments: got 0, need at least 1
`;

exports[`with arguments []: stderr 1`] = `
[Error: Command failed: bin/cli.js
[Error: Command failed: lib/cli.js
cli.js <command>

Commands:
Expand All @@ -71,7 +71,7 @@ Not enough non-option arguments: got 0, need at least 1
`;

exports[`with arguments [unknown, xyz] 1`] = `
"Command failed: bin/cli.js unknown xyz
"Command failed: lib/cli.js unknown xyz
cli.js <command>

Commands:
Expand All @@ -90,7 +90,7 @@ Unknown arguments: unknown, xyz
`;

exports[`with arguments [unknown, xyz]: stderr 1`] = `
[Error: Command failed: bin/cli.js unknown xyz
[Error: Command failed: lib/cli.js unknown xyz
cli.js <command>

Commands:
Expand All @@ -109,7 +109,7 @@ Unknown arguments: unknown, xyz
`;

exports[`with arguments [unknown] 1`] = `
"Command failed: bin/cli.js unknown
"Command failed: lib/cli.js unknown
cli.js <command>

Commands:
Expand All @@ -128,7 +128,7 @@ Unknown argument: unknown
`;

exports[`with arguments [unknown]: stderr 1`] = `
[Error: Command failed: bin/cli.js unknown
[Error: Command failed: lib/cli.js unknown
cli.js <command>

Commands:
Expand Down
11 changes: 6 additions & 5 deletions test/help.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const pkg = require("../package.json");
const exec = require("./helpers/exec");

[[], ["unknown"], ["unknown", "xyz"]].forEach((args) => {
test(`with arguments [${args.join(", ")}]`, async () => {
await expect(exec("bin/cli.js", ...args)).rejects.toThrowErrorMatchingSnapshot();
await expect(exec("bin/cli.js", ...args)).rejects.toHaveProperty("code", 1);
await expect(exec("bin/cli.js", ...args)).rejects.toHaveProperty("stdout", "");
await expect(exec("bin/cli.js", ...args)).rejects.toMatchSnapshot("stderr");
await expect(exec(pkg.bin, ...args)).rejects.toThrowErrorMatchingSnapshot();
await expect(exec(pkg.bin, ...args)).rejects.toHaveProperty("code", 1);
await expect(exec(pkg.bin, ...args)).rejects.toHaveProperty("stdout", "");
await expect(exec(pkg.bin, ...args)).rejects.toMatchSnapshot("stderr");
});
});

["--help", "-h"].forEach((option) => {
test(`with "${option}" option`, async () => {
const { stdout, stderr } = await exec("bin/cli.js", option);
const { stdout, stderr } = await exec(pkg.bin, option);
expect(stdout).toMatchSnapshot();
expect(stderr).toEqual("");
});
Expand Down
2 changes: 1 addition & 1 deletion test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test("throw error if no package.json", () =>
test("End-to-End via CLI", () =>
sandbox(async (ctx) => {
await ctx.fixture("package-normal.json");
const { stdout, stderr } = await exec(path.resolve("bin/cli.js"), "init", {
const { stdout, stderr } = await exec(path.resolve(pkg.bin), "init", {
cwd: ctx.initArgs.cwd,
});
expect(stdout).toMatchInlineSnapshot(`
Expand Down
2 changes: 1 addition & 1 deletion test/version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const exec = require("./helpers/exec");

["--version", "-v"].forEach((option) => {
test(`with "${option}" option`, async () => {
const { stdout, stderr } = await exec("bin/cli.js", option);
const { stdout, stderr } = await exec(pkg.bin, option);
expect(stdout).toEqual(`${pkg.version}\n`);
expect(stderr).toEqual("");
});
Expand Down