From 144911a9acdf7318f315c00333b6bc283f881c33 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Wed, 1 Jun 2016 11:24:43 +0200 Subject: [PATCH] detect keywords in description --- src/package.ts | 46 +++++++++++++++++++++++++++++++++++++++- src/test/package.test.ts | 25 +++++++++++++++++++--- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/package.ts b/src/package.ts index 3e88fb0..8d68479 100644 --- a/src/package.ts +++ b/src/package.ts @@ -120,6 +120,45 @@ class ManifestProcessor extends BaseProcessor { export class TagsProcessor extends BaseProcessor { + private static Keywords = { + 'git': ['git'], + 'npm': ['node'], + 'spell': ['markdown'], + 'bootstrap': ['bootstrap'], + 'lint': ['linters'], + 'linting': ['linters'], + 'react': ['javascript'], + 'js': ['javsacript'], + 'node': ['javascript', 'node'], + 'C plus plus': ['c++'], + 'Cplusplus': ['c++'], + 'xml': ['xml'], + 'angular': ['javascript'], + 'jquery': ['javascript'], + 'php': ['php'], + 'python': ['python'], + 'latex': ['latex'], + 'ruby': ['ruby'], + 'java': ['java'], + 'erlang': ['erlang'], + 'sql': ['sql'], + 'nodejs': ['node'], + 'c#': ['c#'], + 'css': ['css'], + 'javascript': ['javascript'], + 'ftp': ['ftp'], + 'haskell': ['haskell'], + 'unity': ['unity'], + 'terminal': ['terminal'], + 'powershell': ['powershell'], + 'laravel': ['laravel'], + 'meteor': ['meteor'], + 'emmet': ['emmet'], + 'eslint': ['linters'], + 'tfs': ['tfs'], + 'rust': ['rust'] + }; + onEnd(): Promise { const keywords = this.manifest.keywords || []; const trimmedKeywords = keywords.slice(0, 5); @@ -150,6 +189,10 @@ export class TagsProcessor extends BaseProcessor { .filter(r => !!r) .map(r => r[1]); + const description = this.manifest.description || ''; + const descriptionKeywords = Object.keys(TagsProcessor.Keywords) + .reduce((r, k) => r.concat(new RegExp(k, 'gi').test(description) ? TagsProcessor.Keywords[k] : []), []); + keywords = [ ...keywords, ...themes, @@ -158,7 +201,8 @@ export class TagsProcessor extends BaseProcessor { ...debuggers, ...json, ...languageContributions, - ...languageActivations + ...languageActivations, + ...descriptionKeywords ]; this.vsix.tags = _.unique(keywords).join(','); diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 04fb327..9a51003 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -536,7 +536,7 @@ describe('toVsixManifest', () => { return _toVsixManifest(manifest, []) .then(parseXml) .then(result => { - const tags = result.PackageManifest.Metadata[0].Tags as string[]; + const tags = result.PackageManifest.Metadata[0].Tags[0].split(',') as string[]; assert(tags.some(tag => tag === 'keybindings')); }); }); @@ -561,7 +561,7 @@ describe('toVsixManifest', () => { return _toVsixManifest(manifest, []) .then(parseXml) .then(result => { - const tags = result.PackageManifest.Metadata[0].Tags as string[]; + const tags = result.PackageManifest.Metadata[0].Tags[0].split(',') as string[]; assert(tags.some(tag => tag === 'debuggers')); }); }); @@ -583,10 +583,29 @@ describe('toVsixManifest', () => { return _toVsixManifest(manifest, []) .then(parseXml) .then(result => { - const tags = result.PackageManifest.Metadata[0].Tags as string[]; + const tags = result.PackageManifest.Metadata[0].Tags[0].split(',') as string[]; assert(tags.some(tag => tag === 'json')); }); }); + + it('should detect keywords in description', () => { + const manifest = { + name: 'test', + publisher: 'mocha', + version: '0.0.1', + engines: Object.create(null), + description: 'This C plus plus extension likes combines ftp with javascript' + }; + + return _toVsixManifest(manifest, []) + .then(parseXml) + .then(result => { + const tags = result.PackageManifest.Metadata[0].Tags[0].split(',') as string[]; + assert(tags.some(tag => tag === 'c++'), 'detect c++'); + assert(tags.some(tag => tag === 'ftp'), 'detect ftp'); + assert(tags.some(tag => tag === 'javascript'), 'detect javascript'); + }); + }); }); describe('toContentTypes', () => {