diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2017-09-22 11:39:47 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-09-22 11:39:47 +0300 |
commit | 55f772bb98a67ad346442a2cacb5646f6719b987 (patch) | |
tree | fdcda42d5ee9c746b5654a50fa88a0fd1464d3a8 /config/svg.config.js | |
parent | d103e95513704314a38ab8ae441851524031c4a1 (diff) |
Resolve "Better SVG Usage in the Frontend"
Diffstat (limited to 'config/svg.config.js')
-rw-r--r-- | config/svg.config.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/config/svg.config.js b/config/svg.config.js new file mode 100644 index 00000000000..be72741abec --- /dev/null +++ b/config/svg.config.js @@ -0,0 +1,48 @@ +/* eslint-disable no-commonjs */ +const path = require('path'); +const fs = require('fs'); + +const sourcePath = path.join('node_modules', 'gitlab-svgs', 'dist'); +const sourcePathIllustrations = path.join('node_modules', 'gitlab-svgs', 'dist', 'illustrations'); +const destPath = path.normalize(path.join('app', 'assets', 'images')); + +// Actual Task copying the 2 files + all illustrations +copyFileSync(path.join(sourcePath, 'icons.svg'), destPath); +copyFileSync(path.join(sourcePath, 'icons.json'), destPath); +copyFolderRecursiveSync(sourcePathIllustrations, destPath); + +// Helper Functions +function copyFileSync(source, target) { + var targetFile = target; + //if target is a directory a new file with the same name will be created + if (fs.existsSync(target)) { + if (fs.lstatSync(target).isDirectory()) { + targetFile = path.join(target, path.basename(source)); + } + } + console.log(`Copy SVG File : ${targetFile}`); + fs.writeFileSync(targetFile, fs.readFileSync(source)); +} + +function copyFolderRecursiveSync(source, target) { + var files = []; + + //check if folder needs to be created or integrated + var targetFolder = path.join(target, path.basename(source)); + if (!fs.existsSync(targetFolder)) { + fs.mkdirSync(targetFolder); + } + + //copy + if (fs.lstatSync(source).isDirectory()) { + files = fs.readdirSync(source); + files.forEach(function (file) { + var curSource = path.join(source, file); + if (fs.lstatSync(curSource).isDirectory()) { + copyFolderRecursiveSync(curSource, targetFolder); + } else { + copyFileSync(curSource, targetFolder); + } + }); + } +} |