miqro 6.2.3 → 6.2.5

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.
@@ -119,298 +119,241 @@ function createStaticRouterFromDirectory(service, logger, dir, inflateDir, route
119
119
  async function createRouterFromDirectory(server, hotreload, service, logger, dir, errors = [], routeFileMap = {}, staticFileMap = null, inflateDir, inflateSea) {
120
120
  const router = new Router();
121
121
  router.use(assertGlobalTampered);
122
- await Promise.all(scanFiles(dir).map(file => new Promise(async (resolve) => {
123
- try {
124
- switch (file.ext) {
125
- case ".jsx":
126
- case ".js":
127
- case ".ts":
128
- case ".tsx": {
129
- switch (file.subExt) {
130
- case ".test":
131
- return resolve();
132
- case ".ignore":
133
- logger.warn("ignoring [%s]", file.filePath);
134
- return resolve();
135
- case ".api": {
136
- const module = await importAPIRoute(file.filePath, logger);
137
- const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
138
- routeFileMap[file.filePath] = {
139
- routes,
140
- service,
141
- filePath: file.filePath,
142
- previewMethod: "api"
143
- };
144
- const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
145
- embemedJSX: false,
146
- minify: false,
147
- useExport: true,
148
- platform: "node",
149
- logger
150
- }) : "";
151
- for (const r of routes) {
152
- /*if (inflateDir && r.inflatePath) {
153
- const rPath = r.inflatePath;
154
- const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
155
- mkdirSync(dirname(inflatePath), {
156
- recursive: true
157
- });
158
- logger.log("writing [%s]", relative(cwd(), inflatePath));
159
- writeFileSync(inflatePath, inflatedCode);
160
- }*/
161
- if (inflateDir && r.defaultInflatePath && inflateSea) {
162
- const rPath = r.defaultInflatePath;
163
- const inflatePath = join(inflateDir, service, "http", rPath + ".api.cjs");
164
- mkdirSync(dirname(inflatePath), {
122
+ for (const file of scanFiles(dir)) {
123
+ await new Promise(async (resolve) => {
124
+ try {
125
+ switch (file.ext) {
126
+ case ".jsx":
127
+ case ".cjs":
128
+ case ".js":
129
+ case ".ts":
130
+ case ".tsx": {
131
+ switch (file.subExt) {
132
+ case ".test":
133
+ return resolve();
134
+ case ".ignore":
135
+ logger.warn("ignoring [%s]", file.filePath);
136
+ return resolve();
137
+ case ".api": {
138
+ const module = await importAPIRoute(file.filePath, logger);
139
+ const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
140
+ routeFileMap[file.filePath] = {
141
+ routes,
142
+ service,
143
+ filePath: file.filePath,
144
+ previewMethod: "api"
145
+ };
146
+ const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
147
+ embemedJSX: false,
148
+ minify: false,
149
+ useExport: true,
150
+ platform: "node",
151
+ logger
152
+ }) : "";
153
+ for (const r of routes) {
154
+ /*if (inflateDir && r.inflatePath) {
155
+ const rPath = r.inflatePath;
156
+ const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
157
+ mkdirSync(dirname(inflatePath), {
165
158
  recursive: true
166
- });
167
- logger.log("writing [%s]", relative(cwd(), inflatePath));
168
- writeFileSync(inflatePath, inflatedCode);
169
- }
170
- router.use(assertGlobalTampered);
171
- router.use(module.handler, r.path, r.method, r.options);
172
- }
173
- return resolve();
174
- }
175
- case ".json": {
176
- const module = await importJSONModule(file.filePath, logger);
177
- const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".json", module.apiOptions);
178
- routeFileMap[file.filePath] = {
179
- routes,
180
- service,
181
- filePath: file.filePath,
182
- previewMethod: "html"
183
- };
184
- for (const r of routes) {
185
- const contentType = CONTENT_TYPE_MAP[".json"] ? CONTENT_TYPE_MAP[".json"] : DEFAULT_CONTENT_TYPE;
186
- if (inflateDir) {
187
- if (r.inflatePath) {
188
- //if (r.method === "GET" || r.method === "get") {
189
- const rPath = r.inflatePath;
190
- const inflatePath = join(inflateDir, service, "static", rPath);
159
+ });
160
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
161
+ writeFileSync(inflatePath, inflatedCode);
162
+ }*/
163
+ if (inflateDir && r.defaultInflatePath && inflateSea) {
164
+ const rPath = r.defaultInflatePath;
165
+ const inflatePath = join(inflateDir, service, "http", rPath + ".api.cjs");
191
166
  mkdirSync(dirname(inflatePath), {
192
167
  recursive: true
193
168
  });
194
- if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
195
- logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
196
- continue;
197
- }
198
- const JSON_STATIC = await getJSON({ server }, null, newURL(r.path), module.apiOptions?.basePath, module.default);
199
- //const JSON = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
200
169
  logger.log("writing [%s]", relative(cwd(), inflatePath));
201
- writeFileSync(inflatePath, JSON_STATIC);
202
- //}
203
- if (staticFileMap && inflateSea) {
204
- staticFileMap[file.filePath] = {
205
- contentType,
206
- filePath: file.filePath,
207
- method: r.method,
208
- previewMethod: "html",
209
- path: r.path,
210
- body: Buffer.from(JSON_STATIC),
211
- inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
212
- };
213
- }
170
+ writeFileSync(inflatePath, inflatedCode);
214
171
  }
172
+ router.use(assertGlobalTampered);
173
+ router.use(module.handler, r.path, r.method, r.options);
215
174
  }
216
- router.use(assertGlobalTampered);
217
- router.use(async function (req, res) {
218
- const JSON = await getJSON(req, res, newURL(req.path), module.apiOptions?.basePath, module.default);
219
- return res.asyncEnd({
220
- status: 200,
221
- headers: {
222
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
223
- },
224
- body: JSON
225
- });
226
- }, r.path, r.method, r.options);
175
+ return resolve();
227
176
  }
228
- return resolve();
229
- }
230
- case ".html": {
231
- const module = await importHTMLModule(file.filePath, logger);
232
- const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".html", module.apiOptions);
233
- routeFileMap[file.filePath] = {
234
- routes,
235
- filePath: file.filePath,
236
- service,
237
- previewMethod: "html"
238
- };
239
- for (const r of routes) {
240
- const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
241
- if (inflateDir) {
242
- if (r.inflatePath) {
243
- //if (r.method === "GET" || r.method === "get") {
244
- const rPath = r.inflatePath;
245
- const inflatePath = join(inflateDir, service, "static", rPath);
246
- mkdirSync(dirname(inflatePath), {
247
- recursive: true
248
- });
249
- if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
250
- logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
251
- continue;
252
- }
253
- const toRender = typeof module.default === "function" ? module.default({ server }, null) : module.default;
254
- const HTML_STATIC = await getHTML(hotreload, { server }, null, newURL(r.path), module.apiOptions?.basePath, await toRender);
255
- logger.log("writing [%s]", relative(cwd(), inflatePath));
256
- writeFileSync(inflatePath, HTML_STATIC);
257
- //}
258
- if (staticFileMap && inflateSea) {
259
- staticFileMap[file.filePath + r.method + r.path] = {
260
- filePath: file.filePath,
261
- contentType,
262
- method: r.method,
263
- previewMethod: "html",
264
- path: r.path,
265
- body: Buffer.from(HTML_STATIC),
266
- inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
267
- };
177
+ case ".json": {
178
+ const module = await importJSONModule(file.filePath, logger);
179
+ const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".json", module.apiOptions);
180
+ routeFileMap[file.filePath] = {
181
+ routes,
182
+ service,
183
+ filePath: file.filePath,
184
+ previewMethod: "html"
185
+ };
186
+ for (const r of routes) {
187
+ const contentType = CONTENT_TYPE_MAP[".json"] ? CONTENT_TYPE_MAP[".json"] : DEFAULT_CONTENT_TYPE;
188
+ if (inflateDir) {
189
+ if (r.inflatePath) {
190
+ //if (r.method === "GET" || r.method === "get") {
191
+ const rPath = r.inflatePath;
192
+ const inflatePath = join(inflateDir, service, "static", rPath);
193
+ mkdirSync(dirname(inflatePath), {
194
+ recursive: true
195
+ });
196
+ if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
197
+ logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
198
+ continue;
199
+ }
200
+ const JSON_STATIC = await getJSON({ server }, null, newURL(r.path), module.apiOptions?.basePath, module.default);
201
+ //const JSON = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
202
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
203
+ writeFileSync(inflatePath, JSON_STATIC);
204
+ //}
205
+ if (staticFileMap && inflateSea) {
206
+ staticFileMap[file.filePath] = {
207
+ contentType,
208
+ filePath: file.filePath,
209
+ method: r.method,
210
+ previewMethod: "html",
211
+ path: r.path,
212
+ body: Buffer.from(JSON_STATIC),
213
+ inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
214
+ };
215
+ }
268
216
  }
269
217
  }
218
+ router.use(assertGlobalTampered);
219
+ router.use(async function (req, res) {
220
+ const JSON = await getJSON(req, res, newURL(req.path), module.apiOptions?.basePath, module.default);
221
+ return res.asyncEnd({
222
+ status: 200,
223
+ headers: {
224
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
225
+ },
226
+ body: JSON
227
+ });
228
+ }, r.path, r.method, r.options);
270
229
  }
271
- router.use(assertGlobalTampered);
272
- router.use(async function (req, res) {
273
- const toRender = typeof module.default === "function" ? module.default(req, res) : module.default;
274
- const HTML = await getHTML(hotreload, req, res, newURL(req.path), module.apiOptions?.basePath, await toRender);
275
- return res.asyncEnd({
276
- status: 200,
277
- headers: {
278
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
279
- },
280
- body: HTML
281
- });
282
- }, r.path, r.method, r.options);
230
+ return resolve();
283
231
  }
284
- return resolve();
285
- }
286
- case ".min":
287
- case ".js":
288
- default: {
289
- // allow fall-through when extension is .js and .ts because is a static route without embemedJSX
290
- if (file.ext !== ".js" && file.ext !== ".ts") {
291
- const code = await inflateJSX(file.filePath, {
292
- embemedJSX: true,
293
- minify: file.subExt === ".min" ? true : false,
294
- useExport: false,
295
- logger
296
- });
297
- const contentType = CONTENT_TYPE_MAP[".js"];
298
- const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
232
+ case ".html": {
233
+ const module = await importHTMLModule(file.filePath, logger);
234
+ const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".html", module.apiOptions);
299
235
  routeFileMap[file.filePath] = {
300
- routes: [{
301
- method: "GET",
302
- path
303
- }],
236
+ routes,
304
237
  filePath: file.filePath,
305
238
  service,
306
239
  previewMethod: "html"
307
240
  };
308
- if (inflateDir) {
309
- const inflatePath = join(inflateDir, service, "static", path);
310
- mkdirSync(dirname(inflatePath), {
311
- recursive: true
312
- });
313
- logger.log("writing [%s]", relative(cwd(), inflatePath));
314
- writeFileSync(inflatePath, code);
315
- if (staticFileMap && inflateSea) {
316
- staticFileMap[file.filePath] = {
317
- contentType,
318
- filePath: file.filePath,
319
- method: "GET",
320
- previewMethod: "html",
321
- path,
322
- body: Buffer.from(code),
323
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
324
- };
241
+ for (const r of routes) {
242
+ const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
243
+ if (inflateDir) {
244
+ if (r.inflatePath) {
245
+ //if (r.method === "GET" || r.method === "get") {
246
+ const rPath = r.inflatePath;
247
+ const inflatePath = join(inflateDir, service, "static", rPath);
248
+ mkdirSync(dirname(inflatePath), {
249
+ recursive: true
250
+ });
251
+ if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
252
+ logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
253
+ continue;
254
+ }
255
+ const toRender = typeof module.default === "function" ? module.default({ server }, null) : module.default;
256
+ const HTML_STATIC = await getHTML(hotreload, { server }, null, newURL(r.path), module.apiOptions?.basePath, await toRender);
257
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
258
+ writeFileSync(inflatePath, HTML_STATIC);
259
+ //}
260
+ if (staticFileMap && inflateSea) {
261
+ staticFileMap[file.filePath + r.method + r.path] = {
262
+ filePath: file.filePath,
263
+ contentType,
264
+ method: r.method,
265
+ previewMethod: "html",
266
+ path: r.path,
267
+ body: Buffer.from(HTML_STATIC),
268
+ inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
269
+ };
270
+ }
271
+ }
325
272
  }
273
+ router.use(assertGlobalTampered);
274
+ router.use(async function (req, res) {
275
+ const toRender = typeof module.default === "function" ? module.default(req, res) : module.default;
276
+ const HTML = await getHTML(hotreload, req, res, newURL(req.path), module.apiOptions?.basePath, await toRender);
277
+ return res.asyncEnd({
278
+ status: 200,
279
+ headers: {
280
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
281
+ },
282
+ body: HTML
283
+ });
284
+ }, r.path, r.method, r.options);
326
285
  }
327
- router.use(assertGlobalTampered);
328
- router.get(path, async function (req, res) {
329
- return res.asyncEnd({
330
- status: 200,
331
- headers: {
332
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
333
- },
334
- body: code
335
- });
336
- });
337
286
  return resolve();
338
287
  }
339
- }
340
- }
341
- }
342
- case ".md": {
343
- switch (file.subExt) {
344
- case ".html": {
345
- const code = await inflateMD2HTML(file.filePath, logger);
346
- const contentType = CONTENT_TYPE_MAP[".html"];
347
- const path = join("/", dirname(relative(dir, file.filePath)), file.name);
348
- routeFileMap[file.filePath] = {
349
- routes: [{
350
- method: "GET",
351
- path
352
- }],
353
- service,
354
- filePath: file.filePath,
355
- previewMethod: "html"
356
- };
357
- if (inflateDir) {
358
- const inflatePath = join(inflateDir, service, "static", path);
359
- mkdirSync(dirname(inflatePath), {
360
- recursive: true
361
- });
362
- logger.log("writing [%s]", relative(cwd(), inflatePath));
363
- writeFileSync(inflatePath, code);
364
- if (staticFileMap && inflateSea) {
365
- staticFileMap[file.filePath] = {
366
- contentType,
367
- method: "GET",
288
+ case ".min":
289
+ case ".js":
290
+ default: {
291
+ // allow fall-through when extension is .js and .ts because is a static route without embemedJSX
292
+ if (file.ext !== ".js" && file.ext !== ".ts") {
293
+ const code = await inflateJSX(file.filePath, {
294
+ embemedJSX: true,
295
+ minify: file.subExt === ".min" ? true : false,
296
+ useExport: false,
297
+ logger
298
+ });
299
+ const contentType = CONTENT_TYPE_MAP[".js"];
300
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
301
+ routeFileMap[file.filePath] = {
302
+ routes: [{
303
+ method: "GET",
304
+ path
305
+ }],
368
306
  filePath: file.filePath,
369
- previewMethod: "html",
370
- path,
371
- body: Buffer.from(code),
372
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
307
+ service,
308
+ previewMethod: "html"
373
309
  };
310
+ if (inflateDir) {
311
+ const inflatePath = join(inflateDir, service, "static", path);
312
+ mkdirSync(dirname(inflatePath), {
313
+ recursive: true
314
+ });
315
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
316
+ writeFileSync(inflatePath, code);
317
+ if (staticFileMap && inflateSea) {
318
+ staticFileMap[file.filePath] = {
319
+ contentType,
320
+ filePath: file.filePath,
321
+ method: "GET",
322
+ previewMethod: "html",
323
+ path,
324
+ body: Buffer.from(code),
325
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
326
+ };
327
+ }
328
+ }
329
+ router.use(assertGlobalTampered);
330
+ router.get(path, async function (req, res) {
331
+ return res.asyncEnd({
332
+ status: 200,
333
+ headers: {
334
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
335
+ },
336
+ body: code
337
+ });
338
+ });
339
+ return resolve();
374
340
  }
375
341
  }
376
- router.use(assertGlobalTampered);
377
- router.get(path, async function (_req, res) {
378
- res.asyncEnd({
379
- status: 200,
380
- headers: {
381
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
382
- },
383
- body: code
384
- });
385
- });
386
- return resolve();
387
342
  }
388
343
  }
389
- }
390
- default:
391
- if (file.ext === ".js" || file.ext === ".ts") {
344
+ case ".md": {
392
345
  switch (file.subExt) {
393
- case ".ignore": {
394
- logger.warn("ignoring [%s]", file.filePath);
395
- return resolve();
396
- }
397
- case ".bundle":
398
- case ".min": {
399
- const code = await inflateJSX(file.filePath, {
400
- embemedJSX: false,
401
- minify: file.subExt === ".min" ? true : false,
402
- useExport: false,
403
- logger
404
- });
405
- const contentType = CONTENT_TYPE_MAP[".js"];
406
- const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
346
+ case ".html": {
347
+ const code = await inflateMD2HTML(file.filePath, logger);
348
+ const contentType = CONTENT_TYPE_MAP[".html"];
349
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name);
407
350
  routeFileMap[file.filePath] = {
408
351
  routes: [{
409
352
  method: "GET",
410
353
  path
411
354
  }],
412
- filePath: file.filePath,
413
355
  service,
356
+ filePath: file.filePath,
414
357
  previewMethod: "html"
415
358
  };
416
359
  if (inflateDir) {
@@ -446,79 +389,139 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
446
389
  }
447
390
  }
448
391
  }
449
- else if (file.ext === ".bundle") {
450
- switch (file.subExt) {
451
- case ".ignore": {
452
- logger.warn("ignoring [%s]", file.filePath);
453
- return resolve();
454
- }
455
- case ".css": {
456
- const code = readFileSync(file.filePath).toString()
457
- .split("\n")
458
- .filter(c => c)
459
- .filter(c => c.charAt(0) !== "#")
460
- .map(cssPath => readFileSync(pathResolve(dirname(file.filePath), cssPath)).toString())
461
- .join("\n");
462
- const contentType = CONTENT_TYPE_MAP[".css"];
463
- const path = join("/", dirname(relative(dir, file.filePath)), file.name);
464
- routeFileMap[file.filePath] = {
465
- routes: [{
466
- method: "GET",
467
- path
468
- }],
469
- service,
470
- filePath: file.filePath,
471
- previewMethod: "html"
472
- };
473
- if (inflateDir) {
474
- const inflatePath = join(inflateDir, service, "static", path);
475
- mkdirSync(dirname(inflatePath), {
476
- recursive: true
392
+ default:
393
+ if (file.ext === ".js" || file.ext === ".ts") {
394
+ switch (file.subExt) {
395
+ case ".ignore": {
396
+ logger.warn("ignoring [%s]", file.filePath);
397
+ return resolve();
398
+ }
399
+ case ".bundle":
400
+ case ".min": {
401
+ const code = await inflateJSX(file.filePath, {
402
+ embemedJSX: false,
403
+ minify: file.subExt === ".min" ? true : false,
404
+ useExport: false,
405
+ logger
477
406
  });
478
- logger.log("writing [%s]", relative(cwd(), inflatePath));
479
- writeFileSync(inflatePath, code);
480
- if (staticFileMap && inflateSea) {
481
- staticFileMap[file.filePath] = {
482
- contentType,
483
- method: "GET",
484
- filePath: file.filePath,
485
- previewMethod: "html",
486
- path,
487
- body: Buffer.from(code),
488
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
489
- };
407
+ const contentType = CONTENT_TYPE_MAP[".js"];
408
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
409
+ routeFileMap[file.filePath] = {
410
+ routes: [{
411
+ method: "GET",
412
+ path
413
+ }],
414
+ filePath: file.filePath,
415
+ service,
416
+ previewMethod: "html"
417
+ };
418
+ if (inflateDir) {
419
+ const inflatePath = join(inflateDir, service, "static", path);
420
+ mkdirSync(dirname(inflatePath), {
421
+ recursive: true
422
+ });
423
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
424
+ writeFileSync(inflatePath, code);
425
+ if (staticFileMap && inflateSea) {
426
+ staticFileMap[file.filePath] = {
427
+ contentType,
428
+ method: "GET",
429
+ filePath: file.filePath,
430
+ previewMethod: "html",
431
+ path,
432
+ body: Buffer.from(code),
433
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
434
+ };
435
+ }
490
436
  }
437
+ router.use(assertGlobalTampered);
438
+ router.get(path, async function (_req, res) {
439
+ res.asyncEnd({
440
+ status: 200,
441
+ headers: {
442
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
443
+ },
444
+ body: code
445
+ });
446
+ });
447
+ return resolve();
491
448
  }
492
- router.use(assertGlobalTampered);
493
- router.get(path, async function (_req, res) {
494
- res.asyncEnd({
495
- status: 200,
496
- headers: {
497
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
498
- },
499
- body: code
449
+ }
450
+ }
451
+ else if (file.ext === ".bundle") {
452
+ switch (file.subExt) {
453
+ case ".ignore": {
454
+ logger.warn("ignoring [%s]", file.filePath);
455
+ return resolve();
456
+ }
457
+ case ".css": {
458
+ const code = readFileSync(file.filePath).toString()
459
+ .split("\n")
460
+ .filter(c => c)
461
+ .filter(c => c.charAt(0) !== "#")
462
+ .map(cssPath => readFileSync(pathResolve(dirname(file.filePath), cssPath)).toString())
463
+ .join("\n");
464
+ const contentType = CONTENT_TYPE_MAP[".css"];
465
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name);
466
+ routeFileMap[file.filePath] = {
467
+ routes: [{
468
+ method: "GET",
469
+ path
470
+ }],
471
+ service,
472
+ filePath: file.filePath,
473
+ previewMethod: "html"
474
+ };
475
+ if (inflateDir) {
476
+ const inflatePath = join(inflateDir, service, "static", path);
477
+ mkdirSync(dirname(inflatePath), {
478
+ recursive: true
479
+ });
480
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
481
+ writeFileSync(inflatePath, code);
482
+ if (staticFileMap && inflateSea) {
483
+ staticFileMap[file.filePath] = {
484
+ contentType,
485
+ method: "GET",
486
+ filePath: file.filePath,
487
+ previewMethod: "html",
488
+ path,
489
+ body: Buffer.from(code),
490
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
491
+ };
492
+ }
493
+ }
494
+ router.use(assertGlobalTampered);
495
+ router.get(path, async function (_req, res) {
496
+ res.asyncEnd({
497
+ status: 200,
498
+ headers: {
499
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
500
+ },
501
+ body: code
502
+ });
500
503
  });
501
- });
502
- return resolve();
504
+ return resolve();
505
+ }
503
506
  }
504
507
  }
505
- }
506
- createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
507
- return resolve();
508
+ createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
509
+ return resolve();
510
+ }
508
511
  }
509
- }
510
- catch (e) {
511
- logger.error("error with " + file.filePath);
512
- logger.error(e);
513
- errors.push({
514
- filePath: file.filePath,
515
- error: e
516
- });
517
- }
518
- finally {
519
- return resolve();
520
- }
521
- })));
512
+ catch (e) {
513
+ logger.error("error with " + file.filePath);
514
+ logger.error(e);
515
+ errors.push({
516
+ filePath: file.filePath,
517
+ error: e
518
+ });
519
+ }
520
+ finally {
521
+ return resolve();
522
+ }
523
+ });
524
+ }
522
525
  router.use(assertGlobalTampered);
523
526
  return {
524
527
  routeFileMap,