aboutsummaryrefslogtreecommitdiff
path: root/tools/utils/template-injectables.ts
blob: 83ac31523a3bffc5c7d73178a7b37d26a42d2424 (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
import * as slash from 'slash';
import {join} from 'path';
import {APP_BASE, APP_DEST, ENV} from '../config';

let injectables: string[] = [];

export function injectableAssetsRef() {
  return injectables;
}

export function registerInjectableAssetsRef(paths: string[], target: string = '') {
  injectables = injectables.concat(
    paths
      .filter(path => !/(\.map)$/.test(path))
      .map(path => join(target, slash(path).split('/').pop()))
  );
}

export function transformPath(plugins, env) {
  return function (filepath) {
    filepath = ENV === 'prod' ? filepath.replace(`/${APP_DEST}`, '') : filepath;
    arguments[0] = join(APP_BASE, filepath);
    return slash(plugins.inject.transform.apply(plugins.inject.transform, arguments));
  };
}