2018-12-13 17:37:10 +03:00
|
|
|
import * as common from "./common";
|
|
|
|
import * as nodeApi from "azure-devops-node-api";
|
2018-09-12 21:51:55 +03:00
|
|
|
|
2018-12-13 17:37:10 +03:00
|
|
|
import * as CoreApi from "azure-devops-node-api/CoreApi"
|
|
|
|
import * as CoreInterfaces from "azure-devops-node-api/interfaces/CoreInterfaces"
|
|
|
|
import * as WikiApi from "azure-devops-node-api/WikiApi";
|
|
|
|
import * as WikiInterfaces from "azure-devops-node-api/interfaces/WikiInterfaces";
|
2018-09-12 21:51:55 +03:00
|
|
|
|
|
|
|
export async function run() {
|
2018-09-12 23:17:02 +03:00
|
|
|
const webApi: nodeApi.WebApi = await common.getWebApi();
|
|
|
|
const wikiApiObject: WikiApi.IWikiApi = await webApi.getWikiApi();
|
|
|
|
const coreApiObject: CoreApi.ICoreApi = await webApi.getCoreApi();
|
2018-09-12 21:51:55 +03:00
|
|
|
|
2018-12-13 17:37:10 +03:00
|
|
|
common.banner("Wiki Samples");
|
|
|
|
const project = common.getProject();
|
2018-09-12 23:17:02 +03:00
|
|
|
const projectObject: CoreInterfaces.TeamProject = await coreApiObject.getProject(project);
|
2018-12-13 17:37:10 +03:00
|
|
|
console.log("Project:", project);
|
2018-09-12 21:51:55 +03:00
|
|
|
|
2018-12-13 17:37:10 +03:00
|
|
|
common.heading("Get all wikis");
|
2018-09-12 21:51:55 +03:00
|
|
|
const wikis: WikiInterfaces.WikiV2[] = await wikiApiObject.getAllWikis(project);
|
|
|
|
console.log("Wikis", wikis.map((wiki) => wiki.name));
|
|
|
|
|
|
|
|
let wikiId: string;
|
2018-12-13 17:37:10 +03:00
|
|
|
const createNewWiki = (wikis.length === 0);
|
2018-09-12 23:17:02 +03:00
|
|
|
if (createNewWiki) {
|
2018-09-12 21:51:55 +03:00
|
|
|
common.heading("Create a wiki");
|
|
|
|
const wikiParams: WikiInterfaces.WikiCreateParametersV2 = <WikiInterfaces.WikiCreateParametersV2>{name: "Hello Wiki", projectId: projectObject.id};
|
|
|
|
const newWiki = await wikiApiObject.createWiki(wikiParams, project);
|
|
|
|
console.log("Wiki created:", newWiki.name);
|
|
|
|
wikiId = newWiki.id;
|
2018-09-12 23:17:02 +03:00
|
|
|
} else {
|
|
|
|
wikiId = wikis[0].id;
|
2018-09-12 21:51:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
common.heading("Get the text from a wiki");
|
2018-09-12 23:17:02 +03:00
|
|
|
const pageText: NodeJS.ReadableStream = await wikiApiObject.getPageText(project, wikiId)
|
|
|
|
console.log("Wiki text", pageText.read().toString());
|
2018-09-12 21:51:55 +03:00
|
|
|
|
2018-09-12 23:17:02 +03:00
|
|
|
if (createNewWiki) {
|
2018-09-12 21:51:55 +03:00
|
|
|
common.heading("Delete the created wiki");
|
2018-09-12 23:17:02 +03:00
|
|
|
const deletedWiki: WikiInterfaces.WikiV2 = await wikiApiObject.deleteWiki(wikiId, project);
|
|
|
|
console.log("Wiki", deletedWiki.name, "deleted");
|
2018-09-12 21:51:55 +03:00
|
|
|
}
|
|
|
|
}
|