1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | exports.AdonisRcFile = void 0;
|
12 | const Json_1 = require("../Formats/Json");
|
13 |
|
14 |
|
15 |
|
16 | class AdonisRcFile extends Json_1.JsonFile {
|
17 | constructor(basePath) {
|
18 | super(basePath, '.adonisrc.json');
|
19 | |
20 |
|
21 |
|
22 |
|
23 | this.preloads = [];
|
24 | |
25 |
|
26 |
|
27 |
|
28 | this.metaFiles = [];
|
29 | |
30 |
|
31 |
|
32 |
|
33 | this.commands = [];
|
34 | |
35 |
|
36 |
|
37 |
|
38 | this.providers = [];
|
39 | |
40 |
|
41 |
|
42 |
|
43 | this.aceProviders = [];
|
44 | |
45 |
|
46 |
|
47 |
|
48 | this.testProviders = [];
|
49 | this.preloads = this.get('preloads', []);
|
50 | this.metaFiles = this.get('metaFiles', []);
|
51 | this.commands = this.get('commands', []);
|
52 | this.providers = this.get('providers', []);
|
53 | this.aceProviders = this.get('aceProviders', []);
|
54 | this.testProviders = this.get('testProviders', []);
|
55 | }
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | onset(lifecycle, body) {
|
62 | if (lifecycle === 'rollback') {
|
63 | let key = null;
|
64 | if (body.key.startsWith('preloads')) {
|
65 | key = 'preloads';
|
66 | }
|
67 | if (body.key.startsWith('metaFiles')) {
|
68 | key = 'metaFiles';
|
69 | }
|
70 | if (body.key.startsWith('commands')) {
|
71 | key = 'commands';
|
72 | }
|
73 | if (body.key.startsWith('providers')) {
|
74 | key = 'providers';
|
75 | }
|
76 | if (body.key.startsWith('aceProviders')) {
|
77 | key = 'aceProviders';
|
78 | }
|
79 | if (body.key.startsWith('testProviders')) {
|
80 | key = 'testProviders';
|
81 | }
|
82 | if (!key) {
|
83 | return;
|
84 | }
|
85 | const index = body.key.split('[')[1].replace(/\]/g, '');
|
86 | this.get(key, []).splice(index, 1);
|
87 | return true;
|
88 | }
|
89 | }
|
90 | |
91 |
|
92 |
|
93 | setExceptionHandler(namespace) {
|
94 | this.set('exceptionHandlerNamespace', namespace);
|
95 | return this;
|
96 | }
|
97 | |
98 |
|
99 |
|
100 | setPreload(filePath, environment, optional) {
|
101 | let preloadIndex = this.preloads.findIndex((preload) => {
|
102 | if (preload.file) {
|
103 | return preload.file === filePath;
|
104 | }
|
105 | return preload === filePath;
|
106 | });
|
107 | preloadIndex = preloadIndex === -1 ? this.preloads.length : preloadIndex;
|
108 | let preloadEntry = {
|
109 | file: filePath,
|
110 | };
|
111 | |
112 |
|
113 |
|
114 | if (environment && environment.length) {
|
115 | preloadEntry.environment = environment;
|
116 | }
|
117 | |
118 |
|
119 |
|
120 | if (optional !== undefined) {
|
121 | preloadEntry.optional = optional;
|
122 | }
|
123 | |
124 |
|
125 |
|
126 |
|
127 | if (preloadEntry.optional === undefined && preloadEntry.environment === undefined) {
|
128 | preloadEntry = preloadEntry.file;
|
129 | }
|
130 | this.preloads[preloadIndex] = preloadEntry;
|
131 | this.set(`preloads[${preloadIndex}]`, preloadEntry);
|
132 | return this;
|
133 | }
|
134 | |
135 |
|
136 |
|
137 | setAlias(namespace, autoloadPath) {
|
138 | this.set(`aliases.${namespace}`, autoloadPath);
|
139 | return this;
|
140 | }
|
141 | |
142 |
|
143 |
|
144 | setDirectory(key, value) {
|
145 | this.set(`directories.${key}`, value);
|
146 | return this;
|
147 | }
|
148 | |
149 |
|
150 |
|
151 | addMetaFile(filePath, reloadServer) {
|
152 | let entryIndex = this.metaFiles.findIndex((file) => {
|
153 | if (file.pattern) {
|
154 | return file.pattern === filePath;
|
155 | }
|
156 | return file === filePath;
|
157 | });
|
158 | entryIndex = entryIndex === -1 ? this.metaFiles.length : entryIndex;
|
159 | const entry = reloadServer === false
|
160 | ? {
|
161 | pattern: filePath,
|
162 | reloadServer: false,
|
163 | }
|
164 | : filePath;
|
165 | this.metaFiles[entryIndex] = entry;
|
166 | this.set(`metaFiles[${entryIndex}]`, entry);
|
167 | }
|
168 | |
169 |
|
170 |
|
171 | addCommand(commandPath) {
|
172 | let entryIndex = this.commands.findIndex((command) => {
|
173 | return command === commandPath;
|
174 | });
|
175 | entryIndex = entryIndex === -1 ? this.commands.length : entryIndex;
|
176 | this.commands[entryIndex] = commandPath;
|
177 | this.set(`commands[${entryIndex}]`, commandPath);
|
178 | }
|
179 | |
180 |
|
181 |
|
182 | addProvider(provider) {
|
183 | let entryIndex = this.providers.findIndex((command) => {
|
184 | return command === provider;
|
185 | });
|
186 | entryIndex = entryIndex === -1 ? this.providers.length : entryIndex;
|
187 | this.providers[entryIndex] = provider;
|
188 | this.set(`providers[${entryIndex}]`, provider);
|
189 | }
|
190 | |
191 |
|
192 |
|
193 | addAceProvider(provider) {
|
194 | let entryIndex = this.aceProviders.findIndex((command) => {
|
195 | return command === provider;
|
196 | });
|
197 | entryIndex = entryIndex === -1 ? this.aceProviders.length : entryIndex;
|
198 | this.aceProviders[entryIndex] = provider;
|
199 | this.set(`aceProviders[${entryIndex}]`, provider);
|
200 | }
|
201 | |
202 |
|
203 |
|
204 | addTestProvider(provider) {
|
205 | let entryIndex = this.testProviders.findIndex((command) => {
|
206 | return command === provider;
|
207 | });
|
208 | entryIndex = entryIndex === -1 ? this.testProviders.length : entryIndex;
|
209 | this.testProviders[entryIndex] = provider;
|
210 | this.set(`testProviders[${entryIndex}]`, provider);
|
211 | }
|
212 | }
|
213 | exports.AdonisRcFile = AdonisRcFile;
|