@@ -16,8 +16,12 @@ import { isUrl } from "@/src/registry/utils"
1616import { getTemplateForFramework } from "@/src/templates/index"
1717import { loadEnvFiles } from "@/src/utils/env-loader"
1818import * as ERRORS from "@/src/utils/errors"
19- import { withFileBackup } from "@/src/utils/file-helper"
20- import { getBase } from "@/src/utils/get-config"
19+ import { FileBackupError , withFileBackup } from "@/src/utils/file-helper"
20+ import {
21+ getBase ,
22+ getWorkspaceConfig ,
23+ type Config ,
24+ } from "@/src/utils/get-config"
2125import {
2226 getProjectComponents ,
2327 getProjectInfo ,
@@ -26,6 +30,7 @@ import { handleError } from "@/src/utils/handle-error"
2630import { highlighter } from "@/src/utils/highlighter"
2731import { logger } from "@/src/utils/logger"
2832import { Command } from "commander"
33+ import fs from "fs-extra"
2934import prompts from "prompts"
3035import { z } from "zod"
3136
@@ -209,7 +214,7 @@ export const apply = new Command()
209214 only,
210215 } )
211216
212- await runInit ( {
217+ const config = await runInit ( {
213218 cwd : options . cwd ,
214219 yes : true ,
215220 force : false ,
@@ -223,15 +228,8 @@ export const apply = new Command()
223228 existingConfig,
224229 components : [ cleanUrl , ...reinstallComponents ] ,
225230 } )
226- } ,
227- {
228- onBackupFailure : ( ) => {
229- logger . error (
230- `Could not back up ${ highlighter . info (
231- "components.json"
232- ) } . Aborting.`
233- )
234- } ,
231+
232+ await syncApplyWorkspaceConfigs ( config , { only } )
235233 }
236234 )
237235
@@ -247,6 +245,14 @@ export const apply = new Command()
247245 process . exit ( 1 )
248246 }
249247
248+ if ( error instanceof FileBackupError ) {
249+ logger . error (
250+ `Could not back up ${ highlighter . info ( "components.json" ) } . Aborting.`
251+ )
252+ logger . break ( )
253+ process . exit ( 1 )
254+ }
255+
250256 logger . break ( )
251257 handleError ( error )
252258 } finally {
@@ -406,6 +412,79 @@ async function resolveApplyTemplate(cwd: string) {
406412 return getTemplateForFramework ( projectInfo ?. framework . name )
407413}
408414
415+ async function syncApplyWorkspaceConfigs (
416+ config : Config ,
417+ options ?: {
418+ only ?: string [ ]
419+ }
420+ ) {
421+ if ( options ?. only && ! options . only . includes ( "theme" ) ) {
422+ return
423+ }
424+
425+ const linkedConfigs = await getApplyWorkspaceConfigs ( config )
426+ if ( ! linkedConfigs . length ) {
427+ return
428+ }
429+
430+ const patch = {
431+ style : config . style ,
432+ tailwind : {
433+ baseColor : config . tailwind . baseColor ,
434+ cssVariables : config . tailwind . cssVariables ,
435+ } ,
436+ ...( config . iconLibrary ? { iconLibrary : config . iconLibrary } : { } ) ,
437+ ...( config . rtl !== undefined ? { rtl : config . rtl } : { } ) ,
438+ ...( config . menuColor ? { menuColor : config . menuColor } : { } ) ,
439+ ...( config . menuAccent ? { menuAccent : config . menuAccent } : { } ) ,
440+ }
441+
442+ for ( const linkedConfig of linkedConfigs ) {
443+ const configPath = path . resolve (
444+ linkedConfig . resolvedPaths . cwd ,
445+ "components.json"
446+ )
447+ if ( ! ( await fs . pathExists ( configPath ) ) ) {
448+ continue
449+ }
450+
451+ const existingConfig = await fs . readJson ( configPath )
452+ await fs . writeJson (
453+ configPath ,
454+ {
455+ ...existingConfig ,
456+ ...patch ,
457+ tailwind : {
458+ ...existingConfig . tailwind ,
459+ ...patch . tailwind ,
460+ } ,
461+ } ,
462+ { spaces : 2 }
463+ )
464+ }
465+ }
466+
467+ async function getApplyWorkspaceConfigs ( config : Config ) {
468+ const workspaceConfig = await getWorkspaceConfig ( config )
469+ if ( ! workspaceConfig ) {
470+ return [ ]
471+ }
472+
473+ const linkedConfigs = new Map < string , Config > ( )
474+
475+ for ( const linkedConfig of Object . values ( workspaceConfig ) ) {
476+ if ( linkedConfig . resolvedPaths . cwd === config . resolvedPaths . cwd ) {
477+ continue
478+ }
479+
480+ linkedConfigs . set ( linkedConfig . resolvedPaths . cwd , linkedConfig )
481+ }
482+
483+ return Array . from ( linkedConfigs . values ( ) ) . sort ( ( a , b ) =>
484+ a . resolvedPaths . cwd . localeCompare ( b . resolvedPaths . cwd )
485+ )
486+ }
487+
409488export function resolveApplyInitUrl (
410489 preset : string ,
411490 currentBase : "radix" | "base" ,
0 commit comments