tsp - move configuration of verb-mapping to the emitter (#1367)

* tsp - move configuration of verb-mapping to the emitter

* Update emitter.ts

Add await for generatePwshModule
This commit is contained in:
Xiaogang 2024-08-06 13:12:54 +08:00 коммит произвёл GitHub
Родитель 8446da0dc2
Коммит 58a389a584
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 228 добавлений и 2 удалений

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

@ -0,0 +1,213 @@
# Configurations
# The following verb-mapping is used as an aid to infer cmdlet-verbs. Every entry maps an operationId-method to a PowerShell cmdlet-verb. The operationId-method is the identifier that comes after the underscore in the operationId. For example:
# - In MyResource_List, the method is List.
# - In SomeAPI_CheckNameAvailability, the method is CheckNameAvailability.
# Note: It is not necessary to have an entry for every method because the generator will still be able to infer a verb by examining the operationId. However, if an entry is added in the configuration, it is guaranteed that the cmdlet created will get the cmdlet-verb from the operationId-method -> cmdlet verb mapping.
verb-mapping:
Access: Get
Acquire: Get
Activate: Initialize
Add: Add
Allocate: New
Analyze: Test
Append: Add
Apply: Add
Approve: Approve
Assert: Assert
Assign: Set
Associate: Join
Attach: Add
Authorize: Grant
Backup: Backup
Block: Block
Build: Build
Bypass: Skip
Cancel: Stop
Capture: Export
Cat: Get
Change: Rename
Check: Test
Checkpoint: Checkpoint
Clear: Clear
Clone: Copy
Close: Close
Combine: Join
Compare: Compare
Compile: Build
Complete: Complete
Compress: Compress
Concatenate: Add
Configure: Set
Confirm: Confirm
Connect: Connect
Convert: Convert
ConvertFrom: ConvertFrom
ConvertTo: ConvertTo
Copy: Copy
Create: New
Cut: Remove
Debug: Debug
Delete: Remove
Deny: Deny
Deploy: Deploy
Dir: Get
Disable: Disable
Discard: Remove
Disconnect: Disconnect
Discover: Find
Dismount: Dismount
Display: Show
Dispose: Remove
Dump: Get
Duplicate: Copy
Edit: Edit
Enable: Enable
End: Stop
Enter: Enter
Erase: Clear
Evaluate: Test
Examine: Get
Execute: Invoke
Exit: Exit
Expand: Expand
Export: Export
Failover: Set
Find: Find
Finish: Complete
Flush: Clear
ForceReboot: Restart
Format: Format
Generalize: Reset
Generate: New
Get: Get
Grant: Grant
Group: Group
Hide: Hide
Import: Import
Initialize: Initialize
Insert: Add
Install: Install
Into: Enter
Invoke: Invoke
Is: Test
Join: Join
Jump: Skip
Limit: Limit
List: Get
Load: Import
Locate: Find
Lock: Lock
Make: New
Measure: Measure
Merge: Merge
Migrate: Move
Mount: Mount
Move: Move
Name: Move
New: New
Notify: Send
Nullify: Clear
Obtain: Get
Open: Open
Optimize: Optimize
Out: Out
Patch: Update
Pause: Suspend
Perform: Invoke
Ping: Ping
Pop: Pop
Post: Invoke
Power: Start
PowerOff: Stop
PowerOn: Start
Produce: Show
Protect: Protect
Provision: New
Publish: Publish
Purge: Clear
Push: Push
Put: Set
Read: Read
Reassociate: Move
Reboot: Restart
Receive: Receive
Recover: Restore
Redo: Redo
Refresh: Update
Regenerate: New
Register: Register
Reimage: Update
Release: Publish
Remove: Remove
Rename: Rename
Repair: Repair
Replace: Update
Replicate: Copy
Reprocess: Update
Request: Request
Reset: Reset
Resize: Resize
Resolve: Resolve
Restart: Restart
Restore: Restore
Restrict: Lock
Resubmit: Submit
Resume: Resume
Retarget: Update
Retrieve: Get
Revoke: Revoke
Run: Start
Save: Save
Search: Search
Secure: Lock
Select: Select
Send: Send
Separate: Split
Set: Set
Show: Show
Shutdown: Stop
Skip: Skip
Split: Split
Start: Start
Step: Step
Stop: Stop
Submit: Submit
Suggest: Get
Suspend: Suspend
Swap: Switch
Switch: Switch
Sync: Sync
Synch: Sync
Synchronize: Sync
Test: Test
Trace: Trace
Transfer: Move
Trigger: Start
Type: Get
Unblock: Unblock
Undelete: Restore
Undo: Undo
Uninstall: Uninstall
Unite: Join
Unlock: Unlock
Unmark: Clear
Unprotect: Unprotect
Unpublish: Unpublish
Unregister: Unregister
Unrestrict: Unlock
Unsecure: Unlock
Unset: Clear
Update: Update
Upgrade: Update
Use: Use
Validate: Test
Verify: Test
Wait: Wait
Watch: Watch
Wipe: Clear
Write: Write

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

@ -1,5 +1,5 @@
import { Program, EmitContext, listServices, emitFile, resolvePath } from "@typespec/compiler";
import { serialize } from '@azure-tools/codegen';
import { serialize, deserialize } from '@azure-tools/codegen';
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
// Following files finally should be imported from @autorest/powershell
// import { ModelState } from "./powershell/utils/model-state.js";
@ -8,6 +8,19 @@ import { getClients } from "./utils/clientUtils.js";
import { transformPwshModel } from "./convertor/convertor.js";
import { PSOptions } from "./types/interfaces.js";
import { generatePwshModule } from "@autorest/powershell";
import { readFileSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";
//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);
// If there is overlap between the configuration and the emitter options, the emitter options will take precedence
return { ...configuration, ...emitterOptions };
}
export async function $onEmit(context: EmitContext) {
const program: Program = context.program;
@ -37,7 +50,7 @@ export async function $onEmit(context: EmitContext) {
path: resolvePath(context.emitterOutputDir, `${client.name}.yaml`),
content: serialize(model),
});
generatePwshModule(model, emitterOptions);
await generatePwshModule(model, loadConfiguration(emitterOptions));
}
}