From 4d329cc759150824aee680d9c361e1a81df93f2f Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 9 Feb 2018 11:44:21 +0100 Subject: [PATCH] avoid hardcoded extensions list in update all grammars --- build/npm/update-all-grammars.js | 62 +++++++++----------------------- 1 file changed, 16 insertions(+), 46 deletions(-) diff --git a/build/npm/update-all-grammars.js b/build/npm/update-all-grammars.js index d05a182f31c..af2db363e6a 100644 --- a/build/npm/update-all-grammars.js +++ b/build/npm/update-all-grammars.js @@ -4,9 +4,11 @@ *--------------------------------------------------------------------------------------------*/ const cp = require('child_process'); -const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'; +const fs = require('fs'); +const path = require('path'); function updateGrammar(location) { + const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'; const result = cp.spawnSync(npm, ['run', 'update-grammar'], { cwd: location, stdio: 'inherit' @@ -17,50 +19,17 @@ function updateGrammar(location) { } } -const extensions = [ - 'bat', - 'clojure', - 'coffeescript', - 'cpp', - 'csharp', - 'css', - 'diff', - 'docker', - 'fsharp', - 'gitsyntax', - 'go', - 'groovy', - 'handlebars', - 'hlsl', - 'html', - 'ini', - 'java', - // 'javascript', updated through JavaScript - 'json', - 'less', - 'lua', - 'make', - 'markdown', - 'objective-c', - 'perl', - 'php', - 'powershell', - 'pug', - 'python', - 'r', - 'razor', - 'ruby', - 'rust', - 'scss', - 'shaderlab', - 'shellscript', - 'sql', - 'swift', - 'typescript', - 'vb', - 'xml', - 'yaml' -]; +const allExtensionFolders = fs.readdirSync('extensions'); +const extensions = allExtensionFolders.filter(e => { + try { + let packageJSON = JSON.parse(fs.readFileSync(path.join('extensions', e, 'package.json')).toString()); + return packageJSON && packageJSON.scripts && packageJSON.scripts['update-grammar']; + } catch (e) { + return false; + } +}); + +console.log(`Updating ${extensions.length} grammars...`); extensions.forEach(extension => updateGrammar(`extensions/${extension}`)); @@ -70,4 +39,5 @@ if (process.platform === 'win32') { cp.spawn('.\scripts\test-integration.bat', [], { env: process.env, stdio: 'inherit' }); } else { cp.spawn('/bin/bash', ['./scripts/test-integration.sh'], { env: process.env, stdio: 'inherit' }); -} \ No newline at end of file +} + -- GitLab