import plugin , { StartDataFilesProps , StartDataFile } from '@start/plugin/src/' ; export default ( outDirRelative ) => plugin ( 'write' , ( { logPath } ) => async ( { files } ) => { const path = await import ( 'path' ) ; const { promisify } = await import ( 'util' ) ; const { writeFile } = await import ( 'graceful-fs' ) ; const { default : movePath } = await import ( 'move-path' ) ; const { default : makeDir } = await import ( 'make-dir' ) ; const pWriteFile = promisify ( writeFile ) ; return { files : await Promise . all ( files . map ( async ( file ) : Promise < StartDataFile > => { const outFile = movePath ( file . path , outDirRelative ) ; const outDir = path . dirname ( outFile ) ; await makeDir ( outDir ) ; const writeFiles = [ ] ; let fileData = file . data ; if ( file . map != null ) { const inFile = path . basename ( file . path ) ; const inExtname = path . extname ( file . path ) ; const sourcemapFile = inFile + '.map' ; const sourcemapPath = path . join ( outDir , sourcemapFile ) ; const sourcemapData = JSON . stringify ( file . map ) ; if ( inExtname === '.css' ) { fileData += '\n/*# sourceMappingURL=' ; fileData += sourcemapFile ; fileData += ' */' ; } else { fileData += '\n//# sourceMappingURL=' ; fileData += sourcemapFile ; } writeFiles . push ( pWriteFile ( sourcemapPath , sourcemapData , 'utf8' ) . then ( ( ) => { logPath ( sourcemapPath ) ; } ) ) ; } writeFiles . push ( pWriteFile ( outFile , fileData , 'utf8' ) . then ( ( ) => { logPath ( outFile ) ; } ) ) ; await Promise . all ( writeFiles ) ; return { ... file , path : outFile } ; } ) ) } ; } ) ;