tsp - move common config to the emitter (#1372)

This commit is contained in:
Xiaogang 2024-08-21 16:58:07 +08:00 коммит произвёл GitHub
Родитель 6922d41954
Коммит 14856fe9d4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 58 добавлений и 7 удалений

Просмотреть файл

@ -12,8 +12,8 @@ dependencies:
specifier: ~3.5.2
version: 3.5.2
'@autorest/powershell':
specifier: ~4.0.702
version: 4.0.702
specifier: ~4.0.708
version: 4.0.708
'@azure-tools/async-io':
specifier: ~3.0.0
version: 3.0.254
@ -126,8 +126,8 @@ packages:
vscode-jsonrpc: 3.6.2
dev: false
/@autorest/powershell@4.0.702:
resolution: {integrity: sha512-xdRReopyjBbfKDip7Zd2MkXhm4NJsDRo+SbV30ij07/ELa9E63T5EopLSzHOwJlllq2KmGjnfn4xYU4GVySu3w==}
/@autorest/powershell@4.0.708:
resolution: {integrity: sha512-qRVA7Dbuy9x8cxFtXSoAy0Tj8hNLrcb2wKwGR4v9NQ+u1Oaigjf46roWvypr44hkeBHVBz5UML6VNHSUiB26ag==}
engines: {node: '>=10.12.0'}
dependencies:
'@autorest/codemodel': 4.19.3
@ -138,10 +138,13 @@ 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
ejs: 3.1.9
js-yaml: 3.13.1
source-map-support: 0.5.13
xmlbuilder: 10.1.1
transitivePeerDependencies:
- supports-color
dev: false
/@azure-tools/async-io@3.0.254:
@ -4489,13 +4492,13 @@ packages:
dev: false
file:projects/typespec-powershell.tgz:
resolution: {integrity: sha512-faeQhGWL+GN07n8p4riwDBWlZLNc36hqf6Gu5LVK1mJow5IiBe+mgUSDkrOn48dfTPRY1mJx7jn52w1HE4O5Tg==, tarball: file:projects/typespec-powershell.tgz}
resolution: {integrity: sha512-nJTut+dJB/qoOsof76bauP5BhxsrcPuz+QkxF3JSf+bQhhmk+SGESqigrJpvNCH1uj1w7rzg69TvWdPR9ihl1g==, tarball: file:projects/typespec-powershell.tgz}
name: '@rush-temp/typespec-powershell'
version: 0.0.0
dependencies:
'@autorest/codemodel': 4.19.3
'@autorest/extension-base': 3.5.2
'@autorest/powershell': 4.0.702
'@autorest/powershell': 4.0.708
'@azure-tools/async-io': 3.0.254
'@azure-tools/codegen': 2.5.294
'@azure-tools/codegen-csharp': 3.0.264

Просмотреть файл

@ -211,3 +211,35 @@ verb-mapping:
Wipe: Clear
Write: Write
# Folder configurations
current-folder: "./"
module-folder: "./generated"
cmdlet-folder: "./generated/cmdlets"
model-cmdlet-folder: "./custom/autogen-model-cmdlets"
custom-cmdlet-folder: "./custom"
utils-cmdlet-folder: "./utils"
internal-cmdlet-folder: "./internal"
test-folder: "./test"
runtime-folder: "./generated/runtime"
api-folder: "./generated/api"
bin-folder: "./bin"
obj-folder: "./obj"
exports-folder: "./exports"
docs-folder: "./docs"
dependency-module-folder: "./generated/modules"
examples-folder: "./examples"
resources-folder: "./resources"
ux-folder: "./UX"
csproj: "./{module-name}.csproj"
dll-name: "{module-name}.private"
dll: "./bin/{module-name}.private.dll"
psd1: "./{module-name}.psd1"
psm1: "./{module-name}.psm1"
psm1-custom: "./custom/{module-name}.custom.psm1"
psm1-internal: "./internal/{module-name}.internal.psm1"
format-ps1xml: "./{module-name}.format.ps1xml"
nuspec: "./{module-name}.nuspec"
# misc configurations
skip-model-cmdlets: false
module-version: 0.1.0

Просмотреть файл

@ -15,7 +15,7 @@
}
},
"dependencies": {
"@autorest/powershell": "~4.0.702",
"@autorest/powershell": "~4.0.708",
"@autorest/codemodel": "~4.19.3",
"@autorest/extension-base": "~3.5.2",
"@azure-tools/async-io": "~3.0.0",

Просмотреть файл

@ -12,12 +12,28 @@ import { readFileSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";
// Function to recursively interpolate placeholders in an object
function interpolatePlaceholders(obj: any, values: any) {
for (const key in obj) {
if (typeof obj[key] === 'string') {
obj[key] = obj[key].replace(/{([^}]+)}/g, (match: string, placeholder: string) => values[placeholder]);
} else if (typeof obj[key] === 'object') {
interpolatePlaceholders(obj[key], values);
}
}
}
//load configuration from configuration.md
function loadConfiguration(emitterOptions: Record<string, any>): Record<string, any> {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const configPath = path.join(__dirname, '../../configuration.yaml');
const configuration = deserialize<Record<string, any>>(readFileSync(configPath, 'utf8'), configPath);
// Define the values for interpolation
const interpolationValues = {
'module-name': emitterOptions['module-name']
};
interpolatePlaceholders(configuration, interpolationValues);
// If there is overlap between the configuration and the emitter options, the emitter options will take precedence
return { ...configuration, ...emitterOptions };
}