Skip to content

Commit 5b5755d

Browse files
committed
add support for endpoints
1 parent 3b3dc18 commit 5b5755d

File tree

13 files changed

+749
-46
lines changed

13 files changed

+749
-46
lines changed

dist/configuration.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var path = require("path");
4+
;
5+
function getConfiguration() {
6+
var currentDirectory = process.cwd();
7+
return require(path.join(currentDirectory, 'configuration.json'));
8+
}
9+
exports.getConfiguration = getConfiguration;

dist/endpoints.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var path = require("path");
4+
var fs = require("fs-extra");
5+
function getEndpoints(endpointsRoot) {
6+
if (!endpointsRoot) {
7+
var currentDirectory = process.cwd();
8+
endpointsRoot = path.join(currentDirectory, 'Endpoints');
9+
}
10+
if (!fs.existsSync(endpointsRoot)) {
11+
return [];
12+
}
13+
return fs.readdirSync(endpointsRoot).map(function (file) {
14+
var endpointPath = path.join(endpointsRoot, file);
15+
var manifest = JSON.parse(fs.readFileSync(endpointPath, { encoding: 'utf8' }));
16+
return {
17+
path: endpointPath,
18+
name: manifest.properties.name,
19+
manifest: manifest,
20+
};
21+
});
22+
}
23+
exports.getEndpoints = getEndpoints;

dist/install.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ var npmInstall = function (project) {
4646
};
4747
};
4848
var installTasks = tasks_1.getTasks().map(npmInstall);
49-
installTasks.unshift(npmInstall({
50-
directory: __dirname,
51-
name: "BuildScripts"
52-
}));
5349
async_1.series(installTasks, function (err) {
5450
if (err) {
5551
console.error("Failed to install child dependencies");

dist/package.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ var child_process_1 = require("child_process");
55
var fs = require("fs-extra");
66
var async_1 = require("async");
77
var extension_version_1 = require("./extension-version");
8-
var tasks = require("./tasks");
9-
;
8+
var tasks_1 = require("./tasks");
9+
var configuration_1 = require("./configuration");
10+
var endpoints_1 = require("./endpoints");
1011
var currentDirectory = process.cwd();
1112
var buildOutputDirectory = path.join(currentDirectory, '.BuildOutput');
1213
var extensionDirectory = path.join(currentDirectory, 'Extension');
1314
var tasksDirectory = path.join(currentDirectory, 'Tasks');
1415
fs.ensureDirSync(buildOutputDirectory);
1516
var version = extension_version_1.getSemanticVersion();
16-
var configuration = require(path.join(currentDirectory, 'configuration.json'));
17+
var configuration = configuration_1.getConfiguration();
1718
var createExtensionTasks = configuration.environments.map(function (env) {
1819
var environmentDirectory = path.join(buildOutputDirectory, env.Name);
1920
var environmentTasksDirectory = path.join(environmentDirectory, 'Tasks');
@@ -29,18 +30,37 @@ var createExtensionTasks = configuration.environments.map(function (env) {
2930
if (extension.contributions === undefined) {
3031
extension.contributions = [];
3132
}
32-
var patchTasks = tasks.getTasks(environmentTasksDirectory).map(function (taskDirectory) {
33+
var endpointMap = {};
34+
endpoints_1.getEndpoints().forEach(function (endpoint) {
35+
endpointMap["connectedService:" + endpoint.name] = "connectedService:" + endpoint.name + env.VssExtensionIdSuffix;
36+
var config = endpoint.manifest;
37+
config.id = config.id + env.VssExtensionIdSuffix;
38+
config.properties.name = endpoint.name + env.VssExtensionIdSuffix;
39+
config.properties.displayName = config.properties.displayName + env.DisplayNamesSuffix;
40+
extension.contributions.push(config);
41+
});
42+
tasks_1.getTasks(environmentTasksDirectory).map(function (taskDirectory) {
3343
var taskFilePath = path.join(taskDirectory.directory, 'task.json');
3444
var task = fs.readJsonSync(taskFilePath);
3545
task.id = env.TaskIds[taskDirectory.name];
3646
if (task.id) {
3747
task.friendlyName += env.DisplayNamesSuffix;
38-
task.version.Major = version.major;
39-
task.version.Minor = version.minor;
40-
task.version.Patch = version.patch;
48+
task.version = {
49+
Major: version.major,
50+
Minor: version.minor,
51+
Patch: version.patch,
52+
};
4153
if (task.helpMarkDown) {
4254
task.helpMarkDown = task.helpMarkDown.replace('#{Version}#', version.getVersionString());
4355
}
56+
if (task.inputs) {
57+
task.inputs.forEach(function (input) {
58+
var mappedType = endpointMap[input.type];
59+
if (mappedType) {
60+
input.type = mappedType;
61+
}
62+
});
63+
}
4464
fs.writeJsonSync(taskFilePath, task);
4565
var taskLocFilePath = path.join(taskDirectory.directory, 'task.loc.json');
4666
if (fs.existsSync(taskLocFilePath)) {

dist/prebuild.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ var fs = require("fs-extra");
44
var path = require("path");
55
var tasks = require("./tasks");
66
var lodash_1 = require("lodash");
7+
var configuration_1 = require("./configuration");
78
var currentDirectory = process.cwd();
89
var nodeCommonFilesRoot = path.join(currentDirectory, 'Common', 'Node');
910
var powershellCommonFilesRoot = path.join(currentDirectory, 'Common', 'PowerShell3');
1011
var tasksRoot = path.join(currentDirectory, 'Tasks');
12+
var configuration = configuration_1.getConfiguration();
13+
var endpointsRoot = path.join(currentDirectory, 'Endpoints');
1114
var nodeFiles = fs.existsSync(nodeCommonFilesRoot) ? fs.readdirSync(nodeCommonFilesRoot) : [];
1215
var powershellFiles = fs.existsSync(powershellCommonFilesRoot) ? fs.readdirSync(powershellCommonFilesRoot) : [];
1316
lodash_1.forEach(tasks.getTasks(), function (task) {

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
"vsts-build-tools-prebuild": "./run/vsts-build-tools-prebuild"
1111
},
1212
"scripts": {
13-
"build": "tsc"
13+
"build": "tsc",
14+
"schema:task": "json2ts --input tasks.schema.json --output src/task.d.ts"
1415
},
1516
"devDependencies": {
1617
"async": "^2.6.1",
1718
"fs-extra": "6.0.1",
1819
"glob": "7.1.2",
1920
"jasmine": "^3.1.0",
21+
"json-schema-to-typescript": "^5.5.0",
2022
"lodash": "4.17.10",
2123
"minimist": "1.2.0",
2224
"modclean": "2.1.0",
@@ -34,4 +36,4 @@
3436
"@types/node": "^10.5.2",
3537
"@types/semver": "^5.5.0"
3638
}
37-
}
39+
}

src/configuration.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as path from 'path';
2+
3+
export interface IConfiguration {
4+
"environments": {
5+
"Name": string;
6+
"VssExtensionIdSuffix": string;
7+
"VssExtensionGalleryFlags": ("Preview" | "Public")[];
8+
"DisplayNamesSuffix": string;
9+
"TaskIds": {
10+
[key: string]: string;
11+
};
12+
}[];
13+
};
14+
15+
export function getConfiguration(): IConfiguration {
16+
var currentDirectory = process.cwd();
17+
return require(path.join(currentDirectory, 'configuration.json')) as IConfiguration;
18+
}

src/endpoints.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as path from "path";
2+
import * as fs from "fs-extra";
3+
4+
export interface IEndpoint {
5+
path: string;
6+
name: string;
7+
manifest: any;
8+
}
9+
10+
export function getEndpoints(endpointsRoot?: string): IEndpoint[] {
11+
12+
if (!endpointsRoot) {
13+
var currentDirectory = process.cwd();
14+
endpointsRoot = path.join(currentDirectory, 'Endpoints');
15+
}
16+
17+
if (!fs.existsSync(endpointsRoot)){
18+
return [];
19+
}
20+
21+
return fs.readdirSync(endpointsRoot as string).map(file => {
22+
const endpointPath = path.join(endpointsRoot as string, file);
23+
const manifest = JSON.parse(fs.readFileSync(endpointPath, { encoding: 'utf8' }))
24+
25+
return {
26+
path: endpointPath,
27+
name: manifest.properties.name,
28+
manifest: manifest,
29+
};
30+
});
31+
32+
}

src/package.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,10 @@ import { exec } from 'child_process';
33
import * as fs from 'fs-extra';
44
import { series } from "async";
55
import { getSemanticVersion } from './extension-version';
6-
import * as tasks from './tasks';
7-
8-
export interface IConfiguration {
9-
"environments": {
10-
"Name": string;
11-
"VssExtensionIdSuffix": string;
12-
"VssExtensionGalleryFlags": ("Preview" | "Public")[];
13-
"DisplayNamesSuffix": string;
14-
"TaskIds": {
15-
[key: string]: string;
16-
};
17-
}[];
18-
};
6+
import { getTasks } from './tasks';
7+
import { getConfiguration } from './configuration';
8+
import { getEndpoints } from './endpoints';
9+
import { VstsTasksSchema } from './task';
1910

2011
var currentDirectory = process.cwd();
2112
var buildOutputDirectory = path.join(currentDirectory, '.BuildOutput');
@@ -26,7 +17,7 @@ fs.ensureDirSync(buildOutputDirectory);
2617

2718
var version = getSemanticVersion();
2819

29-
var configuration = require(path.join(currentDirectory, 'configuration.json')) as IConfiguration;
20+
var configuration = getConfiguration();
3021
var createExtensionTasks = configuration.environments.map((env) => {
3122

3223
var environmentDirectory = path.join(buildOutputDirectory, env.Name);
@@ -47,21 +38,44 @@ var createExtensionTasks = configuration.environments.map((env) => {
4738
extension.contributions = [];
4839
}
4940

50-
var patchTasks = tasks.getTasks(environmentTasksDirectory).map((taskDirectory) => {
41+
let endpointMap: { [source: string]: string } = {};
42+
43+
getEndpoints().forEach(endpoint => {
44+
endpointMap[`connectedService:${endpoint.name}`] = `connectedService:${endpoint.name}${env.VssExtensionIdSuffix}`;
45+
var config = endpoint.manifest;
46+
config.id = config.id + env.VssExtensionIdSuffix;
47+
config.properties.name = endpoint.name + env.VssExtensionIdSuffix;
48+
config.properties.displayName = config.properties.displayName + env.DisplayNamesSuffix;
49+
extension.contributions.push(config);
50+
});
51+
52+
getTasks(environmentTasksDirectory).map((taskDirectory) => {
5153
var taskFilePath = path.join(taskDirectory.directory, 'task.json');
52-
var task = fs.readJsonSync(taskFilePath);
54+
var task = fs.readJsonSync(taskFilePath) as VstsTasksSchema;
5355

5456
task.id = env.TaskIds[taskDirectory.name];
5557
if (task.id) {
5658
task.friendlyName += env.DisplayNamesSuffix;
5759

58-
task.version.Major = version.major;
59-
task.version.Minor = version.minor;
60-
task.version.Patch = version.patch;
60+
task.version = {
61+
Major : version.major,
62+
Minor : version.minor,
63+
Patch : version.patch,
64+
};
65+
6166
if (task.helpMarkDown) {
6267
task.helpMarkDown = task.helpMarkDown.replace('#{Version}#', version.getVersionString());
6368
}
6469

70+
if (task.inputs) {
71+
task.inputs.forEach((input) => {
72+
var mappedType = endpointMap[input.type];
73+
if (mappedType) {
74+
input.type = mappedType;
75+
}
76+
});
77+
}
78+
6579
fs.writeJsonSync(taskFilePath, task);
6680

6781
var taskLocFilePath = path.join(taskDirectory.directory, 'task.loc.json');

src/prebuild.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import * as fs from "fs-extra";
22
import * as path from "path";
33
import * as tasks from './tasks';
44
import { forEach } from 'lodash';
5+
import { getConfiguration } from './configuration';
56

67
var currentDirectory = process.cwd();
78
var nodeCommonFilesRoot = path.join(currentDirectory, 'Common', 'Node');
89
var powershellCommonFilesRoot = path.join(currentDirectory, 'Common', 'PowerShell3');
910
var tasksRoot = path.join(currentDirectory, 'Tasks');
11+
var configuration = getConfiguration();
12+
var endpointsRoot = path.join(currentDirectory, 'Endpoints');
1013

1114
var nodeFiles = fs.existsSync(nodeCommonFilesRoot) ? fs.readdirSync(nodeCommonFilesRoot) : [];
1215
var powershellFiles = fs.existsSync(powershellCommonFilesRoot) ? fs.readdirSync(powershellCommonFilesRoot) : [];

0 commit comments

Comments
 (0)