Skip to content

Commit e41972e

Browse files
committed
fix(copy): call function
closes #630
1 parent c4e0be0 commit e41972e

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/features/copy.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path'
22
import { fsCopy } from '../utils/fs.ts'
33
import { toArray } from '../utils/general.ts'
4+
import { prettyName } from '../utils/logger.ts'
45
import type { ResolvedConfig } from '../config/index.ts'
56
import type { Arrayable, Awaitable } from '../utils/types.ts'
67

@@ -19,18 +20,29 @@ export async function copy(options: ResolvedConfig): Promise<void> {
1920
? await options.copy(options)
2021
: options.copy
2122

23+
const resolved: [from: string, to: string][] = toArray(copy).map((dir) => {
24+
const from = path.resolve(
25+
options.cwd,
26+
typeof dir === 'string' ? dir : dir.from,
27+
)
28+
const to =
29+
typeof dir === 'string'
30+
? path.resolve(options.outDir, path.basename(from))
31+
: path.resolve(options.cwd, dir.to)
32+
return [from, to]
33+
})
34+
35+
const name = prettyName(options.name)
2236
await Promise.all(
23-
toArray(copy).map((dir) => {
24-
const from = typeof dir === 'string' ? dir : dir.from
25-
const to =
26-
typeof dir === 'string'
27-
? path.resolve(options.outDir, path.basename(from))
28-
: dir.to
29-
return cp(options.cwd, from, to)
37+
resolved.map(([from, to]) => {
38+
options.logger.info(
39+
name,
40+
`Copying files from ${path.relative(options.cwd, from)} to ${path.relative(
41+
options.cwd,
42+
to,
43+
)}`,
44+
)
45+
return fsCopy(from, to)
3046
}),
3147
)
3248
}
33-
34-
function cp(cwd: string, from: string, to: string): Promise<void> {
35-
return fsCopy(path.resolve(cwd, from), path.resolve(cwd, to))
36-
}

src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,8 @@ export async function buildSingle(
276276
}
277277

278278
async function postBuild() {
279-
if (updated) {
280-
await copy(config)
281-
} else {
279+
await copy(config)
280+
if (!updated) {
282281
await done(bundle)
283282
}
284283

0 commit comments

Comments
 (0)