import type * as d from '../../../declarations' ; import { dirname , join , relative } from 'path' ; import { normalizePath } from '@utils' ; export const getComponentAssetsCopyTasks = ( config , buildCtx , dest , collectionsPath ) => { if ( ! dest ) { return [ ] ; } const copyTasks = [ ] ; const cmps = buildCtx . components ; cmps . filter ( ( cmp ) => cmp . assetsDirs != null && cmp . assetsDirs . length > 0 ) . forEach ( ( cmp ) => { if ( ! collectionsPath ) { cmp . assetsDirs . forEach ( ( assetsMeta ) => { copyTasks . push ( { src : assetsMeta . absolutePath , dest : join ( dest , assetsMeta . cmpRelativePath ) , warn : false , keepDirStructure : false , } ) ; } ) ; } else if ( ! cmp . excludeFromCollection && ! cmp . isCollectionDependency ) { cmp . assetsDirs . forEach ( ( assetsMeta ) => { const collectionDirDestination = join ( dest , relative ( config . srcDir , assetsMeta . absolutePath ) ) ; copyTasks . push ( { src : assetsMeta . absolutePath , dest : collectionDirDestination , warn : false , keepDirStructure : false , } ) ; } ) ; } } ) ; buildCtx . debug ( `getComponentAssetsCopyTasks: ${ copyTasks . length }` ) ; return copyTasks ; } ; export const canSkipAssetsCopy = ( compilerCtx , entryModules , filesChanged ) => { if ( ! compilerCtx . hasSuccessfulBuild ) { return false ; } let shouldSkipAssetsCopy = true ; filesChanged . forEach ( ( changedFile ) => { const changedFileDirPath = normalizePath ( dirname ( changedFile ) ) ; entryModules . forEach ( ( entryModule ) => { entryModule . cmps . forEach ( ( cmp ) => { if ( cmp . assetsDirs != null ) { cmp . assetsDirs . forEach ( ( assetsDir ) => { const assetDirPath = normalizePath ( assetsDir . absolutePath ) ; if ( changedFileDirPath === assetDirPath ) { shouldSkipAssetsCopy = false ; return ; } } ) ; } } ) ; } ) ; } ) ; return shouldSkipAssetsCopy ; } ;