Skip to content

Commit

Permalink
Split ui package into utils and azureutils packages (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger authored Feb 9, 2022
1 parent 6bacf14 commit d38498f
Show file tree
Hide file tree
Showing 139 changed files with 37,041 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .azure-pipelines/job-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ steps:
- template: package-steps.yml
parameters:
package: 'ui'
- template: package-steps.yml
parameters:
package: 'utils'
- template: package-steps.yml
parameters:
package: 'azure'
- template: package-steps.yml
parameters:
package: 'kudu'
Expand Down
2 changes: 1 addition & 1 deletion .azure-pipelines/package-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ steps:
- task: CopyFiles@2
displayName: '${{ parameters.package }}: copy package'
inputs:
Contents: '${{ parameters.package }}/vscode-*.tgz'
Contents: '${{ parameters.package }}/@(microsoft|vscode)-*.tgz'
TargetFolder: '$(build.artifactstagingdirectory)'
condition: and(not(variables['skipPackage']), eq(variables['Agent.OS'], 'Linux'), ne(variables['System.PullRequest.IsFork'], 'True'))

Expand Down
3 changes: 3 additions & 0 deletions azure/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gulpfile.ts
.eslintrc.js
**/*.d.ts
3 changes: 3 additions & 0 deletions azure/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"extends": "@microsoft/eslint-config-azuretools"
};
14 changes: 14 additions & 0 deletions azure/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules/
.vscode/
src/
tsconfig.json
*.tgz
test/
out/test/
**/*.js.map
.vscode-test/
gulpfile.js
test-results.xml
.eslintignore
.eslintrc.js
resources/*.png
5 changes: 5 additions & 0 deletions azure/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
25 changes: 25 additions & 0 deletions azure/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/test/extension",
"--extensionTestsPath=${workspaceFolder}/out/test/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}",
"env": {
"MOCHA_grep": "", // RegExp of tests to run (empty for all)
"MOCHA_timeout": "0", // Disable time-outs
"DEBUGTELEMETRY": "v",
"NODE_DEBUG": ""
}
}
]
}
15 changes: 15 additions & 0 deletions azure/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.tabSize": 4,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"search.exclude": {
"out": true,
"**/node_modules": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
23 changes: 23 additions & 0 deletions azure/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"group": {
"kind": "build",
"isDefault": true
},
"isBackground": true,
"presentation": {
"reveal": "never"
},
"problemMatcher": "$tsc-watch"
},
{
"type": "npm",
"script": "lint",
"problemMatcher": "$eslint-stylish"
}
]
}
21 changes: 21 additions & 0 deletions azure/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
95 changes: 95 additions & 0 deletions azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# VSCode Azure SDK for Node.js - Azure Utils (Preview)

[![Build Status](https://dev.azure.com/ms-azuretools/AzCode/_apis/build/status/vscode-azuretools)](https://dev.azure.com/ms-azuretools/AzCode/_build/latest?definitionId=17)

This package provides common Azure utilities for Azure VS Code extensions, and is intented to be used alongside @microsoft/vscode-azext-utils.

## Usage

You must call `registerAzureUtilsExtensionVariables` first in your extension's `activate()` method. The first parameter of the function passed in will always be an `IActionContext`, which allows you to specify custom telemetry and describes the behavior of this command. The simplest example is to register a command (in this case, refreshing a node):

```typescript
registerAzureUtilsExtensionVariables(...);
registerCommand('yourExtension.Refresh', (context: IActionContext, node: AzExtTreeItem) => {
context.telemetry.properties.customProp = "example prop";
context.telemetry.measurements.customMeas = 49;
node.refresh();
});
```

## Azure Extension Tree Data Provider

![ExampleTree](resources/ExampleTree.png)

### Display Azure Resources

Follow these steps to create your basic Azure Tree:

1. Create an `AzExtTreeItem` (or `AzExtParentTreeItem`) describing the items to be displayed under your subscription:

```typescript
export class WebAppTreeItem extends AzExtTreeItem {
public static contextValue: string = "azureWebApp";
public readonly contextValue: string = WebAppTreeItem.contextValue;
private readonly _site: Site;
constructor(parent: AzExtParentTreeItem, site: Site) {
super(parent);
this._site = site;
}

public get id(): string {
return this._site.id;
}

public get label(): string {
return this._site.name;
}
}
```

1. Create a `SubscriptionTreeItemBase` that provides the tree items you just implemented. It must implement at least `hasMoreChildrenImpl` and `loadMoreChildrenImpl`:

> NOTE: Methods suffixed with `Impl` should not be called directly - just implemented.
```typescript
export class SubscriptionTreeItem extends SubscriptionTreeItemBase {
private _nextLink: string | undefined;

public hasMoreChildrenImpl(): boolean {
return this._nextLink !== undefined;
}

public async loadMoreChildrenImpl(clearCache: boolean, _context: IActionContext): Promise<WebAppTreeItem[]> {
if (clearCache) {
this._nextLink = undefined;
}

const client: WebSiteManagementClient = createAzureClient(this.root, WebSiteManagementClient);
const webAppCollection: WebAppCollection = this._nextLink === undefined ?
await client.webApps.list() :
await client.webApps.listNext(this._nextLink);
this._nextLink = webAppCollection.nextLink;
return webAppCollection.map((site: Site) => new WebAppTreeItem(this, site)));
}
}
```

1. Create an `AzureAccountTreeItemBase` that provides the subscriptions you just implemented. It must implement at least `createSubscriptionTreeItem`:
```typescript
export class AzureAccountTreeItem extends AzureAccountTreeItemBase {
public createSubscriptionTreeItem(root: ISubscriptionContext): SubscriptionTreeItemBase {
return new SubscriptionTreeItem(this, root);
}
}
```
1. Finally, set up the tree in your extension's `activate()` method. Instantiate an `AzureAccountTreeItem` and add it to `context.subscriptions` since it's a disposable. Then instantiate an `AzExtTreeDataProvider`, passing in your root tree item and the `loadMoreCommandId` (which maps the 'Load More...' node to the command registered by your extension).
```typescript
const azureAccountTreeItem = new AzureAccountTreeItem();
context.subscriptions.push(azureAccountTreeItem);
const treeDataProvider = new AzExtTreeDataProvider(azureAccountTreeItem, "appService.loadMore");
context.subscriptions.push(vscode.window.createTreeView("azureAppService", { treeDataProvider }));
```

## License

[MIT](LICENSE.md)
Loading

0 comments on commit d38498f

Please sign in to comment.