11import chalk from 'chalk' ;
2+ import { LinuxDistro , OS } from 'codify-schemas' ;
3+ import os from 'node:os' ;
24import path from 'node:path' ;
35
46import { PluginInitOrchestrator } from '../common/initialize-plugins.js' ;
57import { ResourceConfig } from '../entities/resource-config.js' ;
68import { ProcessName , SubProcessName , ctx } from '../events/context.js' ;
9+ import { ResourceDefinitionMap } from '../plugins/plugin-manager.js' ;
710import { Reporter } from '../ui/reporters/reporter.js' ;
811import { FileUtils } from '../utils/file.js' ;
912import { resolvePathWithVariables , tildify , untildify } from '../utils/index.js' ;
13+ import { ShellUtils } from '../utils/shell.js' ;
1014
1115export interface InitArgs {
1216 path ?: string ;
@@ -30,9 +34,12 @@ export const InitializeOrchestrator = {
3034
3135 ctx . subprocessStarted ( SubProcessName . IMPORT_RESOURCE )
3236
33- // Omit sensitive resources if not included
37+ const currentDistro = os . type ( ) === OS . Linux ? await ShellUtils . getLinuxDistro ( ) : undefined ;
38+
39+ // Omit sensitive resources and resources not supported on the current OS
3440 const typeIdsToImport = [ ...resourceDefinitions . keys ( ) ]
3541 . filter ( ( typeId ) => args . includeSensitive || ( ! args . includeSensitive && ( resourceDefinitions . get ( typeId ) ?. sensitiveParameters ?? [ ] ) . length === 0 ) )
42+ . filter ( ( typeId ) => this . filterByOperatingSystemAndDistro ( typeId , resourceDefinitions , currentDistro ) )
3643
3744 const importResults = await Promise . all ( typeIdsToImport . map ( async ( typeId ) => {
3845 try {
@@ -103,6 +110,21 @@ Enjoy!
103110 }
104111
105112 return locationToSave ;
106- }
113+ } ,
114+
115+ filterByOperatingSystemAndDistro ( typeId : string , resourceDefinitions : ResourceDefinitionMap , linuxDistro ?: LinuxDistro ) : boolean {
116+ const supportedOperatingSystems = resourceDefinitions . get ( typeId ) ?. operatingSystems ;
117+ if ( supportedOperatingSystems ) {
118+ return supportedOperatingSystems . includes ( os . type ( ) as OS ) ;
119+ }
107120
121+ if ( os . type ( ) === OS . Linux && linuxDistro ) {
122+ const distros = resourceDefinitions . get ( typeId ) ?. linuxDistros ;
123+ if ( distros ) {
124+ return distros . includes ( linuxDistro ) ;
125+ }
126+ }
127+
128+ return true ;
129+ }
108130} ;
0 commit comments