Autogenerate language configuration map

This commit is contained in:
4086606 2021-06-28 17:55:39 +01:00
parent 6b4e2d9d85
commit b48d6fd7c5
No known key found for this signature in database
GPG Key ID: 3625C5B3FD573E70
18 changed files with 523 additions and 330 deletions

5
.editorconfig Normal file
View File

@ -0,0 +1,5 @@
[*]
end_of_line = crlf
insert_final_newline = true
indent_style = space
indent_size = 2

8
.gitignore vendored
View File

@ -3,9 +3,11 @@ temp/
.vscode/
material-icons-github-chrome-extension.zip
material-icons-firefox-extension.zip
src/iconsCache.js
src/iconMap.json
optimizedSVGs/
src/icon-cache.js
src/icon-map.json
src/language-map.json
svg/
data/
# Logs
logs

152
package-lock.json generated
View File

@ -1261,6 +1261,108 @@
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==",
"dev": true
},
"@octokit/auth-token": {
"version": "2.4.5",
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.5.tgz",
"integrity": "sha512-BpGYsPgJt05M7/L/5FoE1PiAbdxXFZkX/3kDYcsvd1v6UhlnE5e96dTDr0ezX/EFwciQxf3cNV0loipsURU+WA==",
"dev": true,
"requires": {
"@octokit/types": "^6.0.3"
}
},
"@octokit/core": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.5.1.tgz",
"integrity": "sha512-omncwpLVxMP+GLpLPgeGJBF6IWJFjXDS5flY5VbppePYX9XehevbDykRH9PdCdvqt9TS5AOTiDide7h0qrkHjw==",
"dev": true,
"requires": {
"@octokit/auth-token": "^2.4.4",
"@octokit/graphql": "^4.5.8",
"@octokit/request": "^5.6.0",
"@octokit/request-error": "^2.0.5",
"@octokit/types": "^6.0.3",
"before-after-hook": "^2.2.0",
"universal-user-agent": "^6.0.0"
}
},
"@octokit/endpoint": {
"version": "6.0.12",
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.12.tgz",
"integrity": "sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==",
"dev": true,
"requires": {
"@octokit/types": "^6.0.3",
"is-plain-object": "^5.0.0",
"universal-user-agent": "^6.0.0"
},
"dependencies": {
"is-plain-object": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
"integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==",
"dev": true
}
}
},
"@octokit/graphql": {
"version": "4.6.4",
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.6.4.tgz",
"integrity": "sha512-SWTdXsVheRmlotWNjKzPOb6Js6tjSqA2a8z9+glDJng0Aqjzti8MEWOtuT8ZSu6wHnci7LZNuarE87+WJBG4vg==",
"dev": true,
"requires": {
"@octokit/request": "^5.6.0",
"@octokit/types": "^6.0.3",
"universal-user-agent": "^6.0.0"
}
},
"@octokit/openapi-types": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-7.3.5.tgz",
"integrity": "sha512-6bm5lzGDOeSnWHM5W8OZ86RD2KpchynU+/Qlm5hNEFjfLDhwfAY2lSe68YRUEYFGlxSHe0HmakyhvmtWoD3Zog==",
"dev": true
},
"@octokit/request": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.0.tgz",
"integrity": "sha512-4cPp/N+NqmaGQwbh3vUsYqokQIzt7VjsgTYVXiwpUP2pxd5YiZB2XuTedbb0SPtv9XS7nzAKjAuQxmY8/aZkiA==",
"dev": true,
"requires": {
"@octokit/endpoint": "^6.0.1",
"@octokit/request-error": "^2.1.0",
"@octokit/types": "^6.16.1",
"is-plain-object": "^5.0.0",
"node-fetch": "^2.6.1",
"universal-user-agent": "^6.0.0"
},
"dependencies": {
"is-plain-object": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
"integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==",
"dev": true
}
}
},
"@octokit/request-error": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz",
"integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==",
"dev": true,
"requires": {
"@octokit/types": "^6.0.3",
"deprecation": "^2.0.0",
"once": "^1.4.0"
}
},
"@octokit/types": {
"version": "6.16.7",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.16.7.tgz",
"integrity": "sha512-OuQELiwIKeDySgNID52vm33wDRc2aaX8lKYgAw9Hmw939ITow1HspT8/AH3M3jgGFUMDmHlMNBNEmH7xV7ggXQ==",
"dev": true,
"requires": {
"@octokit/openapi-types": "^7.3.5"
}
},
"@parcel/fs": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/@parcel/fs/-/fs-1.11.0.tgz",
@ -1593,6 +1695,20 @@
"dev": true,
"optional": true
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
@ -2268,6 +2384,12 @@
"integrity": "sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=",
"dev": true
},
"before-after-hook": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz",
"integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==",
"dev": true
},
"binary-extensions": {
"version": "1.13.1",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz",
@ -4031,6 +4153,12 @@
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=",
"dev": true
},
"deprecation": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz",
"integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==",
"dev": true
},
"des.js": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz",
@ -5649,6 +5777,12 @@
"integrity": "sha512-0Bk1AsliuYB550zr4JV9AYhsETsD3ELXUQzdXGJfIc1Ni/ukAfBdQInDhVMYJUaT2QxoamNslwkYF7MlOrPUwg==",
"dev": true
},
"follow-redirects": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz",
"integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==",
"dev": true
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
@ -5871,9 +6005,9 @@
}
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"version": "7.1.7",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz",
"integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
@ -8080,6 +8214,12 @@
"integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==",
"dev": true
},
"node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==",
"dev": true
},
"node-forge": {
"version": "0.7.6",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.6.tgz",
@ -11641,6 +11781,12 @@
"crypto-random-string": "^2.0.0"
}
},
"universal-user-agent": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz",
"integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==",
"dev": true
},
"universalify": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",

View File

@ -2,26 +2,31 @@
"name": "material-icons-github-chrome-extension",
"version": "1.4.0",
"description": "Chrome Extension that enhances the GitHub file browser with material icons",
"main": "index.js",
"main": "src/main.js",
"scripts": {
"build": "npx rimraf ./dist && npx run-s build-dependencies build-src bundle",
"build": "npx rimraf ./dist && npx run-s build-dependencies build-languages build-src bundle",
"build-dependencies": "node ./scripts/build-dependencies.js",
"build-languages": "node ./scripts/build-languages.js",
"build-src": "node ./scripts/build-src.js",
"rebuild-logos": "node ./scripts/build-extensionIcons.js",
"rebuild-logos": "node ./scripts/build-icons.js",
"bundle": "run-p bundle-chrome bundle-firefox",
"bundle-chrome": "7z a material-icons-github-chrome-extension.zip dist",
"bundle-firefox": "web-ext -s ./dist/ -n material-icons-firefox-extension.zip -a . build",
"parcel": "parcel build ./src/main.js"
},
"author": "",
"author": "Claudiohbsantos",
"devDependencies": {
"@octokit/core": "^3.5.1",
"eslint": "^7.2.0",
"eslint-config": "^0.3.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.14.0",
"eslint-plugin-prettier": "^3.1.4",
"follow-redirects": "^1.14.1",
"fs-extra": "^9.0.1",
"mkdirp": "^1.0.4",
"glob": "^7.1.7",
"json-stable-stringify": "^1.0.1",
"make-dir": "^3.1.0",
"node-html-parser": "^2.0.1",
"npm-run-all": "^4.1.5",
"parcel-bundler": "^1.12.4",

View File

@ -1,11 +1,13 @@
const git = require('simple-git')();
const child_process = require('child_process');
const simpleGit = require('simple-git');
const cp = require('child_process');
const path = require('path');
const mkdirp = require('mkdirp');
const fs = require('fs-extra');
const rimraf = require('rimraf');
const destSVGPath = path.resolve(__dirname, '..', 'optimizedSVGs');
const git = simpleGit();
const destSVGPath = path.resolve(__dirname, '..', 'svg');
const vsExtPath = path.resolve(__dirname, '..', 'temp');
const srcPath = path.resolve(__dirname, '..', 'src');
@ -14,16 +16,28 @@ const srcPath = path.resolve(__dirname, '..', 'src');
rimraf.sync(vsExtPath);
rimraf.sync(destSVGPath);
mkdirp(destSVGPath)
.then(() => git.clone(`https://github.com/PKief/vscode-material-icon-theme.git`, 'temp'))
.then(() => {
console.log('[1/7] Cloning PKief/vscode-material-icon-theme into temporary cache.');
return git.clone(`https://github.com/PKief/vscode-material-icon-theme.git`, 'temp');
})
.then(() => {
console.log('[2/7] Terminate Git repository in temporary cache.');
return rimraf.sync(path.resolve(vsExtPath, '.git'));
})
.then(npmInstallExt)
.then(() => fs.copy(path.resolve(vsExtPath, 'icons'), path.resolve(destSVGPath)))
.then(() => {
console.log('[4/7] Terminate Git tracking in temporary cache.');
return fs.copy(path.resolve(vsExtPath, 'icons'), path.resolve(destSVGPath))
})
.then(optimizeSVGs)
.then(npmBuildExt)
.then(() =>
fs.copy(
.then(() => {
console.log('[7/7] Copy file icon configuration to source code directory.');
return fs.copy(
path.resolve(vsExtPath, 'dist', 'material-icons.json'),
path.resolve(srcPath, 'iconMap.json')
)
path.resolve(srcPath, 'icon-map.json')
);
}
)
.then(() => rimraf.sync(vsExtPath))
////
@ -33,16 +47,22 @@ const vsExtExecOptions = {
stdio: 'inherit',
};
const distIconsExecOptions = {
cwd: path.resolve(destSVGPath),
stdio: 'inherit'
}
function npmInstallExt() {
child_process.execSync(`npm install`, vsExtExecOptions);
console.log('[3/7] Install NPM dependencies for VSC extension.');
cp.execSync(`npm install`, vsExtExecOptions);
}
function optimizeSVGs() {
console.log('[5/7] Optimise extension icons using SVGO.');
cp.exec(`npx svgo --disable=removeViewBox .`, distIconsExecOptions);
}
function npmBuildExt() {
child_process.execSync(`npm run build`, vsExtExecOptions);
}
const distIconsExecOptions = { cwd: path.resolve(destSVGPath), stdio: 'inherit' };
function optimizeSVGs() {
child_process.exec(`npx svgo --disable=removeViewBox .`, distIconsExecOptions);
console.log('[6/7] Run build tasks for VSC extension.');
cp.execSync(`npm run build`, vsExtExecOptions);
}

View File

@ -2,10 +2,10 @@
// renders src/logo.svg to desired icon sizes for the extension
const child_process = require('child_process');
const mkdirp = require('mkdirp');
const mkdirp = require('make-dir');
const path = require('path');
const extIconsPath = path.resolve(__dirname, '..', 'src', 'extensionIcons');
const extIconsPath = path.resolve(__dirname, '..', 'src', 'icons');
const srcPath = path.resolve(__dirname, '..', 'src');
const svgPath = path.resolve(srcPath, 'logo.svg');
const targetSizes = [16, 32, 48, 128];

229
scripts/build-languages.js Normal file
View File

@ -0,0 +1,229 @@
const rimraf = require('rimraf');
const path = require('path')
const api = require('@octokit/core');
const fs = require('fs-extra');
const fr = require('follow-redirects');
const mkdirp = require('make-dir');
const glob = require('glob');
const remap = require('./remap.json');
const iconMap = require('../src/icon-map.json');
const stringify = require('json-stable-stringify')
const vsDataPath = path.resolve(__dirname, '..', 'data');
const srcPath = path.resolve(__dirname, '..', 'src');
rimraf.sync(vsDataPath);
mkdirp.sync(vsDataPath);
rimraf.sync(path.resolve(srcPath, 'language-map.json'));
let index = 0;
let total;
let items = [];
let languages = [];
console.log('[1/7] Querying Github API for official VSC language contributions.');
const octokit = new api.Octokit();
const query = {
page: 0,
q: [
'contributes languages',
'filename:package.json',
'org:microsoft',
'-repo:microsoft/azuredatastudio'
].join(' ')
};
const GITHUB_RATELIMIT = 6000;
(function queryLanguageContributions() {
try {
octokit.request('GET /search/code', query).then(
(res) => {
if (!res.data) throw new Error();
query.page = index++;
total = total || res.data.total_count;
items = items.concat(res.data.items);
if (30 * index >= total) {
console.log('[2/7] Fetching Microsoft language contributions from Github.');
index = 0;
total = items.length;
items.forEach(fetchLanguageContribution);
} else {
setTimeout(queryLanguageContributions, GITHUB_RATELIMIT);
}
},
(reason) => {
throw new Error(reason);
}
);
} catch (reason) {
throw new Error(reason);
}
})();
function fetchLanguageContribution(item) {
const urlPath = item.html_url.replace(/\/blob\//, '/raw/');
const resPath = item.path.replace(/package\.json$/, 'extension.json');
const extPath = path.join(item.repository.name, resPath);
const extDir = path.dirname(extPath);
if (/sample|template/.test(extDir)) {
total--;
return;
}
try {
mkdirp(path.join(vsDataPath, extDir)).then(
() => {
const extFile = fs.createWriteStream(path.join(vsDataPath, extPath));
fr.https.get(urlPath, (res) => {
res.pipe(extFile);
res.on('end', () => {
index++;
if (index === total) {
console.log('[3/7] Loading VSC language contributions into Node.');
glob(path.join(vsDataPath, '**', 'extension.json'), (err, matches) => {
index = 0;
total = matches.length;
matches.forEach(loadLanguageContribution);
});
}
});
}).on('error', (err) => {
fs.unlink(extPath);
throw new Error(err);
})
}
);
} catch (reason) {
throw new Error(reason);
}
}
function loadLanguageContribution(path) {
try {
const data = JSON.parse(fs.readFileSync(path));
data.contributes = data.contributes || {};
data.contributes.languages = data.contributes.languages || [];
languages.push(...data.contributes.languages);
index++;
if (index === total) {
console.log('[4/7] Processing language contributions for VSC File Icon API compatibility.');
index = 0;
total = languages.length;
languages.forEach(processLanguageContribution);
}
} catch (error) {
throw new Error(`${error} (${path})`);
}
}
function processLanguageContribution(lang) {
delete lang.aliases;
delete lang.configuration;
delete lang.firstLine;
lang.extensions = lang.extensions || [];
lang.filenames = lang.filenames || [];
if (lang.filenamePatterns) {
lang.filenamePatterns.forEach((ptn) => {
if (/^\*\.[^*\/\?]+$/.test(ptn)) {
lang.extensions.push(ptn.substring(1));
}
if (/^[^*\/\?]+$/.test(ptn)) {
lang.filenames.push(ptn);
}
});
delete lang.filenamePatterns;
}
lang.extensions = lang.extensions
.filter((ext) => {
const isExt = ext.startsWith('.');
if (!isExt) {
lang.filenames.push(ext);
}
return isExt;
})
.map(ext => ext.substring(1));
index++;
if (index === total) {
console.log('[5/7] Mapping language contributions into file icon configuration.');
index = 0;
languages.forEach(mapLanguageContribution)
}
}
const languageMap = {
fileExtensions: {},
fileNames: {}
}
function mapLanguageContribution(lang) {
lang.extensions.forEach((ext) => {
let extIconName = lang.id;
if (remap.extensions.hasOwnProperty(extIconName)) {
let overrideIcon = remap.extensions[extIconName];
if (typeof overrideIcon === 'object') {
for (const [ptn, override] in Object.entries(overrideIcon)) {
if (ptn.startsWith('^') && ext.startsWith(ptn.substring(1))) {
extIconName = override;
}
if (ptn.length && ext === ptn) {
extIconName = override;
}
}
}
} else {
extIconName = iconMap.languageIds[extIconName] || extIconName;
}
if (
!remap.deletions[`extensions:${extIconName}`]
&& !iconMap.fileExtensions.hasOwnProperty(extIconName)
&& iconMap.iconDefinitions.hasOwnProperty(extIconName)
) {
languageMap.fileExtensions[ext] = extIconName;
}
});
lang.filenames.forEach((ext) => {
let fileIconName = lang.id;
if (remap.filenames.hasOwnProperty(fileIconName)) {
let overrideIcon = remap.filenames[fileIconName];
if (typeof overrideIcon === 'object') {
for (const [ptn, override] in Object.entries(overrideIcon)) {
if (ptn.startsWith('^') && ext.startsWith(ptn.substring(1))) {
fileIconName = override;
}
if (ptn.length && ext === ptn) {
fileIconName = override;
}
}
}
} else {
fileIconName = iconMap.languageIds[fileIconName] || fileIconName;
}
if (
!remap.deletions[`filenames:${fileIconName}`]
&& !iconMap.fileNames.hasOwnProperty(fileIconName)
&& iconMap.iconDefinitions.hasOwnProperty(fileIconName)
) {
languageMap.fileNames[ext] = fileIconName;
}
});
index++;
if (index === total) {
index = 0;
generateLanguageMap();
}
}
function generateLanguageMap() {
console.log('[6/7] Writing language contribution map to icon configuration file.');
fs.writeFileSync(
path.resolve(srcPath, 'language-map.json'),
stringify(languageMap, { space: ' ' })
);
console.log('[7/7] Deleting language contribution cache.');
rimraf.sync(vsDataPath);
}

View File

@ -2,9 +2,9 @@ const path = require('path');
const mkdirp = require('mkdirp');
const fs = require('fs-extra');
const Parcel = require('parcel-bundler');
const extractSVGs = require('./extract-svgHtml');
const extractSvgHtml = require('./extract-svg-html');
const destSVGPath = path.resolve(__dirname, '..', 'optimizedSVGs');
const destSVGPath = path.resolve(__dirname, '..', 'svg');
const distPath = path.resolve(__dirname, '..', 'dist');
const srcPath = path.resolve(__dirname, '..', 'src');
@ -12,7 +12,19 @@ mkdirp(distPath).then(createIconsCache).then(src);
// copy src files
function createIconsCache() {
console.log('[1/2] Generate icon cache for extension.');
return new Promise((resolve, reject) => {
fs.copy(path.resolve(srcPath, 'custom'), destSVGPath)
.then(() => extractSvgHtml({ task: '1' }))
.then(resolve)
.catch(reject);
});
}
function src() {
console.log('[2/2] Bundle extension manifest, images and main script.');
const entryFile = path.resolve(srcPath, 'main.js');
const parcelOptions = {
watch: false,
@ -26,16 +38,7 @@ function src() {
path.resolve(distPath, 'manifest.json')
);
const copyExtensionLogos = fs.copy(path.resolve(srcPath, 'extensionIcons'), distPath);
const copyExtensionLogos = fs.copy(path.resolve(srcPath, 'icons'), distPath);
return Promise.all([copyManifest, copyExtensionLogos, bundleMainScript]);
}
function createIconsCache() {
return new Promise((resolve, reject) => {
fs.copy(path.resolve(srcPath, 'customIcons'), destSVGPath)
.then(() => extractSVGs())
.then(resolve)
.catch(reject);
});
}

View File

@ -0,0 +1,46 @@
const path = require('path');
const fs = require('fs').promises;
const { parse } = require('node-html-parser');
module.exports = function extract(opts) {
console.log(`[${opts.task}:1/4] Initialise SVG extraction process.`);
const iconsPath = path.resolve(__dirname, '..', 'svg');
const destCachePath = path.resolve(__dirname, '..', 'src', 'icon-cache.js');
return new Promise((resolve, reject) => {
fs.readdir(iconsPath)
.then((icons) => {
console.log(`[${opts.task}:2/4] Fetch map of icon file names and SVG data.`);
return Promise.all(
icons.map((name) => fs.readFile(path.resolve(iconsPath, name), { encoding: 'utf8' }))
).then((xmlContent) => xmlContent.map((xml, i) => [icons[i], parse(xml)]))
})
.then((svgEntries) => {
console.log(`[${opts.task}:3/4] Determine HTML code and viewbox for icon cache.`);
svgEntries.map((entry) => [
entry[0],
{
innerHtml: entry[1].firstChild.innerHTML,
viewBox: entry[1].firstChild.getAttribute('viewBox'),
},
])
})
.then((cacheEntries) => Object.fromEntries(cacheEntries))
.then((svgCacheObj) => {
console.log(`[${opts.task}:4/4] Serialise icon map to JS cache module.`);
return fs.writeFile(destCachePath, formatCache(svgCacheObj));
})
.then(resolve)
.catch(reject);
});
};
function formatCache(obj) {
const declaration = `const cache = `;
const cacheObj = JSON.stringify(obj);
const bottomExport = `export default cache;`;
const fileContents = `${declaration}${cacheObj}\n\n${bottomExport}`;
return fileContents;
}

View File

@ -1,40 +0,0 @@
const path = require('path');
const fs = require('fs').promises;
const { parse } = require('node-html-parser');
module.exports = function extractSVGs() {
const iconsPath = path.resolve(__dirname, '..', 'optimizedSVGs');
const destCachePath = path.resolve(__dirname, '..', 'src', 'iconsCache.js');
return new Promise((resolve, reject) => {
fs.readdir(iconsPath)
.then((iconsNames) =>
Promise.all(
iconsNames.map((name) => fs.readFile(path.resolve(iconsPath, name), { encoding: 'utf8' }))
).then((svgStrs) => svgStrs.map((svgStr, i) => [iconsNames[i], parse(svgStr)]))
)
.then((svgElsEntries) =>
svgElsEntries.map((entry) => [
entry[0],
{
innerHtml: entry[1].firstChild.innerHTML,
viewBox: entry[1].firstChild.getAttribute('viewBox'),
},
])
)
.then((cacheEntries) => Object.fromEntries(cacheEntries))
.then((svgsObj) => fs.writeFile(destCachePath, formatCache(svgsObj)))
.then(resolve)
.catch(reject);
});
};
function formatCache(obj) {
const declaration = `const cache = `;
const cacheObj = JSON.stringify(obj);
const bottomExport = `export default cache;`;
const fileContents = `${declaration}${cacheObj}\n\n${bottomExport}`;
return fileContents;
}

22
scripts/remap.json Normal file
View File

@ -0,0 +1,22 @@
{
"extensions": {
"properties": {
"^git": "git",
"^npm": "npm",
"editorconfig": "editorconfig",
"": "settings"
},
"python": "python-misc",
"tablegen": "fsharp",
"vb": "visualstudio"
},
"filenames": {
"properties": "git",
"python": "python-misc"
},
"deletions": {
"extensions:hlsl": true,
"extensions:ignore": true,
"extensions:log": true
}
}

View File

Before

Width:  |  Height:  |  Size: 195 B

After

Width:  |  Height:  |  Size: 195 B

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

Before

Width:  |  Height:  |  Size: 558 B

After

Width:  |  Height:  |  Size: 558 B

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1,245 +0,0 @@
{
"fileExtensions": {
"github-issues.txt": "git",
"ascx": "xml",
"aspx": "html",
"atom": "xml",
"auradoc": "html",
"axaml": "xml",
"axml": "xml",
"azcli": "azure-pipelines",
"azs": "azure-pipelines",
"bas": "vb",
"bash_aliases": "console",
"bash_login": "console",
"bash_logout": "console",
"bash_profile": "console",
"bashrc": "console",
"bbx": "tex",
"bowerrc": "json",
"bpmn": "xml",
"brs": "vb",
"cbx": "tex",
"cjs": "javascript",
"cljx": "clojure",
"clojure": "clojure",
"cmp": "html",
"code-snippets": "json",
"code-workspace": "json",
"component": "salesforce",
"containerfile": "dockerfile",
"cpy": "python",
"cshrc": "console",
"csl": "xml",
"csproj.user": "xml",
"ctp": "php",
"design": "html",
"dialog": "json",
"diff": "diff",
"directory": "settings",
"dita": "xml",
"ditamap": "xml",
"dsql": "sql",
"dtml": "xml",
"ebuild": "console",
"editorconfig": "editorconfig",
"edn": "clojure",
"ent": "xml",
"es6": "javascript",
"evt": "html",
"eyaml": "yaml",
"eyml": "yaml",
"flake8": "python-misc",
"fsscript": "fsharp",
"fxml": "xml",
"gemspec": "ruby",
"gitattributes": "git",
"gitconfig": "git",
"gitmodules": "git",
"gvy": "groovy",
"gyp": "python",
"gypi": "python",
"h.in": "cpp",
"handlebars": "handlebars",
"har": "json",
"hjs": "handlebars",
"hpp.in": "cpp",
"html": "html",
"html1": "html",
"intf": "html",
"ipp": "cpp",
"ipy": "python",
"isml": "xml",
"jav": "java",
"jmd": "julia",
"jmx": "xml",
"js": "javascript",
"jscsrc": "json",
"jsfmtrc": "json",
"jshtm": "html",
"jslintrc": "json",
"jsonc": "json",
"jsonld": "json",
"launch": "xml",
"mak": "makefile",
"markdn": "markdown",
"mdoc": "html",
"mdown": "markdown",
"mdtext": "markdown",
"mdtxt": "markdown",
"mdwn": "markdown",
"menu": "xml",
"mk": "makefile",
"mkd": "markdown",
"mm": "objective-c",
"mod": "xml",
"mongo": "database",
"nf": "groovy",
"npmrc": "npm",
"nqp": "perl",
"nuspec": "xml",
"opml": "xml",
"orchestration": "json",
"owl": "xml",
"p6": "perl",
"pac": "javascript",
"page": "salesforce",
"pep8": "python-misc",
"php": "php",
"php4": "php",
"php5": "php",
"php6": "php",
"php7": "php",
"phtml": "php",
"pl6": "perl",
"pm6": "perl",
"pod": "perl",
"podspec": "ruby",
"pq": "fsharp",
"pqm": "fsharp",
"profile": "console",
"proj": "xml",
"psgi": "perl",
"psrc": "powershell",
"pt": "xml",
"publishsettings": "xml",
"pubxml": "xml",
"pubxml.user": "xml",
"pyi": "python",
"pypirc": "python-misc",
"pyw": "python",
"rake": "ruby",
"rbi": "ruby",
"rbx": "ruby",
"rbxlx": "xml",
"rbxmx": "xml",
"rdf": "xml",
"rej": "diff",
"rhistory": "r",
"rhtml": "html",
"rjs": "ruby",
"rng": "xml",
"rprofile": "r",
"rpy": "python",
"rss": "xml",
"rt": "r",
"ru": "ruby",
"sarif": "json",
"shader": "shaderlab",
"shproj": "xml",
"shtml": "html",
"soql": "salesforce",
"storyboard": "xml",
"swcrc": "json",
"t": "perl",
"targets": "xml",
"tcshrc": "console",
"td": "cpp",
"tld": "xml",
"tmx": "xml",
"tour": "json",
"trigger": "salesforce",
"ts": "typescript",
"ts.map": "json",
"vbproj": "xml",
"vbproj.user": "xml",
"volt": "html",
"vsts-ci.yml": "azure-pipelines",
"wdash": "json",
"wdf": "json",
"wdpr": "json",
"webmanifest": "json",
"wlens": "json",
"workbook": "markdown",
"wsdl": "xml",
"wxi": "xml",
"wxl": "xml",
"wxs": "xml",
"xbl": "xml",
"xht": "html",
"xib": "xml",
"xlf": "xml",
"xliff": "xml",
"xoml": "xml",
"xpdl": "xml",
"xprofile": "console",
"xsession": "console",
"xsessionrc": "console",
"xul": "xml",
"yash_profile": "console",
"yashrc": "console",
"zlogin": "console",
"zlogout": "console",
"zprofile": "console",
"zsh-theme": "console",
"zshenv": "console",
"zshrc": "console"
},
"fileNames": {
".condarc": "python-misc",
".ember-cli": "json",
".envrc": "console",
".forceignore": "ignore",
".hushlogin": "console",
".vscodeignore": "vscode",
"APKBUILD": "console",
"appraisals": "ruby",
"bashrc_Apple_Terminal": "console",
"berksfile": "ruby",
"berksfile.lock": "ruby",
"brewfile": "ruby",
"capfile": "ruby",
"cheffile": "ruby",
"Containerfile": "dockerfile",
"dangerfile": "ruby",
"deliverfile": "ruby",
"gitconfig": "git",
"GNUmakefile": "makefile",
"guardfile": "ruby",
"gymfile": "ruby",
"hobofile": "ruby",
"jakefile": "javascript",
"matchfile": "ruby",
"OCamlMakefile": "makefile",
"Pipfile": "python-misc",
"Pipfile.lock": "python-misc",
"PKGBUILD": "console",
"podfile": "ruby",
"puppetfile": "ruby",
"rakefile": "ruby",
"rantfile": "ruby",
"scanfile": "ruby",
"SConscript": "python",
"SConstruct": "python",
"Snakefile": "python",
"snapfile": "ruby",
"thorfile": "ruby",
"vsts-ci.yml": "azure-pipelines",
"zlogin": "console",
"zlogout": "console",
"zprofile": "console",
"zshenv": "console",
"zshrc": "console",
"zshrc_Apple_Terminal": "console"
}
}

View File

@ -1,7 +1,7 @@
import { observe } from 'selector-observer';
import iconsCache from './iconsCache';
import iconMap from './iconMap';
import languageMap from './languageMap';
import iconsCache from './icon-cache';
import iconMap from './icon-map';
import languageMap from './language-map';
// run on load
const iconSelector = '.js-navigation-container > .js-navigation-item';