@michijs/dev-server 0.2.3 → 0.2.4-beta.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.
- package/README.md +9 -3
- package/bin/actions/build.js +7 -9
- package/bin/actions/dist.js +9 -15
- package/bin/actions/generateIcons.d.ts +1 -0
- package/bin/actions/generateIcons.js +25 -0
- package/bin/actions/start.js +40 -41
- package/bin/classes/Timer.js +1 -5
- package/bin/cli.js +42 -49
- package/bin/config/config.d.ts +2 -2
- package/bin/config/config.js +53 -50
- package/bin/config/getIPAddress.js +3 -7
- package/bin/config/public/client.d.ts +1 -0
- package/bin/config/public/client.js +1 -0
- package/bin/config/tsconfig.js +7 -12
- package/bin/config/userConfig.d.ts +1 -1
- package/bin/config/userConfig.js +17 -16
- package/bin/index.d.ts +1 -1
- package/bin/index.js +2 -4
- package/bin/tsconfig.tsbuildinfo +1 -1
- package/bin/types.d.ts +20 -20
- package/bin/types.js +1 -2
- package/bin/utils/coloredString.js +1 -3
- package/bin/utils/copy.d.ts +1 -1
- package/bin/utils/copy.js +17 -25
- package/bin/utils/getAllFiles.js +7 -14
- package/bin/utils/getPath.js +3 -7
- package/bin/utils/minify.js +2 -7
- package/bin/utils/serviceWorkerTransformer.d.ts +1 -1
- package/bin/utils/serviceWorkerTransformer.js +11 -15
- package/bin/utils/transformers.d.ts +1 -1
- package/bin/utils/transformers.js +16 -17
- package/package.json +24 -11
- package/bin/global.d.ts +0 -4
- package/bin/global.js +0 -0
package/README.md
CHANGED
|
@@ -24,20 +24,29 @@ You have the following CLI commands:
|
|
|
24
24
|
<tr>
|
|
25
25
|
<th>CLI command</th>
|
|
26
26
|
<th>Default environment</th>
|
|
27
|
+
<th>Description</th>
|
|
27
28
|
</tr>
|
|
28
29
|
</thead>
|
|
29
30
|
<tbody>
|
|
30
31
|
<tr>
|
|
31
32
|
<td>start</td>
|
|
32
33
|
<td>DEVELOPMENT</td>
|
|
34
|
+
<td>Allows to start a dev server as a webpage.</td>
|
|
33
35
|
</tr>
|
|
34
36
|
<tr>
|
|
35
37
|
<td>build</td>
|
|
36
38
|
<td>PRODUCTION</td>
|
|
39
|
+
<td>Allows to build the src code as a webpage.</td>
|
|
37
40
|
</tr>
|
|
38
41
|
<tr>
|
|
39
42
|
<td>dist</td>
|
|
40
43
|
<td>DISTRIBUTION</td>
|
|
44
|
+
<td>Allows to distribute the src code as a package. At the moment ESBuild does not support .d.ts files so we still use the Typescript compiler with the tsconfig provided by esbuildOptions field.</td>
|
|
45
|
+
</tr>
|
|
46
|
+
<tr>
|
|
47
|
+
<td>generate-icons</td>
|
|
48
|
+
<td>-</td>
|
|
49
|
+
<td>Allows to generate a full set of icons from a src icon.</td>
|
|
41
50
|
</tr>
|
|
42
51
|
</tbody>
|
|
43
52
|
</table>
|
|
@@ -179,9 +188,6 @@ export default config;
|
|
|
179
188
|
</tbody>
|
|
180
189
|
</table>
|
|
181
190
|
|
|
182
|
-
## Distribution
|
|
183
|
-
At the moment ESBuild does not support .d.ts files so we still use the Typescript compiler with the tsconfig provided by esbuildOptions field.
|
|
184
|
-
|
|
185
191
|
## License
|
|
186
192
|
- [MIT](https://github.com/michijs/dev-server/blob/master/LICENSE.md)
|
|
187
193
|
|
package/bin/actions/build.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const config_1 = require("../config/config");
|
|
5
|
-
const esbuild_1 = require("esbuild");
|
|
6
|
-
function build(callback) {
|
|
1
|
+
import { config } from '../config/config.js';
|
|
2
|
+
import { build as esbuild } from 'esbuild';
|
|
3
|
+
export function build(callback) {
|
|
7
4
|
return new Promise((resolve) => {
|
|
8
|
-
(
|
|
5
|
+
esbuild(config.esbuildOptions)
|
|
6
|
+
.then(() => {
|
|
9
7
|
callback?.();
|
|
10
8
|
resolve(true);
|
|
11
|
-
})
|
|
9
|
+
})
|
|
10
|
+
.catch(() => {
|
|
12
11
|
return Promise.resolve();
|
|
13
12
|
});
|
|
14
13
|
});
|
|
15
14
|
}
|
|
16
|
-
exports.build = build;
|
package/bin/actions/dist.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
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
|
+
export function dist(callback, watch = false) {
|
|
6
|
+
if (tsconfig.compilerOptions.outDir &&
|
|
7
|
+
fs.existsSync(tsconfig.compilerOptions.outDir)) {
|
|
8
|
+
fs.rmSync(tsconfig.compilerOptions.outDir, { recursive: true });
|
|
14
9
|
}
|
|
15
|
-
|
|
10
|
+
exec(`tsc ${watch ? '-w' : ''} --project ${config.esbuildOptions.tsconfig}`, callback);
|
|
16
11
|
}
|
|
17
|
-
exports.dist = dist;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateIcons(callback: () => void, src: string): Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import sharp from 'sharp';
|
|
2
|
+
import { getPath } from '../utils/getPath.js';
|
|
3
|
+
import { config } from '../config/config.js';
|
|
4
|
+
import { mkdirSync, existsSync } from 'fs';
|
|
5
|
+
import ico from 'sharp-ico';
|
|
6
|
+
export async function generateIcons(callback, src) {
|
|
7
|
+
const sizes = [24, 48, 72, 96, 128, 256, 512];
|
|
8
|
+
const image = sharp(src);
|
|
9
|
+
const destPath = getPath(`${config.public.path}/assets/generated`);
|
|
10
|
+
if (!existsSync(destPath))
|
|
11
|
+
mkdirSync(destPath, { recursive: true });
|
|
12
|
+
await Promise.all([
|
|
13
|
+
...sizes.map((x) => {
|
|
14
|
+
return image
|
|
15
|
+
.resize(x, x)
|
|
16
|
+
.webp()
|
|
17
|
+
.toFile(getPath(`${destPath}/${src.split('/').at(-1)?.split('.')[0]}-${x}.webp`));
|
|
18
|
+
}),
|
|
19
|
+
ico.sharpsToIco([image], getPath(`${config.public.path}/favicon.ico`), {
|
|
20
|
+
sizes: [16],
|
|
21
|
+
resizeOptions: { width: 16, height: 16 },
|
|
22
|
+
}),
|
|
23
|
+
]);
|
|
24
|
+
callback();
|
|
25
|
+
}
|
package/bin/actions/start.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const node_watch_1 = __importDefault(require("node-watch"));
|
|
15
|
-
const copy_1 = require("../utils/copy");
|
|
16
|
-
const path_1 = require("path");
|
|
17
|
-
const transformers_1 = require("../utils/transformers");
|
|
18
|
-
const start = (callback) => {
|
|
19
|
-
config_1.config.esbuildOptions.plugins?.push({
|
|
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';
|
|
12
|
+
export const start = (callback) => {
|
|
13
|
+
config.esbuildOptions.plugins?.push({
|
|
20
14
|
name: 'michijs-dev-server-watch-public-folder',
|
|
21
15
|
setup(build) {
|
|
22
|
-
if (
|
|
23
|
-
|
|
16
|
+
if (config.public.path)
|
|
17
|
+
watch.default(config.public.path, {
|
|
24
18
|
encoding: 'utf-8',
|
|
25
19
|
persistent: true,
|
|
26
20
|
recursive: true,
|
|
@@ -28,31 +22,36 @@ const start = (callback) => {
|
|
|
28
22
|
const updated = new Array();
|
|
29
23
|
const removed = new Array();
|
|
30
24
|
const added = new Array();
|
|
31
|
-
const splittedPath = fileChangedPath.split(
|
|
32
|
-
const srcDir = splittedPath.slice(0, -1).join(
|
|
25
|
+
const splittedPath = fileChangedPath.split(sep);
|
|
26
|
+
const srcDir = splittedPath.slice(0, -1).join(sep);
|
|
33
27
|
const fileName = splittedPath.at(-1);
|
|
34
|
-
const outDir = srcDir.replace(
|
|
35
|
-
|
|
28
|
+
const outDir = srcDir.replace(config.public.path, build.initialOptions.outdir);
|
|
29
|
+
fs.rmSync(getPath(`${outDir}/${transformers
|
|
30
|
+
.find((x) => x.fileRegex.test(fileName))
|
|
31
|
+
?.pathTransformer?.(fileName) ?? fileName}`), { force: true, recursive: true });
|
|
36
32
|
if (event === 'remove')
|
|
37
33
|
removed.push(fileChangedPath);
|
|
38
34
|
else {
|
|
39
35
|
updated.push(fileChangedPath);
|
|
40
|
-
|
|
36
|
+
copyFile(srcDir, fileName, outDir);
|
|
41
37
|
}
|
|
42
38
|
// Refresh browser
|
|
43
|
-
|
|
44
|
-
added,
|
|
39
|
+
connections.forEach((x) => x.write(`event: change\ndata: ${JSON.stringify({
|
|
40
|
+
added,
|
|
41
|
+
removed,
|
|
42
|
+
updated,
|
|
45
43
|
})}\n\n`));
|
|
46
44
|
});
|
|
47
|
-
}
|
|
45
|
+
},
|
|
48
46
|
});
|
|
49
|
-
|
|
47
|
+
context(config.esbuildOptions).then(async (buildContext) => {
|
|
50
48
|
const { host: esbuildHost, port: esbuildPort } = await buildContext.serve({
|
|
51
|
-
servedir:
|
|
49
|
+
servedir: config.esbuildOptions.outdir,
|
|
52
50
|
});
|
|
53
|
-
|
|
51
|
+
http
|
|
52
|
+
.createServer(async (req, res) => {
|
|
54
53
|
if (req.url === '/esbuild')
|
|
55
|
-
|
|
54
|
+
connections.push(res);
|
|
56
55
|
const esbuildProxyRequestOptions = {
|
|
57
56
|
hostname: esbuildHost,
|
|
58
57
|
port: esbuildPort,
|
|
@@ -61,12 +60,12 @@ const start = (callback) => {
|
|
|
61
60
|
headers: req.headers,
|
|
62
61
|
};
|
|
63
62
|
// Forward each incoming request to esbuild
|
|
64
|
-
const proxyReq =
|
|
63
|
+
const proxyReq = http.request(esbuildProxyRequestOptions, (proxyRes) => {
|
|
65
64
|
// If esbuild returns "not found", send a custom 404 page
|
|
66
65
|
if (!proxyRes.statusCode || proxyRes.statusCode === 404) {
|
|
67
66
|
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
68
67
|
// TODO: Find a better way to do this
|
|
69
|
-
res.end(
|
|
68
|
+
res.end(fs.readFileSync(getPath(`${config.esbuildOptions.outdir}/${config.public.indexName}`)));
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
72
71
|
// Otherwise, forward the response from esbuild to the client
|
|
@@ -75,16 +74,16 @@ const start = (callback) => {
|
|
|
75
74
|
});
|
|
76
75
|
// Forward the body of the request to esbuild
|
|
77
76
|
req.pipe(proxyReq, { end: true });
|
|
78
|
-
})
|
|
77
|
+
})
|
|
78
|
+
.listen(config.port);
|
|
79
79
|
console.log(`
|
|
80
80
|
Server running at:
|
|
81
81
|
|
|
82
|
-
> Network: ${(
|
|
83
|
-
> Local: ${(
|
|
82
|
+
> Network: ${coloredString(hostURL)}
|
|
83
|
+
> Local: ${coloredString(localURL)}`);
|
|
84
84
|
callback();
|
|
85
85
|
buildContext.watch();
|
|
86
|
-
if (
|
|
87
|
-
(
|
|
86
|
+
if (config.openBrowser)
|
|
87
|
+
open(localURL);
|
|
88
88
|
});
|
|
89
89
|
};
|
|
90
|
-
exports.start = start;
|
package/bin/classes/Timer.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Timer = void 0;
|
|
4
|
-
class Timer {
|
|
1
|
+
export class Timer {
|
|
5
2
|
start;
|
|
6
3
|
startTimer() {
|
|
7
4
|
this.start = Date.now();
|
|
@@ -10,4 +7,3 @@ class Timer {
|
|
|
10
7
|
return Date.now() - this.start;
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
exports.Timer = Timer;
|
package/bin/cli.js
CHANGED
|
@@ -1,72 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 = require("./classes/Timer");
|
|
33
|
-
async function cli() {
|
|
34
|
-
const timer = new Timer_1.Timer();
|
|
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
|
+
export async function cli() {
|
|
6
|
+
const timer = new Timer();
|
|
35
7
|
const showReadyMessage = () => console.log(`
|
|
36
|
-
${(
|
|
8
|
+
${coloredString(`Ready in ${timer.endTimer()}ms.`)}`);
|
|
37
9
|
timer.startTimer();
|
|
38
|
-
const args = await yargs
|
|
10
|
+
const args = await yargs(hideBin(process.argv))
|
|
39
11
|
.option('start', {
|
|
40
12
|
type: 'boolean',
|
|
41
|
-
default: false
|
|
13
|
+
default: false,
|
|
14
|
+
description: 'Allows to start a dev server as a webpage.',
|
|
42
15
|
})
|
|
43
16
|
.option('build', {
|
|
44
17
|
type: 'boolean',
|
|
45
|
-
default: false
|
|
18
|
+
default: false,
|
|
19
|
+
description: 'Allows to build the src code as a webpage.',
|
|
46
20
|
})
|
|
47
21
|
.option('dist', {
|
|
48
22
|
type: 'boolean',
|
|
49
|
-
default: false
|
|
23
|
+
default: false,
|
|
24
|
+
description: 'Allows to distribute the src code as a package.',
|
|
25
|
+
})
|
|
26
|
+
.option('generate-icons', {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description: 'Allows to generate a full set of icons from a src icon.',
|
|
29
|
+
})
|
|
30
|
+
.option('watch', {
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
default: false,
|
|
33
|
+
alias: 'w',
|
|
50
34
|
})
|
|
51
35
|
.option('env', {
|
|
52
|
-
type: 'string'
|
|
36
|
+
type: 'string',
|
|
37
|
+
})
|
|
38
|
+
.option('env', {
|
|
39
|
+
type: 'string',
|
|
53
40
|
})
|
|
54
41
|
.help()
|
|
55
|
-
.alias('help', 'h')
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
42
|
+
.alias('help', 'h').argv;
|
|
43
|
+
process.env.NODE_ENV =
|
|
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);
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
console.log(coloredString(` Running in ${process.env.NODE_ENV} mode`));
|
|
59
53
|
if (args.start) {
|
|
60
|
-
const action = await
|
|
54
|
+
const action = await import('./actions/start.js');
|
|
61
55
|
action.start(showReadyMessage);
|
|
62
56
|
}
|
|
63
57
|
if (args.build) {
|
|
64
|
-
const action = await
|
|
58
|
+
const action = await import('./actions/build.js');
|
|
65
59
|
action.build(showReadyMessage);
|
|
66
60
|
}
|
|
67
61
|
if (args.dist) {
|
|
68
|
-
const action = await
|
|
69
|
-
action.dist(showReadyMessage);
|
|
62
|
+
const action = await import('./actions/dist.js');
|
|
63
|
+
action.dist(showReadyMessage, args.watch);
|
|
70
64
|
}
|
|
71
65
|
}
|
|
72
|
-
exports.cli = cli;
|
package/bin/config/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Config } from '../types';
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Config } from '../types.js';
|
|
3
3
|
import http from 'http';
|
|
4
4
|
export declare const connections: (http.ServerResponse<http.IncomingMessage> & {
|
|
5
5
|
req: http.IncomingMessage;
|
package/bin/config/config.js
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const getIPAddress_1 = require("./getIPAddress");
|
|
13
|
-
const userConfig_1 = require("./userConfig");
|
|
14
|
-
const path_1 = require("path");
|
|
15
|
-
const transformers_1 = require("../utils/transformers");
|
|
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';
|
|
16
12
|
const minify = process.env.NODE_ENV === 'PRODUCTION';
|
|
17
|
-
const devServerListener = process.env.NODE_ENV === 'DEVELOPMENT'
|
|
18
|
-
|
|
13
|
+
const devServerListener = process.env.NODE_ENV === 'DEVELOPMENT'
|
|
14
|
+
? [getPath(`${dirname(fileURLToPath(import.meta.url))}/public/client.js`)]
|
|
15
|
+
: [];
|
|
16
|
+
export const connections = [];
|
|
19
17
|
const config = {
|
|
20
18
|
port: 3000,
|
|
21
19
|
openBrowser: process.env.NODE_ENV === 'DEVELOPMENT',
|
|
22
20
|
showLinkedPackages: true,
|
|
23
|
-
...
|
|
21
|
+
...userConfig,
|
|
24
22
|
// protocol: 'http',
|
|
25
23
|
public: {
|
|
26
24
|
path: 'public',
|
|
27
25
|
indexName: 'index.html',
|
|
28
26
|
minify: minify,
|
|
29
|
-
...(
|
|
27
|
+
...(userConfig.public ?? {}),
|
|
30
28
|
manifest: {
|
|
31
29
|
name: 'manifest.json',
|
|
32
|
-
...(
|
|
30
|
+
...(userConfig.public?.manifest ?? {}),
|
|
33
31
|
},
|
|
34
32
|
},
|
|
35
33
|
esbuildOptions: {
|
|
@@ -45,7 +43,7 @@ const config = {
|
|
|
45
43
|
format: 'esm',
|
|
46
44
|
target: 'esnext',
|
|
47
45
|
logLevel: 'error',
|
|
48
|
-
...(
|
|
46
|
+
...(userConfig.esbuildOptions ?? {}),
|
|
49
47
|
// Still not supported
|
|
50
48
|
// bug .css.ts
|
|
51
49
|
// plugins: [
|
|
@@ -68,73 +66,78 @@ const config = {
|
|
|
68
66
|
// }
|
|
69
67
|
// ],
|
|
70
68
|
plugins: [
|
|
71
|
-
...(
|
|
69
|
+
...(userConfig.esbuildOptions?.plugins ?? []),
|
|
72
70
|
{
|
|
73
71
|
name: 'michijs-dev-server',
|
|
74
72
|
setup(build) {
|
|
75
73
|
// Clean outdir
|
|
76
74
|
if (build.initialOptions.outdir) {
|
|
77
|
-
if (
|
|
78
|
-
|
|
75
|
+
if (fs.existsSync(build.initialOptions.outdir)) {
|
|
76
|
+
fs.rmSync(build.initialOptions.outdir, { recursive: true });
|
|
79
77
|
}
|
|
80
|
-
|
|
78
|
+
fs.mkdirSync(build.initialOptions.outdir, { recursive: true });
|
|
81
79
|
}
|
|
82
80
|
if (config.public.manifest?.options && config.public.manifest.name) {
|
|
83
|
-
const transformedFile =
|
|
84
|
-
|
|
81
|
+
const transformedFile = jsonTransformer.transformer(JSON.stringify(config.public.manifest.options, null, 2));
|
|
82
|
+
fs.writeFileSync(getPath(`${build.initialOptions.outdir}/${config.public.manifest.name}`), transformedFile);
|
|
85
83
|
}
|
|
86
84
|
// Copy public path - Omit to copy service worker - will be transformed after
|
|
87
85
|
if (config.public.path && build.initialOptions.outdir)
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
copy(config.public.path, build.initialOptions.outdir, [
|
|
87
|
+
jsAndTsRegex,
|
|
88
|
+
]);
|
|
89
|
+
const buildTimer = new Timer();
|
|
90
90
|
let firstLoad = true;
|
|
91
91
|
build.onStart(() => buildTimer.startTimer());
|
|
92
92
|
build.onEnd(() => {
|
|
93
93
|
// first-load sw - Omit to copy any other non-js file
|
|
94
94
|
if (firstLoad && config.public.path && build.initialOptions.outdir)
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
copy(config.public.path, build.initialOptions.outdir, [
|
|
96
|
+
notJsAndTsRegex,
|
|
97
|
+
]);
|
|
98
|
+
console.log(coloredString(` Build finished in ${buildTimer.endTimer()}ms`));
|
|
97
99
|
firstLoad = false;
|
|
98
100
|
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
+
},
|
|
102
|
+
},
|
|
101
103
|
],
|
|
102
104
|
define: {
|
|
103
105
|
// Intentionally added before process
|
|
104
106
|
process: JSON.stringify({
|
|
105
107
|
env: {
|
|
106
108
|
NODE_ENV: process.env.NODE_ENV,
|
|
107
|
-
...(
|
|
108
|
-
}
|
|
109
|
-
})
|
|
109
|
+
...(userConfig.env ?? {}),
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
110
112
|
},
|
|
111
|
-
inject: [
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
inject: [
|
|
114
|
+
...devServerListener,
|
|
115
|
+
...(userConfig.esbuildOptions?.inject ?? []),
|
|
116
|
+
],
|
|
117
|
+
...(userConfig.esbuildOptions?.define ?? {}),
|
|
118
|
+
},
|
|
114
119
|
};
|
|
115
|
-
|
|
116
|
-
const hostURL = `http://${(0, getIPAddress_1.getIPAddress)()}:${config.port}`;
|
|
117
|
-
exports.hostURL = hostURL;
|
|
120
|
+
const hostURL = `http://${getIPAddress()}:${config.port}`;
|
|
118
121
|
const localURL = `http://localhost:${config.port}`;
|
|
119
|
-
exports.localURL = localURL;
|
|
120
122
|
// const hostURL = `${config.protocol}://${config.hostname}:${config.port}`;
|
|
121
123
|
// const localURL = `${config.protocol}://localhost:${config.port}`;
|
|
122
124
|
function findSymbolickLinkRealPath(packagePath) {
|
|
123
|
-
if (
|
|
125
|
+
if (fs.lstatSync(packagePath).isSymbolicLink()) {
|
|
124
126
|
// Getting absolute path for the simbolic link
|
|
125
|
-
return
|
|
127
|
+
return resolve(fs.readlinkSync(packagePath));
|
|
126
128
|
}
|
|
127
129
|
return packagePath;
|
|
128
130
|
}
|
|
129
131
|
if (config.showLinkedPackages) {
|
|
130
|
-
const packageJson = JSON.parse(
|
|
132
|
+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
131
133
|
const dependencies = Object.keys(packageJson.dependencies || {});
|
|
132
134
|
const devDependencies = Object.keys(packageJson.devDependencies || {});
|
|
133
|
-
dependencies.concat(devDependencies).forEach(packagePath => {
|
|
134
|
-
const packagePathOnNodeModules =
|
|
135
|
-
if (
|
|
135
|
+
dependencies.concat(devDependencies).forEach((packagePath) => {
|
|
136
|
+
const packagePathOnNodeModules = getPath(`node_modules/${packagePath}`);
|
|
137
|
+
if (fs.lstatSync(packagePathOnNodeModules).isSymbolicLink()) {
|
|
136
138
|
const pathToWatch = findSymbolickLinkRealPath(packagePathOnNodeModules);
|
|
137
|
-
console.log((
|
|
139
|
+
console.log(coloredString(` Linked package found at "${pathToWatch}"`));
|
|
138
140
|
}
|
|
139
141
|
});
|
|
140
142
|
}
|
|
143
|
+
export { config, hostURL, localURL };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const os_1 = require("os");
|
|
5
|
-
function getIPAddress() {
|
|
6
|
-
const interfaces = (0, os_1.networkInterfaces)();
|
|
1
|
+
import { networkInterfaces } from 'os';
|
|
2
|
+
export function getIPAddress() {
|
|
3
|
+
const interfaces = networkInterfaces();
|
|
7
4
|
for (const devName in interfaces) {
|
|
8
5
|
const iface = interfaces[devName];
|
|
9
6
|
if (iface)
|
|
@@ -15,4 +12,3 @@ function getIPAddress() {
|
|
|
15
12
|
}
|
|
16
13
|
return '0.0.0.0';
|
|
17
14
|
}
|
|
18
|
-
exports.getIPAddress = getIPAddress;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/bin/config/tsconfig.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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"));
|
|
1
|
+
import { config } from './config.js';
|
|
2
|
+
import fs from 'fs';
|
|
9
3
|
let tsconfig;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
if (config.esbuildOptions.tsconfig &&
|
|
5
|
+
fs.existsSync(config.esbuildOptions?.tsconfig)) {
|
|
6
|
+
tsconfig = JSON.parse(fs.readFileSync(config.esbuildOptions.tsconfig, 'utf-8'));
|
|
13
7
|
}
|
|
14
8
|
else {
|
|
15
|
-
throw `Unable to find tsconfig at ${
|
|
9
|
+
throw `Unable to find tsconfig at ${config.esbuildOptions.tsconfig}`;
|
|
16
10
|
}
|
|
11
|
+
export { tsconfig };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ServerConfig } from '../types';
|
|
1
|
+
import { ServerConfig } from '../types.js';
|
|
2
2
|
export declare const userConfig: ServerConfig;
|