File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments