Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/js-sdk-release-tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/js-sdk-release-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/js-sdk-release-tools",
"version": "2.7.6",
"version": "2.7.7",
"description": "",
"scripts": {
"start": "node dist/changelogToolCli.js",
Expand Down
100 changes: 53 additions & 47 deletions tools/js-sdk-release-tools/src/autoGenerateInPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env node

import * as path from 'path';
import {generateMgmt} from "./hlc/generateMgmt";
import { generateMgmt } from "./hlc/generateMgmt";
import { backupNodeModules, restoreNodeModules } from './utils/backupNodeModules';
import {logger} from "./utils/logger";
import {generateRLCInPipeline} from "./llc/generateRLCInPipeline/generateRLCInPipeline";
import {RunningEnvironment} from "./utils/runningEnvironment";
import { logger } from "./utils/logger";
import { generateRLCInPipeline } from "./llc/generateRLCInPipeline/generateRLCInPipeline";
import { RunningEnvironment } from "./utils/runningEnvironment";

const shell = require('shelljs');
const fs = require('fs');

async function automationGenerateInPipeline(inputJsonPath: string, outputJsonPath: string, use: string | undefined, typespecEmitter: string | undefined, sdkGenerationType: string | undefined) {
const inputJson = JSON.parse(fs.readFileSync(inputJsonPath, {encoding: 'utf-8'}));
const inputJson = JSON.parse(fs.readFileSync(inputJsonPath, { encoding: 'utf-8' }));
const specFolder: string = inputJson['specFolder'];
const readmeFiles: string[] | string | undefined = inputJson['relatedReadmeMdFiles']? inputJson['relatedReadmeMdFiles']: inputJson['relatedReadmeMdFile'];
const readmeFiles: string[] | string | undefined = inputJson['relatedReadmeMdFiles'] ? inputJson['relatedReadmeMdFiles'] : inputJson['relatedReadmeMdFile'];
const typespecProjectFolder: string[] | string | undefined = inputJson['relatedTypeSpecProjectFolder'];
const gitCommitId: string = inputJson['headSha'];
const repoHttpsUrl: string = inputJson['repoHttpsUrl'];
Expand All @@ -39,51 +39,57 @@ async function automationGenerateInPipeline(inputJsonPath: string, outputJsonPat
const outputJson = {
packages: packages
};
const readmeMd = isTypeSpecProject? undefined : typeof readmeFiles === 'string'? readmeFiles : readmeFiles![0];
const typespecProject = isTypeSpecProject? typeof typespecProjectFolder === 'string'? typespecProjectFolder : typespecProjectFolder![0] : undefined;
const isMgmt = isTypeSpecProject? false : readmeMd!.includes('resource-manager');
const runningEnvironment = typeof readmeFiles === 'string' || typeof typespecProjectFolder === 'string'? RunningEnvironment.SdkGeneration : RunningEnvironment.SwaggerSdkAutomation;
await backupNodeModules(String(shell.pwd()));
if (isMgmt) {
await generateMgmt({
sdkRepo: String(shell.pwd()),
swaggerRepo: specFolder,
readmeMd: readmeMd!,
gitCommitId: gitCommitId,
use: use,
outputJson: outputJson,
swaggerRepoUrl: repoHttpsUrl,
downloadUrlPrefix: downloadUrlPrefix,
skipGeneration: skipGeneration,
runningEnvironment: runningEnvironment
});
} else {
await generateRLCInPipeline({
sdkRepo: String(shell.pwd()),
swaggerRepo: path.isAbsolute(specFolder)? specFolder : path.join(String(shell.pwd()), specFolder),
readmeMd: readmeMd,
typespecProject: typespecProject,
autorestConfig,
use: use,
typespecEmitter: !!typespecEmitter? typespecEmitter : `@azure-tools/typespec-ts`,
outputJson: outputJson,
skipGeneration: skipGeneration,
sdkGenerationType: (sdkGenerationType === "command") ? "command" : "script",
runningEnvironment: runningEnvironment,
swaggerRepoUrl: repoHttpsUrl,
gitCommitId: gitCommitId,
})
const readmeMd = isTypeSpecProject ? undefined : typeof readmeFiles === 'string' ? readmeFiles : readmeFiles![0];
const typespecProject = isTypeSpecProject ? typeof typespecProjectFolder === 'string' ? typespecProjectFolder : typespecProjectFolder![0] : undefined;
const isMgmt = isTypeSpecProject ? false : readmeMd!.includes('resource-manager');
const runningEnvironment = typeof readmeFiles === 'string' || typeof typespecProjectFolder === 'string' ? RunningEnvironment.SdkGeneration : RunningEnvironment.SwaggerSdkAutomation;
try {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main change is to add a try/finally block for this.

await backupNodeModules(String(shell.pwd()));
if (isMgmt) {
await generateMgmt({
sdkRepo: String(shell.pwd()),
swaggerRepo: specFolder,
readmeMd: readmeMd!,
gitCommitId: gitCommitId,
use: use,
outputJson: outputJson,
swaggerRepoUrl: repoHttpsUrl,
downloadUrlPrefix: downloadUrlPrefix,
skipGeneration: skipGeneration,
runningEnvironment: runningEnvironment
});
} else {
await generateRLCInPipeline({
sdkRepo: String(shell.pwd()),
swaggerRepo: path.isAbsolute(specFolder) ? specFolder : path.join(String(shell.pwd()), specFolder),
readmeMd: readmeMd,
typespecProject: typespecProject,
autorestConfig,
use: use,
typespecEmitter: !!typespecEmitter ? typespecEmitter : `@azure-tools/typespec-ts`,
outputJson: outputJson,
skipGeneration: skipGeneration,
sdkGenerationType: (sdkGenerationType === "command") ? "command" : "script",
runningEnvironment: runningEnvironment,
swaggerRepoUrl: repoHttpsUrl,
gitCommitId: gitCommitId,
})
}
} catch (e: any) {
logger.logError(e.message);
throw e;
} finally {
await restoreNodeModules(String(shell.pwd()));
fs.writeFileSync(outputJsonPath, JSON.stringify(outputJson, null, ' '), { encoding: 'utf-8' });
}
await restoreNodeModules(String(shell.pwd()));
fs.writeFileSync(outputJsonPath, JSON.stringify(outputJson, null, ' '), {encoding: 'utf-8'})
}

const optionDefinitions = [
{name: 'use', type: String},
{name: 'typespecEmitter', type: String},
{name: 'sdkGenerationType', type: String},
{name: 'inputJsonPath', type: String},
{name: 'outputJsonPath', type: String},
{ name: 'use', type: String },
{ name: 'typespecEmitter', type: String },
{ name: 'sdkGenerationType', type: String },
{ name: 'inputJsonPath', type: String },
{ name: 'outputJsonPath', type: String },
];
const commandLineArgs = require('command-line-args');
const options = commandLineArgs(optionDefinitions);
Expand Down
8 changes: 4 additions & 4 deletions tools/js-sdk-release-tools/src/utils/backupNodeModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export async function backupNodeModules(folder: string) {

export async function restoreNodeModules(folder: string) {
const nodeModulesPath = path.join(folder, "node_modules_backup");
if (fs.existsSync(nodeModulesPath)) {
logger.logGreen(`rename ${nodeModulesPath} to ${nodeModulesPath.replace('_backup', '')}`);
fs.renameSync(nodeModulesPath, `${nodeModulesPath.replace('_backup', '')}`);
if (!fs.existsSync(nodeModulesPath) || '/' === path.dirname(folder)) {
return;
}
if ('/' === path.dirname(folder)) return;
logger.logGreen(`rename ${nodeModulesPath} to ${nodeModulesPath.replace('_backup', '')}`);
fs.renameSync(nodeModulesPath, `${nodeModulesPath.replace('_backup', '')}`);
await restoreNodeModules(path.dirname(folder));
}