1+ import * as common from './common' ;
2+ import * as nodeApi from 'azure-devops-node-api' ;
3+
4+ import * as CoreApi from 'azure-devops-node-api/CoreApi'
5+ import * as CoreInterfaces from 'azure-devops-node-api/interfaces/CoreInterfaces'
6+ import * as WikiApi from 'azure-devops-node-api/WikiApi' ;
7+ import * as WikiInterfaces from 'azure-devops-node-api/interfaces/WikiInterfaces' ;
8+
9+ export async function run ( ) {
10+ let webApi : nodeApi . WebApi = await common . getWebApi ( ) ;
11+ let wikiApiObject : WikiApi . IWikiApi = await webApi . getWikiApi ( ) ;
12+ let coreApiObject : CoreApi . ICoreApi = await webApi . getCoreApi ( ) ;
13+
14+ common . banner ( 'Wiki Samples' ) ;
15+ let project : string = common . getProject ( ) ;
16+ let projectObject : CoreInterfaces . TeamProject = await coreApiObject . getProject ( project ) ;
17+ console . log ( 'Project:' , project ) ;
18+
19+ common . heading ( 'Get all wikis' ) ;
20+ const wikis : WikiInterfaces . WikiV2 [ ] = await wikiApiObject . getAllWikis ( project ) ;
21+ console . log ( "Wikis" , wikis . map ( ( wiki ) => wiki . name ) ) ;
22+
23+ let wikiId : string ;
24+ if ( wikis . length > 0 ) {
25+ wikiId = wikis [ 0 ] . id ;
26+ }
27+ else {
28+ common . heading ( "Create a wiki" ) ;
29+ const wikiParams : WikiInterfaces . WikiCreateParametersV2 = < WikiInterfaces . WikiCreateParametersV2 > { name : "Hello Wiki" , projectId : projectObject . id } ;
30+ const newWiki = await wikiApiObject . createWiki ( wikiParams , project ) ;
31+ console . log ( "Wiki created:" , newWiki . name ) ;
32+ wikiId = newWiki . id ;
33+ }
34+
35+ common . heading ( "Get the text from a wiki" ) ;
36+ const textStream : NodeJS . ReadableStream = await wikiApiObject . getPageText ( project , wikiId )
37+ console . log ( "Wiki text" , textStream . read ( ) . toString ( ) ) ;
38+
39+ if ( wikis . length == 0 ) {
40+ common . heading ( "Delete the created wiki" ) ;
41+ await wikiApiObject . deleteWiki ( wikiId , project ) ;
42+ console . log ( "Wiki deleted" ) ;
43+ }
44+ }
0 commit comments