mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 09:35:38 -05:00
add samples (#920)
This commit is contained in:
8
samples/extensionSamples/.gitignore
vendored
Normal file
8
samples/extensionSamples/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
out
|
||||
node_modules
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
.DS_Store
|
||||
.idea
|
||||
test-reports/**
|
||||
28
samples/extensionSamples/.vscode/launch.json
vendored
Normal file
28
samples/extensionSamples/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"program": "${workspaceFolder}\\out\\src\\extension"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"name": "Attach to Ops Studio",
|
||||
"protocol": "inspector",
|
||||
"port": 5870,
|
||||
"restart": true,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "",
|
||||
"timeout": 25000
|
||||
},
|
||||
]
|
||||
}
|
||||
29
samples/extensionSamples/.vscodeignore
Normal file
29
samples/extensionSamples/.vscodeignore
Normal file
@@ -0,0 +1,29 @@
|
||||
# Unwanted compiled files
|
||||
out/test/**
|
||||
out/**/*.map
|
||||
*.vsix
|
||||
|
||||
# Build/Source files
|
||||
src/**
|
||||
tasks/**
|
||||
test/**
|
||||
typings/**
|
||||
packages/**
|
||||
samples/**
|
||||
.gitignore
|
||||
tsconfig.json
|
||||
|
||||
# IDE Settings
|
||||
.vscode/**
|
||||
.vscode-test/**
|
||||
.idea/**
|
||||
.sqlops/**
|
||||
|
||||
# Reference files
|
||||
**/*.ts
|
||||
**/*.map
|
||||
.gitignore
|
||||
tsconfig.json
|
||||
*.exe
|
||||
*.dat
|
||||
gulpfile.js
|
||||
1
samples/extensionSamples/CHANGELOG.md
Normal file
1
samples/extensionSamples/CHANGELOG.md
Normal file
@@ -0,0 +1 @@
|
||||
# Change Log
|
||||
21
samples/extensionSamples/LICENSE.txt
Normal file
21
samples/extensionSamples/LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Microsoft
|
||||
|
||||
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.
|
||||
0
samples/extensionSamples/README.md
Normal file
0
samples/extensionSamples/README.md
Normal file
14
samples/extensionSamples/gulpfile.js
Normal file
14
samples/extensionSamples/gulpfile.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
"use strict";
|
||||
|
||||
// NOTE: These are es6 gulpfiles
|
||||
|
||||
// Basic build tasks
|
||||
require('./tasks/buildtasks');
|
||||
|
||||
// VSIX generation tasks
|
||||
require('./tasks/packagetasks');
|
||||
7751
samples/extensionSamples/package-lock.json
generated
Normal file
7751
samples/extensionSamples/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
199
samples/extensionSamples/package.json
Normal file
199
samples/extensionSamples/package.json
Normal file
@@ -0,0 +1,199 @@
|
||||
{
|
||||
"name": "extensionSamples",
|
||||
"displayName": "Extension Samples",
|
||||
"description": "Extension Samples",
|
||||
"version": "0.1.0",
|
||||
"publisher": "Microsoft",
|
||||
"engines": {
|
||||
"vscode": "^1.19.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"repository": "qqq.com",
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"*"
|
||||
],
|
||||
"main": "./out/src/extension",
|
||||
"contributes": {
|
||||
"configuration": [],
|
||||
"commands": [],
|
||||
"views": {},
|
||||
"menus": {},
|
||||
"dashboard.tabs": [
|
||||
{
|
||||
"id": "extension-samples",
|
||||
"title": "Extension Samples",
|
||||
"description": "This is the dashboard extension samples.",
|
||||
"container": {
|
||||
"nav-section": [
|
||||
{
|
||||
"id": "widgets-container1",
|
||||
"title": "Widgets",
|
||||
"icon": {
|
||||
"light": "./out/src/media/file.svg",
|
||||
"dark": "./out/src/media/file_inverse.svg"
|
||||
},
|
||||
"container": {
|
||||
"widgets-container1": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "grid-tab",
|
||||
"title": "GridLayout",
|
||||
"icon": {
|
||||
"light": "./out/src/media/file.svg",
|
||||
"dark": "./out/src/media/file_inverse.svg"
|
||||
},
|
||||
"container": {
|
||||
"grid-container1": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "webviewExample",
|
||||
"title": "Webivew",
|
||||
"icon": {
|
||||
"light": "./out/src/media/file.svg",
|
||||
"dark": "./out/src/media/file_inverse.svg"
|
||||
},
|
||||
"container": {
|
||||
"webview-container": null
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"dashboard.insights": {
|
||||
"id": "query-data-store-db-insight",
|
||||
"contrib": {
|
||||
"name": "Top 5 Slowest Queries",
|
||||
"provider": "MSSQL",
|
||||
"gridItemConfig": {
|
||||
"x": 2,
|
||||
"y": 1
|
||||
},
|
||||
"type": {
|
||||
"timeSeries": {
|
||||
"dataDirection": "horizontal",
|
||||
"dataType": "point",
|
||||
"legendPosition": "top",
|
||||
"labelFirstColumn": false,
|
||||
"columnsAsLabels": false
|
||||
}
|
||||
},
|
||||
"queryFile": "./out/src/sql/qds.sql",
|
||||
"details": {
|
||||
"queryFile": "./out/src/sql/qds_detail.sql",
|
||||
"label": {
|
||||
"icon": "file",
|
||||
"column": "query_id",
|
||||
"state": []
|
||||
},
|
||||
"value": "max_duration"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dashboard.containers": [
|
||||
{
|
||||
"id": "grid-container1",
|
||||
"container": {
|
||||
"grid-container": [
|
||||
{
|
||||
"name": "Tasks",
|
||||
"row": 0,
|
||||
"col": 0,
|
||||
"widget": {
|
||||
"tasks-widget": [
|
||||
{
|
||||
"name": "backup",
|
||||
"when": "!mssql:iscloud"
|
||||
},
|
||||
{
|
||||
"name": "restore",
|
||||
"when": "!mssql:iscloud"
|
||||
},
|
||||
"configureDashboard",
|
||||
"newQuery"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Web view buttons",
|
||||
"widget": {
|
||||
"webview-widget": {
|
||||
"id": "webview-button"
|
||||
}
|
||||
},
|
||||
"row": 0,
|
||||
"col": 1
|
||||
},
|
||||
{
|
||||
"name": "Web view count",
|
||||
"webview": {
|
||||
"id": "webview-count"
|
||||
},
|
||||
"row": 1,
|
||||
"col": 0,
|
||||
"colspan": "*"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "widgets-container1",
|
||||
"container": {
|
||||
"widgets-container": [
|
||||
{
|
||||
"widget": {
|
||||
"query-data-store-db-insight": {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"widget": {
|
||||
"explorer-widget": {
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"snippets": []
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp build",
|
||||
"compile": "gulp compile",
|
||||
"watch": "gulp watch",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs-extra": "^5.0.0",
|
||||
"handlebars": "^4.0.11",
|
||||
"vscode-nls": "2.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/handlebars": "^4.0.11",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/node": "^7.0.43",
|
||||
"child-process-promise": "^2.2.1",
|
||||
"del": "^3.0.0",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-color": "0.0.1",
|
||||
"gulp-sourcemaps": "^2.6.4",
|
||||
"gulp-tslint": "^6.0.2",
|
||||
"gulp-typescript": "^3.2.4",
|
||||
"pm-mocha-jenkins-reporter": "^0.2.6",
|
||||
"should": "^13.2.1",
|
||||
"temp-write": "^3.4.0",
|
||||
"tslint": "^3.14.0",
|
||||
"typemoq": "^2.1.0",
|
||||
"typescript": "^2.6.1",
|
||||
"vscode": "^1.1.6",
|
||||
"vsce": "1.36.2",
|
||||
"vso-node-api": "6.1.2-preview"
|
||||
}
|
||||
}
|
||||
5
samples/extensionSamples/src/constants.ts
Normal file
5
samples/extensionSamples/src/constants.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
// CONFIG VALUES ///////////////////////////////////////////////////////////
|
||||
export const extensionConfigSectionName = 'extensionSamples';
|
||||
export const configLogDebugInfo = 'logDebugInfo';
|
||||
16
samples/extensionSamples/src/controllers/button.html
Normal file
16
samples/extensionSamples/src/controllers/button.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<html>
|
||||
<header>
|
||||
</header>
|
||||
<body>
|
||||
<button onclick="count()">Count</button>
|
||||
<button onclick="openFlyout()">Open Flyout</button>
|
||||
<script>
|
||||
function count() {
|
||||
parent.postMessage('count', '*');
|
||||
}
|
||||
function openFlyout() {
|
||||
parent.postMessage('openFlyout', '*');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
25
samples/extensionSamples/src/controllers/controllerBase.ts
Normal file
25
samples/extensionSamples/src/controllers/controllerBase.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export default abstract class ControllerBase implements vscode.Disposable {
|
||||
protected _context: vscode.ExtensionContext;
|
||||
|
||||
public constructor(context: vscode.ExtensionContext) {
|
||||
this._context = context;
|
||||
}
|
||||
|
||||
abstract activate(): Promise<boolean>;
|
||||
|
||||
abstract deactivate(): void;
|
||||
|
||||
public dispose(): void {
|
||||
this.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
15
samples/extensionSamples/src/controllers/counter.html
Normal file
15
samples/extensionSamples/src/controllers/counter.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<header>
|
||||
|
||||
</header>
|
||||
<body>
|
||||
<div id="output">Total Counts: 0</div>
|
||||
<script>
|
||||
let output = document.getElementById('output');
|
||||
window.addEventListener("message", receiveMessage, false);
|
||||
function receiveMessage(e) {
|
||||
output.innerText = 'Total Counts: ' + e.data;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
61
samples/extensionSamples/src/controllers/mainController.ts
Normal file
61
samples/extensionSamples/src/controllers/mainController.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as sqlops from 'sqlops';
|
||||
import * as Utils from '../utils';
|
||||
import ControllerBase from './controllerBase';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* The main controller class that initializes the extension
|
||||
*/
|
||||
export default class MainController extends ControllerBase {
|
||||
// PUBLIC METHODS //////////////////////////////////////////////////////
|
||||
/**
|
||||
* Deactivates the extension
|
||||
*/
|
||||
public deactivate(): void {
|
||||
Utils.logDebug('Main controller deactivated');
|
||||
}
|
||||
|
||||
public activate(): Promise<boolean> {
|
||||
const webviewExampleHtml = fs.readFileSync(path.join(__dirname, 'webviewExample.html')).toString();
|
||||
const buttonHtml = fs.readFileSync(path.join(__dirname, 'button.html')).toString();
|
||||
const counterHtml = fs.readFileSync(path.join(__dirname, 'counter.html')).toString();
|
||||
|
||||
let countWidget: sqlops.DashboardWebview;
|
||||
let buttonWidget: sqlops.DashboardWebview;
|
||||
let count = 0;
|
||||
|
||||
let dialog: sqlops.ModalDialog = sqlops.window.createDialog('Flyout extension');
|
||||
dialog.html = '<div>This is a flyout extension.</div>';
|
||||
|
||||
sqlops.dashboard.registerWebviewProvider('webview-count', e => {
|
||||
e.html = counterHtml;
|
||||
countWidget = e;
|
||||
});
|
||||
sqlops.dashboard.registerWebviewProvider('webview-button', e => {
|
||||
e.html = buttonHtml;
|
||||
buttonWidget = e;
|
||||
e.onMessage(event => {
|
||||
if (event === 'openFlyout') {
|
||||
dialog.open();
|
||||
} else {
|
||||
count++;
|
||||
countWidget.postMessage(count);
|
||||
}
|
||||
});
|
||||
});
|
||||
sqlops.dashboard.registerWebviewProvider('webviewExample', e => {
|
||||
e.html = webviewExampleHtml;
|
||||
});
|
||||
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
19
samples/extensionSamples/src/controllers/webviewExample.html
Normal file
19
samples/extensionSamples/src/controllers/webviewExample.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<header>
|
||||
<style>
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: skyblue;
|
||||
}
|
||||
</style>
|
||||
</header>
|
||||
<body>
|
||||
Hello :)
|
||||
</body>
|
||||
</html>
|
||||
39
samples/extensionSamples/src/extension.ts
Normal file
39
samples/extensionSamples/src/extension.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import ControllerBase from './controllers/controllerBase';
|
||||
import MainController from './controllers/mainController';
|
||||
|
||||
let controllers: ControllerBase[] = [];
|
||||
|
||||
export function activate(context: vscode.ExtensionContext): Promise<boolean> {
|
||||
let activations: Promise<boolean>[] = [];
|
||||
|
||||
// Start the main controller
|
||||
let mainController = new MainController(context);
|
||||
controllers.push(mainController);
|
||||
context.subscriptions.push(mainController);
|
||||
activations.push(mainController.activate());
|
||||
|
||||
return Promise.all(activations)
|
||||
.then((results: boolean[]) => {
|
||||
for (let result of results) {
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
for (let controller of controllers) {
|
||||
controller.deactivate();
|
||||
}
|
||||
}
|
||||
5
samples/extensionSamples/src/localizedConstants.ts
Normal file
5
samples/extensionSamples/src/localizedConstants.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
// TODO: localize!
|
||||
|
||||
export const msgErrorLoadingTab = 'An error occurred while loading the tab.';
|
||||
1
samples/extensionSamples/src/media/file.svg
Normal file
1
samples/extensionSamples/src/media/file.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><defs><style>.cls-1{fill:#231f20;}.cls-2{fill:#212121;}</style></defs><title>file_16x16</title><polygon class="cls-1" points="13.59 2.21 13.58 2.22 13.58 2.2 13.59 2.21"/><path class="cls-2" d="M8.71,0,14,5.29V16H2V0ZM3,15H13V6H8V1H3ZM9,1.71V5h3.29Z"/></svg>
|
||||
|
After Width: | Height: | Size: 351 B |
1
samples/extensionSamples/src/media/file_inverse.svg
Normal file
1
samples/extensionSamples/src/media/file_inverse.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><defs><style>.cls-1{fill:#fff;}</style></defs><title>file_inverse_16x16</title><polygon class="cls-1" points="13.59 2.21 13.58 2.22 13.58 2.2 13.59 2.21"/><path class="cls-1" d="M8.71,0,14,5.29V16H2V0ZM3,15H13V6H8V1H3ZM9,1.71V5h3.29Z"/></svg>
|
||||
|
After Width: | Height: | Size: 335 B |
39
samples/extensionSamples/src/sql/qds.sql
Normal file
39
samples/extensionSamples/src/sql/qds.sql
Normal file
@@ -0,0 +1,39 @@
|
||||
declare @qds_status int = (SELECT actual_state
|
||||
FROM sys.database_query_store_options)
|
||||
if @qds_status > 0
|
||||
Begin
|
||||
WITH SlowestQry AS(
|
||||
SELECT TOP 5
|
||||
q.query_id,
|
||||
MAX(rs.max_duration ) max_duration
|
||||
FROM sys.query_store_query_text AS qt
|
||||
JOIN sys.query_store_query AS q
|
||||
ON qt.query_text_id = q.query_text_id
|
||||
JOIN sys.query_store_plan AS p
|
||||
ON q.query_id = p.query_id
|
||||
JOIN sys.query_store_runtime_stats AS rs
|
||||
ON p.plan_id = rs.plan_id
|
||||
WHERE rs.last_execution_time > DATEADD(week, -1, GETUTCDATE())
|
||||
AND is_internal_query = 0
|
||||
GROUP BY q.query_id
|
||||
ORDER BY MAX(rs.max_duration ) DESC)
|
||||
SELECT
|
||||
q.query_id,
|
||||
format(rs.last_execution_time,'yyyy-MM-dd hh:mm:ss') as [last_execution_time],
|
||||
rs.max_duration,
|
||||
p.plan_id
|
||||
FROM sys.query_store_query_text AS qt
|
||||
JOIN sys.query_store_query AS q
|
||||
ON qt.query_text_id = q.query_text_id
|
||||
JOIN sys.query_store_plan AS p
|
||||
ON q.query_id = p.query_id
|
||||
JOIN sys.query_store_runtime_stats AS rs
|
||||
ON p.plan_id = rs.plan_id
|
||||
JOIN SlowestQry tq
|
||||
ON tq.query_id = q.query_id
|
||||
WHERE rs.last_execution_time > DATEADD(week, -1, GETUTCDATE())
|
||||
AND is_internal_query = 0
|
||||
order by format(rs.last_execution_time,'yyyy-MM-dd hh:mm:ss')
|
||||
END
|
||||
else
|
||||
select 0 as [query_id], getdate() as [QDS is not enabled], 0 as [max_duration]
|
||||
45
samples/extensionSamples/src/utils.ts
Normal file
45
samples/extensionSamples/src/utils.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
import * as fs from 'fs-extra';
|
||||
import * as handlebars from 'handlebars';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import * as Constants from './constants';
|
||||
import * as LocalizedConstants from './localizedConstants';
|
||||
|
||||
/**
|
||||
* Helper to log messages to the developer console if enabled
|
||||
* @param msg Message to log to the console
|
||||
*/
|
||||
export function logDebug(msg: any): void {
|
||||
let config = vscode.workspace.getConfiguration(Constants.extensionConfigSectionName);
|
||||
let logDebugInfo = config[Constants.configLogDebugInfo];
|
||||
if (logDebugInfo === true) {
|
||||
let currentTime = new Date().toLocaleTimeString();
|
||||
let outputMsg = '[' + currentTime + ']: ' + msg ? msg.toString() : '';
|
||||
console.log(outputMsg);
|
||||
}
|
||||
}
|
||||
|
||||
export function renderTemplateHtml(extensionPath: string, templateName: string, templateValues: object): Thenable<string> {
|
||||
let templatePath = path.join(extensionPath, 'resources', templateName);
|
||||
|
||||
// 1) Read the template from the disk
|
||||
// 2) Compile it as a handlebars template and render the HTML
|
||||
// 3) On failure, return a simple string as an error
|
||||
return fs.readFile(templatePath, 'utf-8')
|
||||
.then(templateText => {
|
||||
let template = handlebars.compile(templateText);
|
||||
return template(templateValues);
|
||||
})
|
||||
.then(
|
||||
undefined,
|
||||
error => {
|
||||
logDebug(error);
|
||||
return LocalizedConstants.msgErrorLoadingTab;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
118
samples/extensionSamples/tasks/buildtasks.js
Normal file
118
samples/extensionSamples/tasks/buildtasks.js
Normal file
@@ -0,0 +1,118 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
"use strict";
|
||||
|
||||
let del = require('del');
|
||||
let gulp = require('gulp');
|
||||
let srcmap = require('gulp-sourcemaps');
|
||||
let tslint = require('gulp-tslint');
|
||||
let ts = require('gulp-typescript');
|
||||
let cproc = require('child_process');
|
||||
let os = require('os');
|
||||
|
||||
let config = require('./config');
|
||||
let tsProject = ts.createProject('tsconfig.json');
|
||||
|
||||
|
||||
// GULP TASKS //////////////////////////////////////////////////////////////
|
||||
gulp.task('clean', function(done) {
|
||||
return del('out', done);
|
||||
});
|
||||
|
||||
gulp.task('lint', () => {
|
||||
return gulp.src([
|
||||
config.paths.project.root + '/src/**/*.ts',
|
||||
config.paths.project.root + '/test/**/*.ts'
|
||||
])
|
||||
.pipe((tslint({
|
||||
formatter: "verbose"
|
||||
})))
|
||||
.pipe(tslint.report());
|
||||
});
|
||||
|
||||
gulp.task('compile:src', function(done) {
|
||||
gulp.src([
|
||||
config.paths.project.root + '/src/**/*.sql',
|
||||
config.paths.project.root + '/src/**/*.svg',
|
||||
config.paths.project.root + '/src/**/*.html'
|
||||
]).pipe(gulp.dest('out/src/'));
|
||||
|
||||
let srcFiles = [
|
||||
config.paths.project.root + '/src/**/*.ts',
|
||||
config.paths.project.root + '/src/**/*.js',
|
||||
config.paths.project.root + '/typings/**/*.ts'
|
||||
];
|
||||
|
||||
return gulp.src(srcFiles)
|
||||
.pipe(srcmap.init())
|
||||
.pipe(tsProject())
|
||||
.on('error', function() {
|
||||
if(process.env.BUILDMACHINE) {
|
||||
done('Failed to compile extension source, see above.');
|
||||
process.exit(1);
|
||||
}
|
||||
})
|
||||
// TODO: Reinstate localization code
|
||||
// .pipe(nls.rewriteLocalizeCalls())
|
||||
// .pipe(nls.createAdditionalLanguageFiles(nls.coreLanguages, config.paths.project.root + '/localization/i18n', undefined, false))
|
||||
.pipe(srcmap.write('.', { sourceRoot: function(file) { return file.cwd + '/src'; }}))
|
||||
.pipe(gulp.dest('out/src/'));
|
||||
});
|
||||
|
||||
gulp.task('compile:test', function(done) {
|
||||
let srcFiles = [
|
||||
config.paths.project.root + '/test/**/*.ts',
|
||||
config.paths.project.root + '/typings/**/*.ts'
|
||||
];
|
||||
|
||||
return gulp.src(srcFiles)
|
||||
.pipe(srcmap.init())
|
||||
.pipe(tsProject())
|
||||
.on('error', function() {
|
||||
if(process.env.BUILDMACHINE) {
|
||||
done('Failed to compile test source, see above.');
|
||||
process.exit(1);
|
||||
}
|
||||
})
|
||||
.pipe(srcmap.write('.', {sourceRoot: function(file) { return file.cwd + '/test'; }}))
|
||||
.pipe(gulp.dest('out/test/'));
|
||||
});
|
||||
|
||||
// COMPOSED GULP TASKS /////////////////////////////////////////////////////
|
||||
gulp.task("compile", gulp.series("compile:src", "compile:test"));
|
||||
|
||||
gulp.task("build", gulp.series("clean", "lint", "compile"));
|
||||
|
||||
gulp.task("watch", function() {
|
||||
gulp.watch([config.paths.project.root + '/src/**/*',
|
||||
config.paths.project.root + '/test/**/*.ts'],
|
||||
gulp.series('build'))
|
||||
});
|
||||
|
||||
gulp.task('test', (done) => {
|
||||
let workspace = process.env['WORKSPACE'];
|
||||
if (!workspace) {
|
||||
workspace = process.cwd();
|
||||
}
|
||||
process.env.JUNIT_REPORT_PATH = workspace + '/test-reports/ext_xunit.xml';
|
||||
|
||||
let sqlopsPath = 'sqlops';
|
||||
if (process.env['SQLOPS_DEV']) {
|
||||
let suffix = os.platform === 'win32' ? 'bat' : 'sh';
|
||||
sqlopsPath = `${process.env['SQLOPS_DEV']}/scripts/sql-cli.${suffix}`;
|
||||
}
|
||||
console.log(`Using SQLOPS Path of ${sqlopsPath}`);
|
||||
|
||||
cproc.exec(`${sqlopsPath} --extensionDevelopmentPath="${workspace}" --extensionTestsPath="${workspace}/out/test" --verbose`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`exec error: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`stdout: ${stdout}`);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
done();
|
||||
});
|
||||
});
|
||||
27
samples/extensionSamples/tasks/config.js
Normal file
27
samples/extensionSamples/tasks/config.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var path = require('path');
|
||||
|
||||
var projectRoot = path.resolve(path.dirname(__dirname));
|
||||
var srcRoot = path.resolve(projectRoot, 'src');
|
||||
var viewsRoot = path.resolve(srcRoot, 'views');
|
||||
var htmlcontentRoot = path.resolve(viewsRoot, 'htmlcontent');
|
||||
var outRoot = path.resolve(projectRoot, 'out');
|
||||
var htmloutroot = path.resolve(outRoot, 'src/views/htmlcontent');
|
||||
var localization = path.resolve(projectRoot, 'localization');
|
||||
|
||||
var config = {
|
||||
paths: {
|
||||
project: {
|
||||
root: projectRoot,
|
||||
localization: localization
|
||||
},
|
||||
extension: {
|
||||
root: srcRoot
|
||||
},
|
||||
html: {
|
||||
root: htmlcontentRoot,
|
||||
out: htmloutroot
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
148
samples/extensionSamples/tasks/packagetasks.js
Normal file
148
samples/extensionSamples/tasks/packagetasks.js
Normal file
@@ -0,0 +1,148 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
let gulp = require('gulp');
|
||||
let exec = require('child-process-promise').exec;
|
||||
let color = require('gulp-color');
|
||||
|
||||
// CONSTANTS ///////////////////////////////////////////////////////////////
|
||||
let packageVals = require('../package');
|
||||
|
||||
// HELPER FUNCTIONS ////////////////////////////////////////////////////////
|
||||
|
||||
let buildPackage = function(packageName) {
|
||||
// Make sure there are
|
||||
if (!packageVals.repository) {
|
||||
return Promise.reject("Repository field is not defined in package.json");
|
||||
}
|
||||
|
||||
// Initialize the package command with program and command
|
||||
let vsceArgs = [];
|
||||
vsceArgs.push('./node_modules/vsce/out/vsce');
|
||||
vsceArgs.push('package'); // package command
|
||||
|
||||
// Add the package name
|
||||
vsceArgs.push('-o');
|
||||
vsceArgs.push(packageName);
|
||||
|
||||
// Put it all together and execute the command
|
||||
let command = vsceArgs.join(' ');
|
||||
console.log(command);
|
||||
return exec(command);
|
||||
};
|
||||
|
||||
|
||||
// function getServiceInstaller() {
|
||||
// let Constants = require('../out/src/models/constants').Constants;
|
||||
// let ServiceInstaller = require('../out/src/languageservice/serviceInstallerUtil').ServiceInstaller;
|
||||
// return new ServiceInstaller(new Constants())
|
||||
// }
|
||||
//
|
||||
// function installToolsService(platform) {
|
||||
// let installer = getServiceInstaller();
|
||||
// return installer.installService(platform);
|
||||
// }
|
||||
|
||||
// function cleanServiceInstallFolder() {
|
||||
// let installer = getServiceInstaller();
|
||||
// return new Promise(function(resolve, reject) {
|
||||
// installer.getServiceInstallDirectoryRoot().then(function (serviceInstallFolder) {
|
||||
// console.log('Deleting Service Install folder: ' + serviceInstallFolder);
|
||||
// del(serviceInstallFolder + '/*').then(function () {
|
||||
// resolve();
|
||||
// }).catch(function (error) {
|
||||
// reject(error)
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// function doOfflinePackage(runtimeId, platform, packageName) {
|
||||
// return installSqlToolsService(platform).then(function() {
|
||||
// return doPackageSync(packageName + '-' + runtimeId + '.vsix');
|
||||
// });
|
||||
// }
|
||||
|
||||
// ORIGINAL GULP TASKS /////////////////////////////////////////////////////
|
||||
// TODO: Reinstate when we have code for loading a tools service
|
||||
|
||||
// gulp.task('ext:install-service', function() {
|
||||
// return installSqlToolsService();
|
||||
// });
|
||||
|
||||
// Install vsce to be able to run this task: npm install -g vsce
|
||||
// gulp.task('package:online', function() {
|
||||
// return cleanServiceInstallFolder()
|
||||
// .then(function() { return doPackageSync(); });
|
||||
// });
|
||||
|
||||
// Install vsce to be able to run this task: npm install -g vsce
|
||||
// gulp.task('package:offline', function() {
|
||||
// const platform = require('../out/src/models/platform');
|
||||
// const Runtime = platform.Runtime;
|
||||
// let json = JSON.parse(fs.readFileSync('package.json').toString());
|
||||
// let name = json.name;
|
||||
// let version = json.version;
|
||||
// let packageName = name + '-' + version;
|
||||
//
|
||||
// let packages = [];
|
||||
// packages.push({rid: 'win-x64', runtime: Runtime.Windows_64});
|
||||
// packages.push({rid: 'win-x86', runtime: Runtime.Windows_86});
|
||||
// packages.push({rid: 'osx', runtime: Runtime.OSX});
|
||||
// packages.push({rid: 'linux-x64', runtime: Runtime.Linux_64});
|
||||
//
|
||||
// let promise = Promise.resolve();
|
||||
// cleanServiceInstallFolder().then(function () {
|
||||
// packages.forEach(function (data) {
|
||||
// promise = promise.then(function () {
|
||||
// return doOfflinePackage(data.rid, data.runtime, packageName).then(function () {
|
||||
// return cleanServiceInstallFolder();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// return promise;
|
||||
// });
|
||||
|
||||
function getOnlinePackageName() {
|
||||
return packageVals.name + "-" + packageVals.version + ".vsix";
|
||||
}
|
||||
|
||||
function getOnlinePackagePath() {
|
||||
return './' + getOnlinePackageName();
|
||||
}
|
||||
|
||||
// TEMPORARY GULP TASKS ////////////////////////////////////////////////////
|
||||
gulp.task('package:online', gulp.series("build", function() {
|
||||
return buildPackage(getOnlinePackageName());
|
||||
}));
|
||||
|
||||
gulp.task('package:offline', gulp.series("build", function(done) {
|
||||
// TODO: Get list of platforms
|
||||
// TODO: For each platform: clean the package service folder, download the service, build the package
|
||||
console.error("This mode is not yet supported");
|
||||
done("This mode is not yet supported");
|
||||
}));
|
||||
|
||||
gulp.task('install:sqlops', gulp.series("package:online", function() {
|
||||
let command = 'sqlops --install-extension ' + getOnlinePackagePath();
|
||||
console.log(command);
|
||||
return exec(command);
|
||||
}));
|
||||
|
||||
gulp.task("help:debug", function(done) {
|
||||
let command = '$SQLOPS_DEV/scripts/sql.sh --extensionDevelopmentPath='+process.cwd();
|
||||
console.log('Launch sqlops + your extension (from a sqlops dev enlistment after setting $SQLOPS_DEV to your enlistment root):\n')
|
||||
console.log(color(command, 'GREEN'));
|
||||
|
||||
command = 'sqlops --extensionDevelopmentPath='+process.cwd();
|
||||
console.log('\nLaunch sqlops + your extension (full SQLOPS - requires setting PATH variable)\n');
|
||||
console.log(color(command, 'GREEN'));
|
||||
done();
|
||||
})
|
||||
|
||||
16
samples/extensionSamples/tsconfig.json
Normal file
16
samples/extensionSamples/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "."
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
]
|
||||
}
|
||||
123
samples/extensionSamples/tslint.json
Normal file
123
samples/extensionSamples/tslint.json
Normal file
@@ -0,0 +1,123 @@
|
||||
{
|
||||
"rules": {
|
||||
"align": [
|
||||
true,
|
||||
"parameters",
|
||||
"statements"
|
||||
],
|
||||
"ban": false,
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"curly": true,
|
||||
"eofline": true,
|
||||
"forin": true,
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"interface-name": true,
|
||||
"jsdoc-format": true,
|
||||
"label-position": true,
|
||||
"label-undefined": true,
|
||||
"max-line-length": [
|
||||
true,
|
||||
160
|
||||
],
|
||||
"member-access": false,
|
||||
"member-ordering": false,
|
||||
"no-any": false,
|
||||
"no-arg": true,
|
||||
"no-bitwise": true,
|
||||
"no-conditional-assignment": true,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-console": [
|
||||
true,
|
||||
"debug",
|
||||
"info",
|
||||
"time",
|
||||
"timeEnd",
|
||||
"trace"
|
||||
],
|
||||
"no-construct": true,
|
||||
"no-constructor-vars": false,
|
||||
"no-debugger": true,
|
||||
"no-duplicate-key": true,
|
||||
"no-duplicate-variable": true,
|
||||
"no-empty": true,
|
||||
"no-eval": true,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": true,
|
||||
"no-null-keyword": true,
|
||||
"no-require-imports": false,
|
||||
"no-shadowed-variable": true,
|
||||
"no-string-literal": false,
|
||||
"no-switch-case-fall-through": false,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unreachable": true,
|
||||
"no-unused-expression": false,
|
||||
"no-unused-variable": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-var-keyword": true,
|
||||
"no-var-requires": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-catch",
|
||||
"check-else",
|
||||
"check-finally",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"single",
|
||||
"avoid-escape"
|
||||
],
|
||||
"radix": true,
|
||||
"semicolon": true,
|
||||
"switch-default": true,
|
||||
"trailing-comma": [
|
||||
true,
|
||||
{
|
||||
"multiline": "never",
|
||||
"singleline": "never"
|
||||
}
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typedef": [
|
||||
true,
|
||||
"call-signature",
|
||||
"property-declaration"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"use-strict": false,
|
||||
"variable-name": [
|
||||
true,
|
||||
"allow-leading-underscore",
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
}
|
||||
}
|
||||
1530
samples/extensionSamples/typings/sqlops.d.ts
vendored
Normal file
1530
samples/extensionSamples/typings/sqlops.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user