makepack 1.5.13 → 1.5.14
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makepack",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
6
|
"files": [
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"build": "node ./src/index.js build"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@vitejs/plugin-react": "^4.3.4",
|
|
34
33
|
"chalk": "^5.4.1",
|
|
34
|
+
"chokidar": "^4.0.3",
|
|
35
35
|
"commander": "^12.1.0",
|
|
36
36
|
"cosmiconfig": "^9.0.0",
|
|
37
|
-
"esbuild": "^0.
|
|
37
|
+
"esbuild": "^0.25.0",
|
|
38
38
|
"express": "^4.21.1",
|
|
39
39
|
"figlet": "^1.8.0",
|
|
40
40
|
"figures": "^6.1.0",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { logger } from '../../helpers.js'
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import makepackConfig from '../../makepack-config.js';
|
|
5
|
+
import viteSetup from './vite.js';
|
|
6
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
7
|
+
|
|
8
|
+
const app = express();
|
|
9
|
+
const server = async () => {
|
|
10
|
+
const config = await makepackConfig()
|
|
11
|
+
const explorer = cosmiconfig('express');
|
|
12
|
+
const result = await explorer.load('.server/express.js');
|
|
13
|
+
if (result) {
|
|
14
|
+
if (typeof result.config !== 'function') {
|
|
15
|
+
logger.error('Configuration file must export a function')
|
|
16
|
+
}
|
|
17
|
+
result.config(app)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await viteSetup(app)
|
|
21
|
+
|
|
22
|
+
app.use((_req, res) => {
|
|
23
|
+
res.status(500).send('Internal Server Error');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
app.listen(config.start.port, () => {
|
|
27
|
+
logger.success(`Server is running on ${chalk.blue(chalk.underline(`http://localhost:${config.start.port}`))}`);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
process.on('SIGINT', async () => {
|
|
31
|
+
process.exit(0);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
server()
|
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
import fs from 'fs-extra'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import { createServer as createViteServer } from 'vite';
|
|
4
|
-
import express from 'express';
|
|
5
|
-
import react from '@vitejs/plugin-react'
|
|
6
3
|
import { logger } from '../../helpers.js'
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import figlet from 'figlet';
|
|
9
4
|
import makepackConfig from '../../makepack-config.js';
|
|
5
|
+
import esbuild from 'esbuild';
|
|
6
|
+
import chokidar from 'chokidar';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { spawn } from 'child_process';
|
|
9
|
+
let __filename, __dirname;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
if (typeof import.meta.url !== 'undefined') {
|
|
12
|
+
__filename = fileURLToPath(import.meta.url);
|
|
13
|
+
__dirname = path.dirname(__filename);
|
|
14
|
+
} else {
|
|
15
|
+
__filename = __filename;
|
|
16
|
+
__dirname = __dirname;
|
|
17
|
+
}
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
let server = null;
|
|
20
|
+
function startServer(config) {
|
|
21
|
+
if (server) {
|
|
22
|
+
server.kill('SIGINT');
|
|
23
|
+
server = null;
|
|
24
|
+
}
|
|
25
|
+
server = spawn('node', [path.resolve(__dirname, 'express.js')], {});
|
|
26
|
+
server.stdout.on('data', (data) => {
|
|
27
|
+
console.log(data.toString().trim());
|
|
28
|
+
});
|
|
29
|
+
server.stderr.on('data', (data) => {
|
|
30
|
+
console.error(data.toString().trim());
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const start = async () => {
|
|
14
35
|
const config = await makepackConfig()
|
|
15
36
|
const exists = fs.existsSync(path.join(process.cwd(), config.start.entry))
|
|
16
37
|
if (!exists) {
|
|
@@ -18,74 +39,43 @@ const start = async (args) => {
|
|
|
18
39
|
process.exit(1)
|
|
19
40
|
}
|
|
20
41
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<head>
|
|
25
|
-
<meta charset="UTF-8" />
|
|
26
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
27
|
-
</head>
|
|
28
|
-
<body>
|
|
29
|
-
<div id="root"></div>
|
|
30
|
-
<script type="module" src="${config.start.entry}"></script>
|
|
31
|
-
</body>
|
|
32
|
-
</html>
|
|
33
|
-
`;
|
|
42
|
+
startServer(config)
|
|
43
|
+
const expressjs = path.join(process.cwd(), 'express.js')
|
|
44
|
+
const expressts = path.join(process.cwd(), 'express.ts')
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
error: (msg) => logger.error(msg),
|
|
47
|
-
},
|
|
48
|
-
appType: 'custom'
|
|
49
|
-
}
|
|
46
|
+
if (fs.existsSync(expressjs) || fs.existsSync(expressts)) {
|
|
47
|
+
let filename = fs.existsSync(expressjs) ? "express.js" : "express.ts";
|
|
48
|
+
const build = () => {
|
|
49
|
+
esbuild.build({
|
|
50
|
+
entryPoints: [filename],
|
|
51
|
+
outfile: '.server/express.js',
|
|
52
|
+
bundle: true,
|
|
53
|
+
format: 'esm',
|
|
54
|
+
platform: 'node',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
app.use(vite.middlewares);
|
|
58
|
+
build()
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
const watcher = chokidar.watch(filename, {
|
|
61
|
+
persistent: true,
|
|
62
|
+
ignoreInitial: true,
|
|
63
|
+
});
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
res.status(200).set({
|
|
63
|
-
'Content-Type': 'text/html'
|
|
64
|
-
}).end(template);
|
|
65
|
-
} catch (e) {
|
|
66
|
-
vite.ssrFixStacktrace(e);
|
|
67
|
-
next(e);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
65
|
+
watcher.on('change', async () => {
|
|
66
|
+
build()
|
|
67
|
+
startServer(config)
|
|
68
|
+
});
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
watcher.on('unlink', (path) => {
|
|
71
|
+
startServer(config)
|
|
72
|
+
});
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.log("Something went wrong...");
|
|
79
|
-
console.dir(err);
|
|
80
|
-
server.close(() => {
|
|
81
|
-
console.log('Server has been stopped.');
|
|
82
|
-
});
|
|
83
|
-
process.exit()
|
|
84
|
-
}
|
|
85
|
-
console.log(data);
|
|
86
|
-
logger.success(`Server is running on ${chalk.blue(chalk.underline(`http://localhost:${config.start.port}`))}`);
|
|
74
|
+
process.on('SIGINT', async () => {
|
|
75
|
+
watcher.close();
|
|
76
|
+
process.exit(0);
|
|
87
77
|
});
|
|
88
|
-
}
|
|
78
|
+
}
|
|
89
79
|
}
|
|
90
80
|
|
|
91
81
|
export default start
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// import react from '@vitejs/plugin-react'
|
|
2
|
+
import { createServer as createViteServer } from 'vite';
|
|
3
|
+
import { logger } from '../../helpers.js'
|
|
4
|
+
import makepackConfig from '../../makepack-config.js';
|
|
5
|
+
|
|
6
|
+
const viteSetup = async (app) => {
|
|
7
|
+
const config = await makepackConfig()
|
|
8
|
+
const viteConfig = {
|
|
9
|
+
root: process.cwd(),
|
|
10
|
+
// plugins: [react()],
|
|
11
|
+
server: {
|
|
12
|
+
middlewareMode: true,
|
|
13
|
+
},
|
|
14
|
+
customLogger: {
|
|
15
|
+
info: (msg) => {
|
|
16
|
+
logger.info(msg)
|
|
17
|
+
},
|
|
18
|
+
warn: (msg) => logger.warning(msg),
|
|
19
|
+
error: (msg) => logger.error(msg),
|
|
20
|
+
},
|
|
21
|
+
appType: 'custom'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const vite = await createViteServer(viteConfig);
|
|
25
|
+
app.use(vite.middlewares);
|
|
26
|
+
|
|
27
|
+
app.get('*', async (req, res, next) => {
|
|
28
|
+
const url = req.originalUrl;
|
|
29
|
+
try {
|
|
30
|
+
let template = await vite.transformIndexHtml(url, `
|
|
31
|
+
<!doctype html>
|
|
32
|
+
<html lang="en">
|
|
33
|
+
<head>
|
|
34
|
+
<meta charset="UTF-8" />
|
|
35
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
36
|
+
</head>
|
|
37
|
+
<body>
|
|
38
|
+
<div id="root"></div>
|
|
39
|
+
<script type="module" src="${config.start.entry}"></script>
|
|
40
|
+
</body>
|
|
41
|
+
</html>
|
|
42
|
+
`);
|
|
43
|
+
res.status(200).set({
|
|
44
|
+
'Content-Type': 'text/html'
|
|
45
|
+
}).end(template);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
vite.ssrFixStacktrace(e);
|
|
48
|
+
next(e);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
export default viteSetup
|