1 | 'use strict';
|
2 |
|
3 | var _regenerator = require('babel-runtime/regenerator');
|
4 |
|
5 | var _regenerator2 = _interopRequireDefault(_regenerator);
|
6 |
|
7 | var _getIterator2 = require('babel-runtime/core-js/get-iterator');
|
8 |
|
9 | var _getIterator3 = _interopRequireDefault(_getIterator2);
|
10 |
|
11 | var _promise = require('babel-runtime/core-js/promise');
|
12 |
|
13 | var _promise2 = _interopRequireDefault(_promise);
|
14 |
|
15 | var _keys = require('babel-runtime/core-js/object/keys');
|
16 |
|
17 | var _keys2 = _interopRequireDefault(_keys);
|
18 |
|
19 | var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
20 |
|
21 | var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
22 |
|
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | var fse = require('fs-extra');
|
42 | var path = require('path');
|
43 |
|
44 | var errors = require('./errors');
|
45 | var useBuildType = require('./use-build-type');
|
46 |
|
47 |
|
48 | var WORKBOX_PREFIX = 'workbox-';
|
49 | var BUILD_TYPES = ['dev', 'prod'];
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | module.exports = function () {
|
72 | var _ref = (0, _asyncToGenerator3.default)( _regenerator2.default.mark(function _callee(destDirectory) {
|
73 | var thisPkg, workboxDirectoryName, workboxDirectoryPath, copyPromises, librariesToCopy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, library, pkg, defaultPathToLibrary, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, buildType, srcPath, destPath;
|
74 |
|
75 | return _regenerator2.default.wrap(function _callee$(_context) {
|
76 | while (1) {
|
77 | switch (_context.prev = _context.next) {
|
78 | case 0:
|
79 | thisPkg = require('../../package.json');
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | workboxDirectoryName = `workbox-v${thisPkg.version}`;
|
86 | workboxDirectoryPath = path.join(destDirectory, workboxDirectoryName);
|
87 | _context.next = 5;
|
88 | return fse.ensureDir(workboxDirectoryPath);
|
89 |
|
90 | case 5:
|
91 | copyPromises = [];
|
92 | librariesToCopy = (0, _keys2.default)(thisPkg.dependencies).filter(function (dependency) {
|
93 | return dependency.startsWith(WORKBOX_PREFIX);
|
94 | });
|
95 | _iteratorNormalCompletion = true;
|
96 | _didIteratorError = false;
|
97 | _iteratorError = undefined;
|
98 | _context.prev = 10;
|
99 | _iterator = (0, _getIterator3.default)(librariesToCopy);
|
100 |
|
101 | case 12:
|
102 | if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
103 | _context.next = 49;
|
104 | break;
|
105 | }
|
106 |
|
107 | library = _step.value;
|
108 | pkg = require(`${library}/package.json`);
|
109 | defaultPathToLibrary = require.resolve(`${library}/${pkg.main}`);
|
110 | _iteratorNormalCompletion2 = true;
|
111 | _didIteratorError2 = false;
|
112 | _iteratorError2 = undefined;
|
113 | _context.prev = 19;
|
114 | _iterator2 = (0, _getIterator3.default)(BUILD_TYPES);
|
115 |
|
116 | case 21:
|
117 | if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
|
118 | _context.next = 32;
|
119 | break;
|
120 | }
|
121 |
|
122 | buildType = _step2.value;
|
123 |
|
124 | if (!(library === 'workbox-sw' && buildType === BUILD_TYPES[0])) {
|
125 | _context.next = 25;
|
126 | break;
|
127 | }
|
128 |
|
129 | return _context.abrupt('continue', 29);
|
130 |
|
131 | case 25:
|
132 | srcPath = useBuildType(defaultPathToLibrary, buildType);
|
133 | destPath = path.join(workboxDirectoryPath, path.basename(srcPath));
|
134 |
|
135 | copyPromises.push(fse.copy(srcPath, destPath));
|
136 | copyPromises.push(fse.copy(`${srcPath}.map`, `${destPath}.map`));
|
137 |
|
138 | case 29:
|
139 | _iteratorNormalCompletion2 = true;
|
140 | _context.next = 21;
|
141 | break;
|
142 |
|
143 | case 32:
|
144 | _context.next = 38;
|
145 | break;
|
146 |
|
147 | case 34:
|
148 | _context.prev = 34;
|
149 | _context.t0 = _context['catch'](19);
|
150 | _didIteratorError2 = true;
|
151 | _iteratorError2 = _context.t0;
|
152 |
|
153 | case 38:
|
154 | _context.prev = 38;
|
155 | _context.prev = 39;
|
156 |
|
157 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
158 | _iterator2.return();
|
159 | }
|
160 |
|
161 | case 41:
|
162 | _context.prev = 41;
|
163 |
|
164 | if (!_didIteratorError2) {
|
165 | _context.next = 44;
|
166 | break;
|
167 | }
|
168 |
|
169 | throw _iteratorError2;
|
170 |
|
171 | case 44:
|
172 | return _context.finish(41);
|
173 |
|
174 | case 45:
|
175 | return _context.finish(38);
|
176 |
|
177 | case 46:
|
178 | _iteratorNormalCompletion = true;
|
179 | _context.next = 12;
|
180 | break;
|
181 |
|
182 | case 49:
|
183 | _context.next = 55;
|
184 | break;
|
185 |
|
186 | case 51:
|
187 | _context.prev = 51;
|
188 | _context.t1 = _context['catch'](10);
|
189 | _didIteratorError = true;
|
190 | _iteratorError = _context.t1;
|
191 |
|
192 | case 55:
|
193 | _context.prev = 55;
|
194 | _context.prev = 56;
|
195 |
|
196 | if (!_iteratorNormalCompletion && _iterator.return) {
|
197 | _iterator.return();
|
198 | }
|
199 |
|
200 | case 58:
|
201 | _context.prev = 58;
|
202 |
|
203 | if (!_didIteratorError) {
|
204 | _context.next = 61;
|
205 | break;
|
206 | }
|
207 |
|
208 | throw _iteratorError;
|
209 |
|
210 | case 61:
|
211 | return _context.finish(58);
|
212 |
|
213 | case 62:
|
214 | return _context.finish(55);
|
215 |
|
216 | case 63:
|
217 | _context.prev = 63;
|
218 | _context.next = 66;
|
219 | return _promise2.default.all(copyPromises);
|
220 |
|
221 | case 66:
|
222 | return _context.abrupt('return', workboxDirectoryName);
|
223 |
|
224 | case 69:
|
225 | _context.prev = 69;
|
226 | _context.t2 = _context['catch'](63);
|
227 | throw Error(`${errors['unable-to-copy-workbox-libraries']} ${_context.t2}`);
|
228 |
|
229 | case 72:
|
230 | case 'end':
|
231 | return _context.stop();
|
232 | }
|
233 | }
|
234 | }, _callee, undefined, [[10, 51, 55, 63], [19, 34, 38, 46], [39,, 41, 45], [56,, 58, 62], [63, 69]]);
|
235 | }));
|
236 |
|
237 | return function (_x) {
|
238 | return _ref.apply(this, arguments);
|
239 | };
|
240 | }(); |
\ | No newline at end of file |