makepack 1.4.0 → 1.5.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 +122 -167
- package/package.json +58 -56
- package/src/actions/build/index.js +91 -0
- package/src/actions/create/files/{serve.js → App.js} +51 -51
- package/src/actions/create/files/config.js +55 -0
- package/src/actions/create/files/gitignore.js +8 -5
- package/src/actions/create/files/package-json.js +52 -59
- package/src/actions/create/files/project-js.js +12 -12
- package/src/actions/create/files/project-jsx.js +50 -50
- package/src/actions/create/files/project-ts.js +10 -10
- package/src/actions/create/files/project-tsx.js +50 -50
- package/src/actions/create/files/readme.md.js +13 -13
- package/src/actions/create/files/tsconfig.js +32 -32
- package/src/actions/create/index.js +106 -29
- package/src/actions/create/makeFiles.js +64 -64
- package/src/actions/publish/index.js +19 -0
- package/src/actions/{serve → start}/index.js +92 -97
- package/src/helpers.js +37 -122
- package/src/index.js +33 -30
- package/src/makepack-config.js +64 -0
- package/src/actions/create/files/makepack.js +0 -19
- package/src/actions/create/makeProjectDirectory.js +0 -42
- package/src/actions/create/makeProjectInformation.js +0 -68
- package/src/actions/pack/index.js +0 -112
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
// import makepack from "./files/makepack.js";
|
|
2
|
-
import packageJson from "./files/package-json.js";
|
|
3
|
-
import gitignore from "./files/gitignore.js";
|
|
4
|
-
import
|
|
5
|
-
import tsconfig from "./files/tsconfig.js";
|
|
6
|
-
import projectJs from "./files/project-js.js";
|
|
7
|
-
import projectJsx from "./files/project-jsx.js";
|
|
8
|
-
import projectTs from "./files/project-ts.js";
|
|
9
|
-
import projectTsx from "./files/project-tsx.js";
|
|
10
|
-
|
|
11
|
-
import inquirer from 'inquirer'
|
|
12
|
-
import fs from "fs-extra"
|
|
13
|
-
import path from "path"
|
|
14
|
-
import readmeMd from "./files/readme.md.js";
|
|
15
|
-
|
|
16
|
-
export default async (
|
|
17
|
-
const files = [
|
|
18
|
-
packageJson(
|
|
19
|
-
gitignore(
|
|
20
|
-
|
|
21
|
-
readmeMd(
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
switch (
|
|
25
|
-
case "typescript":
|
|
26
|
-
files.push(projectTs(
|
|
27
|
-
break
|
|
28
|
-
case "react with typescript":
|
|
29
|
-
files.push(projectTsx(
|
|
30
|
-
break;
|
|
31
|
-
case "javascript":
|
|
32
|
-
files.push(projectJs(
|
|
33
|
-
break
|
|
34
|
-
case "react with javascript":
|
|
35
|
-
files.push(projectJsx(
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// push ts config
|
|
40
|
-
if (
|
|
41
|
-
files.push(tsconfig(
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (let file of files) {
|
|
45
|
-
// check if the file exists
|
|
46
|
-
if (fs.existsSync(path.join(
|
|
47
|
-
const { overwrite } = await inquirer.prompt([
|
|
48
|
-
{
|
|
49
|
-
type: "confirm",
|
|
50
|
-
name: 'overwrite',
|
|
51
|
-
message: `The file ${file.filename} already exists, do you want to overwrite it?`,
|
|
52
|
-
default: true
|
|
53
|
-
}
|
|
54
|
-
])
|
|
55
|
-
if (!overwrite) {
|
|
56
|
-
continue
|
|
57
|
-
} else {
|
|
58
|
-
fs.removeSync(path.join(
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
fs.writeFileSync(path.join(
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
// import makepack from "./files/makepack.js";
|
|
2
|
+
import packageJson from "./files/package-json.js";
|
|
3
|
+
import gitignore from "./files/gitignore.js";
|
|
4
|
+
import App from "./files/App.js";
|
|
5
|
+
import tsconfig from "./files/tsconfig.js";
|
|
6
|
+
import projectJs from "./files/project-js.js";
|
|
7
|
+
import projectJsx from "./files/project-jsx.js";
|
|
8
|
+
import projectTs from "./files/project-ts.js";
|
|
9
|
+
import projectTsx from "./files/project-tsx.js";
|
|
10
|
+
|
|
11
|
+
import inquirer from 'inquirer'
|
|
12
|
+
import fs from "fs-extra"
|
|
13
|
+
import path from "path"
|
|
14
|
+
import readmeMd from "./files/readme.md.js";
|
|
15
|
+
|
|
16
|
+
export default async (info) => {
|
|
17
|
+
const files = [
|
|
18
|
+
await packageJson(info),
|
|
19
|
+
await gitignore(info),
|
|
20
|
+
await App(info),
|
|
21
|
+
await readmeMd(info)
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
switch (info.template) {
|
|
25
|
+
case "typescript":
|
|
26
|
+
files.push(await projectTs(info))
|
|
27
|
+
break
|
|
28
|
+
case "react with typescript":
|
|
29
|
+
files.push(await projectTsx(info))
|
|
30
|
+
break;
|
|
31
|
+
case "javascript":
|
|
32
|
+
files.push(await projectJs(info))
|
|
33
|
+
break
|
|
34
|
+
case "react with javascript":
|
|
35
|
+
files.push(await projectJsx(info))
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// push ts config
|
|
40
|
+
if (info.template.includes("typescript")) {
|
|
41
|
+
files.push(await tsconfig(info))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (let file of files) {
|
|
45
|
+
// check if the file exists
|
|
46
|
+
if (fs.existsSync(path.join(info.cwd, file.filename))) {
|
|
47
|
+
const { overwrite } = await inquirer.prompt([
|
|
48
|
+
{
|
|
49
|
+
type: "confirm",
|
|
50
|
+
name: 'overwrite',
|
|
51
|
+
message: `The file ${file.filename} already exists, do you want to overwrite it?`,
|
|
52
|
+
default: true
|
|
53
|
+
}
|
|
54
|
+
])
|
|
55
|
+
if (!overwrite) {
|
|
56
|
+
continue
|
|
57
|
+
} else {
|
|
58
|
+
fs.removeSync(path.join(info.cwd, file.filename))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fs.writeFileSync(path.join(info.cwd, file.filename), file.content)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { execSync, logger } from '../../helpers.js'
|
|
3
|
+
import makepackConfig from '../../makepack-config.js'
|
|
4
|
+
|
|
5
|
+
const publish = async () => {
|
|
6
|
+
const { build } = await makepackConfig()
|
|
7
|
+
const buildDir = path.join(process.cwd(), build.outdir)
|
|
8
|
+
const exists = fs.existsSync(buildDir)
|
|
9
|
+
if (!exists) {
|
|
10
|
+
logger.error(`Build directory ${buildDir} does not exist. Please build the project first`)
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
logger.info(`Publishing the production build to the npm repository...`)
|
|
14
|
+
execSync(`npm publish`, {
|
|
15
|
+
cwd: path.join(process.cwd(), build.outdir)
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default publish
|
|
@@ -1,97 +1,92 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
const app = express();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
res.status(500).send('Internal Server Error');
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default serve
|
|
1
|
+
import fs from 'fs-extra'
|
|
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
|
+
import { logger } from '../../helpers.js'
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import figlet from 'figlet';
|
|
9
|
+
import makepackConfig from '../../makepack-config.js';
|
|
10
|
+
|
|
11
|
+
const app = express();
|
|
12
|
+
|
|
13
|
+
const start = async (args) => {
|
|
14
|
+
const config = await makepackConfig()
|
|
15
|
+
const exists = fs.existsSync(path.join(process.cwd(), config.start.entry))
|
|
16
|
+
if (!exists) {
|
|
17
|
+
logger.error(`Entry file ${entry} does not exist. please check your config file`)
|
|
18
|
+
process.exit(1)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let template = `
|
|
22
|
+
<!doctype html>
|
|
23
|
+
<html lang="en">
|
|
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
|
+
`;
|
|
34
|
+
|
|
35
|
+
const viteConfig = {
|
|
36
|
+
root: process.cwd(),
|
|
37
|
+
plugins: [react()],
|
|
38
|
+
server: {
|
|
39
|
+
middlewareMode: true,
|
|
40
|
+
},
|
|
41
|
+
customLogger: {
|
|
42
|
+
info: (msg) => {
|
|
43
|
+
logger.info(msg)
|
|
44
|
+
},
|
|
45
|
+
warn: (msg) => logger.warning(msg),
|
|
46
|
+
error: (msg) => logger.error(msg),
|
|
47
|
+
},
|
|
48
|
+
appType: 'custom'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const vite = await createViteServer(viteConfig);
|
|
52
|
+
app.use(vite.middlewares);
|
|
53
|
+
|
|
54
|
+
if (config.start.express) {
|
|
55
|
+
config.start.express(app)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
app.get('*', async (req, res, next) => {
|
|
59
|
+
const url = req.originalUrl;
|
|
60
|
+
try {
|
|
61
|
+
template = await vite.transformIndexHtml(url, template);
|
|
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
|
+
});
|
|
70
|
+
|
|
71
|
+
let server = app.listen(config.start.port, () => {
|
|
72
|
+
figlet("Makepack", function (err, data) {
|
|
73
|
+
if (err) {
|
|
74
|
+
console.log("Something went wrong...");
|
|
75
|
+
console.dir(err);
|
|
76
|
+
server.close(() => {
|
|
77
|
+
console.log('Server has been stopped.');
|
|
78
|
+
});
|
|
79
|
+
process.exit()
|
|
80
|
+
}
|
|
81
|
+
console.log(data);
|
|
82
|
+
logger.success(`Server is running on ${chalk.blue(chalk.underline(`http://localhost:${config.start.port}`))}`);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
app.use((err, req, res) => {
|
|
87
|
+
logger.error(`Unhandled Error: ${err.message}`);
|
|
88
|
+
res.status(500).send('Internal Server Error');
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default start
|
package/src/helpers.js
CHANGED
|
@@ -1,122 +1,37 @@
|
|
|
1
|
-
import child_process from 'child_process'
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import figures from 'figures';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
process.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export const logger = {
|
|
45
|
-
info: (message, prefix = 'INFO', icon = true) => {
|
|
46
|
-
console.log(`${icon ? chalk.blue(figures.info) + " " : ""}${chalk.cyan.bold(prefix)} ${message}`);
|
|
47
|
-
},
|
|
48
|
-
success: (message, prefix = 'SUCCESS:', icon = true) => {
|
|
49
|
-
console.log(`${icon ? chalk.green(figures.tick) + " " : ""}${chalk.green.bold(prefix)} ${message}`);
|
|
50
|
-
},
|
|
51
|
-
warning: (message, prefix = 'WARNING:', icon = true) => {
|
|
52
|
-
console.log(`${icon ? chalk.yellow(figures.warning) + " " : ""}${chalk.yellow.bold(prefix)} ${message}`);
|
|
53
|
-
},
|
|
54
|
-
error: (message, prefix = 'ERROR:', icon = true) => {
|
|
55
|
-
console.log(`${icon ? chalk.red(figures.cross) + " " : ""}${chalk.red.bold(prefix)} ${message}`);
|
|
56
|
-
},
|
|
57
|
-
custom: (icon, color, label, message) => {
|
|
58
|
-
console.log(`${chalk[color](icon)} ${chalk[color].bold(`${label}:`)} ${message}`);
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export const loadConfig = async (args) => {
|
|
64
|
-
const makepack = path.resolve(process.cwd(), "makepack.js");
|
|
65
|
-
let esbuild = {
|
|
66
|
-
minify: true,
|
|
67
|
-
sourcemap: true,
|
|
68
|
-
jsx: 'automatic',
|
|
69
|
-
loader: {
|
|
70
|
-
'.ts': 'ts',
|
|
71
|
-
'.tsx': 'tsx'
|
|
72
|
-
},
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const defaultConfig = {
|
|
76
|
-
pack: {
|
|
77
|
-
tsconfig: {
|
|
78
|
-
declaration: true,
|
|
79
|
-
emitDeclarationOnly: true,
|
|
80
|
-
outDir: path.join(process.cwd(), args.outdir || "pack", 'types'),
|
|
81
|
-
strict: true,
|
|
82
|
-
allowJs: true,
|
|
83
|
-
jsx: ts.JsxEmit.React,
|
|
84
|
-
esModuleInterop: true,
|
|
85
|
-
},
|
|
86
|
-
esm: esbuild,
|
|
87
|
-
cjs: esbuild,
|
|
88
|
-
},
|
|
89
|
-
serve: {
|
|
90
|
-
express: () => { },
|
|
91
|
-
vite: {
|
|
92
|
-
root: process.cwd(),
|
|
93
|
-
plugins: [react()],
|
|
94
|
-
server: {
|
|
95
|
-
middlewareMode: true,
|
|
96
|
-
},
|
|
97
|
-
customLogger: {
|
|
98
|
-
info: (msg) => {
|
|
99
|
-
logger.info(msg)
|
|
100
|
-
},
|
|
101
|
-
warn: (msg) => logger.warning(msg),
|
|
102
|
-
error: (msg) => logger.error(msg),
|
|
103
|
-
},
|
|
104
|
-
appType: 'custom'
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (fs.existsSync(makepack)) {
|
|
110
|
-
try {
|
|
111
|
-
const c = await import(pathToFileURL(makepack).href)
|
|
112
|
-
const configFn = c.default
|
|
113
|
-
if (typeof configFn === 'function') {
|
|
114
|
-
return configFn(defaultConfig)
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.log(error);
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return defaultConfig
|
|
122
|
-
}
|
|
1
|
+
import child_process from 'child_process'
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import figures from 'figures';
|
|
4
|
+
|
|
5
|
+
export const execSync = (command, option = {}) => {
|
|
6
|
+
try {
|
|
7
|
+
const result = child_process.execSync(command, {
|
|
8
|
+
encoding: "utf-8",
|
|
9
|
+
stdio: 'inherit',
|
|
10
|
+
...option
|
|
11
|
+
});
|
|
12
|
+
result && console.log(result);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(`Command failed: ${error.message}`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export const logger = {
|
|
22
|
+
info: (message, prefix = 'INFO', icon = true) => {
|
|
23
|
+
console.log(`${icon ? chalk.blue(figures.info) + " " : ""}${chalk.cyan.bold(prefix)} ${message}`);
|
|
24
|
+
},
|
|
25
|
+
success: (message, prefix = 'SUCCESS:', icon = true) => {
|
|
26
|
+
console.log(`${icon ? chalk.green(figures.tick) + " " : ""}${chalk.green.bold(prefix)} ${message}`);
|
|
27
|
+
},
|
|
28
|
+
warning: (message, prefix = 'WARNING:', icon = true) => {
|
|
29
|
+
console.log(`${icon ? chalk.yellow(figures.warning) + " " : ""}${chalk.yellow.bold(prefix)} ${message}`);
|
|
30
|
+
},
|
|
31
|
+
error: (message, prefix = 'ERROR:', icon = true) => {
|
|
32
|
+
console.log(`${icon ? chalk.red(figures.cross) + " " : ""}${chalk.red.bold(prefix)} ${message}`);
|
|
33
|
+
},
|
|
34
|
+
custom: (icon, color, label, message) => {
|
|
35
|
+
console.log(`${chalk[color](icon)} ${chalk[color].bold(`${label}:`)} ${message}`);
|
|
36
|
+
},
|
|
37
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import create from "./actions/create/index.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.
|
|
30
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import start from "./actions/start/index.js";
|
|
5
|
+
import build from "./actions/build/index.js";
|
|
6
|
+
import create from "./actions/create/index.js";
|
|
7
|
+
import publish from "./actions/publish/index.js";
|
|
8
|
+
|
|
9
|
+
const program = new Command();
|
|
10
|
+
|
|
11
|
+
program.name("Makepack").description("Usages");
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.command("create")
|
|
15
|
+
.description("create a new project")
|
|
16
|
+
.action(create);
|
|
17
|
+
|
|
18
|
+
program
|
|
19
|
+
.command("start")
|
|
20
|
+
.description("Start the server")
|
|
21
|
+
.action(start);
|
|
22
|
+
|
|
23
|
+
program
|
|
24
|
+
.command("build")
|
|
25
|
+
.description("Build the project")
|
|
26
|
+
.action(build);
|
|
27
|
+
|
|
28
|
+
program
|
|
29
|
+
.command("publish")
|
|
30
|
+
.description("Publish it to the npm repository")
|
|
31
|
+
.action(publish);
|
|
32
|
+
|
|
33
|
+
program.parse();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs-extra'
|
|
3
|
+
import { pathToFileURL } from 'url';
|
|
4
|
+
|
|
5
|
+
const makepackConfig = async () => {
|
|
6
|
+
const makepack = path.resolve(process.cwd(), "makepack.js");
|
|
7
|
+
|
|
8
|
+
const defaultConfig = {
|
|
9
|
+
build: {
|
|
10
|
+
outdir: "build",
|
|
11
|
+
types: true,
|
|
12
|
+
formatPackageJson: (p) => p,
|
|
13
|
+
configs: [
|
|
14
|
+
{
|
|
15
|
+
entryPoints: "src/**/*.{tsx,ts,js,jsx}",
|
|
16
|
+
outdir: "esm",
|
|
17
|
+
format: "esm",
|
|
18
|
+
sourcemap: true,
|
|
19
|
+
jsx: 'automatic',
|
|
20
|
+
loader: {
|
|
21
|
+
'.ts': 'ts',
|
|
22
|
+
'.tsx': 'tsx'
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
entryPoints: "src/**/*.{tsx,ts,js,jsx}",
|
|
27
|
+
outdir: "",
|
|
28
|
+
format: "cjs",
|
|
29
|
+
sourcemap: true,
|
|
30
|
+
jsx: 'automatic',
|
|
31
|
+
loader: {
|
|
32
|
+
'.ts': 'ts',
|
|
33
|
+
'.tsx': 'tsx'
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
start: {
|
|
39
|
+
port: 5000,
|
|
40
|
+
entry: "App.tsx",
|
|
41
|
+
express: (_app) => { }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (fs.existsSync(makepack)) {
|
|
46
|
+
try {
|
|
47
|
+
const c = await import(pathToFileURL(makepack).href)
|
|
48
|
+
const configFn = c.default
|
|
49
|
+
if (typeof configFn === 'function') {
|
|
50
|
+
const nc = configFn(defaultConfig)
|
|
51
|
+
if (!nc) {
|
|
52
|
+
console.log("Config function must return a config object")
|
|
53
|
+
process.exit(1)
|
|
54
|
+
}
|
|
55
|
+
return nc
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.log(error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return defaultConfig
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default makepackConfig
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default (args) => {
|
|
2
|
-
const makepack = {
|
|
3
|
-
"template": `${args.template}`,
|
|
4
|
-
"serve": {
|
|
5
|
-
"port": 3000,
|
|
6
|
-
"entry": `${args.rootdir}/${args.entry}`
|
|
7
|
-
},
|
|
8
|
-
"build": {
|
|
9
|
-
"entry": `${args.rootdir}/**/*.{tsx,ts,js,jsx}`,
|
|
10
|
-
"outdir": `${args.outdir}`,
|
|
11
|
-
"esbuild": {
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
content: `const makepack = ${JSON.stringify(makepack, null, 2)}\nexport default makepack\n`,
|
|
17
|
-
filename: "makepack.js"
|
|
18
|
-
}
|
|
19
|
-
}
|