|
|
import { RollupOptions, OutputOptions } from 'rollup'; |
|
|
import * as fs from 'fs-extra'; |
|
|
import { concatAllArray } from 'jpjs'; |
|
|
|
|
|
import { paths } from './constants'; |
|
|
import { TsdxOptions, NormalizedOpts } from './types'; |
|
|
|
|
|
import { createRollupConfig } from './createRollupConfig'; |
|
|
|
|
|
|
|
|
let tsdxConfig = { |
|
|
rollup(config: RollupOptions, _options: TsdxOptions): RollupOptions { |
|
|
return config; |
|
|
}, |
|
|
}; |
|
|
|
|
|
if (fs.existsSync(paths.appConfig)) { |
|
|
tsdxConfig = require(paths.appConfig); |
|
|
} |
|
|
|
|
|
export async function createBuildConfigs( |
|
|
opts: NormalizedOpts |
|
|
): Promise<Array<RollupOptions & { output: OutputOptions }>> { |
|
|
const allInputs = concatAllArray( |
|
|
opts.input.map((input: string) => |
|
|
createAllFormats(opts, input).map( |
|
|
(options: TsdxOptions, index: number) => ({ |
|
|
...options, |
|
|
|
|
|
|
|
|
writeMeta: index === 0, |
|
|
}) |
|
|
) |
|
|
) |
|
|
); |
|
|
|
|
|
return await Promise.all( |
|
|
allInputs.map(async (options: TsdxOptions, index: number) => { |
|
|
|
|
|
const config = await createRollupConfig(options, index); |
|
|
return tsdxConfig.rollup(config, options); |
|
|
}) |
|
|
); |
|
|
} |
|
|
|
|
|
function createAllFormats( |
|
|
opts: NormalizedOpts, |
|
|
input: string |
|
|
): [TsdxOptions, ...TsdxOptions[]] { |
|
|
return [ |
|
|
opts.format.includes('cjs') && { |
|
|
...opts, |
|
|
format: 'cjs', |
|
|
env: 'development', |
|
|
input, |
|
|
}, |
|
|
opts.format.includes('cjs') && { |
|
|
...opts, |
|
|
format: 'cjs', |
|
|
env: 'production', |
|
|
input, |
|
|
}, |
|
|
opts.format.includes('esm') && { ...opts, format: 'esm', input }, |
|
|
opts.format.includes('umd') && { |
|
|
...opts, |
|
|
format: 'umd', |
|
|
env: 'development', |
|
|
input, |
|
|
}, |
|
|
opts.format.includes('umd') && { |
|
|
...opts, |
|
|
format: 'umd', |
|
|
env: 'production', |
|
|
input, |
|
|
}, |
|
|
opts.format.includes('system') && { |
|
|
...opts, |
|
|
format: 'system', |
|
|
env: 'development', |
|
|
input, |
|
|
}, |
|
|
opts.format.includes('system') && { |
|
|
...opts, |
|
|
format: 'system', |
|
|
env: 'production', |
|
|
input, |
|
|
}, |
|
|
].filter(Boolean) as [TsdxOptions, ...TsdxOptions[]]; |
|
|
} |
|
|
|