Skip to content

Commit 8feb907

Browse files
committed
refactor: add build
1 parent 0af91fe commit 8feb907

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/build.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { isString, isObject } from '@hypernym/utils'
2+
import { getOutputPath } from './utils/index.js'
3+
import type { Options, BuildStats } from './types/index.js'
4+
5+
export async function build(
6+
cwd: string,
7+
options: Options,
8+
): Promise<BuildStats> {
9+
const { outDir = 'dist', hooks } = options
10+
11+
const buildStats: BuildStats = {
12+
time: { start: 0, end: 0 },
13+
size: 0,
14+
files: [],
15+
}
16+
17+
if (hooks?.['build:before']) await hooks['build:before'](options)
18+
19+
if (options.entries && options.entries.length) {
20+
buildStats.time.start = Date.now()
21+
22+
for (const entry of options.entries) {
23+
if (isString(entry)) {
24+
const output = getOutputPath(outDir, entry)
25+
buildStats.files.push(output)
26+
}
27+
28+
if (isObject(entry)) {
29+
buildStats.files.push(entry.output)
30+
}
31+
}
32+
33+
buildStats.time.end = Date.now()
34+
}
35+
36+
if (hooks?.['build:done']) await hooks['build:done'](options)
37+
38+
return buildStats
39+
}

0 commit comments

Comments
 (0)