Skip to content
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

[dev-tool] sample publish fix duplicate env vars in readme.md from samples #28771

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
71 changes: 34 additions & 37 deletions common/tools/dev-tool/src/templates/sampleReadme.md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ function resourceLinks(info: SampleReadmeConfiguration) {
function resources(info: SampleReadmeConfiguration) {
const resources = Object.entries(info.requiredResources ?? {});

const header = `You need [an Azure subscription][freesub] ${
resources.length > 0 ? "and the following Azure resources " : ""
}to run these sample programs${resources.length > 0 ? ":\n\n" : "."}`;
const header = `You need [an Azure subscription][freesub] ${resources.length > 0 ? "and the following Azure resources " : ""
}to run these sample programs${resources.length > 0 ? ":\n\n" : "."}`;

return (
header + resources.map(([name]) => `- [${name}][${resourceNameToLinkSlug(name)}]`).join("\n")
Expand Down Expand Up @@ -131,13 +130,12 @@ function table(info: SampleReadmeConfiguration) {
*/
function exampleNodeInvocation(info: SampleReadmeConfiguration) {
const firstModule = filterModules(info)[0];
const envVars = firstModule.usedEnvironmentVariables
const envVars = [...new Set(firstModule.usedEnvironmentVariables)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremymeng Could you help review this? The sample publish tools didn't handle the env vars duplications so we add this support.

.map((envVar) => `${envVar}="<${envVar.replace(/_/g, " ").toLowerCase()}>"`)
.join(" ");

return `${envVars} node ${
info.useTypeScript ? "dist/" : ""
}${firstModule.relativeSourcePath.replace(/\.ts$/, ".js")}`;
return `${envVars} node ${info.useTypeScript ? "dist/" : ""
}${firstModule.relativeSourcePath.replace(/\.ts$/, ".js")}`;
}

/**
Expand Down Expand Up @@ -167,8 +165,7 @@ export default (info: SampleReadmeConfiguration): Promise<string> => {

${info.customSnippets?.header ?? ""}

These sample programs show how to use the ${language} client libraries for ${
info.productName
These sample programs show how to use the ${language} client libraries for ${info.productName
} in some common scenarios.

${table(info)}
Expand All @@ -178,17 +175,17 @@ ${table(info)}
The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule).

${(() => {
if (info.useTypeScript) {
return [
"Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using:",
"",
fence("bash", "npm install -g typescript"),
"",
].join("\n");
} else {
return "";
}
})()}\
if (info.useTypeScript) {
return [
"Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using:",
"",
fence("bash", "npm install -g typescript"),
"",
].join("\n");
} else {
return "";
}
})()}\
${resources(info)}

${info.customSnippets?.prerequisites ?? ""}
Expand All @@ -205,28 +202,28 @@ ${step("Install the dependencies using `npm`:")}

${fence("bash", "npm install")}
${(() => {
if (info.useTypeScript) {
return [step("Compile the samples:"), "", fence("bash", "npm run build"), ""].join("\n");
} else {
return "";
}
})()}
if (info.useTypeScript) {
return [step("Compile the samples:"), "", fence("bash", "npm run build"), ""].join("\n");
} else {
return "";
}
})()}
${step(
"Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.",
)}
"Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.",
)}

${step(
"Run whichever samples you like (note that some samples may require additional setup, see the table above):",
)}
"Run whichever samples you like (note that some samples may require additional setup, see the table above):",
)}

${fence(
"bash",
`node ${(() => {
const firstSource = filterModules(info)[0].relativeSourcePath;
const filePath = info.useTypeScript ? "dist/" : "";
return filePath + firstSource.replace(/\.ts$/, ".js");
})()}`,
)}
"bash",
`node ${(() => {
const firstSource = filterModules(info)[0].relativeSourcePath;
const filePath = info.useTypeScript ? "dist/" : "";
return filePath + firstSource.replace(/\.ts$/, ".js");
})()}`,
)}

Alternatively, run a single sample with the correct environment variables set (setting up the \`.env\` file is not required if you do this), for example (cross-platform):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ node apiCreateOrUpdateSample.js
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx cross-env APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" node apiCreateOrUpdateSample.js
npx cross-env APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" node apiCreateOrUpdateSample.js
```

## Next Steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ node dist/apiCreateOrUpdateSample.js
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx cross-env APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" node dist/apiCreateOrUpdateSample.js
npx cross-env APIMANAGEMENT_SUBSCRIPTION_ID="<apimanagement subscription id>" APIMANAGEMENT_RESOURCE_GROUP="<apimanagement resource group>" node dist/apiCreateOrUpdateSample.js
```

## Next Steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ node configurationStoresCreateSample.js
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx cross-env APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" node configurationStoresCreateSample.js
npx cross-env APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" node configurationStoresCreateSample.js
```

## Next Steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ node dist/configurationStoresCreateSample.js
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx cross-env APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" node dist/configurationStoresCreateSample.js
npx cross-env APPCONFIGURATION_SUBSCRIPTION_ID="<appconfiguration subscription id>" APPCONFIGURATION_RESOURCE_GROUP="<appconfiguration resource group>" node dist/configurationStoresCreateSample.js
```

## Next Steps
Expand Down
Loading