Skip to content

Commit 505f2f3

Browse files
authored
Merge pull request microsoft#12035 from XVincentX/master
Provide a changelog tab when this file is bundled in the package
2 parents c81f130 + b98c3f7 commit 505f2f3

5 files changed

Lines changed: 63 additions & 9 deletions

File tree

src/vs/platform/extensionManagement/common/extensionManagement.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export interface ILocalExtension {
141141
metadata: IGalleryMetadata;
142142
path: string;
143143
readmeUrl: string;
144+
changelogUrl: string;
144145
}
145146

146147
export const IExtensionManagementService = createDecorator<IExtensionManagementService>('extensionManagementService');

src/vs/platform/extensionManagement/node/extensionManagementService.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ export class ExtensionManagementService implements IExtensionManagementService {
148148
const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0];
149149
const readmeUrl = readme ? URI.file(path.join(extensionPath, readme)).toString() : null;
150150

151-
const local: ILocalExtension = { id, manifest, metadata, path: extensionPath, readmeUrl };
151+
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
152+
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)).toString() : null;
153+
154+
const local: ILocalExtension = { id, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
152155
const rawManifest = assign(manifest, { __metadata: metadata });
153156

154157
return pfs.writeFile(manifestPath, JSON.stringify(rawManifest, null, '\t'))
@@ -200,9 +203,12 @@ export class ExtensionManagementService implements IExtensionManagementService {
200203
const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0];
201204
const readmeUrl = readme ? URI.file(path.join(extensionPath, readme)).toString() : null;
202205

206+
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
207+
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)).toString() : null;
208+
203209
return pfs.readFile(path.join(extensionPath, 'package.json'), 'utf8')
204210
.then(raw => parseManifest(raw))
205-
.then<ILocalExtension>(({ manifest, metadata }) => ({ id, manifest, metadata, path: extensionPath, readmeUrl }));
211+
.then<ILocalExtension>(({ manifest, metadata }) => ({ id, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl }));
206212
}).then(null, () => null);
207213

208214
return limiter.queue(each);

src/vs/workbench/parts/extensions/electron-browser/extensionEditor.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class NavBar {
9898

9999
const NavbarSection = {
100100
Readme: 'readme',
101-
Contributions: 'contributions'
101+
Contributions: 'contributions',
102+
Changelog: 'changelog'
102103
};
103104

104105
interface ILayoutParticipant {
@@ -124,6 +125,7 @@ export class ExtensionEditor extends BaseEditor {
124125
private highlightDisposable: IDisposable;
125126

126127
private extensionReadme: Cache<string>;
128+
private extensionChangelog: Cache<string>;
127129
private extensionManifest: Cache<IExtensionManifest>;
128130

129131
private layoutParticipants: ILayoutParticipant[] = [];
@@ -149,6 +151,7 @@ export class ExtensionEditor extends BaseEditor {
149151
this.highlightDisposable = empty;
150152
this.disposables = [];
151153
this.extensionReadme = null;
154+
this.extensionChangelog = null;
152155
this.extensionManifest = null;
153156
}
154157

@@ -200,6 +203,7 @@ export class ExtensionEditor extends BaseEditor {
200203
this.telemetryService.publicLog('extensionGallery:openExtension', extension.telemetryData);
201204

202205
this.extensionReadme = new Cache(() => extension.getReadme());
206+
this.extensionChangelog = new Cache(() => extension.getChangelog());
203207
this.extensionManifest = new Cache(() => extension.getManifest());
204208

205209
const onError = once(domEvent(this.icon, 'error'));
@@ -253,20 +257,25 @@ export class ExtensionEditor extends BaseEditor {
253257
this.navbar.push(NavbarSection.Readme, localize('details', "Details"));
254258
this.navbar.push(NavbarSection.Contributions, localize('contributions', "Contributions"));
255259

260+
if (extension.hasChangelog) {
261+
this.navbar.push(NavbarSection.Changelog, localize('changelog', "Changelog"));
262+
}
263+
256264
this.content.innerHTML = '';
257265

258266
return super.setInput(input, options);
259267
}
260268

261269
private onNavbarChange(extension: IExtension, id: string): void {
262270
switch (id) {
263-
case NavbarSection.Readme: return this.openReadme(extension);
264-
case NavbarSection.Contributions: return this.openContributions(extension);
271+
case NavbarSection.Readme: return this.openReadme();
272+
case NavbarSection.Contributions: return this.openContributions();
273+
case NavbarSection.Changelog: return this.openChangelog();
265274
}
266275
}
267276

268-
private openReadme(extension: IExtension) {
269-
return this.loadContents(() => this.extensionReadme.get()
277+
private openMarkdown(content: TPromise<string>, noContentCopy: string) {
278+
return this.loadContents(() => content
270279
.then(marked.parse)
271280
.then(renderBody)
272281
.then<void>(body => {
@@ -284,11 +293,19 @@ export class ExtensionEditor extends BaseEditor {
284293
})
285294
.then(null, () => {
286295
const p = append(this.content, $('p'));
287-
p.textContent = localize('noReadme', "No README available.");
296+
p.textContent = noContentCopy;
288297
}));
289298
}
290299

291-
private openContributions(extension: IExtension) {
300+
private openReadme() {
301+
return this.openMarkdown(this.extensionReadme.get(), localize('noReadme', "No README available."));
302+
}
303+
304+
private openChangelog() {
305+
return this.openMarkdown(this.extensionChangelog.get(), localize('noChangelog', "No CHANGELOG available."));
306+
}
307+
308+
private openContributions() {
292309
return this.loadContents(() => this.extensionManifest.get()
293310
.then(manifest => {
294311
this.content.innerHTML = '';

src/vs/workbench/parts/extensions/electron-browser/extensions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface IExtension {
4242
telemetryData: any;
4343
getManifest(): TPromise<IExtensionManifest>;
4444
getReadme(): TPromise<string>;
45+
hasChangelog : boolean;
46+
getChangelog() : TPromise<string>;
4547
}
4648

4749
export const SERVICE_ID = 'extensionsWorkbenchService';

src/vs/workbench/parts/extensions/electron-browser/extensionsWorkbenchService.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ class Extension implements IExtension {
9494
return this.gallery && this.gallery.assets.readme;
9595
}
9696

97+
get changelogUrl(): string {
98+
if (this.local && this.local.changelogUrl) {
99+
return this.local.changelogUrl;
100+
}
101+
102+
return ''; // Hopefully we will change this once the gallery will support that.
103+
}
104+
97105
get iconUrl(): string {
98106
return this.localIconUrl || this.galleryIconUrl || this.defaultIconUrl;
99107
}
@@ -178,6 +186,26 @@ class Extension implements IExtension {
178186

179187
return this.galleryService.getAsset(readmeUrl).then(asText);
180188
}
189+
190+
get hasChangelog() : boolean {
191+
return !!(this.local && this.local.changelogUrl ? this.local.changelogUrl : '');
192+
}
193+
194+
getChangelog() : TPromise<string> {
195+
const changelogUrl = this.local && this.local.changelogUrl ? this.local.changelogUrl : '';
196+
197+
if (!changelogUrl) {
198+
return TPromise.wrapError('not available');
199+
}
200+
201+
const uri = URI.parse(changelogUrl);
202+
203+
if (uri.scheme === 'file') {
204+
return readFile(uri.fsPath, 'utf8');
205+
}
206+
207+
return TPromise.wrapError('not available');
208+
}
181209
}
182210

183211
function stripVersion(id: string): string {

0 commit comments

Comments
 (0)