Skip to content

Commit

Permalink
tsp - move common config to the emitter (#1372)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli authored Aug 21, 2024
1 parent 6922d41 commit 14856fe
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
15 changes: 9 additions & 6 deletions common/config/rush/pnpm-lock.yaml

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

32 changes: 32 additions & 0 deletions packages/typespec-powershell/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion packages/typespec-powershell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions packages/typespec-powershell/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down

0 comments on commit 14856fe

Please sign in to comment.