add license metadata tag

This commit is contained in:
Joao Moreno 2015-10-14 11:27:26 +02:00
parent 37458356d4
commit 0d9d4822f5
3 changed files with 33 additions and 6 deletions

View file

@ -6,6 +6,7 @@
<Description xml:space="preserve">${ description }</Description> <Description xml:space="preserve">${ description }</Description>
<Tags>${ tags }</Tags> <Tags>${ tags }</Tags>
<GalleryFlags>Public</GalleryFlags> <GalleryFlags>Public</GalleryFlags>
<% if (license) { %><License>${ license }</License><% } %>
</Metadata> </Metadata>
<Installation> <Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Code"/> <InstallationTarget Id="Microsoft.VisualStudio.Code"/>

View file

@ -102,17 +102,19 @@ function getLicenseFilter(manifest:Manifest): (name: string) => boolean {
export function toVsixManifest(manifest: Manifest, files: IFile[]): Promise<string> { export function toVsixManifest(manifest: Manifest, files: IFile[]): Promise<string> {
const licenseFilter = getLicenseFilter(manifest); const licenseFilter = getLicenseFilter(manifest);
const assets = files.map<IAsset>(f => { const assets: IAsset[] = [];
let license: string = null;
files.forEach(f => {
if (/^extension\/README.md$/i.test(f.path)) { if (/^extension\/README.md$/i.test(f.path)) {
return { type: 'Microsoft.VisualStudio.Services.Content.Details', path: f.path }; assets.push({ type: 'Microsoft.VisualStudio.Services.Content.Details', path: f.path });
} }
if (licenseFilter(f.path)) { if (licenseFilter(f.path)) {
return { type: 'Microsoft.VisualStudio.Services.Content.License', path: f.path }; assets.push({ type: 'Microsoft.VisualStudio.Services.Content.License', path: f.path });
license = f.path;
} }
});
return null;
}).filter(f => !!f);
return readFile(vsixManifestTemplatePath, 'utf8') return readFile(vsixManifestTemplatePath, 'utf8')
.then(vsixManifestTemplateStr => _.template(vsixManifestTemplateStr)) .then(vsixManifestTemplateStr => _.template(vsixManifestTemplateStr))
@ -123,6 +125,7 @@ export function toVsixManifest(manifest: Manifest, files: IFile[]): Promise<stri
publisher: manifest.publisher, publisher: manifest.publisher,
description: manifest.description || '', description: manifest.description || '',
tags: (manifest.keywords || []).concat('vscode').join(';'), tags: (manifest.keywords || []).concat('vscode').join(';'),
license,
assets assets
})); }));
} }

View file

@ -134,6 +134,29 @@ describe('toVsixManifest', () => {
assert.equal(result.PackageManifest.Assets[0].Asset[1].$.Path, 'extension/thelicense.md'); assert.equal(result.PackageManifest.Assets[0].Asset[1].$.Path, 'extension/thelicense.md');
}); });
}); });
it('should add a license metadata tag', () => {
const manifest = {
name: 'test',
publisher: 'mocha',
version: '0.0.1',
description: 'test extension',
license: 'SEE LICENSE IN thelicense.md',
engines: Object.create(null)
};
const files = [
{ path: 'extension/thelicense.md' }
];
return toVsixManifest(manifest, files)
.then(xml => parseXml(xml))
.then(result => {
assert.ok(result.PackageManifest.Metadata[0].License);
assert.equal(result.PackageManifest.Metadata[0].License.length, 1);
assert.equal(result.PackageManifest.Metadata[0].License[0], 'extension/thelicense.md');
});
});
}); });
describe('toContentTypes', () => { describe('toContentTypes', () => {