@driveflux/fab 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/build.js CHANGED
@@ -1,414 +1,89 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function _array_without_holes(arr) {
10
- if (Array.isArray(arr)) return _array_like_to_array(arr);
11
- }
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
- try {
14
- var info = gen[key](arg);
15
- var value = info.value;
16
- } catch (error) {
17
- reject(error);
18
- return;
19
- }
20
- if (info.done) {
21
- resolve(value);
22
- } else {
23
- Promise.resolve(value).then(_next, _throw);
24
- }
25
- }
26
- function _async_to_generator(fn) {
27
- return function() {
28
- var self = this, args = arguments;
29
- return new Promise(function(resolve, reject) {
30
- var gen = fn.apply(self, args);
31
- function _next(value) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
- }
34
- function _throw(err) {
35
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
- }
37
- _next(undefined);
38
- });
39
- };
40
- }
41
- function _iterable_to_array(iter) {
42
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
- }
44
- function _iterable_to_array_limit(arr, i) {
45
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
46
- if (_i == null) return;
47
- var _arr = [];
48
- var _n = true;
49
- var _d = false;
50
- var _s, _e;
51
- try {
52
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
53
- _arr.push(_s.value);
54
- if (i && _arr.length === i) break;
55
- }
56
- } catch (err) {
57
- _d = true;
58
- _e = err;
59
- } finally{
60
- try {
61
- if (!_n && _i["return"] != null) _i["return"]();
62
- } finally{
63
- if (_d) throw _e;
64
- }
65
- }
66
- return _arr;
67
- }
68
- function _non_iterable_rest() {
69
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
70
- }
71
- function _non_iterable_spread() {
72
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73
- }
74
- function _sliced_to_array(arr, i) {
75
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
76
- }
77
- function _to_consumable_array(arr) {
78
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
79
- }
80
- function _unsupported_iterable_to_array(o, minLen) {
81
- if (!o) return;
82
- if (typeof o === "string") return _array_like_to_array(o, minLen);
83
- var n = Object.prototype.toString.call(o).slice(8, -1);
84
- if (n === "Object" && o.constructor) n = o.constructor.name;
85
- if (n === "Map" || n === "Set") return Array.from(n);
86
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
87
- }
88
- function _ts_generator(thisArg, body) {
89
- var f, y, t, _ = {
90
- label: 0,
91
- sent: function() {
92
- if (t[0] & 1) throw t[1];
93
- return t[1];
94
- },
95
- trys: [],
96
- ops: []
97
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
98
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
99
- return this;
100
- }), g;
101
- function verb(n) {
102
- return function(v) {
103
- return step([
104
- n,
105
- v
106
- ]);
107
- };
108
- }
109
- function step(op) {
110
- if (f) throw new TypeError("Generator is already executing.");
111
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
112
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
113
- if (y = 0, t) op = [
114
- op[0] & 2,
115
- t.value
116
- ];
117
- switch(op[0]){
118
- case 0:
119
- case 1:
120
- t = op;
121
- break;
122
- case 4:
123
- _.label++;
124
- return {
125
- value: op[1],
126
- done: false
127
- };
128
- case 5:
129
- _.label++;
130
- y = op[1];
131
- op = [
132
- 0
133
- ];
134
- continue;
135
- case 7:
136
- op = _.ops.pop();
137
- _.trys.pop();
138
- continue;
139
- default:
140
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
141
- _ = 0;
142
- continue;
143
- }
144
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
145
- _.label = op[1];
146
- break;
147
- }
148
- if (op[0] === 6 && _.label < t[1]) {
149
- _.label = t[1];
150
- t = op;
151
- break;
152
- }
153
- if (t && _.label < t[2]) {
154
- _.label = t[2];
155
- _.ops.push(op);
156
- break;
157
- }
158
- if (t[2]) _.ops.pop();
159
- _.trys.pop();
160
- continue;
161
- }
162
- op = body.call(thisArg, _);
163
- } catch (e) {
164
- op = [
165
- 6,
166
- e
167
- ];
168
- y = 0;
169
- } finally{
170
- f = t = 0;
171
- }
172
- if (op[0] & 5) throw op[1];
173
- return {
174
- value: op[0] ? op[1] : void 0,
175
- done: true
176
- };
177
- }
178
- }
179
1
  import fs from 'node:fs/promises';
180
2
  import path from 'node:path';
181
3
  import { performance } from 'node:perf_hooks';
182
4
  import merge from 'lodash.merge';
183
5
  import { clean } from './clean.js';
184
6
  import { ensureDir, getDefaultOptions, runBin } from './utils.js';
185
- export var TARGETS = [
186
- 'esm',
187
- 'types',
188
- 'copy'
189
- ];
190
- export var build = function(rawOptions) {
191
- return _async_to_generator(function() {
192
- var options, promises, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, target;
193
- return _ts_generator(this, function(_state) {
194
- switch(_state.label){
195
- case 0:
196
- options = merge({}, getDefaultOptions(), rawOptions);
197
- if (!options.clean) return [
198
- 3,
199
- 2
200
- ];
201
- return [
202
- 4,
203
- clean(options)
204
- ];
205
- case 1:
206
- _state.sent();
207
- _state.label = 2;
208
- case 2:
209
- promises = [];
210
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
211
- try {
212
- for(_iterator = options.targets[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
213
- target = _step.value;
214
- if (target === 'esm') {
215
- promises.push(buildEsm(options));
216
- } else if (target === 'types') {
217
- promises.push(buildTypes(options));
218
- }
219
- if (target === 'copy') {
220
- promises.push(copyVerbatim(options));
221
- }
222
- }
223
- } catch (err) {
224
- _didIteratorError = true;
225
- _iteratorError = err;
226
- } finally{
227
- try {
228
- if (!_iteratorNormalCompletion && _iterator.return != null) {
229
- _iterator.return();
230
- }
231
- } finally{
232
- if (_didIteratorError) {
233
- throw _iteratorError;
234
- }
235
- }
236
- }
237
- // Build necessary files
238
- return [
239
- 4,
240
- Promise.all(promises)
241
- ];
242
- case 3:
243
- _state.sent();
244
- return [
245
- 2
246
- ];
247
- }
248
- });
249
- })();
7
+ export const TARGETS = ['esm', 'types', 'copy'];
8
+ export const build = async (rawOptions) => {
9
+ const options = merge({}, getDefaultOptions(), rawOptions);
10
+ // Cleanup first
11
+ if (options.clean) {
12
+ await clean(options);
13
+ }
14
+ const promises = [];
15
+ for (const target of options.targets) {
16
+ if (target === 'esm') {
17
+ promises.push(buildEsm(options));
18
+ }
19
+ else if (target === 'types') {
20
+ promises.push(buildTypes(options));
21
+ }
22
+ if (target === 'copy') {
23
+ promises.push(copyVerbatim(options));
24
+ }
25
+ }
26
+ // Build necessary files
27
+ await Promise.all(promises);
250
28
  };
251
- export var copyVerbatim = function(rawOptions) {
252
- return _async_to_generator(function() {
253
- var _options_copyVerbatim, options, destination, guessTarget;
254
- return _ts_generator(this, function(_state) {
255
- switch(_state.label){
256
- case 0:
257
- options = merge({}, getDefaultOptions(), rawOptions);
258
- if (!((_options_copyVerbatim = options.copyVerbatim) === null || _options_copyVerbatim === void 0 ? void 0 : _options_copyVerbatim.length)) return [
259
- 3,
260
- 2
261
- ];
262
- destination = options.destination;
263
- guessTarget = function(copySource) {
264
- var relative = path.relative(options.source, copySource);
265
- var targetPath = path.resolve(destination, relative);
266
- if (!copySource.startsWith(options.source)) {
267
- throw new Error('The files to be copied must be a subdirectory of the source directory. Or you can provide a destination path using an array: { copyVerbatim: [source, target] }');
268
- }
269
- return targetPath;
270
- };
271
- return [
272
- 4,
273
- Promise.all(options.copyVerbatim.map(function(fileOrFolderRaw) {
274
- return _async_to_generator(function() {
275
- var source, target, tagetBasedir;
276
- return _ts_generator(this, function(_state) {
277
- switch(_state.label){
278
- case 0:
279
- source = typeof fileOrFolderRaw === 'string' ? fileOrFolderRaw : fileOrFolderRaw[0];
280
- target = Array.isArray(fileOrFolderRaw) ? fileOrFolderRaw[1] : guessTarget(source);
281
- tagetBasedir = path.dirname(target);
282
- return [
283
- 4,
284
- ensureDir(path.dirname(tagetBasedir))
285
- ];
286
- case 1:
287
- _state.sent();
288
- return [
289
- 4,
290
- fs.cp(source, target, {
291
- recursive: true
292
- })
293
- ];
294
- case 2:
295
- _state.sent();
296
- return [
297
- 2
298
- ];
299
- }
300
- });
301
- })();
302
- }))
303
- ];
304
- case 1:
305
- _state.sent();
306
- _state.label = 2;
307
- case 2:
308
- return [
309
- 2
310
- ];
29
+ export const copyVerbatim = async (rawOptions) => {
30
+ const options = merge({}, getDefaultOptions(), rawOptions);
31
+ if (options.copyVerbatim?.length) {
32
+ const destination = options.destination;
33
+ const guessTarget = (copySource) => {
34
+ const relative = path.relative(options.source, copySource);
35
+ const targetPath = path.resolve(destination, relative);
36
+ if (!copySource.startsWith(options.source)) {
37
+ throw new Error('The files to be copied must be a subdirectory of the source directory. Or you can provide a destination path using an array: { copyVerbatim: [source, target] }');
311
38
  }
312
- });
313
- })();
39
+ return targetPath;
40
+ };
41
+ await Promise.all(options.copyVerbatim.map(async (fileOrFolderRaw) => {
42
+ const source = typeof fileOrFolderRaw === 'string'
43
+ ? fileOrFolderRaw
44
+ : fileOrFolderRaw[0];
45
+ const target = Array.isArray(fileOrFolderRaw)
46
+ ? fileOrFolderRaw[1]
47
+ : guessTarget(source);
48
+ const tagetBasedir = path.dirname(target);
49
+ await ensureDir(path.dirname(tagetBasedir));
50
+ await fs.cp(source, target, { recursive: true });
51
+ }));
52
+ }
314
53
  };
315
- export var buildTypes = function(rawOptions) {
316
- return _async_to_generator(function() {
317
- var options, now;
318
- return _ts_generator(this, function(_state) {
319
- switch(_state.label){
320
- case 0:
321
- options = merge({}, getDefaultOptions(), rawOptions);
322
- console.log('Building types...');
323
- now = performance.now();
324
- return [
325
- 4,
326
- runBin('tsc', [
327
- '--emitDeclarationOnly',
328
- '--declarationMap'
329
- ], {
330
- cwd: options.cwd
331
- })
332
- ];
333
- case 1:
334
- _state.sent();
335
- console.log("Types built in ".concat((performance.now() - now).toFixed(2), "ms"));
336
- return [
337
- 2
338
- ];
339
- }
340
- });
341
- })();
54
+ export const buildTypes = async (rawOptions) => {
55
+ const options = merge({}, getDefaultOptions(), rawOptions);
56
+ console.log('Building types...');
57
+ const now = performance.now();
58
+ await runBin('tsc', ['--emitDeclarationOnly', '--declarationMap'], {
59
+ cwd: options.cwd,
60
+ });
61
+ console.log(`Types built in ${(performance.now() - now).toFixed(2)}ms`);
342
62
  };
343
- export var buildEsm = function(rawOptions) {
344
- return _async_to_generator(function() {
345
- var options, finalOptions, swcrc, e, isValid, compilerOptions;
346
- return _ts_generator(this, function(_state) {
347
- switch(_state.label){
348
- case 0:
349
- options = merge({}, getDefaultOptions(), rawOptions);
350
- finalOptions = {
351
- '--out-dir': options.destination,
352
- '--strip-leading-paths': true
353
- };
354
- swcrc = path.resolve(options.cwd, '.swcrc');
355
- _state.label = 1;
356
- case 1:
357
- _state.trys.push([
358
- 1,
359
- 3,
360
- ,
361
- 4
362
- ]);
363
- return [
364
- 4,
365
- fs.stat(swcrc)
366
- ];
367
- case 2:
368
- _state.sent();
369
- finalOptions['--config-file'] = swcrc;
370
- return [
371
- 3,
372
- 4
373
- ];
374
- case 3:
375
- e = _state.sent();
376
- return [
377
- 3,
378
- 4
379
- ];
380
- case 4:
381
- isValid = function(v) {
382
- return typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' && v;
383
- };
384
- compilerOptions = Object.entries(finalOptions).map(function(param) {
385
- var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
386
- return [
387
- k
388
- ].concat(_to_consumable_array(isValid(v) ? [
389
- typeof v === 'boolean' ? '' : "".concat(v)
390
- ] : [
391
- null
392
- ]));
393
- }).filter(function(param) {
394
- var _param = _sliced_to_array(param, 2), _ = _param[0], v = _param[1];
395
- return v !== null && v !== undefined;
396
- }).flat().filter(function(v) {
397
- return v !== '';
398
- });
399
- console.log('Building js files...');
400
- return [
401
- 4,
402
- runBin('swc', [
403
- options.source
404
- ].concat(_to_consumable_array(compilerOptions)))
405
- ];
406
- case 5:
407
- _state.sent();
408
- return [
409
- 2
410
- ];
411
- }
412
- });
413
- })();
63
+ export const buildEsm = async (rawOptions) => {
64
+ const options = merge({}, getDefaultOptions(), rawOptions);
65
+ const finalOptions = {
66
+ '--out-dir': options.destination,
67
+ '--strip-leading-paths': true,
68
+ };
69
+ const swcrc = path.resolve(options.cwd, '.swcrc');
70
+ try {
71
+ await fs.stat(swcrc);
72
+ finalOptions['--config-file'] = swcrc;
73
+ }
74
+ catch (e) { }
75
+ const isValid = (v) => typeof v === 'string' ||
76
+ typeof v === 'number' ||
77
+ (typeof v === 'boolean' && v);
78
+ const compilerOptions = Object.entries(finalOptions)
79
+ .map(([k, v]) => [
80
+ k,
81
+ ...(isValid(v) ? [typeof v === 'boolean' ? '' : `${v}`] : [null]),
82
+ ])
83
+ .filter(([_, v]) => v !== null && v !== undefined)
84
+ .flat()
85
+ .filter((v) => v !== '');
86
+ console.log('Building js files...');
87
+ await runBin('swc', [options.source, ...compilerOptions]);
414
88
  };
89
+ //# sourceMappingURL=build.js.map