UNPKG

@ehmicky/dev-tasks

Version:

Automated development tasks for my own projects

68 lines (53 loc) 1.25 kB
import{pipeline}from"node:stream/promises"; import gulp from"gulp"; import{exec}from"gulp-execa"; import{pathExists}from"path-exists"; import{ BUILD, BUILT_MAIN_SOURCE, SOURCES_GLOB, TYPESCRIPT_AMBIENT_EXT, TYPESCRIPT_AMBIENT_MAIN, TYPESCRIPT_MAIN}from "../../files.js"; export const buildTypes=async()=>{ if(await pathExists(TYPESCRIPT_MAIN)){ await buildFullTypes(); return } if(await pathExists(TYPESCRIPT_AMBIENT_MAIN)){ await buildAmbientTypes() } }; const buildFullTypes=async()=>{ if(await pathExists(TYPESCRIPT_AMBIENT_MAIN)){ throw new Error("\"src/main.d.ts\" and \"src/main.ts\" must not both exist.") } await exec(`tsc ${TSC_FLAGS}`,{echo:false}) }; const TSCONFIG_FLAGS=` --module nodenext \ --moduleResolution nodenext \ --target esnext \ --lib esnext \ --strict \ --exactOptionalPropertyTypes \ --noUncheckedIndexedAccess \ --noUncheckedSideEffectImports \ --forceConsistentCasingInFileNames \ --verbatimModuleSyntax \ `; const TSC_FLAGS=`\ ${TSCONFIG_FLAGS} \ --declaration \ --emitDeclarationOnly \ --declarationDir ${BUILT_MAIN_SOURCE} \ ${TYPESCRIPT_MAIN} `.trim(); const buildAmbientTypes=()=> pipeline( gulp.src([`${SOURCES_GLOB}/*.${TYPESCRIPT_AMBIENT_EXT}`],{ since:gulp.lastRun(buildTypes) }), gulp.dest(BUILD) );