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

Supoort mgmt readme generation, Remove karma generation for modular and Add tshy in .gitignore #2655

Merged
merged 20 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ dist-esm
dist
/artifacts
.tshy-build
.tshy
6 changes: 3 additions & 3 deletions common/config/rush/pnpm-lock.yaml

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"./utils/path.js": "./utils/path.browser.js"
},
"dependencies": {
"@azure/core-lro": "3.0.0"
"@azure/core-lro": "^3.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@azure/core-rest-pipeline": "^1.5.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.6.2",
"@azure/core-lro": "3.0.0",
"@azure/core-lro": "^3.0.0",
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
"@azure/abort-controller": "^2.1.2",
"@azure/core-paging": "^1.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@azure/core-rest-pipeline": "^1.5.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.6.2",
"@azure/core-lro": "3.0.0",
"@azure/core-lro": "^3.0.0",
"@azure/abort-controller": "^2.1.2"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@azure/core-rest-pipeline": "^1.5.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.6.2",
"@azure/core-lro": "3.0.0",
"@azure/core-lro": "^3.0.0",
"@azure/abort-controller": "^2.1.2",
"@azure/core-paging": "^1.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"@azure/core-lro": "3.0.0"
"@azure/core-lro": "^3.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@azure/core-rest-pipeline": "^1.5.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.6.2",
"@azure/core-lro": "3.0.0",
"@azure/core-lro": "^3.0.0",
"@azure/abort-controller": "^2.1.2",
"@azure/core-paging": "^1.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@azure/core-rest-pipeline": "^1.5.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.6.2",
"@azure/core-lro": "3.0.0",
"@azure/core-lro": "^3.0.0",
"@azure/abort-controller": "^2.1.2",
"@azure/core-paging": "^1.5.0"
},
Expand Down
173 changes: 167 additions & 6 deletions packages/rlc-common/src/metadata/buildReadmeFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RLCModel } from "../interfaces.js";
import hbs from "handlebars";
import { NameType, normalizeName } from "../helpers/nameUtils.js";

const azureReadmeTemplate = `# {{ clientDescriptiveName }} library for JavaScript
const azureReadmeRLCTemplate = `# {{ clientDescriptiveName }} library for JavaScript

{{ description }}

Expand Down Expand Up @@ -84,6 +84,147 @@ setLogLevel("info");
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
`;

const azureReadmeModularTemplate = `# {{ clientDescriptiveName }} library for JavaScript

This package contains an isomorphic SDK (runs both in Node.js and in browsers) for {{ clientDescriptiveName }}.

{{ description }}

{{#if packageSourceURL}}
[Source code]({{ packageSourceURL }}) |
{{/if}}
{{#if packageNPMURL}}
[Package (NPM)]({{ packageNPMURL }}) |
{{/if}}
{{#if apiRefURL}}
[API reference documentation]({{ apiRefURL }}) |
{{/if}}
{{#if samplesURL}}
[Samples]({{samplesURL}})
{{/if}}

## Getting started

### Currently supported environments

- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
- Latest versions of Safari, Chrome, Edge and Firefox.

See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.

{{#if azure}}
### Prerequisites

- An [Azure subscription][azure_sub].
{{/if}}

{{#if isReleasablePackage}}
### Install the \`{{ clientPackageName }}\` package

Install the {{ clientDescriptiveName }} library for JavaScript with \`npm\`:

\`\`\`bash
npm install {{ clientPackageName }}
\`\`\`
{{/if}}

{{#if azure}}
{{#if addCredentials}}
### Create and authenticate a \`{{ clientClassName}}\`

To create a client object to access the {{ serviceName }} API, you will need the \`endpoint\` of your {{ serviceName }} resource and a \`credential\`. The {{ clientDescriptiveName }} can use Azure Active Directory credentials to authenticate.
You can find the endpoint for your {{ serviceName }} resource in the [Azure Portal][azure_portal].

You can authenticate with Azure Active Directory using a credential from the [@azure/identity][azure_identity] library or [an existing AAD Token](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token).

To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the \`@azure/identity\` package:

\`\`\`bash
npm install @azure/identity
\`\`\`

You will also need to **register a new AAD application and grant access to {{ serviceName}}** by assigning the suitable role to your service principal (note: roles such as \`"Owner"\` will not grant the necessary permissions).
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: \`AZURE_CLIENT_ID\`, \`AZURE_TENANT_ID\`, \`AZURE_CLIENT_SECRET\`.

For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).

{{#if azureArm}}
\`\`\`javascript
const { {{ clientClassName }} } = require("{{ clientPackageName }}");
const { DefaultAzureCredential } = require("@azure/identity");
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new {{ clientClassName }}(new DefaultAzureCredential(), subscriptionId);

// For client-side applications running in the browser, use this code instead:
// const credential = new InteractiveBrowserCredential({
// tenantId: "<YOUR_TENANT_ID>",
// clientId: "<YOUR_CLIENT_ID>"
// });
// const client = new {{ clientClassName }}(credential, subscriptionId);
\`\`\`
{{else}}
\`\`\`javascript
const { {{ clientClassName }} } = require("{{ clientPackageName }}");
const { DefaultAzureCredential } = require("@azure/identity");
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.

const client = new {{ clientClassName }}("<endpoint>", new DefaultAzureCredential());
// For client-side applications running in the browser, use this code instead:
// const credential = new InteractiveBrowserCredential({
// tenantId: "<YOUR_TENANT_ID>",
// clientId: "<YOUR_CLIENT_ID>"
// });
// const client = new {{ clientClassName }}("<endpoint>", credential);
\`\`\`
{{/if}}
{{/if}}{{/if}}

### JavaScript Bundle
To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).

## Key concepts

### {{ clientClassName }}

\`{{ clientClassName }}\` is the primary interface for developers using the {{ clientDescriptiveName }} library. Explore the methods on this client object to understand the different features of the {{ serviceName }} service that you can access.

{{#if azure}}
## Troubleshooting

### Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the \`AZURE_LOG_LEVEL\` environment variable to \`info\`. Alternatively, logging can be enabled at runtime by calling \`setLogLevel\` in the \`@azure/logger\`:

\`\`\`javascript
const { setLogLevel } = require("@azure/logger");
setLogLevel("info");
\`\`\`

For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs]({{ repoURL }}/tree/main/sdk/core/logger).

{{#if samplesURL}}
## Next steps

Please take a look at the [samples]({{ samplesURL }}) directory for detailed examples on how to use this library.
{{/if}}

## Contributing

If you'd like to contribute to this library, please read the [contributing guide]({{ contributingGuideURL }}) to learn more about how to build and test the code.

## Related projects

- [{{ projectName }}]({{ repoURL }})

[azure_sub]: https://azure.microsoft.com/free/
[azure_portal]: https://portal.azure.com
{{#if identityPackageURL}}[azure_identity]: {{ identityPackageURL }}
{{/if}}[defaultazurecredential]: {{ identityPackageURL }}#defaultazurecredential
{{/if}}
`;

const nonBrandedReadmeTemplate = `# {{ clientDescriptiveName }} library for JavaScript

{{ description }}
Expand Down Expand Up @@ -114,7 +255,7 @@ Key links:

### Install the \`{{ clientPackageName }}\` package

Install the {{ clientDescriptiveName }} REST client library for JavaScript with \`npm\`:
Install the {{ clientDescriptiveName }} library for JavaScript with \`npm\`:

\`\`\`bash
npm install {{ clientPackageName }}
Expand Down Expand Up @@ -160,13 +301,21 @@ interface Metadata {
apiRefURL?: string;
/** Check if the rp is management plane */
azureArm?: boolean;
/** Whether the package being generated is for an Azure service */
azure: boolean;
/** Indicates if the package is a test/releasable package. */
isReleasablePackage?: boolean;
/** The URL for impression */
impressionURL?: string;
}

export function buildReadmeFile(model: RLCModel) {
const metadata = createMetadata(model) ?? {};
const readmeFileContents = hbs.compile(
model.options?.flavor === "azure"
? azureReadmeTemplate
? model.options.isModularLibrary
? azureReadmeModularTemplate
: azureReadmeRLCTemplate
: nonBrandedReadmeTemplate,
{ noEscape: true }
);
Expand All @@ -193,7 +342,8 @@ function createMetadata(model: RLCModel): Metadata | undefined {
dependencyInfo,
multiClient,
batch,
serviceInfo
serviceInfo,
isTypeSpecTest
} = model.options;

const azureHuh =
Expand All @@ -209,6 +359,9 @@ function createMetadata(model: RLCModel): Metadata | undefined {
const clientPackageName = packageDetails?.name;
const clientClassName = getClientName(model);
const serviceName = getServiceName(model);
const names = relativePackageSourcePath?.split("/").slice(1);
const packageParentDirectoryName = names?.[0];
const packageDirectoryName = names?.[1];
let apiRefUrlQueryParameter: string = "";
packageDetails.version = packageDetails.version ?? "1.0.0-beta.1";
if (packageDetails?.version.includes("beta")) {
Expand All @@ -219,7 +372,9 @@ function createMetadata(model: RLCModel): Metadata | undefined {
serviceName,
clientClassName,
clientPackageName: clientPackageName,
clientDescriptiveName: `${serviceName} REST client`,
clientDescriptiveName: model.options.isModularLibrary
? `${serviceName} client`
: `${serviceName} REST client`,
description: serviceInfo?.description ?? packageDetails.description,
serviceDocURL: productDocLink,
packageSourceURL: packageSourceURL,
Expand All @@ -231,7 +386,13 @@ function createMetadata(model: RLCModel): Metadata | undefined {
dependencyDescription: dependencyInfo?.description,
dependencyLink: dependencyInfo?.link,
hasMultiClients: multiClient && batch && batch.length > 1,
azureArm: Boolean(model.options.azureArm)
azureArm: Boolean(model.options.azureArm),
azure: azureHuh,
isReleasablePackage: !isTypeSpecTest,
repoURL: repoURL,
projectName: azureHuh ? "Microsoft Azure SDK for JavaScript" : undefined,
identityPackageURL: repoURL && `${repoURL}/tree/main/sdk/identity/identity`,
addCredentials: model.options.addCredentials
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getAzurePackageDependencies({
if (hasLro) {
dependencies = {
...dependencies,
"@azure/core-lro": "3.0.0",
"@azure/core-lro": "^3.0.0",
"@azure/abort-controller": "^2.1.2"
};
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading