-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[keyvault-secrets] Migrate to TypeSpec #31848
base: main
Are you sure you want to change the base?
Changes from all commits
afaf8e8
05f5abc
f65eea5
c2aedb7
fd9c30a
6e82268
b187cc8
da28875
b9c109d
107dff9
e4ff819
cda58cb
c9000c9
06e738d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env node | ||
|
||
const { execSync } = require("child_process"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
// Helper to execute shell commands and log output | ||
function execCommand(command) { | ||
try { | ||
execSync(command, { stdio: "inherit" }); | ||
} catch (error) { | ||
console.error(`Command failed: ${command}`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
console.log("Setting up the environment..."); | ||
|
||
// Workaround for src-folder support in emitter: | ||
// End state: src/generated/* contains generated code (instead of src/generated/src/*) | ||
|
||
// Step 1: Remove all files in src/generated/* | ||
execCommand("rm -rf src/generated/*"); | ||
|
||
// Step 2: Copy tsp-location.yaml to src/generated | ||
execCommand("cp tsp-location.yaml src/generated"); | ||
|
||
// Step 3: Run tsp-client command | ||
// emitter-option as a workaround for https://github.com/Azure/azure-rest-api-specs/issues/31610 | ||
execCommand(`tsp-client update -d -o src/generated --emitter-options generateMetadata=false`); | ||
// execCommand( | ||
// "tsp-client update -d -o src/generated --tsp-config ~/workspace/azure-rest-api-specs/specification/keyvault/Security.KeyVault.Keys/tspconfig.yaml --local-spec-repo ~/workspace/azure-rest-api-specs/specification/keyvault/Security.KeyVault.Keys --repo ~/workspace/azure-rest-api-specs --commit 9561bad7d2eed94cc91aa6164d3721b8aa8699fe --emitter-options generateMetadata=false" | ||
// ); | ||
|
||
// Step 4: Move generated/src/* files to generated until src-folder is supported | ||
execCommand("mv src/generated/src/* src/generated/"); | ||
|
||
// Step 5: Remove generated/src | ||
execCommand("rm -rf src/generated/src"); | ||
|
||
// Step 6: Remove tsp-location.yaml from generated folder | ||
execCommand("rm src/generated/tsp-location.yaml"); | ||
|
||
// Step 7: Read and update package.json | ||
console.log("Updating package.json dependencies..."); | ||
const packageJsonPath = path.resolve("./package.json"); | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); | ||
|
||
// Remove dependency on @azure/core-client and add @azure-rest/core-client | ||
delete packageJson.dependencies["@azure/core-client"]; | ||
packageJson.dependencies["@azure-rest/core-client"] = "^2.0.0"; | ||
|
||
// Write updated package.json back to disk | ||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8"); | ||
|
||
// Generated code changes | ||
// Workaround for https://github.com/Azure/autorest.typescript/pull/2135/files | ||
const modelsPath = path.resolve("./src/generated/models/models.ts"); | ||
let modelsContent = fs.readFileSync(modelsPath, "utf8"); | ||
modelsContent = modelsContent | ||
.replace( | ||
/created: !item\["created"\] \? item\["created"\] : new Date\(item\["created"\]\),/g, | ||
'created: !item["created"] ? item["created"] : new Date(item["created"] * 1000),' | ||
) | ||
.replace( | ||
/updated: !item\["updated"\] \? item\["updated"\] : new Date\(item\["updated"\]\),/g, | ||
'updated: !item["updated"] ? item["updated"] : new Date(item["updated"] * 1000),' | ||
) | ||
.replace( | ||
/notBefore: !item\["nbf"\] \? item\["nbf"\] : new Date\(item\["nbf"\]\),/g, | ||
'notBefore: !item["nbf"] ? item["nbf"] : new Date(item["nbf"] * 1000),' | ||
) | ||
.replace( | ||
/expires: !item\["exp"\] \? item\["exp"\] : new Date\(item\["exp"\]\),/g, | ||
'expires: !item["exp"] ? item["exp"] : new Date(item["exp"] * 1000),' | ||
) | ||
.replace( | ||
/nbf: !item\["notBefore"\] \? item\["notBefore"\] : item\["notBefore"\].getTime\(\),/g, | ||
'nbf: !item["notBefore"] ? item["notBefore"] : item["notBefore"].getTime() / 1000,' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to truncate the decimal here |
||
) | ||
.replace( | ||
/exp: !item\["expires"\] \? item\["expires"\] : item\["expires"\].getTime\(\),/g, | ||
'exp: !item["expires"] ? item["expires"] : item["expires"].getTime() / 1000,' | ||
); | ||
|
||
fs.writeFileSync(modelsPath, modelsContent, "utf8"); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The end result is that this file should be deleted once all the workarounds are no longer needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this at the top level? Or should we have one per package (in case there are package-specific things which need to be done, generating from a specific package's spec, etc)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I can move it inside the package folder. My hope (and so far that's been the case) is that the same set of customizations need to happen for all packages. I figured if they start diverging I can push them down into the individual package folder. But my real hope is that this script gets deleted by end of January as its a workaround, not a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if there are no differences between packages no problem with just keeping the script here. Whatever is least work for you.