Skip to content

Commit

Permalink
Merge pull request #5 from chandan9074/master
Browse files Browse the repository at this point in the history
Pass token in vercel link
  • Loading branch information
IamLizu authored Aug 1, 2024
2 parents 2218f96 + 1c14441 commit a44cbaf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ yarn global add verceler
After installing verceler, you can use it via the command line. Here are some common commands and options:

```sh
verceler --vt <vercel_token> --gt <github_token> [options]
verceler -vt <vercel_token> -gt <github_token> [options]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async function main() {

npm.installVercelCli();

vercelManager.linkProject();
vercelManager.setVercelToken(vercelToken);
vercelManager.linkProject();

const envList = cliOptions.getEnvList();

Expand Down
2 changes: 1 addition & 1 deletion src/utils/VercelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class VercelManager {

linkProject() {
try {
execSync("vercel link --yes");
execSync(`vercel link --yes --token ${this.vercelToken}`);
} catch (error) {
console.error("Failed to link Vercel project:", error.message);
}
Expand Down
12 changes: 9 additions & 3 deletions tests/utils/VercelManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jest.mock("fs");
jest.mock("path");
jest.mock("progress");
jest.mock("cross-spawn");
jest.mock();

describe("VercelManager", () => {
beforeEach(() => {
Expand All @@ -34,19 +35,24 @@ describe("VercelManager", () => {

it("should link the Vercel project", () => {
execSync.mockReturnValue(undefined);
vercelManager.setVercelToken("mock_token");
vercelManager.linkProject();

expect(execSync).toHaveBeenCalledWith("vercel link --yes");
expect(execSync).toHaveBeenCalledWith(
"vercel link --yes --token mock_token"
);
});

it("should handle error when linking the Vercel project fails", () => {
execSync.mockImplementation(() => {
throw new Error("Linking failed");
});

vercelManager.setVercelToken("mock_token");
vercelManager.linkProject();

expect(execSync).toHaveBeenCalledWith("vercel link --yes");
expect(execSync).toHaveBeenCalledWith(
"vercel link --yes --token mock_token"
);
expect(console.error).toHaveBeenCalledWith(
"Failed to link Vercel project:",
"Linking failed"
Expand Down

0 comments on commit a44cbaf

Please sign in to comment.