1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var _ = require("lodash");
|
4 | var revPath = require("rev-path");
|
5 | var revHash = require("rev-hash");
|
6 | var fs = require("fs");
|
7 | var path = require("path");
|
8 | function getOutFileName(source, fileName, rev) {
|
9 | return rev ? revPath(fileName, revHash(new Buffer(source, 'utf-8'))) : fileName;
|
10 | }
|
11 | exports.getOutFileName = getOutFileName;
|
12 | function validateConfig(config) {
|
13 | if (!fs.existsSync(config.baseURL)) {
|
14 | throw new Error("Path '" + path.resolve(config.baseURL) + "' does not exist. Please provide a valid 'baseURL' in your bundle configuration.");
|
15 | }
|
16 | var configPaths = [];
|
17 | var configPath = config.configPath;
|
18 | if (typeof configPath === 'string') {
|
19 | configPaths.push(configPath);
|
20 | }
|
21 | else {
|
22 | configPath.forEach(function (p) { return configPaths.push(p); });
|
23 | }
|
24 | configPaths.forEach(function (p) {
|
25 | if (!fs.existsSync(p)) {
|
26 | throw new Error("File '" + path.resolve(p) + "' was not found! Please provide a valid 'config.js' file for use during bundling.");
|
27 | }
|
28 | });
|
29 | }
|
30 | exports.validateConfig = validateConfig;
|
31 | function getHTMLMinOpts(opts) {
|
32 | return _.defaultsDeep(opts, {
|
33 | caseSensitive: true,
|
34 | collapseBooleanAttributes: true,
|
35 | collapseWhitespace: true,
|
36 | conservativeCollapse: true,
|
37 | removeCDATASectionsFromCDATA: true,
|
38 | removeComments: true,
|
39 | removeCommentsFromCDATA: true,
|
40 | removeEmptyAttributes: true,
|
41 | removeRedundantAttributes: false,
|
42 | removeScriptTypeAttributes: true,
|
43 | removeStyleLinkTypeAttributes: true,
|
44 | ignoreCustomFragments: [/\${[\s\S]*?}/],
|
45 | useShortDoctype: true,
|
46 | minifyCSS: true,
|
47 | minifyJS: true
|
48 | });
|
49 | }
|
50 | exports.getHTMLMinOpts = getHTMLMinOpts;
|
51 | function getCSSMinOpts(opts) {
|
52 | return _.defaultsDeep(opts, {
|
53 | advanced: true,
|
54 | agressiveMerging: true,
|
55 | mediaMerging: true,
|
56 | restructuring: true,
|
57 | shorthandCompacting: true,
|
58 | });
|
59 | }
|
60 | exports.getCSSMinOpts = getCSSMinOpts;
|
61 | function getBundleConfig(bundleCfg, bundleName, config) {
|
62 | return _.defaultsDeep(bundleCfg, {
|
63 | baseURL: config.baseURL,
|
64 | builderCfg: config.builderCfg,
|
65 | bundleName: bundleName,
|
66 | configPath: config.configPath,
|
67 | excludes: [],
|
68 | includes: [],
|
69 | outputPath: config.outputPath,
|
70 | injectionConfigPath: config.injectionConfigPath,
|
71 | force: config.force,
|
72 | options: {
|
73 | depCache: false,
|
74 | cssminopts: {},
|
75 | htmlminopts: {},
|
76 | inject: true,
|
77 | minify: false,
|
78 | rev: false,
|
79 | },
|
80 | });
|
81 | }
|
82 | exports.getBundleConfig = getBundleConfig;
|
83 | function getHtmlImportBundleConfig(bundleCfg, bundleName, config) {
|
84 | var cfg = _.defaultsDeep(bundleCfg, {
|
85 | htmlimport: true,
|
86 | includes: '*.html',
|
87 | bundleName: bundleName,
|
88 | options: {
|
89 | inject: false
|
90 | },
|
91 | force: config.force,
|
92 | baseURL: config.baseURL,
|
93 | configPath: config.configPath,
|
94 | builderCfg: config.builderCfg
|
95 | });
|
96 | if (!cfg.options.inject) {
|
97 | return cfg;
|
98 | }
|
99 | if (typeof cfg.options.inject === 'boolean') {
|
100 | cfg.options.inject = {
|
101 | indexFile: 'index.html',
|
102 | destFile: 'index.html'
|
103 | };
|
104 | }
|
105 | else {
|
106 | cfg.options.inject.indexFile = cfg.options.inject.indexFile || 'index.html';
|
107 | cfg.options.inject.destFile = cfg.options.inject.destFile || 'index.html';
|
108 | }
|
109 | return cfg;
|
110 | }
|
111 | exports.getHtmlImportBundleConfig = getHtmlImportBundleConfig;
|
112 | function ensureDefaults(config) {
|
113 | return _.defaults(config, {
|
114 | baseURL: '.',
|
115 | builderCfg: {},
|
116 | bundles: {},
|
117 | configPath: './config.js',
|
118 | force: false,
|
119 | injectionConfigPath: getDefaultInjectionConfigFilePath(config.configPath),
|
120 | });
|
121 | }
|
122 | exports.ensureDefaults = ensureDefaults;
|
123 | function getDefaultInjectionConfigFilePath(configPath) {
|
124 | if (typeof configPath === 'string') {
|
125 | return configPath;
|
126 | }
|
127 | if (Array.isArray(configPath)) {
|
128 | return configPath[0];
|
129 | }
|
130 | throw new Error('No bundle injection config file path provided. Set `injectionConfigPath` property in the bundle config.');
|
131 | }
|
132 |
|
\ | No newline at end of file |