MCPcopy
hub / github.com/vercel/next.js / copy

Function copy

packages/create-next-app/helpers/copy.ts:14–50  ·  view source on GitHub ↗
(
  src: string | string[],
  dest: string,
  { cwd, rename = identity, parents = true }: CopyOption = {}
)

Source from the content-addressed store, hash-verified

12const identity = (x: string) => x
13
14export const copy = async (
15 src: string | string[],
16 dest: string,
17 { cwd, rename = identity, parents = true }: CopyOption = {}
18) => {
19 const source = typeof src === 'string' ? [src] : src
20
21 if (source.length === 0 || !dest) {
22 throw new TypeError('`src` and `dest` are required')
23 }
24
25 const sourceFiles = await glob(source, {
26 cwd,
27 dot: true,
28 absolute: false,
29 stats: false,
30 })
31
32 const destRelativeToCwd = cwd ? resolve(cwd, dest) : dest
33
34 return Promise.all(
35 sourceFiles.map(async (p) => {
36 const dirName = dirname(p)
37 const baseName = rename(basename(p))
38
39 const from = cwd ? resolve(cwd, p) : p
40 const to = parents
41 ? join(destRelativeToCwd, dirName, baseName)
42 : join(destRelativeToCwd, baseName)
43
44 // Ensure the destination directory exists
45 await mkdir(dirname(to), { recursive: true })
46
47 return copyFile(from, to)
48 })
49 )
50}

Callers 1

installTemplateFunction · 0.90

Calls 9

basenameFunction · 0.85
allMethod · 0.80
globFunction · 0.50
resolveFunction · 0.50
dirnameFunction · 0.50
renameFunction · 0.50
joinFunction · 0.50
copyFileFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected