summaryrefslogtreecommitdiff
path: root/config/svg.config.js
blob: bb27f0caeefcac4686bbaf240231b10a1373be20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-disable no-commonjs */
const path = require('path');
const fs = require('fs');

const sourcePath = path.join('node_modules', '@gitlab-org/gitlab-svgs', 'dist');
const sourcePathIllustrations = path.join('node_modules', '@gitlab-org/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);
      }
    });
  }
}