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

[cli] Move readme copy logic to a helper function for vc link #10084

Merged
merged 2 commits into from
Jun 7, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-gorillas-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vercel": patch
---

Move readme copy logic to a helper function for `vc link`
16 changes: 3 additions & 13 deletions packages/cli/src/util/link/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import pluralize from 'pluralize';
import { homedir } from 'os';
import { join, normalize } from 'path';
import { normalizePath } from '@vercel/build-utils';
import { lstat, readJSON, outputJSON, writeFile, readFile } from 'fs-extra';
import { lstat, readJSON, outputJSON } from 'fs-extra';
import confirm from '../input/confirm';
import toHumanPath from '../humanize-path';
import {
VERCEL_DIR,
VERCEL_DIR_README,
VERCEL_DIR_REPO,
} from '../projects/link';
import { VERCEL_DIR, VERCEL_DIR_REPO, writeReadme } from '../projects/link';
import { getRemoteUrls } from '../create-git-meta';
import link from '../output/link';
import { emoji, prependEmoji } from '../emoji';
Expand Down Expand Up @@ -193,13 +189,7 @@ export async function ensureRepoLink(
};
await outputJSON(repoConfigPath, repoConfig, { spaces: 2 });

await writeFile(
join(rootPath, VERCEL_DIR, VERCEL_DIR_README),
await readFile(
join(__dirname, '..', 'projects', 'VERCEL_DIR_README.txt'),
'utf8'
)
);
await writeReadme(rootPath);

// update .gitignore
const isGitIgnoreUpdated = await addToGitIgnore(rootPath);
Expand Down
12 changes: 8 additions & 4 deletions packages/cli/src/util/projects/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ export async function getLinkedProject(
return { status: 'linked', org, project, repoRoot: link.repoRoot };
}

export async function writeReadme(path: string) {
await writeFile(
join(path, VERCEL_DIR, VERCEL_DIR_README),
await readFile(join(__dirname, 'VERCEL_DIR_README.txt'), 'utf8')
);
Comment on lines +289 to +292
Copy link
Contributor

@cb1kenobi cb1kenobi Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): Node 14 introduce import { copyFile } from 'fs/promises';: https://nodejs.org/dist/latest-v18.x/docs/api/fs.html#fspromisescopyfilesrc-dest-mode

Suggested change
await writeFile(
join(path, VERCEL_DIR, VERCEL_DIR_README),
await readFile(join(__dirname, 'VERCEL_DIR_README.txt'), 'utf8')
);
await copyFile(
join(__dirname, 'VERCEL_DIR_README.txt'),
join(path, VERCEL_DIR, VERCEL_DIR_README)
);

}

export async function linkFolderToProject(
client: Client,
path: string,
Expand Down Expand Up @@ -314,10 +321,7 @@ export async function linkFolderToProject(
JSON.stringify(projectLink)
);

await writeFile(
join(path, VERCEL_DIR, VERCEL_DIR_README),
await readFile(join(__dirname, 'VERCEL_DIR_README.txt'), 'utf8')
);
await writeReadme(path);

// update .gitignore
const isGitIgnoreUpdated = await addToGitIgnore(path);
Expand Down