import path from "upath" ; import * as logger from "./logger" ; import { Substitutions } from "./types" ; function substituteComponents ( componentsDir , config , substitutions ) { if ( ! substitutions ) { return ; } const componentsMap = Object . fromEntries ( substitutions . map ( ( elem ) => [ elem . name , elem ] ) ) ; const seenComponents = { } ; const markAsSeen = ( name ) => { if ( seenComponents [ name ] ) { logger . crash ( `Component ${ name } found in multiple projects. Please specify the project id!` ) ; } seenComponents [ name ] = true ; } ; config . projects . forEach ( ( project ) => { project . components . forEach ( ( component ) => { if ( ! componentsMap [ component . name ] ) { return ; } const { projectId , path : componentPath } = componentsMap [ component . name ] ; if ( projectId && projectId !== project . projectId ) { return ; } if ( ! projectId ) { markAsSeen ( component . name ) ; } component . importSpec . modulePath = path . relative ( componentsDir , path . resolve ( componentPath ) ) ; } ) ; } ) ; } export function registerSubstitutions ( plasmicDir , config , substitutions ) { const componentsDir = path . join ( plasmicDir , "components" ) ; substituteComponents ( componentsDir , config , substitutions . components ) ; }