1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createEntryListFile = createEntryListFile;
|
7 | exports.createWebpackConfigArray = createWebpackConfigArray;
|
8 | exports.createWebpackConfigFilepathByIndex = createWebpackConfigFilepathByIndex;
|
9 | exports.buildToDir = buildToDir;
|
10 | exports.watchAndBuildToDir = watchAndBuildToDir;
|
11 | exports.devServer = devServer;
|
12 |
|
13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
14 |
|
15 | function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
16 |
|
17 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
18 |
|
19 | var _path = require("path");
|
20 |
|
21 | var _rx = require("rx");
|
22 |
|
23 | var _rx2 = _interopRequireDefault(_rx);
|
24 |
|
25 | var _lodash = require("lodash");
|
26 |
|
27 | var _lodash2 = _interopRequireDefault(_lodash);
|
28 |
|
29 | var _coreIndex = require("./core/index");
|
30 |
|
31 | var _utilIndex = require("./util/index");
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function createEntryListFile(srcPatternList) {
|
38 | return _rx.Observable.from(srcPatternList).selectMany(_coreIndex.createGlobResult).selectMany(_coreIndex.globResultToFile).selectMany(_coreIndex.addCodeToFile).map(_coreIndex.addElementToFile).map(_coreIndex.addEntryListToFile);
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | function createWebpackConfigArray(entryListFile, devServerConfigFilepath) {
|
46 | return entryListFile.selectMany(_utilIndex.entryListFileToEntry).groupBy(function (entry) {
|
47 | return entry.configFilepath;
|
48 | }).selectMany(_coreIndex.groupedEntryListToWebpackConfig).map((0, _utilIndex.addDevServerToWebpackConfigCreator)(devServerConfigFilepath)).reduce(_coreIndex.webpackConfigReducer, []);
|
49 |
|
50 |
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function createWebpackConfigFilepathByIndex(webpackConfigArray) {
|
58 | return webpackConfigArray.map(_utilIndex.webpackConfigArrayToIndexFilepathMap);
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | function buildToDir(destDir, srcPatternList) {
|
66 |
|
67 | var sharedReplayEntryListFileStream = createEntryListFile(srcPatternList).shareReplay();
|
68 |
|
69 | var publishedWebpackConfigArrayStream = createWebpackConfigArray(sharedReplayEntryListFileStream).publish();
|
70 |
|
71 | var webpackConfigFilepathByIndexStream = createWebpackConfigFilepathByIndex(publishedWebpackConfigArrayStream);
|
72 |
|
73 | var writeToFileResultStream = publishedWebpackConfigArrayStream.map(function (webpackConfigArray) {
|
74 | return webpackConfigArray.map(function (_ref) {
|
75 | var webpackConfig = _ref.webpackConfig;
|
76 | return webpackConfig;
|
77 | });
|
78 | }).tap(_coreIndex.webpackConfigArrayInspector).map(_coreIndex.webpackConfigArrayToWebpackCompiler).selectMany(_coreIndex.webpackMultiCompilerToMultiStats).map(_coreIndex.webpackMultiStatsToWebpackSingleStatsArray).withLatestFrom(webpackConfigFilepathByIndexStream, _utilIndex.singleStatsArrayAndIndexFilepathMapCombiner).selectMany(function (w) {
|
79 | return sharedReplayEntryListFileStream.map(function (e) {
|
80 | return (0, _utilIndex.entryListFileAndFilepathWebpackStatsMapCombiner)(e, w);
|
81 | });
|
82 | }).map(_coreIndex.withOutputAssetsFileToMarkupFile).selectMany((0, _utilIndex.markupFileToWriteFileCreator)(destDir));
|
83 |
|
84 | writeToFileResultStream.subscribe(function (it) {
|
85 | return console.log("Next: " + it);
|
86 | }, function (error) {
|
87 | throw error;
|
88 | }, function () {
|
89 | return console.log("Done!");
|
90 | });
|
91 |
|
92 | publishedWebpackConfigArrayStream.connect();
|
93 | }
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | function watchAndBuildToDir(destDir, srcPatternList) {
|
100 |
|
101 | var sharedReplayEntryListFileStream = createEntryListFile(srcPatternList).shareReplay();
|
102 |
|
103 | var publishedWebpackConfigArrayStream = createWebpackConfigArray(sharedReplayEntryListFileStream).publish();
|
104 |
|
105 | var webpackConfigFilepathByIndexStream = createWebpackConfigFilepathByIndex(publishedWebpackConfigArrayStream);
|
106 |
|
107 | var writeToFileResultStream = publishedWebpackConfigArrayStream.map(function (webpackConfigArray) {
|
108 | return webpackConfigArray.map(function (_ref2) {
|
109 | var webpackConfig = _ref2.webpackConfig;
|
110 | return webpackConfig;
|
111 | });
|
112 | }).tap(_coreIndex.webpackConfigArrayInspector).selectMany(function webpackConfigArrayRunWithWatchToSingleStatsArray(webpackConfigArray) {
|
113 |
|
114 |
|
115 | return _rx.Observable.from(webpackConfigArray).map(_coreIndex.webpackConfigArrayToWebpackCompiler).selectMany(_coreIndex.webpackCompilerRunWithWatchToSingleStatsWithIndex).scan(function (acc, it) {
|
116 | acc = [].concat(_toConsumableArray(acc));
|
117 | var index = it.index;
|
118 |
|
119 | var rest = _objectWithoutProperties(it, ["index"]);
|
120 |
|
121 | acc[index] = rest;
|
122 |
|
123 | return acc;
|
124 | }, new Array(webpackConfigArray.length)).takeWhile(function (webpackSingleStatsArray) {
|
125 | return webpackSingleStatsArray.every(_lodash2["default"].identity);
|
126 | });
|
127 | }).withLatestFrom(webpackConfigFilepathByIndexStream, _utilIndex.singleStatsArrayAndIndexFilepathMapCombiner).selectMany(function (w) {
|
128 | return sharedReplayEntryListFileStream.map(function (e) {
|
129 | return (0, _utilIndex.entryListFileAndFilepathWebpackStatsMapCombiner)(e, w);
|
130 | });
|
131 | }).map(_coreIndex.withOutputAssetsFileToMarkupFile).selectMany((0, _utilIndex.markupFileToWriteFileCreator)(destDir));
|
132 |
|
133 | writeToFileResultStream.subscribe(function (it) {
|
134 | return console.log("Next: " + it);
|
135 | }, function (error) {
|
136 | throw error;
|
137 | }, function () {
|
138 | return console.log("Done!");
|
139 | });
|
140 |
|
141 | publishedWebpackConfigArrayStream.connect();
|
142 | }
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | function devServer(relativeDevServerConfigFilepath, destDir, srcPatternList) {
|
149 |
|
150 | var devServerConfigFilepath = (0, _path.resolve)(process.cwd(), relativeDevServerConfigFilepath);
|
151 |
|
152 | var sharedReplayEntryListFileStream = createEntryListFile(srcPatternList).shareReplay();
|
153 |
|
154 | var publishedWebpackConfigArrayStream = createWebpackConfigArray(sharedReplayEntryListFileStream, devServerConfigFilepath).publish();
|
155 |
|
156 | var webpackConfigFilepathByIndexStream = createWebpackConfigFilepathByIndex(publishedWebpackConfigArrayStream);
|
157 |
|
158 | var writeToFileResultStream = publishedWebpackConfigArrayStream.map(function (webpackConfigArray) {
|
159 | return webpackConfigArray.map(function (_ref3) {
|
160 | var webpackConfig = _ref3.webpackConfig;
|
161 | return webpackConfig;
|
162 | });
|
163 | }).tap(_coreIndex.webpackConfigArrayInspector).map(_coreIndex.webpackConfigArrayToWebpackCompiler)
|
164 |
|
165 |
|
166 | .selectMany(_coreIndex.webpackMultiCompilerRunWithDevServerToSingleStatsArray).withLatestFrom(webpackConfigFilepathByIndexStream, _utilIndex.singleStatsArrayAndIndexFilepathMapCombiner).selectMany(function (w) {
|
167 | return sharedReplayEntryListFileStream.map(function (e) {
|
168 | return (0, _utilIndex.entryListFileAndFilepathWebpackStatsMapCombiner)(e, w);
|
169 | });
|
170 | }).map(_coreIndex.withOutputAssetsFileToMarkupFile).selectMany((0, _utilIndex.markupFileToWriteFileCreator)(destDir));
|
171 |
|
172 | writeToFileResultStream.subscribe(function (it) {
|
173 | return console.log("Next: " + it);
|
174 | }, function (error) {
|
175 | throw error;
|
176 | }, function () {
|
177 | return console.log("Done!");
|
178 | });
|
179 |
|
180 | publishedWebpackConfigArrayStream.connect();
|
181 | }
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
\ | No newline at end of file |