@@ -12,7 +12,6 @@ import {
1212 getSummary ,
1313 ignoreDiagnostics ,
1414 isErrorModel ,
15- JSONSchemaType ,
1615 Model ,
1716 ModelProperty ,
1817 Operation ,
@@ -73,15 +72,12 @@ import { getOperationLink } from "@azure-tools/cadl-azure-core";
7372import fs from "fs" ;
7473import path from "node:path" ;
7574import { Configuration } from "./type/Configuration.js" ;
76- import { dllFilePath } from "@autorest/csharp" ;
7775import { execSync } from "child_process" ;
7876import {
7977 Client ,
8078 createDpgContext ,
81- DpgEmitterOptions ,
8279 getConvenienceAPIName ,
8380 isApiVersion ,
84- isOperationGroup ,
8581 listClients ,
8682 listOperationGroups ,
8783 listOperationsInOperationGroup ,
@@ -93,68 +89,12 @@ import { ClientKind } from "./type/ClientKind.js";
9389import { getVersions } from "@cadl-lang/versioning" ;
9490import { EmitContext } from "@cadl-lang/compiler/*" ;
9591import { capitalize } from "./lib/utils.js" ;
96-
97- export type NetEmitterOptions = {
98- outputFile ?: string ;
99- logFile ?: string ;
100- namespace ?: string ;
101- "library-name" ?: string ;
102- "single-top-level-client" ?: boolean ;
103- skipSDKGeneration ?: boolean ;
104- "unreferenced-types-handling" ?:
105- | "removeOrInternalize"
106- | "internalize"
107- | "keepAll" ;
108- "new-project" ?: boolean ;
109- csharpGeneratorPath ?: string ;
110- "clear-output-folder" ?: boolean ;
111- "save-inputs" ?: boolean ;
112- "model-namespace" ?: boolean ;
113- } & DpgEmitterOptions ;
114-
115- const defaultOptions = {
116- outputFile : "cadl.json" ,
117- logFile : "log.json" ,
118- skipSDKGeneration : false ,
119- "new-project" : false ,
120- csharpGeneratorPath : dllFilePath ,
121- "clear-output-folder" : false ,
122- "save-inputs" : false ,
123- "generate-protocol-methods" : true ,
124- "generate-convenience-methods" : true ,
125- "package-name" : undefined
126- } ;
127-
128- const NetEmitterOptionsSchema : JSONSchemaType < NetEmitterOptions > = {
129- type : "object" ,
130- additionalProperties : false ,
131- properties : {
132- outputFile : { type : "string" , nullable : true } ,
133- logFile : { type : "string" , nullable : true } ,
134- namespace : { type : "string" , nullable : true } ,
135- "library-name" : { type : "string" , nullable : true } ,
136- "single-top-level-client" : { type : "boolean" , nullable : true } ,
137- skipSDKGeneration : { type : "boolean" , default : false , nullable : true } ,
138- "unreferenced-types-handling" : {
139- type : "string" ,
140- enum : [ "removeOrInternalize" , "internalize" , "keepAll" ] ,
141- nullable : true
142- } ,
143- "new-project" : { type : "boolean" , nullable : true } ,
144- csharpGeneratorPath : {
145- type : "string" ,
146- default : dllFilePath ,
147- nullable : true
148- } ,
149- "clear-output-folder" : { type : "boolean" , nullable : true } ,
150- "save-inputs" : { type : "boolean" , nullable : true } ,
151- "model-namespace" : { type : "boolean" , nullable : true } ,
152- "generate-protocol-methods" : { type : "boolean" , nullable : true } ,
153- "generate-convenience-methods" : { type : "boolean" , nullable : true } ,
154- "package-name" : { type : "string" , nullable : true }
155- } ,
156- required : [ ]
157- } ;
92+ import {
93+ NetEmitterOptions ,
94+ NetEmitterOptionsSchema ,
95+ resolveOptions ,
96+ resolveOutputFolder
97+ } from "./options.js" ;
15898
15999export const $lib = createCadlLibrary ( {
160100 name : "cadl-csharp" ,
@@ -166,26 +106,8 @@ export const $lib = createCadlLibrary({
166106
167107export async function $onEmit ( context : EmitContext < NetEmitterOptions > ) {
168108 const program : Program = context . program ;
169- const emitterOptions = context . options ;
170- const emitterOutputDir = context . emitterOutputDir ;
171- const resolvedOptions = { ...defaultOptions , ...emitterOptions } ;
172- const outputFolder = resolvePath ( emitterOutputDir ?? "./cadl-output" ) ;
173- const options : NetEmitterOptions = {
174- outputFile : resolvePath ( outputFolder , resolvedOptions . outputFile ) ,
175- logFile : resolvePath (
176- emitterOutputDir ?? "./cadl-output" ,
177- resolvedOptions . logFile
178- ) ,
179- skipSDKGeneration : resolvedOptions . skipSDKGeneration ,
180- "unreferenced-types-handling" :
181- resolvedOptions [ "unreferenced-types-handling" ] ,
182- "new-project" : resolvedOptions [ "new-project" ] ,
183- csharpGeneratorPath : resolvedOptions . csharpGeneratorPath ,
184- "clear-output-folder" : resolvedOptions [ "clear-output-folder" ] ,
185- "save-inputs" : resolvedOptions [ "save-inputs" ] ,
186- "model-namespace" : resolvedOptions [ "model-namespace" ]
187- } ;
188-
109+ const options = resolveOptions ( context ) ;
110+ const outputFolder = resolveOutputFolder ( context ) ;
189111 if ( ! program . compilerOptions . noEmit && ! program . hasError ( ) ) {
190112 // Write out the dotnet model to the output path
191113 const namespace = getServiceNamespaceString ( program ) || "" ;
@@ -199,12 +121,12 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
199121 const resolvedSharedFolders : string [ ] = [ ] ;
200122 const sharedFolders = [
201123 resolvePath (
202- options . csharpGeneratorPath ?? dllFilePath ,
124+ options . csharpGeneratorPath ,
203125 ".." ,
204126 "Generator.Shared"
205127 ) ,
206128 resolvePath (
207- options . csharpGeneratorPath ?? dllFilePath ,
129+ options . csharpGeneratorPath ,
208130 ".." ,
209131 "Azure.Core.Shared"
210132 )
@@ -231,14 +153,13 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
231153 //emit configuration.json
232154 const configurations = {
233155 OutputFolder : "." ,
234- Namespace : resolvedOptions . namespace ?? namespace ,
235- LibraryName : resolvedOptions [ "library-name" ] ?? null ,
156+ Namespace : options . namespace ?? namespace ,
157+ LibraryName : options [ "library-name" ] ?? null ,
236158 SharedSourceFolders : resolvedSharedFolders ?? [ ] ,
237- SingleTopLevelClient :
238- resolvedOptions [ "single-top-level-client" ] ,
159+ SingleTopLevelClient : options [ "single-top-level-client" ] ,
239160 "unreferenced-types-handling" :
240161 options [ "unreferenced-types-handling" ] ,
241- "model-namespace" : resolvedOptions [ "model-namespace" ]
162+ "model-namespace" : options [ "model-namespace" ]
242163 } as Configuration ;
243164
244165 await program . host . writeFile (
@@ -251,7 +172,7 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
251172 ? "--new-project"
252173 : "" ;
253174 const command = `dotnet --roll-forward Major ${ resolvePath (
254- options . csharpGeneratorPath ?? dllFilePath
175+ options . csharpGeneratorPath
255176 ) } --project-path ${ outputFolder } ${ newProjectOption } --clear-output-folder ${
256177 options [ "clear-output-folder" ]
257178 } `;
0 commit comments