Skip to content

Commit

Permalink
tsp - Add support for protectedfiles (#1368)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli committed Aug 12, 2024
1 parent 58a389a commit 15e2490
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
105 changes: 104 additions & 1 deletion common/config/rush/pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions powershell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@azure-tools/codegen": "~2.5.276",
"@azure-tools/codegen-csharp": "~3.0.0",
"@azure-tools/codemodel-v3": "~3.1.0",
"@azure-tools/uri": "~3.1.1",
"@autorest/extension-base": "~3.5.2",
"@autorest/codemodel": "~4.19.3",
"@azure-tools/linq": "~3.1.0",
Expand Down
30 changes: 30 additions & 0 deletions powershell/utils/tsp-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,40 @@ import { ModelState } from './model-state';
import { TspHostImpl } from './tsp-host';
import { stat } from 'fs';
import { serialize } from '@azure-tools/codegen';
import { clearFolder, resolveUri, createFolderUri } from '@azure-tools/uri';
import { join, resolve as currentDirectory } from 'path';

async function clearOutputFiles(state: ModelState<PwshModel>) {
if (await state.getValue('clear-output-folder', false)) {
const outputFolder = createFolderUri(join(currentDirectory(), await state.getValue('output-folder', './generated')));
const psd1: string = await state.getValue('psd1');
const customFolder: string = await state.getValue('custom-cmdlet-folder');
const testFolder: string = await state.getValue('test-folder');
const docsFolder: string = await state.getValue('docs-folder');
const examplesFolder: string = await state.getValue('examples-folder');
const resourcesFolder: string = await state.getValue('resources-folder');
const uxFolder: string = await state.getValue('ux-folder');
const readme = './README.md';

const protectFiles = new Set<string>();
protectFiles.add(psd1);
protectFiles.add(customFolder);
protectFiles.add(testFolder);
protectFiles.add(docsFolder);
protectFiles.add(examplesFolder);
protectFiles.add(resourcesFolder);
protectFiles.add(uxFolder);
protectFiles.add(readme);
await clearFolder(outputFolder, [...protectFiles].map((each) => resolveUri(outputFolder, each)));
}
return;

}
export async function generatePwshModule(pwshModel: PwshModel, emitterOptions: any) {
const tspService = new TspHostImpl(emitterOptions);
const state = await new ModelState<PwshModel>(tspService);
// clear output folder if set, but protect certain files
await clearOutputFiles(state);
state.model = pwshModel;
await tweakM4Model(state);
await tweakModelV2(state);
Expand Down

0 comments on commit 15e2490

Please sign in to comment.