@michijs/dev-server 0.1.0

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 (44) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +150 -0
  3. package/bin/actions/build.d.ts +1 -0
  4. package/bin/actions/build.js +24 -0
  5. package/bin/actions/dist.d.ts +1 -0
  6. package/bin/actions/dist.js +17 -0
  7. package/bin/actions/start.d.ts +1 -0
  8. package/bin/actions/start.js +56 -0
  9. package/bin/cli.d.ts +1 -0
  10. package/bin/cli.js +72 -0
  11. package/bin/config/config.d.ts +5 -0
  12. package/bin/config/config.js +110 -0
  13. package/bin/config/getIPAddress.d.ts +1 -0
  14. package/bin/config/getIPAddress.js +18 -0
  15. package/bin/config/public/client.d.ts +0 -0
  16. package/bin/config/public/client.js +1 -0
  17. package/bin/config/tsconfig.d.ts +7 -0
  18. package/bin/config/tsconfig.js +16 -0
  19. package/bin/config/userConfig.d.ts +2 -0
  20. package/bin/config/userConfig.js +27 -0
  21. package/bin/global.d.ts +4 -0
  22. package/bin/global.js +0 -0
  23. package/bin/index.d.ts +2 -0
  24. package/bin/index.js +5 -0
  25. package/bin/tsconfig.tsbuildinfo +1 -0
  26. package/bin/types.d.ts +51 -0
  27. package/bin/types.js +2 -0
  28. package/bin/utils/coloredString.d.ts +2 -0
  29. package/bin/utils/coloredString.js +3 -0
  30. package/bin/utils/copy.d.ts +7 -0
  31. package/bin/utils/copy.js +30 -0
  32. package/bin/utils/getAllFiles.d.ts +1 -0
  33. package/bin/utils/getAllFiles.js +23 -0
  34. package/bin/utils/getPath.d.ts +1 -0
  35. package/bin/utils/getPath.js +8 -0
  36. package/bin/utils/injectServiceWorker.d.ts +1 -0
  37. package/bin/utils/injectServiceWorker.js +59 -0
  38. package/bin/utils/minifyHTML.d.ts +1 -0
  39. package/bin/utils/minifyHTML.js +8 -0
  40. package/bin/utils/setupBuild.d.ts +1 -0
  41. package/bin/utils/setupBuild.js +24 -0
  42. package/bin/utils/timer.d.ts +5 -0
  43. package/bin/utils/timer.js +12 -0
  44. package/package.json +58 -0
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-present, michijs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # Michi Dev Server
2
+ Development server built with esbuild.
3
+
4
+ ![npm][version] [![license][github-license]][github-license-url] ![npm][npm-downloads] ![npm][repo-size]
5
+ [![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)
6
+ [![Tests](https://github.com/michijs/dev-server/actions/workflows/tests.yml/badge.svg)](https://github.com/michijs/dev-server/actions/workflows/tests.yml)
7
+
8
+ ## Main features
9
+ - Configure esbuild options with Typescript
10
+ - First-class PWA support
11
+ - Custom environments
12
+ - Packages distribution
13
+
14
+ ## Getting started
15
+
16
+ You can use the following [test project](https://github.com/michijs/michijs-template) or setup a project from scratch:
17
+
18
+ npm install -D @michijs/dev-server
19
+
20
+
21
+ To configure the server you just need to create an optional file called michi.config.ts at the root of your project. This file would look like this:
22
+
23
+ ```ts
24
+ import { ServerConfig, ServerConfigFactory, DefaultEnvironment } from '@michijs/server';
25
+
26
+ export const config: ServerConfigFactory = (environment) => {
27
+ const defaultConfig: ServerConfig = {
28
+ // Your custom configuration
29
+ }
30
+ return defaultConfig;
31
+ };
32
+
33
+ export default config;
34
+ ```
35
+
36
+ <table>
37
+ <thead>
38
+ <tr>
39
+ <th colspan="3">ServerConfig</th>
40
+ <th>Default value</th>
41
+ </tr>
42
+ </thead>
43
+ <tbody>
44
+ <tr>
45
+ <td>env</td>
46
+ <td colspan="2">Allows to add environment variables</td>
47
+ <td></td>
48
+ </tr>
49
+ <tr>
50
+ <td>esbuildOptions</td>
51
+ <td colspan="2">All the options available at <a href="https://esbuild.github.io/plugins/#build-options">esbuild documentation</a></td>
52
+ <td>Can be chequed <a href="#esbuild-default-options">here</a></td>
53
+ </tr>
54
+ <tr>
55
+ <td>openBrowser</td>
56
+ <td colspan="2">If the browser should open at localhost url when server starts</td>
57
+ <td>true</td>
58
+ </tr>
59
+ <tr>
60
+ <td>port</td>
61
+ <td colspan="2">Port to run dev server on</td>
62
+ <td>3000</td>
63
+ </tr>
64
+ <tr>
65
+ <td rowspan="5">public</td>
66
+ <td rowspan="5">Public folder - will be copied at server start</td>
67
+ <tr>
68
+ <td>path</td>
69
+ <td>public</td>
70
+ </tr>
71
+ <tr>
72
+ <td>indexName</td>
73
+ <td>index.html</td>
74
+ </tr>
75
+ <tr>
76
+ <td>minifyIndex</td>
77
+ <td>true if environment is PRODUCTION</td>
78
+ </tr>
79
+ <tr>
80
+ <td>serviceWorkerName</td>
81
+ <td></td>
82
+ </tr>
83
+ </tr>
84
+ </tbody>
85
+ </table>
86
+
87
+ ## Esbuild default options
88
+
89
+ <table>
90
+ <thead>
91
+ <tr>
92
+ <th>Field</th>
93
+ <th>Default value</th>
94
+ </tr>
95
+ </thead>
96
+ <tbody>
97
+ <tr>
98
+ <td>outdir</td>
99
+ <td>"build"</td>
100
+ </tr>
101
+ <tr>
102
+ <td>tsconfig</td>
103
+ <td>"tsconfig.json"</td>
104
+ </tr>
105
+ <tr>
106
+ <td>minifySyntax</td>
107
+ <td>"true" if environment is PRODUCTION</td>
108
+ </tr>
109
+ <tr>
110
+ <td>minifyWhitespace</td>
111
+ <td>"true" if environment is PRODUCTION</td>
112
+ </tr>
113
+ <tr>
114
+ <td>sourcemap</td>
115
+ <td>"true" if environment is <b>NOT</b> PRODUCTION</td>
116
+ </tr>
117
+ <tr>
118
+ <td>bundle</td>
119
+ <td>"true"</td>
120
+ </tr>
121
+ <tr>
122
+ <td>keepNames</td>
123
+ <td>"true" if environment is PRODUCTION</td>
124
+ </tr>
125
+ <tr>
126
+ <td>entryPoints</td>
127
+ <td>['src/index.ts']</td>
128
+ </tr>
129
+ <tr>
130
+ <td>format</td>
131
+ <td>"esm"</td>
132
+ </tr>
133
+ <tr>
134
+ <td>target</td>
135
+ <td>"esnext"</td>
136
+ </tr>
137
+ </tbody>
138
+ </table>
139
+
140
+ ## Distribution
141
+ At the moment ESBuild does not support .d.ts files so we still use the Typescript compiler with the tsconfig provided by esbuildOptions field.
142
+
143
+ ## License
144
+ - [MIT](https://github.com/michijs/dev-server/blob/master/LICENSE.md)
145
+
146
+ [repo-size]: https://img.shields.io/github/repo-size/michijs/dev-server
147
+ [npm-downloads]: https://img.shields.io/npm/dt/@michijs/dev-server
148
+ [version]: https://img.shields.io/npm/v/@michijs/dev-server
149
+ [github-license]: https://img.shields.io/github/license/michijs/dev-server
150
+ [github-license-url]: https://github.com/michijs/dev-server/blob/master/LICENSE.md
@@ -0,0 +1 @@
1
+ export declare function build(callback?: Function): Promise<unknown>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.build = void 0;
7
+ const config_1 = require("../config/config");
8
+ const esbuild_1 = require("esbuild");
9
+ const timer_1 = __importDefault(require("../utils/timer"));
10
+ const setupBuild_1 = require("../utils/setupBuild");
11
+ function build(callback) {
12
+ const timer = new timer_1.default();
13
+ timer.startTimer();
14
+ (0, setupBuild_1.setupBuild)();
15
+ return new Promise((resolve) => {
16
+ (0, esbuild_1.build)(config_1.config.esbuildOptions).then(() => {
17
+ callback?.();
18
+ resolve(true);
19
+ }).catch(() => {
20
+ return Promise.resolve();
21
+ });
22
+ });
23
+ }
24
+ exports.build = build;
@@ -0,0 +1 @@
1
+ export declare function dist(callback: () => void, watch?: boolean): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dist = void 0;
7
+ const tsconfig_1 = require("../config/tsconfig");
8
+ const config_1 = require("../config/config");
9
+ const child_process_1 = require("child_process");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ function dist(callback, watch = false) {
12
+ if (tsconfig_1.tsconfig.compilerOptions.outDir && fs_1.default.existsSync(tsconfig_1.tsconfig.compilerOptions.outDir)) {
13
+ fs_1.default.rmSync(tsconfig_1.tsconfig.compilerOptions.outDir, { recursive: true });
14
+ }
15
+ (0, child_process_1.exec)(`tsc ${watch ? '-w' : ''} --project ${config_1.config.esbuildOptions.tsconfig}`, callback);
16
+ }
17
+ exports.dist = dist;
@@ -0,0 +1 @@
1
+ export declare const start: (callback: () => void) => void;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.start = void 0;
7
+ const http_1 = __importDefault(require("http"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const config_1 = require("../config/config");
10
+ const coloredString_1 = __importDefault(require("../utils/coloredString"));
11
+ const getPath_1 = require("../utils/getPath");
12
+ const open_1 = __importDefault(require("open"));
13
+ const esbuild_1 = require("esbuild");
14
+ const setupBuild_1 = require("../utils/setupBuild");
15
+ const start = (callback) => {
16
+ (0, setupBuild_1.setupBuild)();
17
+ (0, esbuild_1.context)(config_1.config.esbuildOptions).then(async (buildContext) => {
18
+ const { host: esbuildHost, port: esbuildPort } = await buildContext.serve({
19
+ servedir: config_1.config.esbuildOptions.outdir,
20
+ });
21
+ http_1.default.createServer(async (req, res) => {
22
+ const esbuildProxyRequestOptions = {
23
+ hostname: esbuildHost,
24
+ port: esbuildPort,
25
+ path: req.url,
26
+ method: req.method,
27
+ headers: req.headers,
28
+ };
29
+ // Forward each incoming request to esbuild
30
+ const proxyReq = http_1.default.request(esbuildProxyRequestOptions, proxyRes => {
31
+ // If esbuild returns "not found", send a custom 404 page
32
+ if (!proxyRes.statusCode || proxyRes.statusCode === 404) {
33
+ res.writeHead(200, { 'Content-Type': 'text/html' });
34
+ // TODO: Find a better way to do this
35
+ res.end(fs_1.default.readFileSync((0, getPath_1.getPath)(`${config_1.config.esbuildOptions.outdir}/${config_1.config.public.indexName}`)));
36
+ return;
37
+ }
38
+ // Otherwise, forward the response from esbuild to the client
39
+ res.writeHead(proxyRes.statusCode, proxyRes.headers);
40
+ proxyRes.pipe(res, { end: true });
41
+ });
42
+ // Forward the body of the request to esbuild
43
+ req.pipe(proxyReq, { end: true });
44
+ }).listen(config_1.config.port);
45
+ console.log(`
46
+ Server running at:
47
+
48
+ > Network: ${(0, coloredString_1.default)(config_1.hostURL)}
49
+ > Local: ${(0, coloredString_1.default)(config_1.localURL)}`);
50
+ callback();
51
+ buildContext.watch();
52
+ if (config_1.config.openBrowser)
53
+ (0, open_1.default)(config_1.localURL);
54
+ });
55
+ };
56
+ exports.start = start;
package/bin/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function cli(): Promise<void>;
package/bin/cli.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.cli = void 0;
30
+ const coloredString_1 = __importDefault(require("./utils/coloredString"));
31
+ const yargs = __importStar(require("yargs"));
32
+ const timer_1 = __importDefault(require("./utils/timer"));
33
+ async function cli() {
34
+ const timer = new timer_1.default();
35
+ const showReadyMessage = () => console.log(`
36
+ ${(0, coloredString_1.default)(`Ready in ${timer.endTimer()}ms.`)}`);
37
+ timer.startTimer();
38
+ const args = await yargs
39
+ .option('start', {
40
+ type: 'boolean',
41
+ default: false
42
+ })
43
+ .option('build', {
44
+ type: 'boolean',
45
+ default: false
46
+ })
47
+ .option('dist', {
48
+ type: 'boolean',
49
+ default: false
50
+ })
51
+ .option('env', {
52
+ type: 'string'
53
+ })
54
+ .help()
55
+ .alias('help', 'h')
56
+ .argv;
57
+ process.env.NODE_ENV = args.env || (args.build ? 'PRODUCTION' : args.dist ? 'DISTRIBUTION' : 'DEVELOPMENT');
58
+ console.log((0, coloredString_1.default)(` Running in ${process.env.NODE_ENV} mode`));
59
+ if (args.start) {
60
+ const action = await Promise.resolve().then(() => __importStar(require('./actions/start')));
61
+ action.start(showReadyMessage);
62
+ }
63
+ if (args.build) {
64
+ const action = await Promise.resolve().then(() => __importStar(require('./actions/build')));
65
+ action.build(showReadyMessage);
66
+ }
67
+ if (args.dist) {
68
+ const action = await Promise.resolve().then(() => __importStar(require('./actions/dist')));
69
+ action.dist(showReadyMessage);
70
+ }
71
+ }
72
+ exports.cli = cli;
@@ -0,0 +1,5 @@
1
+ import { Config } from '../types';
2
+ declare const config: Required<Config>;
3
+ declare const hostURL: string;
4
+ declare const localURL: string;
5
+ export { config, hostURL, localURL };
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.localURL = exports.hostURL = exports.config = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const coloredString_1 = __importDefault(require("../utils/coloredString"));
9
+ const getPath_1 = require("../utils/getPath");
10
+ const timer_1 = __importDefault(require("../utils/timer"));
11
+ const getIPAddress_1 = require("./getIPAddress");
12
+ const userConfig_1 = require("./userConfig");
13
+ const minify = process.env.NODE_ENV === 'PRODUCTION';
14
+ const devServerListener = process.env.NODE_ENV === 'DEVELOPMENT' ? [(0, getPath_1.getPath)(`${__dirname}/public/client.js`)] : [];
15
+ const config = {
16
+ port: 3000,
17
+ openBrowser: process.env.NODE_ENV === 'DEVELOPMENT',
18
+ showLinkedPackages: true,
19
+ ...userConfig_1.userConfig,
20
+ // protocol: 'http',
21
+ public: {
22
+ path: 'public',
23
+ indexName: 'index.html',
24
+ minifyIndex: minify,
25
+ ...(userConfig_1.userConfig.public ?? {})
26
+ },
27
+ esbuildOptions: {
28
+ outdir: 'build',
29
+ tsconfig: 'tsconfig.json',
30
+ minifySyntax: minify,
31
+ minifyWhitespace: minify,
32
+ sourcemap: process.env.NODE_ENV !== 'PRODUCTION',
33
+ bundle: true,
34
+ keepNames: minify,
35
+ entryPoints: ['src/index.ts'],
36
+ format: 'esm',
37
+ target: 'esnext',
38
+ ...(userConfig_1.userConfig.esbuildOptions ?? {}),
39
+ // Still not supported
40
+ // bug .css.ts
41
+ // plugins: [
42
+ // {
43
+ // name: 'css-assert-import',
44
+ // setup(build) {
45
+ // build.onResolve({ filter: /\.css$/ }, (args) => {
46
+ // const splittedPath = args.path.split('/');
47
+ // const fileName = splittedPath[splittedPath.length - 1];
48
+ // const splittedFileName = fileName.split('.');
49
+ // const fileNameOnBuild = `${splittedFileName[0]}-${new Date().getTime()}.${splittedFileName.splice(1).join('.')}`;
50
+ // const srcPath = path.resolve(args.resolveDir, args.path);
51
+ // const destPath = path.resolve(build.initialOptions.outdir, fileNameOnBuild);
52
+ // if (!fs.existsSync(build.initialOptions.outdir))
53
+ // fs.mkdirSync(build.initialOptions.outdir);
54
+ // fs.copyFileSync(srcPath, destPath);
55
+ // return { path: `./${fileNameOnBuild}`, external: true, watchFiles: [srcPath] };
56
+ // });
57
+ // },
58
+ // }
59
+ // ],
60
+ plugins: [
61
+ ...(userConfig_1.userConfig.esbuildOptions?.plugins ?? []),
62
+ {
63
+ name: 'track-build-time',
64
+ setup(build) {
65
+ let timer = new timer_1.default();
66
+ build.onStart(() => timer.startTimer());
67
+ build.onEnd(() => {
68
+ console.log((0, coloredString_1.default)(` Build finished in ${timer.endTimer()}ms`));
69
+ });
70
+ }
71
+ }
72
+ ],
73
+ define: {
74
+ // Intentionally added before process
75
+ process: JSON.stringify({
76
+ env: {
77
+ NODE_ENV: process.env.NODE_ENV,
78
+ ...(userConfig_1.userConfig.env ?? {})
79
+ }
80
+ })
81
+ },
82
+ inject: [...devServerListener, ...(userConfig_1.userConfig.esbuildOptions?.inject ?? [])],
83
+ ...(userConfig_1.userConfig.esbuildOptions?.define ?? {}),
84
+ }
85
+ };
86
+ exports.config = config;
87
+ const hostURL = `http://${(0, getIPAddress_1.getIPAddress)()}:${config.port}`;
88
+ exports.hostURL = hostURL;
89
+ const localURL = `http://localhost:${config.port}`;
90
+ exports.localURL = localURL;
91
+ // const hostURL = `${config.protocol}://${config.hostname}:${config.port}`;
92
+ // const localURL = `${config.protocol}://localhost:${config.port}`;
93
+ function findSymbolickLinkRealPath(path) {
94
+ if (fs_1.default.lstatSync(path).isSymbolicLink()) {
95
+ return findSymbolickLinkRealPath(fs_1.default.readlinkSync(path));
96
+ }
97
+ return path;
98
+ }
99
+ if (config.showLinkedPackages) {
100
+ const packageJson = JSON.parse(fs_1.default.readFileSync('package.json', 'utf8'));
101
+ const dependencies = Object.keys(packageJson.dependencies || {});
102
+ const devDependencies = Object.keys(packageJson.devDependencies || {});
103
+ dependencies.concat(devDependencies).forEach(packagePath => {
104
+ const packagePathOnNodeModules = (0, getPath_1.getPath)(`node_modules/${packagePath}`);
105
+ if (fs_1.default.lstatSync(packagePathOnNodeModules).isSymbolicLink()) {
106
+ const pathToWatch = findSymbolickLinkRealPath(packagePathOnNodeModules);
107
+ console.log((0, coloredString_1.default)(` Linked package found at "${pathToWatch}"`));
108
+ }
109
+ });
110
+ }
@@ -0,0 +1 @@
1
+ export declare function getIPAddress(): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIPAddress = void 0;
4
+ const os_1 = require("os");
5
+ function getIPAddress() {
6
+ const interfaces = (0, os_1.networkInterfaces)();
7
+ for (const devName in interfaces) {
8
+ const iface = interfaces[devName];
9
+ if (iface)
10
+ for (let i = 0; i < iface.length; i++) {
11
+ const alias = iface[i];
12
+ if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal)
13
+ return alias.address;
14
+ }
15
+ }
16
+ return '0.0.0.0';
17
+ }
18
+ exports.getIPAddress = getIPAddress;
File without changes
@@ -0,0 +1 @@
1
+ new EventSource('/esbuild').addEventListener('change', () => location.reload());
@@ -0,0 +1,7 @@
1
+ import type { CompilerOptions } from 'typescript';
2
+ declare let tsconfig: {
3
+ compilerOptions: CompilerOptions;
4
+ include: string[];
5
+ exclude: string[];
6
+ };
7
+ export { tsconfig };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.tsconfig = void 0;
7
+ const config_1 = require("./config");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ let tsconfig;
10
+ exports.tsconfig = tsconfig;
11
+ if (config_1.config.esbuildOptions.tsconfig && fs_1.default.existsSync(config_1.config.esbuildOptions?.tsconfig)) {
12
+ exports.tsconfig = tsconfig = JSON.parse(fs_1.default.readFileSync(config_1.config.esbuildOptions.tsconfig, 'utf-8'));
13
+ }
14
+ else {
15
+ throw `Unable to find tsconfig at ${config_1.config.esbuildOptions.tsconfig}`;
16
+ }
@@ -0,0 +1,2 @@
1
+ import { ServerConfig } from '../types';
2
+ export declare const userConfig: ServerConfig;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.userConfig = void 0;
7
+ const getPath_1 = require("../utils/getPath");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const esbuild_1 = require("esbuild");
10
+ let config = {};
11
+ if (fs_1.default.existsSync('michi.config.ts')) {
12
+ const configTs = fs_1.default.readFileSync('michi.config.ts', 'utf-8');
13
+ const transpiledConfigTs = (0, esbuild_1.transformSync)(configTs, {
14
+ loader: 'ts',
15
+ logLevel: 'debug',
16
+ format: 'cjs',
17
+ platform: 'node',
18
+ target: ['node16'],
19
+ });
20
+ const transpiledConfigPath = (0, getPath_1.getPath)(`${__dirname}/michi.config.js`);
21
+ if (fs_1.default.existsSync(transpiledConfigPath)) {
22
+ fs_1.default.rmSync(transpiledConfigPath);
23
+ }
24
+ fs_1.default.writeFileSync(transpiledConfigPath, transpiledConfigTs.code);
25
+ config = require('./michi.config.js').default(process.env.NODE_ENV);
26
+ }
27
+ exports.userConfig = config;
@@ -0,0 +1,4 @@
1
+ declare module '*.css' {
2
+ const css: string | CSSStyleSheet;
3
+ export = css;
4
+ }
package/bin/global.js ADDED
File without changes
package/bin/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export type { ServerConfigFactory, ServerConfig, PublicOptions, DefaultEnvironment } from './types';
package/bin/index.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cli_1 = require("./cli");
5
+ (0, cli_1.cli)();
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../src/utils/coloredString.ts","../node_modules/@types/yargs-parser/index.d.ts","../node_modules/@types/yargs/index.d.ts","../src/utils/timer.ts","../node_modules/esbuild/lib/main.d.ts","../src/types.ts","../src/utils/getPath.ts","../src/config/getIPAddress.ts","../src/config/userConfig.ts","../src/config/config.ts","../node_modules/open/index.d.ts","../src/utils/copy.ts","../src/utils/getAllFiles.ts","../src/utils/injectServiceWorker.ts","../src/utils/minifyHTML.ts","../src/utils/setupBuild.ts","../src/actions/start.ts","../src/actions/build.ts","../node_modules/typescript/lib/typescript.d.ts","../src/config/tsconfig.ts","../src/actions/dist.ts","../src/cli.ts","../src/global.ts","../src/index.ts","../src/config/public/client.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/dom-events.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/readline/promises.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/test.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts"],"fileInfos":[{"version":"8730f4bf322026ff5229336391a18bcaa1f94d4f82416c8b2f3954e2ccaae2ba","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","4b421cbfb3a38a27c279dec1e9112c3d1da296f77a1a85ddadf7e7a425d45d18","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"3aafcb693fe5b5c3bd277bd4c3a617b53db474fe498fc5df067c5603b1eebde7","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"5f406584aef28a331c36523df688ca3650288d14f39c5d2e555c95f0d2ff8f6f","affectsGlobalScope":true},{"version":"22f230e544b35349cfb3bd9110b6ef37b41c6d6c43c3314a31bd0d9652fcec72","affectsGlobalScope":true},{"version":"7ea0b55f6b315cf9ac2ad622b0a7813315bb6e97bf4bb3fbf8f8affbca7dc695","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"eb26de841c52236d8222f87e9e6a235332e0788af8c87a71e9e210314300410a","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"5e5e095c4470c8bab227dbbc61374878ecead104c74ab9960d3adcccfee23205","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"2768ef564cfc0689a1b76106c421a2909bdff0acbe87da010785adab80efdd5c","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},{"version":"d53690b2fd0130061c375d203542a618f2881fe3d0e8c2466b864862dec7d8eb","signature":"6dc6a466033398972f5c22ccb99fec2c1b680a058afb46fd141672c9cadeb56c"},"70e9a18da08294f75bf23e46c7d69e67634c0765d355887b9b41f0d959e1426e","1d57d3163eba70449a0f91cfdad1262bcdd7e72372bc7fda40620a73e277793c",{"version":"1dd46d72e9d48755a3f9ff186fa6de1de5b4bea94cc822f871e05f44da9021dd","signature":"9bf79e5ad9696c1684c71b8d35cd973855f43c4217dd6f07c0e73bc501107cff"},"99d951629f7096dcd79adbaa83a85e3be57613005533bd23029b3aba4ce9383e",{"version":"d79d5f6b18b9d46db34301ca728a007fac8c6810baf59400fdb269c645bb506c","signature":"9ef279296caef902c9898a830da7c46038b9fe337f5c51ab1466a203db78f3b9"},{"version":"a457749c56ff6b56ac59503eea53caea1f37ee357430074c0acb5f80ddf7eaa2","signature":"63b8b59bbc7f575405461d1d1b91a6cdf09eefa44db414430e93f6df4d3e7be3"},{"version":"cab872ef7156f5d032caf8f6547c5400e8493a7746053728831a5bb7977b77cf","signature":"7a27baf1053443cefab73b720106d1f9d730a50a37f82155d664145663040f20"},{"version":"f254d9c434ddbee567e9cc9a66f7298187f5e3991b9753d185d36337d525cd76","signature":"d6e94f1aef0aea8abc566e84f7a3d5590d8ea57c52aa129db035b5f1613e6974"},{"version":"69932a7ede32825bdca5bc71c420203d9f56c44c649757a9228c7fa73f6d3008","signature":"b3fe1cb54e0ef9f7873c5f93ea7a8a697cac04e7e77f8c647039e997dab85e3e"},"ac0e45806dfb87684696b8a268697c8e789c50e29fd285fec047830e773f9832",{"version":"97ef3797f89ac6de5ffbefddec24688ac811cc21e257086343f71c69532be6b9","signature":"d966694681a2d7ce59515bf30eae290eab504a01e4e04cd98971222d700873e1"},{"version":"c7ada178fad3e08916ba5ed3dcd348140345da462fe6d11e7b34938a3930cb43","signature":"efd0f4958c494e39e91a6291abbff412a2665e43b3138ecbf3611e85cd8a264d"},{"version":"19cb9a72be0b0fec7130816a4614f55bab1ec2d81acb73f8ebf856b95614a720","signature":"e56a6c82ade50a1c5d7c8b1f56bf7f87d82f22fc0ceb1c85011a2a94f965153a"},{"version":"c7d28264b1f9c62c3f2e1a1cfb7727bd4d97b34fd84567e9a1ef98bc57bfbff9","signature":"7b3c9d883fb0785df76e0ba99869dd6f3bfbdc290b9671c1442999cea00e92fd"},{"version":"7d613bf39908b71da0a60e24d853f254f78276399334eda604b24355b676d345","signature":"e49ede384d56e2e32247d838fd32af92b45e5d07de8306e3e60b0dea6c548972"},{"version":"0e0ade5bf39c9a6c2d02ca90de23378119eb620f9432332047c81e210e61cd1c","signature":"e3a5c94a3ecbb59aeda9068f01df05a93b53cc5d2cfe63809b6ec103052c35b9"},{"version":"b1f1948f00b25b26ccfc63f92908d4cd41b702697944a834466c143740c63e32","signature":"c6639f380d643933407420d2fcb5f074984799a24a237bd049b9945b03659a28"},"57e52a0882af4e835473dda27e4316cc31149866970210f9f79b940e916b7838",{"version":"ef4a213c8bcf86d5b0bd2abdc96a824e3272cb88e8997200897bd1c2b7bec985","signature":"53e18a9b1bd6a21ca1a0decbeecb6087f2d65bd5728ac6e47da0ccd3f0d92a2d"},{"version":"211e42a19b8ae37183ccfc159aba63940f91708363f5567441dcd96c4eacb6e2","signature":"b9676c103abbcded39e23921ecfef7f65ad5b091ceee5e964a4921331f15a547"},{"version":"3eeee6cabfc13dd746e1ffe8c2e36b354838c305cb4f03c1f0afacc4a3dac596","signature":"f1c55f9c94533ef546614eedb041912be0e86df25ff276dfbfa72a5d6d1e9ffb"},{"version":"1b6cabe42309fa26bf2f8f489890445185684de80456744bf99f8c697145cfbf","signature":"3d9e96efc2e7d0fc0d2514090856611287fcb7348678e32c30af5c9791725963"},{"version":"1a7be2e3a768a04524264b8f1497e5fc89355e3b9283647ab9e785c34c4c80ce","signature":"009e91165dbb34ab3bf0ffc2048c0317ed1d8b48fd3b7a70afb4caa27679f216"},{"version":"8ea17c6e71e7f8bd756a0455fa69b9261beef45c2e0faa4c585ba28162bc748e","signature":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","affectsGlobalScope":true},"7e771891adaa85b690266bc37bd6eb43bc57eecc4b54693ead36467e7369952a","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"ca72190df0eb9b09d4b600821c8c7b6c9747b75a1c700c4d57dc0bb72abc074c","affectsGlobalScope":true},"21a167fec8f933752fb8157f06d28fab6817af3ad9b0bdb1908a10762391eab9",{"version":"bb65c6267c5d6676be61acbf6604cf0a4555ac4b505df58ac15c831fcbff4e3e","affectsGlobalScope":true},"374ca798f244e464346f14301dc2a8b4b111af1a83b49fffef5906c338a1f922","5a94487653355b56018122d92392beb2e5f4a6c63ba5cef83bbe1c99775ef713",{"version":"d5135ad93b33adcce80b18f8065087934cdc1730d63db58562edcf017e1aad9b","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","dab86d9604fe40854ef3c0a6f9e8948873dc3509213418e5e457f410fd11200f","bb9c4ffa5e6290c6980b63c815cdd1625876dadb2efaf77edbe82984be93e55e","489532ff54b714f0e0939947a1c560e516d3ae93d51d639ab02e907a0e950114","f30bb836526d930a74593f7b0f5c1c46d10856415a8f69e5e2fc3db80371e362","14b5aa23c5d0ae1907bc696ac7b6915d88f7d85799cc0dc2dcf98fbce2c5a67c","5c439dafdc09abe4d6c260a96b822fa0ba5be7203c71a63ab1f1423cd9e838ea",{"version":"6b526a5ec4a401ca7c26cfe6a48e641d8f30af76673bad3b06a1b4504594a960","affectsGlobalScope":true},{"version":"816ad2e607a96de5bcac7d437f843f5afd8957f1fa5eefa6bba8e4ed7ca8fd84","affectsGlobalScope":true},"cec36af22f514322f870e81d30675c78df82ae8bf4863f5fd4e4424c040c678d","d903fafe96674bc0b2ac38a5be4a8fc07b14c2548d1cdb165a80ea24c44c0c54","5eec82ac21f84d83586c59a16b9b8502d34505d1393393556682fe7e7fde9ef2","04eb6578a588d6a46f50299b55f30e3a04ef27d0c5a46c57d8fcc211cd530faa","8d3c583a07e0c37e876908c2d5da575019f689df8d9fa4c081d99119d53dba22","2c828a5405191d006115ab34e191b8474bc6c86ffdc401d1a9864b1b6e088a58",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"d076fede3cb042e7b13fc29442aaa03a57806bc51e2b26a67a01fbc66a7c0c12","7c013aa892414a7fdcfd861ae524a668eaa3ede8c7c0acafaf611948122c8d93","b0973c3cbcdc59b37bf477731d468696ecaf442593ec51bab497a613a580fe30",{"version":"4989e92ba5b69b182d2caaea6295af52b7dc73a4f7a2e336a676722884e7139d","affectsGlobalScope":true},{"version":"b3624aed92dab6da8484280d3cb3e2f4130ec3f4ef3f8201c95144ae9e898bb6","affectsGlobalScope":true},"5153a2fd150e46ce57bb3f8db1318d33f6ad3261ed70ceeff92281c0608c74a3","210d54cd652ec0fec8c8916e4af59bb341065576ecda039842f9ffb2e908507c","36b03690b628eab08703d63f04eaa89c5df202e5f1edf3989f13ad389cd2c091","0effadd232a20498b11308058e334d3339cc5bf8c4c858393e38d9d4c0013dcf","25846d43937c672bab7e8195f3d881f93495df712ee901860effc109918938cc","fd93cee2621ff42dabe57b7be402783fd1aa69ece755bcba1e0290547ae60513","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff","69ee23dd0d215b09907ad30d23f88b7790c93329d1faf31d7835552a10cf7cbf","44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","23b89798789dffbd437c0c423f5d02d11f9736aea73d6abf16db4f812ff36eda","223c37f62ce09a3d99e77498acdee7b2705a4ae14552fbdb4093600cd9164f3f",{"version":"970a90f76d4d219ad60819d61f5994514087ba94c985647a3474a5a3d12714ed","affectsGlobalScope":true},"e10177274a35a9d07c825615340b2fcde2f610f53f3fb40269fd196b4288dda6","4c8525f256873c7ba3135338c647eaf0ca7115a1a2805ae2d0056629461186ce","3c13ef48634e7b5012fcf7e8fce7496352c2d779a7201389ca96a2a81ee4314d","5d0a25ec910fa36595f85a67ac992d7a53dd4064a1ba6aea1c9f14ab73a023f2",{"version":"f0900cd5d00fe1263ff41201fb8073dbeb984397e4af3b8002a5c207a30bdc33","affectsGlobalScope":true},{"version":"4c50342e1b65d3bee2ed4ab18f84842d5724ad11083bd666d8705dc7a6079d80","affectsGlobalScope":true},"06d7c42d256f0ce6afe1b2b6cfbc97ab391f29dadb00dd0ae8e8f23f5bc916c3","ec4bd1b200670fb567920db572d6701ed42a9641d09c4ff6869768c8f81b404c","e59a892d87e72733e2a9ca21611b9beb52977be2696c7ba4b216cbbb9a48f5aa",{"version":"da26af7362f53d122283bc69fed862b9a9fe27e01bc6a69d1d682e0e5a4df3e6","affectsGlobalScope":true},"8a300fa9b698845a1f9c41ecbe2c5966634582a8e2020d51abcace9b55aa959e",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"8dbe725f8d237e70310977afcfa011629804d101ebaa0266cafda6b61ad72236"],"options":{"allowSyntheticDefaultImports":true,"allowUnreachableCode":false,"declaration":true,"esModuleInterop":true,"experimentalDecorators":true,"module":1,"noErrorTruncation":true,"noUnusedLocals":false,"noUnusedParameters":false,"outDir":"./","strictBindCallApply":true,"strictFunctionTypes":true,"strictNullChecks":true,"target":99},"fileIdsList":[[68,114],[71,114],[72,77,105,114],[73,84,85,92,102,113,114],[73,74,84,92,114],[75,114],[76,77,85,93,114],[77,102,110,114],[78,80,84,92,114],[79,114],[80,81,114],[84,114],[82,84,114],[84,85,86,102,113,114],[84,85,86,99,102,105,114],[114,118],[114],[80,87,92,102,113,114],[84,85,87,88,92,102,110,113,114],[87,89,102,110,113,114],[68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120],[84,90,114],[91,113,114],[80,84,92,102,114],[93,114],[94,114],[71,95,114],[96,112,114,118],[97,114],[98,114],[84,99,100,114],[99,101,114,116],[72,84,102,103,104,105,114],[72,102,104,114],[102,103,114],[105,114],[106,114],[84,108,109,114],[108,109,114],[77,92,102,110,114],[111,114],[92,112,114],[72,87,98,113,114],[77,114],[102,114,115],[114,116],[114,117],[72,77,84,86,95,102,113,114,116,118],[102,114,119],[44,114],[73,114],[46,47,52,58,114],[52,62,73,85,114],[43,47,49,52,53,58,85,87,114],[43,45,46,59,60,63,114],[43,46,48,49,50,51,85,114],[52,61,85,114],[47,48,49,85,114],[48,64,114],[47,114],[49,85,114],[47,49,52,55,85,114],[52,54,56,57,85,114],[48],[61],[47]],"referencedMap":[[68,1],[69,1],[71,2],[72,3],[73,4],[74,5],[75,6],[76,7],[77,8],[78,9],[79,10],[80,11],[81,11],[83,12],[82,13],[84,12],[85,14],[86,15],[70,16],[120,17],[87,18],[88,19],[89,20],[121,21],[90,22],[91,23],[92,24],[93,25],[94,26],[95,27],[96,28],[97,29],[98,30],[99,31],[100,31],[101,32],[102,33],[104,34],[103,35],[105,36],[106,37],[107,17],[108,38],[109,39],[110,40],[111,41],[112,42],[113,43],[114,44],[115,45],[116,46],[117,47],[118,48],[119,49],[44,17],[45,50],[47,17],[53,51],[8,17],[10,17],[9,17],[2,17],[11,17],[12,17],[13,17],[14,17],[15,17],[16,17],[17,17],[18,17],[3,17],[4,17],[22,17],[19,17],[20,17],[21,17],[23,17],[24,17],[25,17],[5,17],[26,17],[27,17],[28,17],[29,17],[6,17],[33,17],[30,17],[31,17],[32,17],[34,17],[7,17],[35,17],[40,17],[41,17],[36,17],[37,17],[38,17],[39,17],[1,17],[42,17],[61,17],[60,52],[63,53],[59,54],[64,55],[52,56],[50,25],[67,17],[62,57],[51,58],[65,17],[66,59],[48,60],[43,17],[54,61],[55,61],[49,26],[56,62],[57,17],[58,63],[46,17]],"exportedModulesMap":[[68,1],[69,1],[71,2],[72,3],[73,4],[74,5],[75,6],[76,7],[77,8],[78,9],[79,10],[80,11],[81,11],[83,12],[82,13],[84,12],[85,14],[86,15],[70,16],[120,17],[87,18],[88,19],[89,20],[121,21],[90,22],[91,23],[92,24],[93,25],[94,26],[95,27],[96,28],[97,29],[98,30],[99,31],[100,31],[101,32],[102,33],[104,34],[103,35],[105,36],[106,37],[107,17],[108,38],[109,39],[110,40],[111,41],[112,42],[113,43],[114,44],[115,45],[116,46],[117,47],[118,48],[119,49],[44,17],[45,50],[47,17],[53,51],[8,17],[10,17],[9,17],[2,17],[11,17],[12,17],[13,17],[14,17],[15,17],[16,17],[17,17],[18,17],[3,17],[4,17],[22,17],[19,17],[20,17],[21,17],[23,17],[24,17],[25,17],[5,17],[26,17],[27,17],[28,17],[29,17],[6,17],[33,17],[30,17],[31,17],[32,17],[34,17],[7,17],[35,17],[40,17],[41,17],[36,17],[37,17],[38,17],[39,17],[1,17],[42,17],[61,17],[52,64],[62,65],[51,64],[66,64],[48,66]],"semanticDiagnosticsPerFile":[68,69,71,72,73,74,75,76,77,78,79,80,81,83,82,84,85,86,70,120,87,88,89,121,90,91,92,93,94,95,96,97,98,99,100,101,102,104,103,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,44,45,47,53,8,10,9,2,11,12,13,14,15,16,17,18,3,4,22,19,20,21,23,24,25,5,26,27,28,29,6,33,30,31,32,34,7,35,40,41,36,37,38,39,1,42,61,60,63,59,64,52,50,67,62,51,65,66,48,43,54,55,49,56,57,58,46]},"version":"4.9.4"}
package/bin/types.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { BuildOptions } from 'esbuild';
2
+ export type PublicOptions = {
3
+ /**
4
+ * Public folder path
5
+ * @default public
6
+ */
7
+ path?: string;
8
+ /**
9
+ * Main html file to be served
10
+ * @default index.html
11
+ * */
12
+ indexName?: string;
13
+ /**
14
+ * If the main html needs to be minified
15
+ * @default true if environment is PRODUCTION
16
+ */
17
+ minifyIndex?: boolean;
18
+ /**Service worker name in public folder */
19
+ serviceWorkerName?: string;
20
+ };
21
+ export type Config = {
22
+ /**
23
+ * Port to run dev server on
24
+ * @default 3000
25
+ */
26
+ port?: number;
27
+ /**Public folder - will be copied at server start */
28
+ public?: PublicOptions;
29
+ /**
30
+ * If the browser should open at localhost url when server starts
31
+ * @default true
32
+ */
33
+ openBrowser?: boolean;
34
+ /**
35
+ * Show linked packages of the proyect
36
+ * @default true
37
+ */
38
+ showLinkedPackages?: boolean;
39
+ /** Documentation: https://esbuild.github.io/plugins/#build-options */
40
+ esbuildOptions?: BuildOptions;
41
+ };
42
+ export type DefaultEnvironment = 'PRODUCTION' | 'DISTRIBUTION' | 'DEVELOPMENT';
43
+ export type ServerConfig = Config & {
44
+ /**
45
+ * Allows to add environment variables
46
+ */
47
+ env?: {
48
+ [key: string]: any;
49
+ };
50
+ };
51
+ export type ServerConfigFactory<T extends string = DefaultEnvironment> = (environment: T) => ServerConfig;
package/bin/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ declare const _default: (string: any) => string;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (string) => `\x1b[36m${string}\x1b[0m`;
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ type Tranformer = {
3
+ fileName: string;
4
+ transformer: (fileContent: string) => Buffer | string;
5
+ };
6
+ export declare function copy(src: any, dest: any, fileTransformers?: Tranformer[]): void;
7
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.copy = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const getPath_1 = require("./getPath");
9
+ function copy(src, dest, fileTransformers) {
10
+ const srcDir = fs_1.default.readdirSync(src);
11
+ srcDir.forEach(fileName => {
12
+ const srcPath = (0, getPath_1.getPath)(`${src}/${fileName}`);
13
+ const destPath = (0, getPath_1.getPath)(`${dest}/${fileName}`);
14
+ if (fs_1.default.lstatSync(srcPath).isDirectory()) {
15
+ fs_1.default.mkdirSync(destPath);
16
+ copy(srcPath, destPath, fileTransformers);
17
+ }
18
+ else {
19
+ const fileTransformer = fileTransformers?.find(x => x.fileName === fileName);
20
+ if (fileTransformer) {
21
+ const srcFileContent = fs_1.default.readFileSync(srcPath, { encoding: 'utf-8' });
22
+ const transformedFile = fileTransformer.transformer(srcFileContent);
23
+ fs_1.default.writeFileSync(destPath, transformedFile);
24
+ }
25
+ else
26
+ fs_1.default.copyFileSync(srcPath, destPath);
27
+ }
28
+ });
29
+ }
30
+ exports.copy = copy;
@@ -0,0 +1 @@
1
+ export declare const getAllFiles: (dirPath: string, dirToShow?: string, arrayOfFiles?: string[]) => string[];
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getAllFiles = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const getPath_1 = require("./getPath");
9
+ const getAllFiles = function (dirPath, dirToShow = dirPath, arrayOfFiles = []) {
10
+ const files = fs_1.default.readdirSync(dirPath);
11
+ files.forEach((file) => {
12
+ const normalizedPath = (0, getPath_1.getPath)(`${dirPath}/${file}`);
13
+ const filePath = `${dirToShow}/${file}`;
14
+ if (fs_1.default.statSync(normalizedPath).isDirectory()) {
15
+ arrayOfFiles = (0, exports.getAllFiles)(normalizedPath, filePath, arrayOfFiles);
16
+ }
17
+ else {
18
+ arrayOfFiles.push(filePath);
19
+ }
20
+ });
21
+ return arrayOfFiles;
22
+ };
23
+ exports.getAllFiles = getAllFiles;
@@ -0,0 +1 @@
1
+ export declare function getPath(path: any): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPath = void 0;
4
+ const path_1 = require("path");
5
+ function getPath(path) {
6
+ return (0, path_1.normalize)(path).replace(/\\/g, path_1.sep);
7
+ }
8
+ exports.getPath = getPath;
@@ -0,0 +1 @@
1
+ export declare const injectServiceWorker: () => void;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.injectServiceWorker = void 0;
27
+ const config_1 = require("../config/config");
28
+ const getAllFiles_1 = require("./getAllFiles");
29
+ const esbuild_1 = require("esbuild");
30
+ const getPath_1 = require("./getPath");
31
+ const fs = __importStar(require("fs"));
32
+ const injectServiceWorker = () => {
33
+ const { outdir, minify, minifyIdentifiers, minifySyntax, minifyWhitespace, keepNames, define } = config_1.config.esbuildOptions;
34
+ if (config_1.config.public.serviceWorkerName && outdir) {
35
+ try {
36
+ const allFiles = (0, getAllFiles_1.getAllFiles)(outdir, '.');
37
+ const serviceWorkerPath = (0, getPath_1.getPath)(`${config_1.config.public.path}/${config_1.config.public.serviceWorkerName}`);
38
+ const outServiceWorkerPath = (0, getPath_1.getPath)(`${outdir}/${config_1.config.public.serviceWorkerName}`);
39
+ const file = fs.readFileSync(serviceWorkerPath, 'utf-8');
40
+ const result = (0, esbuild_1.transformSync)(file, {
41
+ define: {
42
+ 'process.env.BUILD_FILES': `${JSON.stringify(allFiles)}`,
43
+ // Time at GMT+0
44
+ 'process.env.CACHE_NAME': `"${new Date(new Date().toLocaleString('en-US', { timeZone: 'Etc/GMT' })).getTime()}"`,
45
+ ...define
46
+ },
47
+ logLevel: 'debug',
48
+ format: 'esm',
49
+ target: ['esnext'],
50
+ minify, minifyIdentifiers, minifySyntax, minifyWhitespace, keepNames
51
+ });
52
+ fs.writeFileSync(outServiceWorkerPath, result.code);
53
+ }
54
+ catch (ex) {
55
+ console.log(ex);
56
+ }
57
+ }
58
+ };
59
+ exports.injectServiceWorker = injectServiceWorker;
@@ -0,0 +1 @@
1
+ export declare function minifyHTML(string: any): any;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.minifyHTML = void 0;
4
+ function minifyHTML(string) {
5
+ const removeEnterResult = string.replace(/\s+/g, ' ').trim();
6
+ return removeEnterResult.replace(/> </g, '><').trim();
7
+ }
8
+ exports.minifyHTML = minifyHTML;
@@ -0,0 +1 @@
1
+ export declare const setupBuild: () => void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setupBuild = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const config_1 = require("../config/config");
9
+ const copy_1 = require("../utils/copy");
10
+ const injectServiceWorker_1 = require("../utils/injectServiceWorker");
11
+ const minifyHTML_1 = require("../utils/minifyHTML");
12
+ const setupBuild = () => {
13
+ if (config_1.config.esbuildOptions?.outdir) {
14
+ if (fs_1.default.existsSync(config_1.config.esbuildOptions.outdir)) {
15
+ fs_1.default.rmSync(config_1.config.esbuildOptions.outdir, { recursive: true });
16
+ }
17
+ fs_1.default.mkdirSync(config_1.config.esbuildOptions.outdir, { recursive: true });
18
+ const indexTranformer = (fileContent) => config_1.config.public.minifyIndex ? (0, minifyHTML_1.minifyHTML)(fileContent) : fileContent;
19
+ if (config_1.config.public.indexName)
20
+ (0, copy_1.copy)(config_1.config.public.path, config_1.config.esbuildOptions.outdir, [{ fileName: config_1.config.public.indexName, transformer: indexTranformer }]);
21
+ (0, injectServiceWorker_1.injectServiceWorker)();
22
+ }
23
+ };
24
+ exports.setupBuild = setupBuild;
@@ -0,0 +1,5 @@
1
+ export default class Timer {
2
+ start: number;
3
+ startTimer(): void;
4
+ endTimer(): number;
5
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Timer {
4
+ start;
5
+ startTimer() {
6
+ this.start = Date.now();
7
+ }
8
+ endTimer() {
9
+ return Date.now() - this.start;
10
+ }
11
+ }
12
+ exports.default = Timer;
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@michijs/dev-server",
3
+ "license": "MIT",
4
+ "version": "0.1.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/michijs/dev-server.git"
8
+ },
9
+ "main": "bin/index",
10
+ "bin": {
11
+ "michi-server": "bin/index.js"
12
+ },
13
+ "description": "Development server based on esbuild",
14
+ "files": [
15
+ "bin/"
16
+ ],
17
+ "baseUrl": "./src",
18
+ "scripts": {
19
+ "dist": "tsc",
20
+ "link": "npm run dist && npm link --force && tsc -w",
21
+ "publish-patch-version": "npm version patch && npm run publish-npm",
22
+ "publish-npm": "npm run dist && npm publish --access public"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "18.11.18",
26
+ "@types/yargs": "17.0.0",
27
+ "lint-staged": "13.1.0",
28
+ "rome": "11.0.0",
29
+ "simple-git-hooks": "2.8.1"
30
+ },
31
+ "keywords": [
32
+ "react",
33
+ "javascript",
34
+ "css",
35
+ "bundler",
36
+ "typescript",
37
+ "compiler",
38
+ "jsx",
39
+ "commonjs",
40
+ "minifier",
41
+ "tsx",
42
+ "esm",
43
+ "server",
44
+ "development"
45
+ ],
46
+ "dependencies": {
47
+ "typescript": "4.9.4",
48
+ "esbuild": "0.17.4",
49
+ "open": "8.4.0",
50
+ "yargs": "17.6.0"
51
+ },
52
+ "simple-git-hooks": {
53
+ "pre-commit": "npx lint-staged"
54
+ },
55
+ "lint-staged": {
56
+ "*.{js,jsx,ts,tsx}": "rome check --apply-suggested"
57
+ }
58
+ }