MCPcopy Create free account
hub / github.com/vercel/vercel / prepareFolder

Function prepareFolder

packages/cli/src/commands/init/init.ts:180–209  ·  view source on GitHub ↗

* Check & prepare destination folder for extracting.

(cwd: string, folder: string, force?: boolean)

Source from the content-addressed store, hash-verified

178 * Check & prepare destination folder for extracting.
179 */
180function prepareFolder(cwd: string, folder: string, force?: boolean) {
181 const dest = path.join(cwd, folder);
182
183 if (fs.existsSync(dest)) {
184 if (!fs.lstatSync(dest).isDirectory()) {
185 throw new Error(
186 `Destination path "${chalk.bold(
187 folder
188 )}" already exists and is not a directory.`
189 );
190 }
191 if (!force && fs.readdirSync(dest).length !== 0) {
192 throw new Error(
193 `Destination path "${chalk.bold(
194 folder
195 )}" already exists and is not an empty directory. You may use ${cmd(
196 '--force'
197 )} or ${cmd('-f')} to override it.`
198 );
199 }
200 } else if (dest !== cwd) {
201 try {
202 fs.mkdirSync(dest);
203 } catch (_e) {
204 throw new Error(`Could not create directory "${chalk.bold(folder)}".`);
205 }
206 }
207
208 return dest;
209}
210
211/**
212 * Guess which example user try to init

Callers 1

extractExampleFunction · 0.85

Calls 7

cmdFunction · 0.85
joinMethod · 0.45
existsSyncMethod · 0.45
isDirectoryMethod · 0.45
lstatSyncMethod · 0.45
readdirSyncMethod · 0.45
mkdirSyncMethod · 0.45

Tested by

no test coverage detected