1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.ConfigPrinter = exports.ChainFormatter = void 0;
|
7 | function _gensync() {
|
8 | const data = require("gensync");
|
9 | _gensync = function () {
|
10 | return data;
|
11 | };
|
12 | return data;
|
13 | }
|
14 | const ChainFormatter = exports.ChainFormatter = {
|
15 | Programmatic: 0,
|
16 | Config: 1
|
17 | };
|
18 | const Formatter = {
|
19 | title(type, callerName, filepath) {
|
20 | let title = "";
|
21 | if (type === ChainFormatter.Programmatic) {
|
22 | title = "programmatic options";
|
23 | if (callerName) {
|
24 | title += " from " + callerName;
|
25 | }
|
26 | } else {
|
27 | title = "config " + filepath;
|
28 | }
|
29 | return title;
|
30 | },
|
31 | loc(index, envName) {
|
32 | let loc = "";
|
33 | if (index != null) {
|
34 | loc += `.overrides[${index}]`;
|
35 | }
|
36 | if (envName != null) {
|
37 | loc += `.env["${envName}"]`;
|
38 | }
|
39 | return loc;
|
40 | },
|
41 | *optionsAndDescriptors(opt) {
|
42 | const content = Object.assign({}, opt.options);
|
43 | delete content.overrides;
|
44 | delete content.env;
|
45 | const pluginDescriptors = [...(yield* opt.plugins())];
|
46 | if (pluginDescriptors.length) {
|
47 | content.plugins = pluginDescriptors.map(d => descriptorToConfig(d));
|
48 | }
|
49 | const presetDescriptors = [...(yield* opt.presets())];
|
50 | if (presetDescriptors.length) {
|
51 | content.presets = [...presetDescriptors].map(d => descriptorToConfig(d));
|
52 | }
|
53 | return JSON.stringify(content, undefined, 2);
|
54 | }
|
55 | };
|
56 | function descriptorToConfig(d) {
|
57 | var _d$file;
|
58 | let name = (_d$file = d.file) == null ? void 0 : _d$file.request;
|
59 | if (name == null) {
|
60 | if (typeof d.value === "object") {
|
61 | name = d.value;
|
62 | } else if (typeof d.value === "function") {
|
63 | name = `[Function: ${d.value.toString().slice(0, 50)} ... ]`;
|
64 | }
|
65 | }
|
66 | if (name == null) {
|
67 | name = "[Unknown]";
|
68 | }
|
69 | if (d.options === undefined) {
|
70 | return name;
|
71 | } else if (d.name == null) {
|
72 | return [name, d.options];
|
73 | } else {
|
74 | return [name, d.options, d.name];
|
75 | }
|
76 | }
|
77 | class ConfigPrinter {
|
78 | constructor() {
|
79 | this._stack = [];
|
80 | }
|
81 | configure(enabled, type, {
|
82 | callerName,
|
83 | filepath
|
84 | }) {
|
85 | if (!enabled) return () => {};
|
86 | return (content, index, envName) => {
|
87 | this._stack.push({
|
88 | type,
|
89 | callerName,
|
90 | filepath,
|
91 | content,
|
92 | index,
|
93 | envName
|
94 | });
|
95 | };
|
96 | }
|
97 | static *format(config) {
|
98 | let title = Formatter.title(config.type, config.callerName, config.filepath);
|
99 | const loc = Formatter.loc(config.index, config.envName);
|
100 | if (loc) title += ` ${loc}`;
|
101 | const content = yield* Formatter.optionsAndDescriptors(config.content);
|
102 | return `${title}\n${content}`;
|
103 | }
|
104 | *output() {
|
105 | if (this._stack.length === 0) return "";
|
106 | const configs = yield* _gensync().all(this._stack.map(s => ConfigPrinter.format(s)));
|
107 | return configs.join("\n\n");
|
108 | }
|
109 | }
|
110 | exports.ConfigPrinter = ConfigPrinter;
|
111 | 0 && 0;
|
112 |
|
113 |
|