treat readme.md as asset

This commit is contained in:
Joao Moreno 2015-10-13 17:43:06 +02:00
parent 91c2dbe8f2
commit acfb3657a1
3 changed files with 50 additions and 11 deletions

View file

@ -12,6 +12,7 @@
</Installation> </Installation>
<Dependencies/> <Dependencies/>
<Assets> <Assets>
<Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json"/> <Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" />
<% _.forEach(assets, function (asset) { %><Asset Type="${ asset.type }" Path="${ asset.path }" /><% }); %>
</Assets> </Assets>
</PackageManifest> </PackageManifest>

View file

@ -27,6 +27,11 @@ export interface IPackageResult {
packagePath: string; packagePath: string;
} }
export interface IAsset {
type: string;
path: string;
}
function validateManifest(manifest: Manifest): Promise<Manifest> { function validateManifest(manifest: Manifest): Promise<Manifest> {
if (!manifest.publisher) { if (!manifest.publisher) {
return Promise.reject('Manifest missing field: publisher'); return Promise.reject('Manifest missing field: publisher');
@ -82,7 +87,15 @@ function prepublish(cwd: string, manifest: Manifest): Promise<Manifest> {
.catch(err => Promise.reject(err.message)); .catch(err => Promise.reject(err.message));
} }
export function toVsixManifest(manifest: Manifest): Promise<string> { export function toVsixManifest(manifest: Manifest, files: IFile[]): Promise<string> {
const assets = files.map<IAsset>(f => {
if (/^extension\/README.md$/i.test(f.path)) {
return { type: 'Microsoft.VisualStudio.Services.Content.Details', path: f.path };
}
return null;
}).filter(f => !!f);
return readFile(vsixManifestTemplatePath, 'utf8') return readFile(vsixManifestTemplatePath, 'utf8')
.then(vsixManifestTemplateStr => _.template(vsixManifestTemplateStr)) .then(vsixManifestTemplateStr => _.template(vsixManifestTemplateStr))
.then(vsixManifestTemplate => vsixManifestTemplate({ .then(vsixManifestTemplate => vsixManifestTemplate({
@ -92,7 +105,7 @@ export function toVsixManifest(manifest: Manifest): Promise<string> {
publisher: manifest.publisher, publisher: manifest.publisher,
description: manifest.description || '', description: manifest.description || '',
tags: (manifest.keywords || []).concat('vscode').join(';'), tags: (manifest.keywords || []).concat('vscode').join(';'),
assets: [] assets
})); }));
} }
@ -122,13 +135,17 @@ function collectFiles(cwd: string, manifest: Manifest): Promise<string[]> {
} }
export function collect(cwd: string, manifest: Manifest): Promise<IFile[]> { export function collect(cwd: string, manifest: Manifest): Promise<IFile[]> {
return Promise.all<any>([toVsixManifest(manifest), collectFiles(cwd, manifest)]) return collectFiles(cwd, manifest).then(fileNames => {
.then<{ vsixManifest: string; files: string[]; }>(promises => <any> _.indexBy(promises, (o,i) => i ? 'files' : 'vsixManifest')) const files = fileNames.map(f => ({ path: `extension/${ f }`, localPath: path.join(cwd, f) }));
.then(({ vsixManifest, files }) => [
{ path: 'extension.vsixmanifest', contents: new Buffer(vsixManifest, 'utf8') }, return toVsixManifest(manifest, files).then(vsixManifest => {
{ path: '[Content_Types].xml', localPath: path.join(resourcesPath, '[Content_Types].xml') }, return [
...files.map(f => ({ path: `extension/${ f }`, localPath: path.join(cwd, f) })) { path: 'extension.vsixmanifest', contents: new Buffer(vsixManifest, 'utf8') },
]); { path: '[Content_Types].xml', localPath: path.join(resourcesPath, '[Content_Types].xml') },
...files
];
});
});
} }
function writeVsix(files: IFile[], packagePath: string): Promise<string> { function writeVsix(files: IFile[], packagePath: string): Promise<string> {

View file

@ -69,7 +69,7 @@ describe('toVsixManifest', () => {
description: 'test extension' description: 'test extension'
}; };
return toVsixManifest(manifest) return toVsixManifest(manifest, [])
.then(xml => parseXml(xml)) .then(xml => parseXml(xml))
.then(result => { .then(result => {
assert.ok(result); assert.ok(result);
@ -97,4 +97,25 @@ describe('toVsixManifest', () => {
assert.equal(result.PackageManifest.Assets[0].Asset[0].$.Path, 'extension/package.json'); assert.equal(result.PackageManifest.Assets[0].Asset[0].$.Path, 'extension/package.json');
}); });
}); });
it('should treat README.md as asset', () => {
const manifest = {
name: 'test',
publisher: 'mocha',
version: '0.0.1',
description: 'test extension'
};
const files = [
{ path: 'extension/readme.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.Details');
assert.equal(result.PackageManifest.Assets[0].Asset[1].$.Path, 'extension/readme.md');
});
});
}); });