11#!/usr/bin/env node
22
33import * as path from 'path' ;
4- import { generateMgmt } from "./hlc/generateMgmt" ;
4+ import { generateMgmt } from "./hlc/generateMgmt" ;
55import { backupNodeModules , restoreNodeModules } from './utils/backupNodeModules' ;
6- import { logger } from "./utils/logger" ;
7- import { generateRLCInPipeline } from "./llc/generateRLCInPipeline/generateRLCInPipeline" ;
8- import { RunningEnvironment } from "./utils/runningEnvironment" ;
6+ import { logger } from "./utils/logger" ;
7+ import { generateRLCInPipeline } from "./llc/generateRLCInPipeline/generateRLCInPipeline" ;
8+ import { RunningEnvironment } from "./utils/runningEnvironment" ;
99
1010const shell = require ( 'shelljs' ) ;
1111const fs = require ( 'fs' ) ;
1212
1313async function automationGenerateInPipeline ( inputJsonPath : string , outputJsonPath : string , use : string | undefined , typespecEmitter : string | undefined , sdkGenerationType : string | undefined ) {
14- const inputJson = JSON . parse ( fs . readFileSync ( inputJsonPath , { encoding : 'utf-8' } ) ) ;
14+ const inputJson = JSON . parse ( fs . readFileSync ( inputJsonPath , { encoding : 'utf-8' } ) ) ;
1515 const specFolder : string = inputJson [ 'specFolder' ] ;
16- const readmeFiles : string [ ] | string | undefined = inputJson [ 'relatedReadmeMdFiles' ] ? inputJson [ 'relatedReadmeMdFiles' ] : inputJson [ 'relatedReadmeMdFile' ] ;
16+ const readmeFiles : string [ ] | string | undefined = inputJson [ 'relatedReadmeMdFiles' ] ? inputJson [ 'relatedReadmeMdFiles' ] : inputJson [ 'relatedReadmeMdFile' ] ;
1717 const typespecProjectFolder : string [ ] | string | undefined = inputJson [ 'relatedTypeSpecProjectFolder' ] ;
1818 const gitCommitId : string = inputJson [ 'headSha' ] ;
1919 const repoHttpsUrl : string = inputJson [ 'repoHttpsUrl' ] ;
@@ -39,51 +39,57 @@ async function automationGenerateInPipeline(inputJsonPath: string, outputJsonPat
3939 const outputJson = {
4040 packages : packages
4141 } ;
42- const readmeMd = isTypeSpecProject ? undefined : typeof readmeFiles === 'string' ? readmeFiles : readmeFiles ! [ 0 ] ;
43- const typespecProject = isTypeSpecProject ? typeof typespecProjectFolder === 'string' ? typespecProjectFolder : typespecProjectFolder ! [ 0 ] : undefined ;
44- const isMgmt = isTypeSpecProject ? false : readmeMd ! . includes ( 'resource-manager' ) ;
45- const runningEnvironment = typeof readmeFiles === 'string' || typeof typespecProjectFolder === 'string' ? RunningEnvironment . SdkGeneration : RunningEnvironment . SwaggerSdkAutomation ;
46- await backupNodeModules ( String ( shell . pwd ( ) ) ) ;
47- if ( isMgmt ) {
48- await generateMgmt ( {
49- sdkRepo : String ( shell . pwd ( ) ) ,
50- swaggerRepo : specFolder ,
51- readmeMd : readmeMd ! ,
52- gitCommitId : gitCommitId ,
53- use : use ,
54- outputJson : outputJson ,
55- swaggerRepoUrl : repoHttpsUrl ,
56- downloadUrlPrefix : downloadUrlPrefix ,
57- skipGeneration : skipGeneration ,
58- runningEnvironment : runningEnvironment
59- } ) ;
60- } else {
61- await generateRLCInPipeline ( {
62- sdkRepo : String ( shell . pwd ( ) ) ,
63- swaggerRepo : path . isAbsolute ( specFolder ) ? specFolder : path . join ( String ( shell . pwd ( ) ) , specFolder ) ,
64- readmeMd : readmeMd ,
65- typespecProject : typespecProject ,
66- autorestConfig,
67- use : use ,
68- typespecEmitter : ! ! typespecEmitter ? typespecEmitter : `@azure-tools/typespec-ts` ,
69- outputJson : outputJson ,
70- skipGeneration : skipGeneration ,
71- sdkGenerationType : ( sdkGenerationType === "command" ) ? "command" : "script" ,
72- runningEnvironment : runningEnvironment ,
73- swaggerRepoUrl : repoHttpsUrl ,
74- gitCommitId : gitCommitId ,
75- } )
42+ const readmeMd = isTypeSpecProject ? undefined : typeof readmeFiles === 'string' ? readmeFiles : readmeFiles ! [ 0 ] ;
43+ const typespecProject = isTypeSpecProject ? typeof typespecProjectFolder === 'string' ? typespecProjectFolder : typespecProjectFolder ! [ 0 ] : undefined ;
44+ const isMgmt = isTypeSpecProject ? false : readmeMd ! . includes ( 'resource-manager' ) ;
45+ const runningEnvironment = typeof readmeFiles === 'string' || typeof typespecProjectFolder === 'string' ? RunningEnvironment . SdkGeneration : RunningEnvironment . SwaggerSdkAutomation ;
46+ try {
47+ await backupNodeModules ( String ( shell . pwd ( ) ) ) ;
48+ if ( isMgmt ) {
49+ await generateMgmt ( {
50+ sdkRepo : String ( shell . pwd ( ) ) ,
51+ swaggerRepo : specFolder ,
52+ readmeMd : readmeMd ! ,
53+ gitCommitId : gitCommitId ,
54+ use : use ,
55+ outputJson : outputJson ,
56+ swaggerRepoUrl : repoHttpsUrl ,
57+ downloadUrlPrefix : downloadUrlPrefix ,
58+ skipGeneration : skipGeneration ,
59+ runningEnvironment : runningEnvironment
60+ } ) ;
61+ } else {
62+ await generateRLCInPipeline ( {
63+ sdkRepo : String ( shell . pwd ( ) ) ,
64+ swaggerRepo : path . isAbsolute ( specFolder ) ? specFolder : path . join ( String ( shell . pwd ( ) ) , specFolder ) ,
65+ readmeMd : readmeMd ,
66+ typespecProject : typespecProject ,
67+ autorestConfig,
68+ use : use ,
69+ typespecEmitter : ! ! typespecEmitter ? typespecEmitter : `@azure-tools/typespec-ts` ,
70+ outputJson : outputJson ,
71+ skipGeneration : skipGeneration ,
72+ sdkGenerationType : ( sdkGenerationType === "command" ) ? "command" : "script" ,
73+ runningEnvironment : runningEnvironment ,
74+ swaggerRepoUrl : repoHttpsUrl ,
75+ gitCommitId : gitCommitId ,
76+ } )
77+ }
78+ } catch ( e : any ) {
79+ logger . logError ( e . message ) ;
80+ throw e ;
81+ } finally {
82+ await restoreNodeModules ( String ( shell . pwd ( ) ) ) ;
83+ fs . writeFileSync ( outputJsonPath , JSON . stringify ( outputJson , null , ' ' ) , { encoding : 'utf-8' } ) ;
7684 }
77- await restoreNodeModules ( String ( shell . pwd ( ) ) ) ;
78- fs . writeFileSync ( outputJsonPath , JSON . stringify ( outputJson , null , ' ' ) , { encoding : 'utf-8' } )
7985}
8086
8187const optionDefinitions = [
82- { name : 'use' , type : String } ,
83- { name : 'typespecEmitter' , type : String } ,
84- { name : 'sdkGenerationType' , type : String } ,
85- { name : 'inputJsonPath' , type : String } ,
86- { name : 'outputJsonPath' , type : String } ,
88+ { name : 'use' , type : String } ,
89+ { name : 'typespecEmitter' , type : String } ,
90+ { name : 'sdkGenerationType' , type : String } ,
91+ { name : 'inputJsonPath' , type : String } ,
92+ { name : 'outputJsonPath' , type : String } ,
8793] ;
8894const commandLineArgs = require ( 'command-line-args' ) ;
8995const options = commandLineArgs ( optionDefinitions ) ;
0 commit comments