Passed
Push — master ( 50adea...d5902b )
by Amit
02:19
created

assetManifestsFormatter.js ➔ ... ➔ ???   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
1
const path = require('path');
2
3
module.exports = (key, value) => {
4
  if (typeof value === 'string') {
5
    return value;
6
  }
7
  const manifest = value;
8
  /**
9
   * Hack to prepend scripts/ or styles/ to manifest keys
10
   *
11
   * This might need to be reworked at some point.
12
   *
13
   * Before:
14
   *   {
15
   *     "main.js": "scripts/main_abcdef.js"
16
   *     "main.css": "styles/main_abcdef.css"
17
   *   }
18
   * After:
19
   *   {
20
   *     "scripts/main.js": "scripts/main_abcdef.js"
21
   *     "styles/main.css": "styles/main_abcdef.css"
22
   *   }
23
   */
24
  Object.keys(manifest).forEach((src) => {
25
    const sourcePath = path.basename(path.dirname(src));
26
    const targetPath = path.basename(path.dirname(manifest[src]));
27
    if (sourcePath === targetPath) {
28
      return;
29
    }
30
    manifest[`${targetPath}/${src}`] = manifest[src];
31
    delete manifest[src];
32
  });
33
  return manifest;
34
};
35