зеркало из https://github.com/microsoft/tfs-cli.git
First pass.
This commit is contained in:
Родитель
b457fe3195
Коммит
72ff356666
|
@ -7,6 +7,8 @@ import path = require("path");
|
|||
import tasksBase = require("./default");
|
||||
import trace = require("../../../lib/trace");
|
||||
import vm = require("../../../lib/jsonvalidate");
|
||||
import { ITaskAgentApi } from "azure-devops-node-api/TaskAgentApi";
|
||||
import zip = require("jszip");
|
||||
|
||||
export function getCommand(args: string[]): BuildTaskUpload {
|
||||
return new BuildTaskUpload(args);
|
||||
|
@ -19,40 +21,63 @@ export class BuildTaskUpload extends tasksBase.BuildTaskBase<agentContracts.Task
|
|||
protected serverCommand = true;
|
||||
|
||||
protected getHelpArgs(): string[] {
|
||||
return ["taskPath", "overwrite"];
|
||||
return ["taskPath", "taskZipPath", "overwrite"];
|
||||
}
|
||||
|
||||
public async exec(): Promise<agentContracts.TaskDefinition> {
|
||||
return this.commandArgs.taskPath.val().then(taskPaths => {
|
||||
let taskPath = taskPaths[0];
|
||||
return this.commandArgs.overwrite.val().then<agentContracts.TaskDefinition>(overwrite => {
|
||||
vm.exists(taskPath, "specified directory " + taskPath + " does not exist.");
|
||||
//directory is good, check json
|
||||
const taskPaths = await this.commandArgs.taskPath.val();
|
||||
const taskZipPath = await this.commandArgs.taskZipPath.val();
|
||||
const overwrite = await this.commandArgs.overwrite.val();
|
||||
|
||||
let tp = path.join(taskPath, c_taskJsonFile);
|
||||
return vm.validate(tp, "no " + c_taskJsonFile + " in specified directory").then(async taskJson => {
|
||||
let archive = archiver("zip");
|
||||
archive.on("error", function(error) {
|
||||
trace.debug("Archiving error: " + error.message);
|
||||
error.message = "Archiving error: " + error.message;
|
||||
throw error;
|
||||
});
|
||||
archive.directory(path.resolve(taskPath), false);
|
||||
let taskStream: NodeJS.ReadableStream = null;
|
||||
let taskId: string = null;
|
||||
let sourceLocation: string = null;
|
||||
|
||||
const collectionUrl = this.connection.getCollectionUrl();
|
||||
console.log("Collection URL: " + collectionUrl);
|
||||
let agentApi = await this.webApi.getTaskAgentApi(collectionUrl);
|
||||
if (!taskZipPath && !taskPaths) {
|
||||
throw new Error("You must specify either --task-path or --task-zip-path.");
|
||||
}
|
||||
|
||||
archive.finalize();
|
||||
return agentApi.uploadTaskDefinition(null, <any>archive, taskJson.id, overwrite).then(() => {
|
||||
trace.debug("Success");
|
||||
return <agentContracts.TaskDefinition>{
|
||||
sourceLocation: taskPath,
|
||||
};
|
||||
});
|
||||
});
|
||||
if (taskZipPath) {
|
||||
// User provided an already zipped task, upload that.
|
||||
const data: Buffer = fs.readFileSync("hello.zip");
|
||||
zip.loadAsync(data);
|
||||
|
||||
// find task.json inside zip, make sure its there then deserialize content
|
||||
|
||||
|
||||
// set variables
|
||||
|
||||
|
||||
} else {
|
||||
// User provided the path to a directory with the task content
|
||||
const taskPath: string = taskPaths[0];
|
||||
vm.exists(taskPath, "specified directory " + taskPath + " does not exist.");
|
||||
|
||||
const taskJsonPath: string = path.join(taskPath, c_taskJsonFile);
|
||||
const taskJson: any = await vm.validate(taskJsonPath, "no " + c_taskJsonFile + " in specified directory");
|
||||
|
||||
const archive = archiver("zip");
|
||||
archive.on("error", function(error) {
|
||||
trace.debug("Archiving error: " + error.message);
|
||||
error.message = "Archiving error: " + error.message;
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
archive.directory(path.resolve(taskPath), false);
|
||||
|
||||
archive.finalize();
|
||||
|
||||
sourceLocation = taskPath;
|
||||
taskId = taskJson.taskId;
|
||||
taskStream = archive;
|
||||
}
|
||||
|
||||
const collectionUrl: string = this.connection.getCollectionUrl();
|
||||
console.log("Collection URL: " + collectionUrl);
|
||||
const agentApi: ITaskAgentApi = await this.webApi.getTaskAgentApi(collectionUrl);
|
||||
|
||||
await agentApi.uploadTaskDefinition(null, taskStream, taskId, overwrite);
|
||||
trace.debug("Success");
|
||||
return <agentContracts.TaskDefinition> { sourceLocation: sourceLocation, };
|
||||
}
|
||||
|
||||
public friendlyOutput(data: agentContracts.TaskDefinition): void {
|
||||
|
|
Загрузка…
Ссылка в новой задаче