flow files through. fixes #22
This commit is contained in:
parent
482c5f8a2b
commit
c6d9aabfd0
2 changed files with 54 additions and 37 deletions
|
@ -262,23 +262,10 @@ export function readManifest(cwd: string): Promise<Manifest> {
|
|||
});
|
||||
}
|
||||
|
||||
export function toVsixManifest(manifest: Manifest, files: IFile[], options: IPackageOptions = {}): Promise<string> {
|
||||
const processors: IProcessor[] = [
|
||||
new MainProcessor(manifest),
|
||||
new ReadmeProcessor(manifest, options),
|
||||
new LicenseProcessor(manifest),
|
||||
new IconProcessor(manifest)
|
||||
];
|
||||
|
||||
return Promise.all(files.map(file => util.chain(file, processors, (file, processor) => processor.onFile(file))))
|
||||
.then(files => {
|
||||
const assets = _.flatten(processors.map(p => p.assets));
|
||||
const vsix = (<any> _.assign)({ assets }, ...processors.map(p => p.vsix));
|
||||
|
||||
export function toVsixManifest(assets: IAsset[], vsix: any, options: IPackageOptions = {}): Promise<string> {
|
||||
return readFile(vsixManifestTemplatePath, 'utf8')
|
||||
.then(vsixManifestTemplateStr => _.template(vsixManifestTemplateStr))
|
||||
.then(vsixManifestTemplate => vsixManifestTemplate(vsix));
|
||||
});
|
||||
}
|
||||
|
||||
export function toContentTypes(files: IFile[]): Promise<string> {
|
||||
|
@ -319,20 +306,38 @@ function collectFiles(cwd: string, manifest: Manifest): Promise<string[]> {
|
|||
});
|
||||
}
|
||||
|
||||
export function processFiles(processors: IProcessor[], files: IFile[], options: IPackageOptions = {}): Promise<IFile[]> {
|
||||
return Promise.all(files.map(file => util.chain(file, processors, (file, processor) => processor.onFile(file)))).then(files => {
|
||||
const assets = _.flatten(processors.map(p => p.assets));
|
||||
const vsix = (<any> _.assign)({ assets }, ...processors.map(p => p.vsix));
|
||||
|
||||
return Promise.all([toVsixManifest(assets, vsix, options), toContentTypes(files)]).then(result => {
|
||||
return [
|
||||
{ path: 'extension.vsixmanifest', contents: new Buffer(result[0], 'utf8') },
|
||||
{ path: '[Content_Types].xml', contents: new Buffer(result[1], 'utf8') },
|
||||
...files
|
||||
];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function createDefaultProcessors(manifest: Manifest, options: IPackageOptions = {}): IProcessor[] {
|
||||
return [
|
||||
new MainProcessor(manifest),
|
||||
new ReadmeProcessor(manifest, options),
|
||||
new LicenseProcessor(manifest),
|
||||
new IconProcessor(manifest)
|
||||
];
|
||||
}
|
||||
|
||||
export function collect(manifest: Manifest, options: IPackageOptions = {}): Promise<IFile[]> {
|
||||
const cwd = options.cwd || process.cwd();
|
||||
const processors = createDefaultProcessors(manifest, options);
|
||||
|
||||
return collectFiles(cwd, manifest).then(fileNames => {
|
||||
const files:IFile[] = fileNames.map(f => ({ path: `extension/${ f }`, localPath: path.join(cwd, f) }));
|
||||
|
||||
return Promise.all([toVsixManifest(manifest, files, options), toContentTypes(files)])
|
||||
.then(result => {
|
||||
return [
|
||||
{ path: 'extension.vsixmanifest', contents: new Buffer(result[0], 'utf8') },
|
||||
{ path: '[Content_Types].xml', contents: new Buffer(result[1], 'utf8') },
|
||||
...files
|
||||
];
|
||||
});
|
||||
const files = fileNames.map(f => ({ path: `extension/${ f }`, localPath: path.join(cwd, f) }));
|
||||
|
||||
return processFiles(processors, files, options);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -378,7 +383,7 @@ export function pack(options: IPackageOptions = {}): Promise<IPackageResult> {
|
|||
|
||||
return readManifest(cwd)
|
||||
.then(manifest => prepublish(cwd, manifest))
|
||||
.then(manifest => collect(manifest, options)
|
||||
.then(manifest => collect(manifest)
|
||||
.then(files => writeVsix(files, path.resolve(options.packagePath || defaultPackagePath(cwd, manifest)))
|
||||
.then(packagePath => ({ manifest, packagePath }))));
|
||||
}
|
||||
|
|
|
@ -1,15 +1,27 @@
|
|||
import { readManifest, collect, toVsixManifest, toContentTypes, ReadmeProcessor, read } from '../package';
|
||||
import { readManifest, collect, toContentTypes, ReadmeProcessor, read, processFiles, createDefaultProcessors, toVsixManifest, IFile } from '../package';
|
||||
import { Manifest } from '../manifest';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as assert from 'assert';
|
||||
import { parseString } from 'xml2js';
|
||||
import * as denodeify from 'denodeify';
|
||||
import * as util from '../util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
const readFile = denodeify<string, string, string>(fs.readFile);
|
||||
const parseXml = denodeify<string,any>(parseString);
|
||||
const fixture = name => path.join(__dirname, 'fixtures', name);
|
||||
|
||||
function _toVsixManifest(manifest: Manifest, files: IFile[]): Promise<string> {
|
||||
const processors = createDefaultProcessors(manifest);
|
||||
return processFiles(processors, files).then(() => {
|
||||
const assets = _.flatten(processors.map(p => p.assets));
|
||||
const vsix = (<any> _.assign)({ assets }, ...processors.map(p => p.vsix));
|
||||
|
||||
return toVsixManifest(assets, vsix);
|
||||
});
|
||||
}
|
||||
|
||||
describe('collect', () => {
|
||||
|
||||
it('should catch all files', () => {
|
||||
|
@ -63,7 +75,7 @@ describe('toVsixManifest', () => {
|
|||
engines: Object.create(null)
|
||||
};
|
||||
|
||||
return toVsixManifest(manifest, [])
|
||||
return _toVsixManifest(manifest, [])
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.ok(result);
|
||||
|
@ -105,7 +117,7 @@ describe('toVsixManifest', () => {
|
|||
{ path: 'extension/readme.md' }
|
||||
];
|
||||
|
||||
return toVsixManifest(manifest, files)
|
||||
return _toVsixManifest(manifest, files)
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.equal(result.PackageManifest.Assets[0].Asset.length, 2);
|
||||
|
@ -123,7 +135,7 @@ describe('toVsixManifest', () => {
|
|||
engines: Object.create(null)
|
||||
};
|
||||
|
||||
return toVsixManifest(manifest, [])
|
||||
return _toVsixManifest(manifest, [])
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.equal(result.PackageManifest.Metadata[0].Identity[0].$.Id, 'test');
|
||||
|
@ -145,7 +157,7 @@ describe('toVsixManifest', () => {
|
|||
{ path: 'extension/thelicense.md' }
|
||||
];
|
||||
|
||||
return toVsixManifest(manifest, files)
|
||||
return _toVsixManifest(manifest, files)
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.equal(result.PackageManifest.Assets[0].Asset.length, 2);
|
||||
|
@ -168,7 +180,7 @@ describe('toVsixManifest', () => {
|
|||
{ path: 'extension/thelicense.md' }
|
||||
];
|
||||
|
||||
return toVsixManifest(manifest, files)
|
||||
return _toVsixManifest(manifest, files)
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.ok(result.PackageManifest.Metadata[0].License);
|
||||
|
@ -193,7 +205,7 @@ describe('toVsixManifest', () => {
|
|||
{ path: 'extension/thelicense.md' }
|
||||
];
|
||||
|
||||
return toVsixManifest(manifest, files)
|
||||
return _toVsixManifest(manifest, files)
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.ok(result.PackageManifest.Metadata[0].Icon);
|
||||
|
@ -217,7 +229,7 @@ describe('toVsixManifest', () => {
|
|||
{ path: 'extension/fake.png' }
|
||||
];
|
||||
|
||||
return toVsixManifest(manifest, files)
|
||||
return _toVsixManifest(manifest, files)
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.ok(result.PackageManifest.Assets[0].Asset.some(d => d.$.Type === 'Microsoft.VisualStudio.Services.Icons.Default' && d.$.Path === 'extension/fake.png'));
|
||||
|
@ -240,7 +252,7 @@ describe('toVsixManifest', () => {
|
|||
{ path: 'extension\\thelicense.md' }
|
||||
];
|
||||
|
||||
return toVsixManifest(manifest, files)
|
||||
return _toVsixManifest(manifest, files)
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
assert.ok(result.PackageManifest.Metadata[0].Icon);
|
||||
|
@ -262,7 +274,7 @@ describe('toVsixManifest', () => {
|
|||
}
|
||||
};
|
||||
|
||||
return toVsixManifest(manifest, [])
|
||||
return _toVsixManifest(manifest, [])
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
const properties = result.PackageManifest.Metadata[0].Properties[0].Property.map(p => p.$);
|
||||
|
@ -287,7 +299,7 @@ describe('toVsixManifest', () => {
|
|||
homepage: "https://github.com/Microsoft/vscode-spell-check",
|
||||
};
|
||||
|
||||
return toVsixManifest(manifest, [])
|
||||
return _toVsixManifest(manifest, [])
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
const properties = result.PackageManifest.Metadata[0].Properties[0].Property.map(p => p.$);
|
||||
|
@ -308,7 +320,7 @@ describe('toVsixManifest', () => {
|
|||
categories: ['hello', 'world']
|
||||
};
|
||||
|
||||
return toVsixManifest(manifest, [])
|
||||
return _toVsixManifest(manifest, [])
|
||||
.then(xml => parseXml(xml))
|
||||
.then(result => {
|
||||
const categories = result.PackageManifest.Metadata[0].Categories[0].split(',');
|
||||
|
|
Loading…
Add table
Reference in a new issue