Skip to content

Write a basic wrapper over jscodeshift #4

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

Merged
merged 13 commits into from
Mar 2, 2022
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
5 changes: 5 additions & 0 deletions .changeset/tall-games-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Add a basic wrapper over jscodeshift
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"files": [
"dist"
],
"main": "dist/index.js",
"main": "dist/cli.js",
"types": "dist/cli.d.ts",
"bin": "dist/cli.js",
"repository": {
"type": "git",
"url": "https://github.com/trivikr/aws-sdk-js-codemod.git"
Expand Down
34 changes: 34 additions & 0 deletions src/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { spawn } from "child_process";

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: package.json will be imported from dist folders
import { version } from "../../package.json"; // eslint-disable-line
import { run } from "../cli";

jest.mock("child_process");

describe("cli", () => {
const jscodeshiftPath = "./node_modules/.bin/jscodeshift";

afterEach(() => {
jest.clearAllMocks();
});

it("should print aws-sdk-js-codemod version", async () => {
jest.spyOn(process.stdout, "write");

const mockArgs = ["--version"];
await run(mockArgs);

expect(process.stdout.write).toHaveBeenCalledWith(
expect.stringMatching(`aws-sdk-js-codemod: ${version}`)
);
expect(spawn).toHaveBeenCalledWith(jscodeshiftPath, mockArgs, { stdio: "inherit" });
});

it("should pass args to jscodeshift", async () => {
const mockArgs = ["random", "args", "one", "two", "three"];
await run(mockArgs);
expect(spawn).toHaveBeenCalledWith(jscodeshiftPath, mockArgs, { stdio: "inherit" });
});
});
21 changes: 21 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

import { spawn } from "child_process";

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: package.json will be imported from dist folders
import { version } from "../package.json"; // eslint-disable-line

const [, , ...args] = process.argv;
const jscodeshiftPath = "./node_modules/.bin/jscodeshift";

export const run = async (args): Promise<void> => {
if (args[0] === "--version") {
process.stdout.write(`aws-sdk-js-codemod: ${version}\n\n`);
spawn(jscodeshiftPath, ["--version"], { stdio: "inherit" });
} else {
spawn(jscodeshiftPath, args, { stdio: "inherit" });
}
};

run(args);
5 changes: 0 additions & 5 deletions src/index.spec.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"declaration": true,
"esModuleInterop": true,
"outDir": "dist",
"resolveJsonModule": true,
"rootDir": "src"
},
"exclude": ["**/dist/**", "**/__tests__/**", "**/__testfixtures__/**"]
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,8 @@ __metadata:
simple-git-hooks: 2.7.0
ts-jest: 27.1.3
typescript: 4.5.5
bin:
aws-sdk-js-codemod: dist/cli.js
languageName: unknown
linkType: soft

Expand Down