import { Log } from '@diez/cli-core' ; import { File , FileType } from '@diez/prefabs' ; import { AndroidOutput , getUnitedStyleSheetVariables , StyleSheet , WebOutput } from '@diez/targets' ; import { stat } from 'fs-extra' ; import { join , resolve } from 'path' ; ignore export const sourcesPath = resolve ( __dirname , '..' , 'sources' ) ; ignore export const fallbacksPath = resolve ( __dirname , '..' , 'fallbacks' ) ; /**
 * Sets the provided variable along with its united variants on the style sheet.
 */ export const updateStyleSheetWithUnitedVariables = ( name , value , styleSheet ) => { styleSheet . variables . set ( name , value ) ; getUnitedStyleSheetVariables ( name , value ) . forEach ( ( variable ) => { styleSheet . variables . set ( variable . name , variable . value ) ; } ) ; } ; internal const getAndroidResourcePath = ( file ) => encodeURI ( file . src ) . toLowerCase ( ) . replace ( /([^a-z0-9_\.]|\.(?=[^.]*\.))/g , '_' ) ; ignore export const portAssetBindingToResource = ( file , output , type , resourceFile ? ) => { if ( ! output . resources . has ( type ) ) { output . resources . set ( type , new Map ( ) ) ; } const oldBinding = output . assetBindings . get ( file . src ) ; if ( ! oldBinding ) { throw new Error ( `Unable to retrieve file binding from ${ file . src }.` ) ; } output . resources . get ( type ) ! . set ( getAndroidResourcePath ( resourceFile || file ) , oldBinding ) ; output . assetBindings . delete ( file . src ) ; } ; /**
 * Returns a qualified CSS URL for a given output and relative path.
 *
 * This method currently assumes that when we do not have a hot URL, static assets will be served in the host
 * application at `/diez`. This detail cannot be guaranteed in every codebase, so further work is required here.
 */ export const getQualifiedCssUrl = ( output , relativePath ) => `url("${ output . hotUrl || '/diez' }/${ relativePath }")` ; ignore export const getPathToFileContents = ( source , type ) : Promise < string > => new Promise ( ( promiseResolve , promiseReject ) => { stat ( source , ( statError , stats ) => { if ( statError || ! stats . isFile ( ) ) { switch ( type ) { case FileType . Image : Log . warning ( `${ source } does not exist, if this image was extracted from a design tool with \`diez extract\` please try extracting again or contact your design tool's support. A placeholder image will be used instead.\n` ) ; return promiseResolve ( join ( fallbacksPath , 'missing-image.jpg' ) ) ; default : return promiseReject ( new Error ( `File at ${ source } does not exists.` ) ) ; } } return promiseResolve ( source ) ; } ) ; } ) ;