From f26f3983001fcd406c4064b8f8414a7d325e6215 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 15 Apr 2016 12:30:26 +0200 Subject: [PATCH] add theme tag automatically related to #83 --- src/package.ts | 15 ++++++++++--- src/test/package.test.ts | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/package.ts b/src/package.ts index bcb95a3..ced035b 100644 --- a/src/package.ts +++ b/src/package.ts @@ -124,15 +124,24 @@ export class TagsProcessor extends BaseProcessor { const keywords = this.manifest.keywords || []; const trimmedKeywords = keywords.slice(0, 5); - let promise = Promise.resolve(null); + let promise = Promise.resolve(trimmedKeywords); if (keywords.length > 5) { console.warn(`The keyword list is limited to 5 keywords; only the following keywords will be in your extension: [${ trimmedKeywords.join(', ') }].`); promise = util.read('Do you want to continue? [y/N] ') - .then(answer => /^y$/i.test(answer) ? Promise.resolve(null) : Promise.reject('Aborted')); + .then(answer => /^y$/i.test(answer) ? Promise.resolve(trimmedKeywords) : Promise.reject('Aborted')); } - return promise.then(() => this.vsix.tags = trimmedKeywords.join(',')); + return promise.then(keywords => { + const contributes = this.manifest.contributes; + const themes = contributes && contributes['themes']; + + if (themes && themes.length > 0) { + keywords = [...keywords, 'theme']; + } + + this.vsix.tags = _.unique(keywords).join(','); + }); } } diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 5ae6c2a..c3ea8fe 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -427,6 +427,52 @@ describe('toVsixManifest', () => { assert.deepEqual(result.PackageManifest.Metadata[0].GalleryFlags, ['Public Preview']); }); }); + + it('should automatically add theme tag', () => { + const manifest = { + name: 'test', + publisher: 'mocha', + version: '0.0.1', + engines: Object.create(null), + contributes: { + themes: [{ label: 'monokai', uiTheme: 'vs', path: 'monokai.tmTheme' }] + } + }; + + return _toVsixManifest(manifest, []) + .then(parseXml) + .then(result => assert.deepEqual(result.PackageManifest.Metadata[0].Tags, ['theme'])); + }); + + it('should not automatically add theme tag when themes are empty', () => { + const manifest = { + name: 'test', + publisher: 'mocha', + version: '0.0.1', + engines: Object.create(null), + contributes: { + themes: [] + } + }; + + return _toVsixManifest(manifest, []) + .then(parseXml) + .then(result => assert.deepEqual(result.PackageManifest.Metadata[0].Tags, [''])); + }); + + it('should remove duplicate tags', () => { + const manifest = { + name: 'test', + publisher: 'mocha', + version: '0.0.1', + engines: Object.create(null), + keywords: ['theme', 'theme'] + }; + + return _toVsixManifest(manifest, []) + .then(parseXml) + .then(result => assert.deepEqual(result.PackageManifest.Metadata[0].Tags, ['theme'])); + }); }); describe('toContentTypes', () => {