-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.mts
47 lines (39 loc) · 1.48 KB
/
build.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* @copyright Sister Software. All rights reserved.
* @author Teffen Ellis, et al.
* @license
* See LICENSE file in the project root for full license information.
*/
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'
import {
SimpleProgramConfig,
TSPathTransformer,
cleanTSBuildDirectory,
createPrettierWriteFileCallback,
createSimpleTSProgram,
createSimpleTSProgramWithWatcher,
readParsedTSConfig,
} from '@sister.software/typescript-esm-packager'
// ESM modules don't have __dirname, so we have to use import.meta.url...
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const programConfig: SimpleProgramConfig = {
// Load the tsconfig.json file...
// This function is just a wrapper around TypeScript's `ts.readConfigFile` function...
tsConfig: readParsedTSConfig(path.join(__dirname, 'tsconfig.json')),
// Create a transformer that...
transformer: new TSPathTransformer(),
// Just for fun, we'll also format the output files with Prettier...
writeFileCallback: await createPrettierWriteFileCallback(),
}
// Clear out any previous builds...
await cleanTSBuildDirectory(programConfig.tsConfig)
const watch = process.argv.includes('--watch')
if (watch) {
// Create a program that watches for changes and re-emits the files...
createSimpleTSProgramWithWatcher(programConfig)
} else {
// Or, create a program that emits the files once...
const program = createSimpleTSProgram(programConfig)
program.emitWithTransformer()
}