handle license files

This commit is contained in:
Joao Moreno 2015-10-13 17:53:25 +02:00
parent acfb3657a1
commit bd4033b68f
2 changed files with 39 additions and 0 deletions

View file

@ -87,12 +87,29 @@ function prepublish(cwd: string, manifest: Manifest): Promise<Manifest> {
.catch(err => Promise.reject(err.message));
}
function getLicenseFilter(manifest:Manifest): (name: string) => boolean {
const match = /^SEE LICENSE IN (.*)$/.exec(manifest.license || '');
if (!match || !match[1]) {
return () => false;
}
const regexp = new RegExp('^extension/' + match[1] + '$');
return regexp.test.bind(regexp);
}
export function toVsixManifest(manifest: Manifest, files: IFile[]): Promise<string> {
const licenseFilter = getLicenseFilter(manifest);
const assets = files.map<IAsset>(f => {
if (/^extension\/README.md$/i.test(f.path)) {
return { type: 'Microsoft.VisualStudio.Services.Content.Details', path: f.path };
}
if (licenseFilter(f.path)) {
return { type: 'Microsoft.VisualStudio.Services.Content.License', path: f.path };
}
return null;
}).filter(f => !!f);

View file

@ -118,4 +118,26 @@ describe('toVsixManifest', () => {
assert.equal(result.PackageManifest.Assets[0].Asset[1].$.Path, 'extension/readme.md');
});
});
it('should treat any license file as asset', () => {
const manifest = {
name: 'test',
publisher: 'mocha',
version: '0.0.1',
description: 'test extension',
license: 'SEE LICENSE IN thelicense.md'
};
const files = [
{ path: 'extension/thelicense.md' }
];
return toVsixManifest(manifest, files)
.then(xml => parseXml(xml))
.then(result => {
assert.equal(result.PackageManifest.Assets[0].Asset.length, 2);
assert.equal(result.PackageManifest.Assets[0].Asset[1].$.Type, 'Microsoft.VisualStudio.Services.Content.License');
assert.equal(result.PackageManifest.Assets[0].Asset[1].$.Path, 'extension/thelicense.md');
});
});
});