import { Command, FileSystem, Path } from '@effect/platform'; import { BunContext, BunRuntime } from '@effect/platform-bun'; import { Effect, Logger, LogLevel } from 'effect'; import { jsonSchemaToEffectSchema, runCommand } from './lib/script-utils'; const getDscResourceJsonSchema = (resourceType: string) => Effect.gen(function* () { const commandParts = [ 'dsc', 'resource', 'schema', '--resource', resourceType, ] as const; yield* Effect.logDebug(`Running command: ${commandParts.join(' ')}`); const schemaString = yield* Command.make(...commandParts).pipe( Command.string, ); return schemaString.trim(); }); const getAvailableDscResources = () => Effect.gen(function* () { yield* Effect.logDebug('Getting available DSC resources...'); const dscrResourcesListOutput = yield* Command.make( 'dsc', 'resource', 'list', '-o', 'json', ).pipe(Command.string); yield* Effect.logDebug( `DSC resources list output: ${dscrResourcesListOutput}`, ); return [] as Array; }); const genDscResourcesTypes = Effect.gen(function* () { yield* Effect.log('Starting DSC resources types generation...'); const availableResourceTypes = yield* getAvailableDscResources(); yield* Effect.log( `Found available resource types: ${availableResourceTypes.join(', ')}`, ); const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const outputDir = path.join( process.cwd(), 'src', 'dsc-resource-schema-types', ); yield* Effect.logDebug(`Output directory: ${outputDir}`); if (yield* fs.exists(outputDir)) { yield* Effect.log('Removing existing output directory...'); yield* fs.remove(outputDir, { recursive: true, force: true }); } yield* fs.makeDirectory(outputDir, { recursive: true }); for (const schemaType of availableResourceTypes) { yield* Effect.logDebug(`Processing: ${schemaType}`); const jsonSchema = yield* getDscResourceJsonSchema(schemaType); const effectSchema = yield* jsonSchemaToEffectSchema({ jsonSchema, name: schemaType, }); const outputPath = path.join(outputDir, `${schemaType}.gen.ts`); yield* fs.writeFileString(outputPath, effectSchema); yield* Effect.log(`Generated: ${schemaType}.gen.ts`); } yield* Effect.log('DSC types generation complete!'); }); BunRuntime.runMain( genDscResourcesTypes.pipe( Effect.provide(BunContext.layer), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.scoped, ), );