UNPKG

1.3 kBPlain TextView Raw
1import * as Promise from 'bluebird';
2import * as bundler from './bundler';
3import * as hitb from './html-import-template-bundler';
4import { Config } from './models';
5import {
6 ensureDefaults,
7 getBundleConfig,
8 validateConfig,
9 getHtmlImportBundleConfig,
10} from './utils';
11
12export * from './unbundle';
13
14export function bundle(inpConfig: Config) {
15 let tasks: Promise<any>[] = [];
16 let config = ensureDefaults(inpConfig);
17 validateConfig(config);
18
19 Object.keys(config.bundles)
20 .forEach(key => {
21 let cfg = config.bundles[key];
22 if (cfg.skip) {
23 return;
24 }
25 if (cfg.htmlimport) {
26 tasks.push(hitb.bundle(getHtmlImportBundleConfig(cfg, key, config)));
27 } else {
28 tasks.push(bundler.bundle(getBundleConfig(cfg, key, config)));
29 }
30 });
31
32 return Promise.all(tasks);
33}
34
35export function depCache(bundleConfig: Config) {
36 let tasks: Promise<any>[] = [];
37 let config = ensureDefaults(bundleConfig);
38 validateConfig(config);
39
40 let bundles = config.bundles;
41 Object.keys(bundles)
42 .forEach(key => {
43 let cfg = bundles[key];
44
45 if (cfg.skip) {
46 return;
47 }
48 if (cfg.htmlimport) {
49 return;
50 }
51 tasks.push(bundler.depCache(getBundleConfig(cfg, key, config)));
52 });
53
54 return Promise.all(tasks);
55}