@michijs/dev-server 0.4.3 → 0.5.1

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.
Files changed (43) hide show
  1. package/README.md +23 -2
  2. package/bin/actions/build.js +2 -2
  3. package/bin/actions/dist.js +5 -5
  4. package/bin/actions/generateAssets.d.ts +4 -0
  5. package/bin/actions/generateAssets.js +125 -0
  6. package/bin/actions/start.d.ts +1 -1
  7. package/bin/actions/start.js +46 -30
  8. package/bin/cli.js +33 -33
  9. package/bin/config/config.d.ts +111 -6
  10. package/bin/config/config.js +40 -31
  11. package/bin/config/getIPAddress.js +5 -3
  12. package/bin/config/michi.config.cjs +130 -134
  13. package/bin/config/public/client.js +1 -1
  14. package/bin/config/tsconfig.d.ts +1 -1
  15. package/bin/config/tsconfig.js +3 -3
  16. package/bin/config/userConfig.d.ts +1 -1
  17. package/bin/config/userConfig.js +18 -14
  18. package/bin/constants.d.ts +8 -0
  19. package/bin/constants.js +12 -0
  20. package/bin/index.d.ts +1 -1
  21. package/bin/index.js +1 -1
  22. package/bin/tsconfig.tsbuildinfo +1 -1
  23. package/bin/types.d.ts +71 -7
  24. package/bin/utils/copy.js +4 -4
  25. package/bin/utils/feature-image-template.svg +62 -0
  26. package/bin/utils/getAllFiles.js +2 -2
  27. package/bin/utils/getHostURL.d.ts +1 -0
  28. package/bin/utils/getHostURL.js +4 -0
  29. package/bin/utils/getLocalURL.d.ts +1 -0
  30. package/bin/utils/getLocalURL.js +3 -0
  31. package/bin/utils/getPath.js +1 -1
  32. package/bin/utils/minify.js +3 -3
  33. package/bin/utils/serviceWorkerTransformer.d.ts +2 -1
  34. package/bin/utils/serviceWorkerTransformer.js +8 -8
  35. package/bin/utils/transformers.d.ts +1 -1
  36. package/bin/utils/transformers.js +4 -4
  37. package/package.json +6 -17
  38. package/bin/actions/generateIcons.d.ts +0 -1
  39. package/bin/actions/generateIcons.js +0 -35
  40. package/bin/utils/transpileFileInThread.d.ts +0 -1
  41. package/bin/utils/transpileFileInThread.js +0 -15
  42. package/bin/utils/transpileFilesWithThreads.d.ts +0 -2
  43. package/bin/utils/transpileFilesWithThreads.js +0 -25
package/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Michijs Dev Server
2
2
  Development server built on top of esbuild.
3
+ <!-- TODO: To generate feature-image require to install roboto -->
3
4
 
4
5
  ![npm][version] [![license][github-license]][github-license-url] ![npm][npm-downloads] ![npm][repo-size]
5
6
  [![CodeQL](https://github.com/michijs/dev-server/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/michijs/dev-server/actions/workflows/codeql-analysis.yml)
@@ -91,14 +92,34 @@ export default config;
91
92
  <td colspan="3">If the browser should open at localhost url when server starts</td>
92
93
  <td>"true"</td>
93
94
  </tr>
95
+ <tr>
96
+ <td>watch</td>
97
+ <td colspan="3">If the server should watch for changes on the folders</td>
98
+ <td>"true"</td>
99
+ </tr>
94
100
  <tr>
95
101
  <td>port</td>
96
102
  <td colspan="3">Port to run dev server on</td>
97
103
  <td>"3000"</td>
98
104
  </tr>
99
105
  <tr>
100
- <td rowspan="10">public</td>
101
- <td rowspan="10">Public folder - will be copied at server start</td>
106
+ <td rowspan="14">public</td>
107
+ <td rowspan="14">Public folder - will be copied at server start</td>
108
+ <tr>
109
+ <td rowspan="4">assets</td>
110
+ <tr>
111
+ <td>path</td>
112
+ <td>"assets"</td>
113
+ </tr>
114
+ <tr>
115
+ <td>screenshots</td>
116
+ <td></td>
117
+ </tr>
118
+ <tr>
119
+ <td>featureImage</td>
120
+ <td></td>
121
+ </tr>
122
+ </tr>
102
123
  <tr>
103
124
  <td colspan="2">indexName</td>
104
125
  <td>"index.html"</td>
@@ -1,5 +1,5 @@
1
- import { config } from '../config/config.js';
2
- import { build as esbuild } from 'esbuild';
1
+ import { config } from "../config/config.js";
2
+ import { build as esbuild } from "esbuild";
3
3
  export function build(callback) {
4
4
  return new Promise((resolve, reject) => {
5
5
  esbuild(config.esbuildOptions)
@@ -1,11 +1,11 @@
1
- import { tsconfig } from '../config/tsconfig.js';
2
- import { config } from '../config/config.js';
3
- import { exec } from 'child_process';
4
- import fs from 'fs';
1
+ import { tsconfig } from "../config/tsconfig.js";
2
+ import { config } from "../config/config.js";
3
+ import { exec } from "child_process";
4
+ import fs from "fs";
5
5
  export function dist(callback, watch = false) {
6
6
  if (tsconfig.compilerOptions.outDir &&
7
7
  fs.existsSync(tsconfig.compilerOptions.outDir)) {
8
8
  fs.rmSync(tsconfig.compilerOptions.outDir, { recursive: true });
9
9
  }
10
- exec(`tsc ${watch ? '-w' : ''} --project ${config.esbuildOptions.tsconfig}`, callback);
10
+ exec(`tsc ${watch ? "-w" : ""} --project ${config.esbuildOptions.tsconfig}`, callback);
11
11
  }
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ export declare function generateFeatureImage(src: string): Promise<void>;
3
+ export declare function generateScreenshots(): Promise<(string | Buffer)[][]>;
4
+ export declare function generateAssets(callback: () => void, src: string): Promise<void>;
@@ -0,0 +1,125 @@
1
+ import { getPath } from "../utils/getPath.js";
2
+ import { config } from "../config/config.js";
3
+ import { mkdirSync, existsSync, writeFileSync, readFileSync, rmSync } from "fs";
4
+ import { pngToIco } from "../utils/pngToIco.js";
5
+ import { fileURLToPath } from "url";
6
+ import { dirname, resolve } from "path";
7
+ import sharp from "sharp";
8
+ import { getLocalURL } from "../utils/getLocalURL.js";
9
+ import { assetsSizes } from "../constants.js";
10
+ import puppeteer from "puppeteer";
11
+ const generatedPath = getPath(`${config.public.path}/${config.public.assets.path}/generated`);
12
+ const screenshotsPath = getPath(`${generatedPath}/screenshots`);
13
+ const svgPath = resolve(getPath(dirname(fileURLToPath(import.meta.url))), "../..");
14
+ const generateFavicon = async (src, dest) => {
15
+ const { default: sharp } = await import("sharp");
16
+ const image = await sharp(src);
17
+ const iconSizes = [16, 24, 32, 48, 64, 128, 256];
18
+ const resizedBuffers = await Promise.all(iconSizes.map((size) => {
19
+ return image.resize(size, size).png().toBuffer();
20
+ }));
21
+ writeFileSync(dest, await pngToIco(resizedBuffers, iconSizes));
22
+ };
23
+ config.watch = false;
24
+ config.openBrowser = false;
25
+ const browser = await puppeteer.launch({
26
+ dumpio: true,
27
+ headless: "new",
28
+ product: "chrome",
29
+ });
30
+ const port = await new Promise(async (resolve) => {
31
+ const { start } = await import("./start.js");
32
+ start((port) => resolve(port));
33
+ });
34
+ async function takeScreenshots({ viewports, options, pageCallback, path, }) {
35
+ return await Promise.all(viewports.map(async (viewport) => {
36
+ // Create a new page
37
+ const page = await browser.newPage();
38
+ await page.goto(`${getLocalURL(port)}${path}`);
39
+ await page.setViewport(viewport);
40
+ const suffix = await pageCallback?.(page);
41
+ const screenshot = await page.screenshot({
42
+ fullPage: true,
43
+ ...options?.(viewport, suffix ? `/${suffix}` : suffix),
44
+ });
45
+ await page.close();
46
+ return screenshot;
47
+ }));
48
+ }
49
+ export async function generateFeatureImage(src) {
50
+ const svgFilePath = getPath(`${svgPath}/feature-image-template.svg`);
51
+ const [screenshots, icon] = await Promise.all([
52
+ takeScreenshots({
53
+ viewports: [
54
+ // Phone
55
+ { width: 288, height: 387 },
56
+ // Tablet
57
+ { width: 390, height: 280 },
58
+ // Desktop
59
+ { width: 900, height: 550 },
60
+ ],
61
+ path: config.public.assets.featureImage.path,
62
+ pageCallback: config.public.assets.featureImage.pageCallback,
63
+ }),
64
+ sharp(src).resize(512, 512).png().toBuffer(),
65
+ ]);
66
+ const svg = readFileSync(svgFilePath);
67
+ const svgString = svg
68
+ .toString()
69
+ .replace("{{phone-href}}", `data:image/png;base64,${screenshots[0].toString("base64")}`)
70
+ .replace("{{tablet-href}}", `data:image/png;base64,${screenshots[1].toString("base64")}`)
71
+ .replace("{{pc-href}}", `data:image/png;base64,${screenshots[2].toString("base64")}`)
72
+ .replace("{{icon-href}}", `data:image/png;base64,${icon.toString("base64")}`)
73
+ .replace("{{background}}", config.public.manifest?.options?.background_color ?? "transparent")
74
+ .replace("{{app-title}}", config.public.manifest?.options?.name ?? "");
75
+ writeFileSync(getPath(`${generatedPath}/feature-image.svg`), svgString);
76
+ await sharp(Buffer.from(svgString))
77
+ .resize(1024, 500)
78
+ .png()
79
+ .toFile(getPath(`${generatedPath}/feature-image.png`));
80
+ }
81
+ export async function generateScreenshots() {
82
+ return await Promise.all(config.public.assets.screenshots.paths.flatMap((path) => config.public.assets.screenshots.pageCallbacks.map(async (pageCallback, index) => await takeScreenshots({
83
+ viewports: assetsSizes.screenshots,
84
+ path,
85
+ pageCallback,
86
+ options(viewport, pageSuffix = config.public.assets.screenshots.pageCallbacks
87
+ .length > 1
88
+ ? `_${index}`
89
+ : "") {
90
+ const screenshotPath = getPath(`${screenshotsPath}${pageSuffix}${path.replace("?", "_")}`);
91
+ if (!existsSync(screenshotPath))
92
+ mkdirSync(screenshotPath, { recursive: true });
93
+ return {
94
+ path: getPath(`${screenshotPath}/screenshot-${viewport.width}x${viewport.height}.png`),
95
+ };
96
+ },
97
+ }))));
98
+ }
99
+ export async function generateAssets(callback, src) {
100
+ rmSync(generatedPath, { recursive: true });
101
+ if (!existsSync(generatedPath))
102
+ mkdirSync(screenshotsPath, { recursive: true });
103
+ const image = sharp(src);
104
+ const fileNameWithoutExtension = src.split("/").at(-1)?.split(".")[0];
105
+ await Promise.all([
106
+ ...assetsSizes.webp.map((x) => {
107
+ return image
108
+ .resize(x, x)
109
+ .webp()
110
+ .toFile(getPath(`${generatedPath}/${fileNameWithoutExtension}-${x}.webp`));
111
+ }),
112
+ ...assetsSizes.png.map((x) => {
113
+ return image
114
+ .resize(x, x)
115
+ .png()
116
+ .toFile(getPath(`${generatedPath}/${fileNameWithoutExtension}-${x}.png`));
117
+ }),
118
+ generateFavicon(src, getPath(`${config.public.path}/favicon.ico`)),
119
+ generateFeatureImage(src),
120
+ generateScreenshots(),
121
+ ]);
122
+ callback();
123
+ await browser.close();
124
+ process.exit();
125
+ }
@@ -1 +1 @@
1
- export declare const start: (callback: () => void) => void;
1
+ export declare const start: (callback: (selectedPort: number) => void) => void;
@@ -1,21 +1,23 @@
1
- import http from 'http';
2
- import fs from 'fs';
3
- import { config, hostURL, localURL, connections } from '../config/config.js';
4
- import coloredString from '../utils/coloredString.js';
5
- import { getPath } from '../utils/getPath.js';
6
- import open from 'open';
7
- import { context } from 'esbuild';
8
- import watch from 'node-watch';
9
- import { copyFile } from '../utils/copy.js';
10
- import { sep } from 'path';
11
- import { transformers } from '../utils/transformers.js';
1
+ import http from "http";
2
+ import fs from "fs";
3
+ import { config, connections } from "../config/config.js";
4
+ import coloredString from "../utils/coloredString.js";
5
+ import { getPath } from "../utils/getPath.js";
6
+ import open from "open";
7
+ import { context } from "esbuild";
8
+ import watch from "node-watch";
9
+ import { copyFile } from "../utils/copy.js";
10
+ import { sep } from "path";
11
+ import { transformers } from "../utils/transformers.js";
12
+ import { getHostURL } from "../utils/getHostURL.js";
13
+ import { getLocalURL } from "../utils/getLocalURL.js";
12
14
  export const start = (callback) => {
13
15
  config.esbuildOptions.plugins?.push({
14
- name: 'michijs-dev-server-watch-public-folder',
16
+ name: "michijs-dev-server-watch-public-folder",
15
17
  setup(build) {
16
- if (config.public.path)
18
+ if (config.public.path && config.watch)
17
19
  watch.default(config.public.path, {
18
- encoding: 'utf-8',
20
+ encoding: "utf-8",
19
21
  persistent: true,
20
22
  recursive: true,
21
23
  }, (event, fileChangedPath) => {
@@ -29,7 +31,7 @@ export const start = (callback) => {
29
31
  fs.rmSync(getPath(`${outDir}/${transformers
30
32
  .find((x) => x.fileRegex.test(fileName))
31
33
  ?.pathTransformer?.(fileName) ?? fileName}`), { force: true, recursive: true });
32
- if (event === 'remove')
34
+ if (event === "remove")
33
35
  removed.push(fileChangedPath);
34
36
  else {
35
37
  updated.push(fileChangedPath);
@@ -48,9 +50,8 @@ export const start = (callback) => {
48
50
  const { host: esbuildHost, port: esbuildPort } = await buildContext.serve({
49
51
  servedir: config.esbuildOptions.outdir,
50
52
  });
51
- http
52
- .createServer(async (req, res) => {
53
- if (req.url === '/esbuild')
53
+ const server = http.createServer(async (req, res) => {
54
+ if (req.url === "/esbuild")
54
55
  connections.push(res);
55
56
  const esbuildProxyRequestOptions = {
56
57
  hostname: esbuildHost,
@@ -63,7 +64,7 @@ export const start = (callback) => {
63
64
  const proxyReq = http.request(esbuildProxyRequestOptions, (proxyRes) => {
64
65
  // If esbuild returns "not found", send a custom 404 page
65
66
  if (!proxyRes.statusCode || proxyRes.statusCode === 404) {
66
- res.writeHead(200, { 'Content-Type': 'text/html' });
67
+ res.writeHead(200, { "Content-Type": "text/html" });
67
68
  // TODO: Find a better way to do this
68
69
  res.end(fs.readFileSync(getPath(`${config.esbuildOptions.outdir}/${config.public.indexName}`)));
69
70
  return;
@@ -74,16 +75,31 @@ export const start = (callback) => {
74
75
  });
75
76
  // Forward the body of the request to esbuild
76
77
  req.pipe(proxyReq, { end: true });
77
- })
78
- .listen(config.port);
79
- console.log(`
80
- Server running at:
81
-
82
- > Network: ${coloredString(hostURL)}
83
- > Local: ${coloredString(localURL)}`);
84
- callback();
85
- buildContext.watch();
86
- if (config.openBrowser)
87
- open(localURL);
78
+ });
79
+ let selectedPort = config.port;
80
+ server.on("error", (e) => {
81
+ // @ts-ignore
82
+ if (e.code === "EADDRINUSE") {
83
+ selectedPort++;
84
+ server.listen(selectedPort);
85
+ }
86
+ else
87
+ throw e;
88
+ });
89
+ server.on("listening", () => {
90
+ const localURL = getLocalURL(selectedPort);
91
+ console.log(`
92
+ Server running at:
93
+
94
+ > Network: ${coloredString(getHostURL(selectedPort))}
95
+ > Local: ${coloredString(localURL)}`);
96
+ callback(selectedPort);
97
+ if (config.watch)
98
+ buildContext.watch();
99
+ if (config.openBrowser)
100
+ open(localURL);
101
+ });
102
+ // First try
103
+ server.listen(selectedPort);
88
104
  });
89
105
  };
package/bin/cli.js CHANGED
@@ -1,65 +1,65 @@
1
- import coloredString from './utils/coloredString.js';
2
- import yargs from 'yargs';
3
- import { Timer } from './classes/Timer.js';
4
- import { hideBin } from 'yargs/helpers';
1
+ import coloredString from "./utils/coloredString.js";
2
+ import yargs from "yargs";
3
+ import { Timer } from "./classes/Timer.js";
4
+ import { hideBin } from "yargs/helpers";
5
5
  export async function cli() {
6
6
  const timer = new Timer();
7
- const showReadyMessage = () => console.log(`
7
+ const showReadyMessage = () => console.log(`
8
8
  ${coloredString(`Ready in ${timer.endTimer()}ms.`)}`);
9
9
  timer.startTimer();
10
10
  const args = await yargs(hideBin(process.argv))
11
- .option('start', {
12
- type: 'boolean',
11
+ .option("start", {
12
+ type: "boolean",
13
13
  default: false,
14
- description: 'Allows to start a dev server as a webpage.',
14
+ description: "Allows to start a dev server as a webpage.",
15
15
  })
16
- .option('build', {
17
- type: 'boolean',
16
+ .option("build", {
17
+ type: "boolean",
18
18
  default: false,
19
- description: 'Allows to build the src code as a webpage.',
19
+ description: "Allows to build the src code as a webpage.",
20
20
  })
21
- .option('dist', {
22
- type: 'boolean',
21
+ .option("dist", {
22
+ type: "boolean",
23
23
  default: false,
24
- description: 'Allows to distribute the src code as a package.',
24
+ description: "Allows to distribute the src code as a package.",
25
25
  })
26
- .option('generate-icons', {
27
- type: 'string',
28
- description: 'Allows to generate a full set of icons from a src icon.',
26
+ .option("generate-assets", {
27
+ type: "string",
28
+ description: "Allows to generate a full set of icons and screenshots from a src icon.",
29
29
  })
30
- .option('watch', {
31
- type: 'boolean',
30
+ .option("watch", {
31
+ type: "boolean",
32
32
  default: false,
33
- alias: 'w',
33
+ alias: "w",
34
34
  })
35
- .option('env', {
36
- type: 'string',
35
+ .option("env", {
36
+ type: "string",
37
37
  })
38
- .option('env', {
39
- type: 'string',
38
+ .option("env", {
39
+ type: "string",
40
40
  })
41
41
  .help()
42
- .alias('help', 'h').argv;
42
+ .alias("help", "h").argv;
43
43
  process.env.NODE_ENV =
44
44
  args.env ||
45
- (args.build ? 'PRODUCTION' : args.dist ? 'DISTRIBUTION' : 'DEVELOPMENT');
46
- const generateIcons = args.generateIcons === '' ? 'public/assets/icon.svg' : args.generateIcons;
47
- if (generateIcons) {
48
- const action = await import('./actions/generateIcons.js');
49
- await action.generateIcons(showReadyMessage, generateIcons);
45
+ (args.build ? "PRODUCTION" : args.dist ? "DISTRIBUTION" : "DEVELOPMENT");
46
+ const generateAssets = args.generateAssets === "" ? "public/assets/icon.svg" : args.generateAssets;
47
+ if (generateAssets) {
48
+ const action = await import("./actions/generateAssets.js");
49
+ await action.generateAssets(showReadyMessage, generateAssets);
50
50
  }
51
51
  else
52
52
  console.log(coloredString(` Running in ${process.env.NODE_ENV} mode`));
53
53
  if (args.start) {
54
- const action = await import('./actions/start.js');
54
+ const action = await import("./actions/start.js");
55
55
  action.start(showReadyMessage);
56
56
  }
57
57
  if (args.build) {
58
- const action = await import('./actions/build.js');
58
+ const action = await import("./actions/build.js");
59
59
  action.build(showReadyMessage);
60
60
  }
61
61
  if (args.dist) {
62
- const action = await import('./actions/dist.js');
62
+ const action = await import("./actions/dist.js");
63
63
  action.dist(showReadyMessage, args.watch);
64
64
  }
65
65
  }
@@ -1,10 +1,115 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import { Config } from '../types.js';
3
- import http from 'http';
2
+ import http from "http";
4
3
  export declare const connections: (http.ServerResponse<http.IncomingMessage> & {
5
4
  req: http.IncomingMessage;
6
5
  })[];
7
- declare const config: Required<Config>;
8
- declare const hostURL: string;
9
- declare const localURL: string;
10
- export { config, hostURL, localURL };
6
+ declare const config: {
7
+ public: {
8
+ assets: {
9
+ screenshots: {
10
+ paths: string[];
11
+ pageCallbacks: import("../types.js").PageCallback<string | void>[];
12
+ };
13
+ featureImage: {
14
+ path: string;
15
+ pageCallback?: import("../types.js").PageCallback<void> | undefined;
16
+ };
17
+ path: string;
18
+ };
19
+ manifest: {
20
+ name: string;
21
+ options?: import("web-app-manifest").WebAppManifest | undefined;
22
+ };
23
+ wellKnown?: import("../types.js").WellKnown[] | undefined;
24
+ path: string;
25
+ indexName: string;
26
+ minify: boolean;
27
+ };
28
+ esbuildOptions: {
29
+ plugins: import("esbuild").Plugin[];
30
+ define: {
31
+ michiProcess: string;
32
+ };
33
+ inject: string[];
34
+ bundle: boolean;
35
+ splitting: boolean;
36
+ preserveSymlinks?: boolean | undefined;
37
+ outfile?: string | undefined;
38
+ metafile?: boolean | undefined;
39
+ outdir: string;
40
+ outbase?: string | undefined;
41
+ external?: string[] | undefined;
42
+ packages?: "external" | undefined;
43
+ alias?: Record<string, string> | undefined;
44
+ loader?: {
45
+ [ext: string]: import("esbuild").Loader;
46
+ } | undefined;
47
+ resolveExtensions?: string[] | undefined;
48
+ mainFields?: string[] | undefined;
49
+ conditions?: string[] | undefined;
50
+ write?: boolean | undefined;
51
+ allowOverwrite?: boolean | undefined;
52
+ tsconfig: string;
53
+ outExtension?: {
54
+ [ext: string]: string;
55
+ } | undefined;
56
+ publicPath?: string | undefined;
57
+ entryNames?: string | undefined;
58
+ chunkNames?: string | undefined;
59
+ assetNames?: string | undefined;
60
+ banner?: {
61
+ [type: string]: string;
62
+ } | undefined;
63
+ footer?: {
64
+ [type: string]: string;
65
+ } | undefined;
66
+ entryPoints: string[] | Record<string, string> | {
67
+ in: string;
68
+ out: string;
69
+ }[];
70
+ stdin?: import("esbuild").StdinOptions | undefined;
71
+ absWorkingDir?: string | undefined;
72
+ nodePaths?: string[] | undefined;
73
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
74
+ legalComments?: "linked" | "inline" | "external" | "none" | "eof" | undefined;
75
+ sourceRoot?: string | undefined;
76
+ sourcesContent?: boolean | undefined;
77
+ format: import("esbuild").Format;
78
+ globalName?: string | undefined;
79
+ target: string | string[];
80
+ supported?: Record<string, boolean> | undefined;
81
+ platform?: import("esbuild").Platform | undefined;
82
+ mangleProps?: RegExp | undefined;
83
+ reserveProps?: RegExp | undefined;
84
+ mangleQuoted?: boolean | undefined;
85
+ mangleCache?: Record<string, string | false> | undefined;
86
+ drop?: import("esbuild").Drop[] | undefined;
87
+ minify?: boolean | undefined;
88
+ minifyWhitespace: boolean;
89
+ minifyIdentifiers?: boolean | undefined;
90
+ minifySyntax: boolean;
91
+ charset?: import("esbuild").Charset | undefined;
92
+ treeShaking?: boolean | undefined;
93
+ ignoreAnnotations?: boolean | undefined;
94
+ jsx?: "transform" | "preserve" | "automatic" | undefined;
95
+ jsxFactory?: string | undefined;
96
+ jsxFragment?: string | undefined;
97
+ jsxImportSource?: string | undefined;
98
+ jsxDev?: boolean | undefined;
99
+ jsxSideEffects?: boolean | undefined;
100
+ pure?: string[] | undefined;
101
+ keepNames: boolean;
102
+ color?: boolean | undefined;
103
+ logLevel: import("esbuild").LogLevel;
104
+ logLimit?: number | undefined;
105
+ logOverride?: Record<string, import("esbuild").LogLevel> | undefined;
106
+ };
107
+ env?: {
108
+ [key: string]: any;
109
+ } | undefined;
110
+ watch: boolean;
111
+ port: number;
112
+ openBrowser: boolean;
113
+ showLinkedPackages: boolean;
114
+ };
115
+ export { config };
@@ -1,48 +1,61 @@
1
- import fs from 'fs';
2
- import coloredString from '../utils/coloredString.js';
3
- import { copy } from '../utils/copy.js';
4
- import { getPath } from '../utils/getPath.js';
5
- import { Timer } from '../classes/Timer.js';
6
- import { getIPAddress } from './getIPAddress.js';
7
- import { userConfig } from './userConfig.js';
8
- import { resolve } from 'path';
9
- import { jsAndTsRegex, jsonTransformer, notJsAndTsRegex, } from '../utils/transformers.js';
10
- import { dirname } from 'path';
11
- import { fileURLToPath } from 'url';
12
- const minify = process.env.NODE_ENV === 'PRODUCTION';
13
- const devServerListener = process.env.NODE_ENV === 'DEVELOPMENT'
1
+ import fs from "fs";
2
+ import coloredString from "../utils/coloredString.js";
3
+ import { copy } from "../utils/copy.js";
4
+ import { getPath } from "../utils/getPath.js";
5
+ import { Timer } from "../classes/Timer.js";
6
+ import { userConfig } from "./userConfig.js";
7
+ import { resolve } from "path";
8
+ import { jsAndTsRegex, jsonTransformer, notJsAndTsRegex, } from "../utils/transformers.js";
9
+ import { dirname } from "path";
10
+ import { fileURLToPath } from "url";
11
+ const minify = process.env.NODE_ENV === "PRODUCTION";
12
+ const devServerListener = process.env.NODE_ENV === "DEVELOPMENT"
14
13
  ? [getPath(`${dirname(fileURLToPath(import.meta.url))}/public/client.js`)]
15
14
  : [];
16
15
  export const connections = [];
17
16
  const config = {
18
17
  port: 3000,
19
- openBrowser: process.env.NODE_ENV === 'DEVELOPMENT',
18
+ openBrowser: process.env.NODE_ENV === "DEVELOPMENT",
20
19
  showLinkedPackages: true,
20
+ watch: true,
21
21
  ...userConfig,
22
22
  // protocol: 'http',
23
23
  public: {
24
- path: 'public',
25
- indexName: 'index.html',
24
+ path: "public",
25
+ indexName: "index.html",
26
26
  minify: minify,
27
27
  ...(userConfig.public ?? {}),
28
+ assets: {
29
+ path: "assets",
30
+ ...(userConfig.public?.assets ?? {}),
31
+ screenshots: {
32
+ paths: ["/"],
33
+ pageCallbacks: [() => { }],
34
+ ...(userConfig.public?.assets?.screenshots ?? {}),
35
+ },
36
+ featureImage: {
37
+ path: "/",
38
+ ...(userConfig.public?.assets?.featureImage ?? {}),
39
+ },
40
+ },
28
41
  manifest: {
29
- name: 'manifest.json',
42
+ name: "manifest.json",
30
43
  ...(userConfig.public?.manifest ?? {}),
31
44
  },
32
45
  },
33
46
  esbuildOptions: {
34
- outdir: 'build',
35
- tsconfig: 'tsconfig.json',
47
+ outdir: "build",
48
+ tsconfig: "tsconfig.json",
36
49
  minifySyntax: minify,
37
50
  minifyWhitespace: minify,
38
- sourcemap: process.env.NODE_ENV !== 'PRODUCTION',
51
+ sourcemap: process.env.NODE_ENV !== "PRODUCTION",
39
52
  splitting: true,
40
53
  bundle: true,
41
54
  keepNames: minify,
42
- entryPoints: ['src/index.ts'],
43
- format: 'esm',
44
- target: 'esnext',
45
- logLevel: 'error',
55
+ entryPoints: ["src/index.ts"],
56
+ format: "esm",
57
+ target: "esnext",
58
+ logLevel: "error",
46
59
  ...(userConfig.esbuildOptions ?? {}),
47
60
  // Still not supported
48
61
  // bug .css.ts
@@ -68,7 +81,7 @@ const config = {
68
81
  plugins: [
69
82
  ...(userConfig.esbuildOptions?.plugins ?? []),
70
83
  {
71
- name: 'michijs-dev-server',
84
+ name: "michijs-dev-server",
72
85
  setup(build) {
73
86
  // Clean outdir
74
87
  if (build.initialOptions.outdir) {
@@ -124,10 +137,6 @@ const config = {
124
137
  ...(userConfig.esbuildOptions?.define ?? {}),
125
138
  },
126
139
  };
127
- const hostURL = `http://${getIPAddress()}:${config.port}`;
128
- const localURL = `http://localhost:${config.port}`;
129
- // const hostURL = `${config.protocol}://${config.hostname}:${config.port}`;
130
- // const localURL = `${config.protocol}://localhost:${config.port}`;
131
140
  function findSymbolickLinkRealPath(packagePath) {
132
141
  if (fs.lstatSync(packagePath).isSymbolicLink()) {
133
142
  // Getting absolute path for the simbolic link
@@ -136,7 +145,7 @@ function findSymbolickLinkRealPath(packagePath) {
136
145
  return packagePath;
137
146
  }
138
147
  if (config.showLinkedPackages) {
139
- const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
148
+ const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
140
149
  const dependencies = Object.keys(packageJson.dependencies || {});
141
150
  const devDependencies = Object.keys(packageJson.devDependencies || {});
142
151
  dependencies.concat(devDependencies).forEach((packagePath) => {
@@ -147,4 +156,4 @@ if (config.showLinkedPackages) {
147
156
  }
148
157
  });
149
158
  }
150
- export { config, hostURL, localURL };
159
+ export { config };