makepack 1.5.24 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -122
- package/package.json +61 -61
- package/src/actions/build/index.js +163 -109
- package/src/actions/create/files/gitignore.js +9 -8
- package/src/actions/create/files/package-json.js +55 -54
- package/src/actions/create/files/project-js.js +12 -12
- package/src/actions/create/files/project-jsx.js +55 -50
- package/src/actions/create/files/project-ts.js +10 -10
- package/src/actions/create/files/project-tsx.js +55 -50
- package/src/actions/create/files/readme.md.js +62 -62
- package/src/actions/create/files/tsconfig.js +33 -33
- package/src/actions/create/index.js +103 -105
- package/src/actions/create/makeFiles.js +64 -64
- package/src/actions/publish/index.js +19 -20
- package/src/actions/start/express.js +42 -25
- package/src/actions/start/index.js +117 -76
- package/src/actions/start/vite.js +61 -56
- package/src/helpers.js +36 -36
- package/src/index.js +41 -33
- package/src/actions/create/files/App.js +0 -52
- package/src/actions/create/files/config.js +0 -55
- package/src/actions/start/user-express.js +0 -7
- package/src/makepack-config.js +0 -59
|
@@ -1,106 +1,104 @@
|
|
|
1
|
-
import { execSync, logger } from "../../helpers.js"
|
|
2
|
-
import makeFiles from "./makeFiles.js"
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import inquirer from 'inquirer'
|
|
5
|
-
import figlet from 'figlet'
|
|
6
|
-
import fs from "fs-extra"
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
94
|
-
console.log(`Run the development server:
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
1
|
+
import { execSync, logger } from "../../helpers.js"
|
|
2
|
+
import makeFiles from "./makeFiles.js"
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import inquirer from 'inquirer'
|
|
5
|
+
import figlet from 'figlet'
|
|
6
|
+
import fs from "fs-extra"
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
const cwd = process.cwd()
|
|
9
|
+
const cwdFolder = cwd.split(path.sep).pop()
|
|
10
|
+
|
|
11
|
+
const valiateProjectName = (name) => {
|
|
12
|
+
if (!name) {
|
|
13
|
+
console.error("Project name cannot be empty.");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
17
|
+
console.error("Project name can only contain lowercase letters, numbers, and hyphens.");
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (name.length < 3) {
|
|
21
|
+
console.error("Project name must be at least 3 characters long.");
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (name.length > 50) {
|
|
25
|
+
console.error("Project name must be less than 50 characters long.");
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const create = async () => {
|
|
32
|
+
|
|
33
|
+
let info = await inquirer.prompt([
|
|
34
|
+
{
|
|
35
|
+
type: 'input',
|
|
36
|
+
name: 'pdir',
|
|
37
|
+
message: 'Enter the project name',
|
|
38
|
+
default: cwdFolder
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
type: 'list',
|
|
42
|
+
name: 'template',
|
|
43
|
+
message: 'Select a template',
|
|
44
|
+
choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
|
|
45
|
+
default: "typescript"
|
|
46
|
+
}
|
|
47
|
+
])
|
|
48
|
+
|
|
49
|
+
// check if the pdir is exists
|
|
50
|
+
let pdir = info.pdir.trim().replace(/\s+/g, '-').toLowerCase();
|
|
51
|
+
const isValidProjectName = valiateProjectName(pdir)
|
|
52
|
+
if (!isValidProjectName) return
|
|
53
|
+
|
|
54
|
+
if (pdir !== cwdFolder) {
|
|
55
|
+
if (fs.existsSync(path.join(cwd, pdir))) {
|
|
56
|
+
const { proceed } = await inquirer.prompt([
|
|
57
|
+
{
|
|
58
|
+
type: "confirm",
|
|
59
|
+
name: 'proceed',
|
|
60
|
+
message: "The directory already exists, do you want to overwrite it?",
|
|
61
|
+
default: "No"
|
|
62
|
+
}
|
|
63
|
+
])
|
|
64
|
+
if (!proceed) {
|
|
65
|
+
console.log('Project creation canceled.');
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const rootdir = path.join(cwd, pdir)
|
|
72
|
+
let isCurrentDir = pdir !== cwdFolder
|
|
73
|
+
logger.info("", "Creating project...", false)
|
|
74
|
+
|
|
75
|
+
if (!fs.existsSync(rootdir)) {
|
|
76
|
+
fs.mkdirSync(rootdir)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!fs.existsSync(path.join(rootdir, 'src'))) {
|
|
80
|
+
fs.mkdirSync(path.join(rootdir, 'src'))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await makeFiles(info)
|
|
84
|
+
|
|
85
|
+
logger.info("", "Installing Dependencies", false)
|
|
86
|
+
execSync("npm install", {
|
|
87
|
+
cwd: rootdir,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
logger.success("Project setup complete!", "")
|
|
91
|
+
if (isCurrentDir) {
|
|
92
|
+
console.log(`Run the development server: ${chalk.blue("npm start")}\nEnjoy your new project! 😊`);
|
|
93
|
+
} else {
|
|
94
|
+
console.log(`Navigate to your project directory:\n${chalk.blue("cd " + info.pdir, false)} and Run the development server: ${chalk.blue("npm start")}\nEnjoy your new project! 😊`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
figlet("Makepack CLI", function (err, data) {
|
|
98
|
+
if (!err) {
|
|
99
|
+
console.log(data);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
106
104
|
export default create
|
|
@@ -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
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
await
|
|
19
|
-
await
|
|
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
|
-
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 tsconfig from "./files/tsconfig.js";
|
|
5
|
+
import projectJs from "./files/project-js.js";
|
|
6
|
+
import projectJsx from "./files/project-jsx.js";
|
|
7
|
+
import projectTs from "./files/project-ts.js";
|
|
8
|
+
import projectTsx from "./files/project-tsx.js";
|
|
9
|
+
|
|
10
|
+
import inquirer from 'inquirer'
|
|
11
|
+
import fs from "fs-extra"
|
|
12
|
+
import path from "path"
|
|
13
|
+
import readmeMd from "./files/readme.md.js";
|
|
14
|
+
|
|
15
|
+
export default async (info) => {
|
|
16
|
+
const files = [
|
|
17
|
+
await packageJson(info),
|
|
18
|
+
await gitignore(info),
|
|
19
|
+
await readmeMd(info)
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
switch (info.template) {
|
|
23
|
+
case "typescript":
|
|
24
|
+
files.push(await projectTs(info))
|
|
25
|
+
break
|
|
26
|
+
case "react with typescript":
|
|
27
|
+
files.push(await projectTsx(info))
|
|
28
|
+
break;
|
|
29
|
+
case "javascript":
|
|
30
|
+
files.push(await projectJs(info))
|
|
31
|
+
break
|
|
32
|
+
case "react with javascript":
|
|
33
|
+
files.push(await projectJsx(info))
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// push ts config
|
|
38
|
+
if (info.template.includes("typescript")) {
|
|
39
|
+
files.push(await tsconfig(info))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const rootdir = path.join(process.cwd(), info.pdir)
|
|
43
|
+
|
|
44
|
+
for (let file of files) {
|
|
45
|
+
// check if the file exists
|
|
46
|
+
if (fs.existsSync(path.join(rootdir, 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(rootdir, file.filename))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fs.writeFileSync(path.join(rootdir, file.filename), file.content)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { execSync, logger } from '../../helpers.js'
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { execSync, logger } from '../../helpers.js'
|
|
3
|
+
import fs from 'fs-extra'
|
|
4
|
+
|
|
5
|
+
const publish = async () => {
|
|
6
|
+
const buildDir = path.join(process.cwd(), '.mpack')
|
|
7
|
+
const packageJsonPath = path.join(buildDir, 'package.json')
|
|
8
|
+
const exists = fs.existsSync(buildDir)
|
|
9
|
+
if (!exists || !fs.existsSync(packageJsonPath)) {
|
|
10
|
+
logger.error(`Project is not built yet. Please build the project first.`)
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
logger.info(`Publishing the production build to the npm repository...`)
|
|
15
|
+
execSync(`npm publish`, {
|
|
16
|
+
cwd: buildDir
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
21
20
|
export default publish
|
|
@@ -1,26 +1,43 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import { logger } from '../../helpers.js'
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
const app = express();
|
|
9
|
-
const server = async () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { logger } from '../../helpers.js'
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
import viteSetup from './vite.js';
|
|
7
|
+
const port = process.env.PORT || 3000;
|
|
8
|
+
const app = express();
|
|
9
|
+
const server = async () => {
|
|
10
|
+
|
|
11
|
+
// get type from package.json
|
|
12
|
+
const pkg = path.join(process.cwd(), 'package.json');
|
|
13
|
+
let type = 'module';
|
|
14
|
+
if (fs.existsSync(pkg)) {
|
|
15
|
+
const pkgjson = JSON.parse(fs.readFileSync(pkg, 'utf-8'));
|
|
16
|
+
type = pkgjson.type || 'module';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const mpack = path.join(process.cwd(), '.mpack');
|
|
20
|
+
const uxp = path.join(mpack, 'uxp.js')
|
|
21
|
+
if (fs.existsSync(uxp)) {
|
|
22
|
+
// load user-express.js based on type
|
|
23
|
+
if (type === 'module') {
|
|
24
|
+
const { default: userExpress } = await import(uxp);
|
|
25
|
+
userExpress(app);
|
|
26
|
+
} else {
|
|
27
|
+
const userExpress = require(uxp).default;
|
|
28
|
+
userExpress(app);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
await viteSetup(app)
|
|
34
|
+
app.use((_req, res) => {
|
|
35
|
+
res.status(500).send('Internal Server Error');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
app.listen(port, () => {
|
|
39
|
+
logger.success(`Server is running on ${chalk.blue(chalk.underline(`http://localhost:${port}`))}`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
26
43
|
server()
|
|
@@ -1,77 +1,118 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import chokidar from 'chokidar';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
server
|
|
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
|
-
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import { spawn } from 'child_process'
|
|
4
|
+
import esbuild from 'esbuild';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import chokidar from 'chokidar';
|
|
7
|
+
|
|
8
|
+
let __filename, __dirname;
|
|
9
|
+
|
|
10
|
+
if (typeof import.meta.url !== 'undefined') {
|
|
11
|
+
__filename = fileURLToPath(import.meta.url);
|
|
12
|
+
__dirname = path.dirname(__filename);
|
|
13
|
+
} else {
|
|
14
|
+
__filename = __filename;
|
|
15
|
+
__dirname = __dirname;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const startServer = () => {
|
|
20
|
+
const mpack = path.join(process.cwd(), '.mpack')
|
|
21
|
+
const server = spawn('node', [path.resolve(mpack, 'index.js')], {
|
|
22
|
+
stdio: 'inherit',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
server.on('error', (err) => {
|
|
26
|
+
console.error(`Error starting server: ${err.message}`);
|
|
27
|
+
});
|
|
28
|
+
return server;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const start = async (args) => {
|
|
32
|
+
let { port } = args
|
|
33
|
+
|
|
34
|
+
if (!port) {
|
|
35
|
+
port = 4000;
|
|
36
|
+
}
|
|
37
|
+
// create a folder call .mpack
|
|
38
|
+
const mpack = path.join(process.cwd(), '.mpack')
|
|
39
|
+
if (fs.existsSync(mpack)) {
|
|
40
|
+
fs.rmSync(mpack, { recursive: true, force: true });
|
|
41
|
+
}
|
|
42
|
+
fs.mkdirSync(mpack)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// build ./express.js to .mpack/index.js with esbuild
|
|
46
|
+
let format = 'esm'
|
|
47
|
+
// get format from package.json
|
|
48
|
+
const pkg = path.join(process.cwd(), 'package.json')
|
|
49
|
+
if (fs.existsSync(pkg)) {
|
|
50
|
+
const pkgjson = JSON.parse(fs.readFileSync(pkg, 'utf-8'))
|
|
51
|
+
if (pkgjson.type === 'commonjs') {
|
|
52
|
+
format = 'cjs'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const uxpjs = path.join(process.cwd(), 'express.js')
|
|
57
|
+
const uxpts = path.join(process.cwd(), 'express.ts')
|
|
58
|
+
|
|
59
|
+
if (fs.existsSync(uxpjs) || fs.existsSync(uxpts)) {
|
|
60
|
+
let filename = fs.existsSync(uxpjs) ? "express.js" : "express.ts";
|
|
61
|
+
let outfile = path.join(mpack, 'uxp.js');
|
|
62
|
+
|
|
63
|
+
const ctx = await esbuild.context({
|
|
64
|
+
entryPoints: [filename],
|
|
65
|
+
outfile,
|
|
66
|
+
bundle: true,
|
|
67
|
+
format: 'esm',
|
|
68
|
+
platform: 'node',
|
|
69
|
+
packages: 'external',
|
|
70
|
+
})
|
|
71
|
+
ctx.watch()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
await esbuild.build({
|
|
75
|
+
entryPoints: [path.resolve(__dirname, 'express.js')],
|
|
76
|
+
outfile: path.join(mpack, 'index.js'),
|
|
77
|
+
bundle: true,
|
|
78
|
+
format,
|
|
79
|
+
platform: 'node',
|
|
80
|
+
packages: 'external',
|
|
81
|
+
define: {
|
|
82
|
+
'process.env.PORT': JSON.stringify(port),
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
let server = startServer();
|
|
87
|
+
|
|
88
|
+
const uxp = path.join(mpack, 'uxp.js')
|
|
89
|
+
|
|
90
|
+
if (fs.existsSync(uxp)) {
|
|
91
|
+
const watcher = chokidar.watch(uxp, {
|
|
92
|
+
persistent: true,
|
|
93
|
+
ignoreInitial: true,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
watcher.on('change', async () => {
|
|
97
|
+
// restart the server and remove log Server exited with code
|
|
98
|
+
server.kill();
|
|
99
|
+
server = startServer();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
process.on('SIGINT', () => {
|
|
104
|
+
console.log('Received SIGINT, killing server...');
|
|
105
|
+
server.kill('SIGINT');
|
|
106
|
+
process.exit(0);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
process.on('SIGTERM', () => {
|
|
110
|
+
console.log('Received SIGTERM, killing server...');
|
|
111
|
+
server.kill('SIGTERM');
|
|
112
|
+
process.exit(0);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
77
118
|
export default start
|