diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index a34705cc98..b7041cb938 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -32,6 +32,9 @@ dependencies: '@azure-tools/tasks': specifier: ~3.0.0 version: 3.0.255 + '@azure-tools/uri': + specifier: ~3.1.1 + version: 3.1.1 '@microsoft.azure/autorest.testserver': specifier: ~2.9.3 version: 2.9.9 @@ -236,6 +239,18 @@ packages: pluralize: 8.0.0 dev: false + /@azure-tools/uri@3.1.1: + resolution: {integrity: sha512-UgPgD+qVtm4ASYqoTDazjowimrmMGGEQqPnNk9K/8CZdi2oSLtGqX9S1++2+NDaHlq74VyxbcNMKoxgO+2CCUQ==} + engines: {node: '>=10.12.0'} + dependencies: + '@azure-tools/async-io': 3.0.254 + file-url: 3.0.0 + get-uri: 3.0.2 + urijs: 1.19.11 + transitivePeerDependencies: + - supports-color + dev: false + /@babel/code-frame@7.24.7: resolution: {integrity: sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==} engines: {node: '>=6.9.0'} @@ -720,6 +735,11 @@ packages: '@testdeck/core': 0.3.3 dev: false + /@tootallnate/once@1.1.2: + resolution: {integrity: sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==} + engines: {node: '>= 6'} + dev: false + /@types/babel-types@7.0.14: resolution: {integrity: sha512-5BC5W3pCoX12SH8nC8ReAOiMBy/rd9xil3es3S6dh83Pl9i4J3ZujfWUu5mXnEwo/WLqcD5+uj9Yk115Dh0obw==} dev: false @@ -1615,6 +1635,11 @@ packages: assert-plus: 1.0.0 dev: false + /data-uri-to-buffer@3.0.1: + resolution: {integrity: sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og==} + engines: {node: '>= 6'} + dev: false + /debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} dependencies: @@ -2080,6 +2105,16 @@ packages: flat-cache: 3.1.1 dev: false + /file-uri-to-path@2.0.0: + resolution: {integrity: sha512-hjPFI8oE/2iQPVe4gbrJ73Pp+Xfub2+WI2LlXDbsaJBwT5wuMh35WNWVYYTpnz895shtwfyutMFLFywpQAFdLg==} + engines: {node: '>= 6'} + dev: false + + /file-url@3.0.0: + resolution: {integrity: sha512-g872QGsHexznxkIAdK8UiZRe7SkE6kvylShU4Nsj8NvfvZag7S0QuQ4IgvPDkk75HxgjIVDwycFTDAgIiO4nDA==} + engines: {node: '>=8'} + dev: false + /filelist@1.0.4: resolution: {integrity: sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==} dependencies: @@ -2155,6 +2190,15 @@ packages: engines: {node: '>= 0.6'} dev: false + /fs-extra@8.1.0: + resolution: {integrity: sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==} + engines: {node: '>=6 <7 || >=8'} + dependencies: + graceful-fs: 4.2.11 + jsonfile: 4.0.0 + universalify: 0.1.2 + dev: false + /fs.realpath@1.0.0: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} dev: false @@ -2167,6 +2211,14 @@ packages: dev: false optional: true + /ftp@0.3.10: + resolution: {integrity: sha512-faFVML1aBx2UoDStmLwv2Wptt4vw5x03xxX172nhA5Y5HBshW5JweqQ2W4xL4dezQTG8inJsuYcpPHHU3X5OTQ==} + engines: {node: '>=0.8.0'} + dependencies: + readable-stream: 1.1.14 + xregexp: 2.0.0 + dev: false + /function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} dev: false @@ -2198,6 +2250,20 @@ packages: engines: {node: '>=16'} dev: false + /get-uri@3.0.2: + resolution: {integrity: sha512-+5s0SJbGoyiJTZZ2JTpFPLMPSch72KEqGOTvQsBqg0RBWvwhWUSYZFAtz3TPW0GXJuLBJPts1E241iHg+VRfhg==} + engines: {node: '>= 6'} + dependencies: + '@tootallnate/once': 1.1.2 + data-uri-to-buffer: 3.0.1 + debug: 4.3.4(supports-color@8.1.1) + file-uri-to-path: 2.0.0 + fs-extra: 8.1.0 + ftp: 0.3.10 + transitivePeerDependencies: + - supports-color + dev: false + /getpass@0.1.7: resolution: {integrity: sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==} dependencies: @@ -2515,6 +2581,10 @@ packages: engines: {node: '>=10'} dev: false + /isarray@0.0.1: + resolution: {integrity: sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==} + dev: false + /isarray@1.0.0: resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==} dev: false @@ -2606,6 +2676,12 @@ packages: resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} dev: false + /jsonfile@4.0.0: + resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==} + optionalDependencies: + graceful-fs: 4.2.11 + dev: false + /jsonparse@1.2.0: resolution: {integrity: sha512-LkDEYtKnPFI9hQ/IURETe6F1dUH80cbRkaF6RaViSwoSNPwaxQpi6TgJGvJKyLQ2/9pQW+XCxK3hBoR44RAjkg==} engines: {'0': node >= 0.2.0} @@ -3288,6 +3364,15 @@ packages: resolution: {integrity: sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==} dev: false + /readable-stream@1.1.14: + resolution: {integrity: sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==} + dependencies: + core-util-is: 1.0.3 + inherits: 2.0.4 + isarray: 0.0.1 + string_decoder: 0.10.31 + dev: false + /readable-stream@2.3.8: resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==} dependencies: @@ -3750,6 +3835,10 @@ packages: strip-ansi: 6.0.1 dev: false + /string_decoder@0.10.31: + resolution: {integrity: sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==} + dev: false + /string_decoder@1.1.1: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} dependencies: @@ -3961,6 +4050,11 @@ packages: engines: {node: '>=18'} dev: false + /universalify@0.1.2: + resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} + engines: {node: '>= 4.0.0'} + dev: false + /unpipe@1.0.0: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} @@ -3972,6 +4066,10 @@ packages: punycode: 2.3.1 dev: false + /urijs@1.19.11: + resolution: {integrity: sha512-HXgFDgDommxn5/bIv0cnQZsPhHDA90NPHD6+c/v21U5+Sx5hoP8+dP9IZXBU1gIfvdRfhG8cel9QNPeionfcCQ==} + dev: false + /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: false @@ -4266,6 +4364,10 @@ packages: engines: {node: '>=0.4.0'} dev: false + /xregexp@2.0.0: + resolution: {integrity: sha512-xl/50/Cf32VsGq/1R8jJE5ajH1yMCQkpmoS10QbFZWl2Oor4H0Me64Pu2yxvsRWK3m6soJbmGfzSR7BYmDcWAA==} + dev: false + /y18n@5.0.8: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} engines: {node: '>=10'} @@ -4351,7 +4453,7 @@ packages: dev: false file:projects/powershell.tgz: - resolution: {integrity: sha512-P3pqnYTQURULV6Nrje4pAJP7F/KAQBPeXMDZj1cT1u09rAj6Gb8yScV9OHhFYHCsH6uigCs3EQ7Z0sPqVtzgDw==, tarball: file:projects/powershell.tgz} + resolution: {integrity: sha512-/cTXzGUZTDhTv00X96g/ev5R8DhTdsQMIKOfHnwTU5XV+VHjonfZkNAE/F4J6Nx+PlUMQDOpu2l8WODdTfbxZQ==, tarball: file:projects/powershell.tgz} name: '@rush-temp/powershell' version: 0.0.0 dependencies: @@ -4363,6 +4465,7 @@ packages: '@azure-tools/codemodel-v3': 3.1.266 '@azure-tools/linq': 3.1.263 '@azure-tools/tasks': 3.0.255 + '@azure-tools/uri': 3.1.1 '@microsoft.azure/autorest.testserver': 2.9.9 '@testdeck/mocha': 0.3.3 '@types/js-yaml': 3.12.1 diff --git a/powershell/package.json b/powershell/package.json index 0ca9d4ee41..ae903a72e9 100644 --- a/powershell/package.json +++ b/powershell/package.json @@ -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", diff --git a/powershell/utils/tsp-generator.ts b/powershell/utils/tsp-generator.ts index c2c9dbffc2..9df644d1a0 100644 --- a/powershell/utils/tsp-generator.ts +++ b/powershell/utils/tsp-generator.ts @@ -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) { + 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(); + 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(tspService); + // clear output folder if set, but protect certain files + await clearOutputFiles(state); state.model = pwshModel; await tweakM4Model(state); await tweakModelV2(state);