makepack 1.7.11 → 1.7.12
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 +62 -62
- package/src/actions/build/bundler.js +114 -114
- package/src/actions/build/index.js +74 -74
- package/src/actions/create/files/gitignore.js +9 -9
- package/src/actions/create/files/main.js +36 -36
- package/src/actions/create/files/package-json.js +49 -49
- 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 +62 -62
- package/src/actions/create/files/tsconfig.js +33 -33
- package/src/actions/create/index.js +95 -95
- package/src/actions/create/makeFiles.js +65 -65
- package/src/actions/release/index.js +19 -19
- package/src/actions/start/index.js +176 -176
- package/src/actions/start/vite.js +68 -61
- package/src/helpers.js +52 -52
- package/src/index.js +39 -39
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
5
|
-
import { createRequire } from 'module';
|
|
6
|
-
import chokidar from 'chokidar';
|
|
7
|
-
import madge from 'madge';
|
|
8
|
-
import viteSetup from './vite.js';
|
|
9
|
-
import * as esbuild from 'esbuild';
|
|
10
|
-
import { randomUUID } from 'crypto';
|
|
11
|
-
import debounce from 'lodash.debounce';
|
|
12
|
-
import { logger, concolor } from '../../helpers.js';
|
|
13
|
-
|
|
14
|
-
const projectRoot = process.cwd();
|
|
15
|
-
const requireFn = createRequire(import.meta.url);
|
|
16
|
-
const mpack = path.join(projectRoot, '.mpack');
|
|
17
|
-
|
|
18
|
-
let server = null;
|
|
19
|
-
let app = null;
|
|
20
|
-
let viteServer = null;
|
|
21
|
-
|
|
22
|
-
const pkg = path.join(process.cwd(), 'package.json');
|
|
23
|
-
const pkgjson = JSON.parse(fs.readFileSync(pkg, 'utf-8'));
|
|
24
|
-
let isEsmProject = pkgjson.type === 'module';
|
|
25
|
-
|
|
26
|
-
const uxpfileJS = path.resolve(projectRoot, 'express.js');
|
|
27
|
-
const uxpfileTS = path.resolve(projectRoot, 'express.ts');
|
|
28
|
-
const expExists = fs.existsSync(uxpfileJS) || fs.existsSync(uxpfileTS);
|
|
29
|
-
let uxpfile = expExists ? (fs.existsSync(uxpfileJS) ? uxpfileJS : uxpfileTS) : null;
|
|
30
|
-
|
|
31
|
-
const connections = new Set();
|
|
32
|
-
|
|
33
|
-
function trackConnections(srv) {
|
|
34
|
-
srv.on('connection', (conn) => {
|
|
35
|
-
connections.add(conn);
|
|
36
|
-
conn.on('close', () => connections.delete(conn));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function bootServer(args) {
|
|
41
|
-
let wasServer = !!server;
|
|
42
|
-
if (server) {
|
|
43
|
-
for (const conn of connections) {
|
|
44
|
-
conn.destroy();
|
|
45
|
-
}
|
|
46
|
-
await new Promise((resolve, reject) => {
|
|
47
|
-
server.close(err => {
|
|
48
|
-
if (err) {
|
|
49
|
-
logger.error(`while closing server: ${err.message || err}`);
|
|
50
|
-
reject(err);
|
|
51
|
-
} else {
|
|
52
|
-
resolve();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
server = null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (viteServer) {
|
|
60
|
-
await viteServer.close();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
app = express();
|
|
64
|
-
try {
|
|
65
|
-
const middleware = await loadExp();
|
|
66
|
-
if (typeof middleware === 'function') {
|
|
67
|
-
middleware(app);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
viteServer = await viteSetup(app);
|
|
71
|
-
const port = args.port || 4000;
|
|
72
|
-
server = app.listen(port, () => {
|
|
73
|
-
if (!wasServer) {
|
|
74
|
-
logger.success(`Server running on: ${concolor.green(concolor.bold(`http://localhost:${port}`))}`, '')
|
|
75
|
-
}
|
|
76
|
-
trackConnections(server);
|
|
77
|
-
})
|
|
78
|
-
} catch (err) {
|
|
79
|
-
logger.error(`Failed to start server: ${err.message || err}`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let esbuildCtx = null;
|
|
85
|
-
|
|
86
|
-
const buildFile = path.join(mpack, `${randomUUID().substring(0, 15)}.js`);
|
|
87
|
-
|
|
88
|
-
async function loadExp() {
|
|
89
|
-
if (!expExists) return null
|
|
90
|
-
|
|
91
|
-
const cacheKeys = Object.keys(requireFn.cache || {});
|
|
92
|
-
if (!isEsmProject) {
|
|
93
|
-
for (const key of cacheKeys) {
|
|
94
|
-
if (key.startsWith(process.cwd())) {
|
|
95
|
-
delete requireFn.cache[key];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const ext = path.extname(uxpfile);
|
|
101
|
-
const isTs = ext === '.ts' || ext === '.tsx';
|
|
102
|
-
|
|
103
|
-
if (isTs) {
|
|
104
|
-
if (esbuildCtx) {
|
|
105
|
-
await esbuildCtx.rebuild();
|
|
106
|
-
} else {
|
|
107
|
-
esbuildCtx = await esbuild.context({
|
|
108
|
-
entryPoints: [uxpfile],
|
|
109
|
-
outfile: buildFile,
|
|
110
|
-
format: isEsmProject ? 'esm' : 'cjs',
|
|
111
|
-
platform: 'node',
|
|
112
|
-
sourcemap: 'inline',
|
|
113
|
-
bundle: true,
|
|
114
|
-
packages: 'external',
|
|
115
|
-
});
|
|
116
|
-
await esbuildCtx.rebuild();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (isEsmProject) {
|
|
120
|
-
const mod = await import(pathToFileURL(buildFile).href + `?update=${Date.now()}`);
|
|
121
|
-
return mod.default || mod;
|
|
122
|
-
} else {
|
|
123
|
-
return requireFn(buildFile);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (isEsmProject) {
|
|
128
|
-
const mod = await import(pathToFileURL(uxpfile).href + `?update=${Date.now()}`);
|
|
129
|
-
return mod.default || mod;
|
|
130
|
-
} else {
|
|
131
|
-
return requireFn(uxpfile);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function getAllDependencies() {
|
|
136
|
-
try {
|
|
137
|
-
if (!expExists) {
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
const result = await madge(uxpfile, { fileExtensions: ['ts', 'js'] });
|
|
141
|
-
const deps = Object.keys(result.obj());
|
|
142
|
-
// const circular = await result.circular();
|
|
143
|
-
// if (circular.length) {
|
|
144
|
-
// logger.warning(`Circular dependencies detected: ${circular.map(c => c.join(' -> ')).join(', ')}`);
|
|
145
|
-
// }
|
|
146
|
-
return deps.map(dep => path.resolve(path.dirname(uxpfile), dep));
|
|
147
|
-
} catch (err) {
|
|
148
|
-
logger.error(`Failed to analyze dependencies with madge: ${err.message || err}`);
|
|
149
|
-
return [uxpfile];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
let watcher;
|
|
155
|
-
async function startDevServer(args) {
|
|
156
|
-
if (fs.existsSync(mpack)) {
|
|
157
|
-
fs.rmSync(mpack, { recursive: true, force: true });
|
|
158
|
-
}
|
|
159
|
-
fs.mkdirSync(mpack, { recursive: true });
|
|
160
|
-
|
|
161
|
-
await bootServer(args);
|
|
162
|
-
const filesToWatch = await getAllDependencies();
|
|
163
|
-
if (watcher) watcher.close();
|
|
164
|
-
watcher = chokidar.watch(filesToWatch, { ignoreInitial: true });
|
|
165
|
-
|
|
166
|
-
const reload = debounce(async (f) => {
|
|
167
|
-
await bootServer(args);
|
|
168
|
-
const prettyPath = concolor.dim(path.relative(process.cwd(), f));
|
|
169
|
-
logger.info(`${concolor.green('server reload')} ${prettyPath}`);
|
|
170
|
-
}, 100);
|
|
171
|
-
|
|
172
|
-
watcher.on('change', reload);
|
|
173
|
-
watcher.on('add', reload);
|
|
174
|
-
watcher.on('unlink', reload);
|
|
175
|
-
}
|
|
176
|
-
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { pathToFileURL } from 'url';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
import chokidar from 'chokidar';
|
|
7
|
+
import madge from 'madge';
|
|
8
|
+
import viteSetup from './vite.js';
|
|
9
|
+
import * as esbuild from 'esbuild';
|
|
10
|
+
import { randomUUID } from 'crypto';
|
|
11
|
+
import debounce from 'lodash.debounce';
|
|
12
|
+
import { logger, concolor } from '../../helpers.js';
|
|
13
|
+
|
|
14
|
+
const projectRoot = process.cwd();
|
|
15
|
+
const requireFn = createRequire(import.meta.url);
|
|
16
|
+
const mpack = path.join(projectRoot, '.mpack');
|
|
17
|
+
|
|
18
|
+
let server = null;
|
|
19
|
+
let app = null;
|
|
20
|
+
let viteServer = null;
|
|
21
|
+
|
|
22
|
+
const pkg = path.join(process.cwd(), 'package.json');
|
|
23
|
+
const pkgjson = JSON.parse(fs.readFileSync(pkg, 'utf-8'));
|
|
24
|
+
let isEsmProject = pkgjson.type === 'module';
|
|
25
|
+
|
|
26
|
+
const uxpfileJS = path.resolve(projectRoot, 'express.js');
|
|
27
|
+
const uxpfileTS = path.resolve(projectRoot, 'express.ts');
|
|
28
|
+
const expExists = fs.existsSync(uxpfileJS) || fs.existsSync(uxpfileTS);
|
|
29
|
+
let uxpfile = expExists ? (fs.existsSync(uxpfileJS) ? uxpfileJS : uxpfileTS) : null;
|
|
30
|
+
|
|
31
|
+
const connections = new Set();
|
|
32
|
+
|
|
33
|
+
function trackConnections(srv) {
|
|
34
|
+
srv.on('connection', (conn) => {
|
|
35
|
+
connections.add(conn);
|
|
36
|
+
conn.on('close', () => connections.delete(conn));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function bootServer(args) {
|
|
41
|
+
let wasServer = !!server;
|
|
42
|
+
if (server) {
|
|
43
|
+
for (const conn of connections) {
|
|
44
|
+
conn.destroy();
|
|
45
|
+
}
|
|
46
|
+
await new Promise((resolve, reject) => {
|
|
47
|
+
server.close(err => {
|
|
48
|
+
if (err) {
|
|
49
|
+
logger.error(`while closing server: ${err.message || err}`);
|
|
50
|
+
reject(err);
|
|
51
|
+
} else {
|
|
52
|
+
resolve();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
server = null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (viteServer) {
|
|
60
|
+
await viteServer.close();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
app = express();
|
|
64
|
+
try {
|
|
65
|
+
const middleware = await loadExp();
|
|
66
|
+
if (typeof middleware === 'function') {
|
|
67
|
+
middleware(app);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
viteServer = await viteSetup(app);
|
|
71
|
+
const port = args.port || 4000;
|
|
72
|
+
server = app.listen(port, () => {
|
|
73
|
+
if (!wasServer) {
|
|
74
|
+
logger.success(`Server running on: ${concolor.green(concolor.bold(`http://localhost:${port}`))}`, '')
|
|
75
|
+
}
|
|
76
|
+
trackConnections(server);
|
|
77
|
+
})
|
|
78
|
+
} catch (err) {
|
|
79
|
+
logger.error(`Failed to start server: ${err.message || err}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
let esbuildCtx = null;
|
|
85
|
+
|
|
86
|
+
const buildFile = path.join(mpack, `${randomUUID().substring(0, 15)}.js`);
|
|
87
|
+
|
|
88
|
+
async function loadExp() {
|
|
89
|
+
if (!expExists) return null
|
|
90
|
+
|
|
91
|
+
const cacheKeys = Object.keys(requireFn.cache || {});
|
|
92
|
+
if (!isEsmProject) {
|
|
93
|
+
for (const key of cacheKeys) {
|
|
94
|
+
if (key.startsWith(process.cwd())) {
|
|
95
|
+
delete requireFn.cache[key];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const ext = path.extname(uxpfile);
|
|
101
|
+
const isTs = ext === '.ts' || ext === '.tsx';
|
|
102
|
+
|
|
103
|
+
if (isTs) {
|
|
104
|
+
if (esbuildCtx) {
|
|
105
|
+
await esbuildCtx.rebuild();
|
|
106
|
+
} else {
|
|
107
|
+
esbuildCtx = await esbuild.context({
|
|
108
|
+
entryPoints: [uxpfile],
|
|
109
|
+
outfile: buildFile,
|
|
110
|
+
format: isEsmProject ? 'esm' : 'cjs',
|
|
111
|
+
platform: 'node',
|
|
112
|
+
sourcemap: 'inline',
|
|
113
|
+
bundle: true,
|
|
114
|
+
packages: 'external',
|
|
115
|
+
});
|
|
116
|
+
await esbuildCtx.rebuild();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (isEsmProject) {
|
|
120
|
+
const mod = await import(pathToFileURL(buildFile).href + `?update=${Date.now()}`);
|
|
121
|
+
return mod.default || mod;
|
|
122
|
+
} else {
|
|
123
|
+
return requireFn(buildFile);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (isEsmProject) {
|
|
128
|
+
const mod = await import(pathToFileURL(uxpfile).href + `?update=${Date.now()}`);
|
|
129
|
+
return mod.default || mod;
|
|
130
|
+
} else {
|
|
131
|
+
return requireFn(uxpfile);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function getAllDependencies() {
|
|
136
|
+
try {
|
|
137
|
+
if (!expExists) {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
const result = await madge(uxpfile, { fileExtensions: ['ts', 'js'] });
|
|
141
|
+
const deps = Object.keys(result.obj());
|
|
142
|
+
// const circular = await result.circular();
|
|
143
|
+
// if (circular.length) {
|
|
144
|
+
// logger.warning(`Circular dependencies detected: ${circular.map(c => c.join(' -> ')).join(', ')}`);
|
|
145
|
+
// }
|
|
146
|
+
return deps.map(dep => path.resolve(path.dirname(uxpfile), dep));
|
|
147
|
+
} catch (err) {
|
|
148
|
+
logger.error(`Failed to analyze dependencies with madge: ${err.message || err}`);
|
|
149
|
+
return [uxpfile];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
let watcher;
|
|
155
|
+
async function startDevServer(args) {
|
|
156
|
+
if (fs.existsSync(mpack)) {
|
|
157
|
+
fs.rmSync(mpack, { recursive: true, force: true });
|
|
158
|
+
}
|
|
159
|
+
fs.mkdirSync(mpack, { recursive: true });
|
|
160
|
+
|
|
161
|
+
await bootServer(args);
|
|
162
|
+
const filesToWatch = await getAllDependencies();
|
|
163
|
+
if (watcher) watcher.close();
|
|
164
|
+
watcher = chokidar.watch(filesToWatch, { ignoreInitial: true });
|
|
165
|
+
|
|
166
|
+
const reload = debounce(async (f) => {
|
|
167
|
+
await bootServer(args);
|
|
168
|
+
const prettyPath = concolor.dim(path.relative(process.cwd(), f));
|
|
169
|
+
logger.info(`${concolor.green('server reload')} ${prettyPath}`);
|
|
170
|
+
}, 100);
|
|
171
|
+
|
|
172
|
+
watcher.on('change', reload);
|
|
173
|
+
watcher.on('add', reload);
|
|
174
|
+
watcher.on('unlink', reload);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
177
|
export default startDevServer
|
|
@@ -1,62 +1,69 @@
|
|
|
1
|
-
// import react from '@vitejs/plugin-react'
|
|
2
|
-
import { createServer as createViteServer } from 'vite';
|
|
3
|
-
import { logger } from '../../helpers.js'
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
|
|
7
|
-
const viteSetup = async (app) => {
|
|
8
|
-
|
|
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
|
-
|
|
1
|
+
// import react from '@vitejs/plugin-react'
|
|
2
|
+
import { createServer as createViteServer } from 'vite';
|
|
3
|
+
import { logger } from '../../helpers.js'
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
|
|
7
|
+
const viteSetup = async (app) => {
|
|
8
|
+
|
|
9
|
+
// delete .vite directory if exists
|
|
10
|
+
const viteDir = path.join(process.cwd(), 'node_modules/.vite');
|
|
11
|
+
if (fs.existsSync(viteDir)) {
|
|
12
|
+
fs.rmSync(viteDir, { recursive: true, force: true });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const viteConfig = {
|
|
16
|
+
root: process.cwd(),
|
|
17
|
+
base: "/",
|
|
18
|
+
// plugins: [react()],
|
|
19
|
+
server: {
|
|
20
|
+
middlewareMode: true,
|
|
21
|
+
},
|
|
22
|
+
customLogger: {
|
|
23
|
+
info: (msg) => {
|
|
24
|
+
logger.info(msg)
|
|
25
|
+
},
|
|
26
|
+
warn: (msg) => logger.warning(msg),
|
|
27
|
+
error: (msg) => logger.error(msg),
|
|
28
|
+
},
|
|
29
|
+
appType: 'custom'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const vite = await createViteServer(viteConfig);
|
|
33
|
+
app.use(vite.middlewares);
|
|
34
|
+
|
|
35
|
+
// exists tsconfig.json in the root directory
|
|
36
|
+
const isTs = fs.existsSync(path.resolve(process.cwd(), 'main.tsx'))
|
|
37
|
+
let entry = `/main.${isTs ? "tsx" : "jsx"}`
|
|
38
|
+
|
|
39
|
+
app.get('*', async (req, res, next) => {
|
|
40
|
+
const url = req.originalUrl;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
let template = await vite.transformIndexHtml(url, `
|
|
44
|
+
<!doctype html>
|
|
45
|
+
<html lang="en">
|
|
46
|
+
<head>
|
|
47
|
+
<meta charset="UTF-8" />
|
|
48
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
49
|
+
</head>
|
|
50
|
+
<body>
|
|
51
|
+
<div id="root"></div>
|
|
52
|
+
<script type="module" src="${entry}"></script>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
55
|
+
`);
|
|
56
|
+
|
|
57
|
+
res.status(200).set({
|
|
58
|
+
'Content-Type': 'text/html'
|
|
59
|
+
}).end(template);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
vite.ssrFixStacktrace(e);
|
|
62
|
+
next(e);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return vite;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
62
69
|
export default viteSetup
|
package/src/helpers.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import child_process from 'child_process'
|
|
2
|
-
export const execSync = (command, option = {}) => {
|
|
3
|
-
try {
|
|
4
|
-
const result = child_process.execSync(command, {
|
|
5
|
-
encoding: "utf-8",
|
|
6
|
-
stdio: 'inherit',
|
|
7
|
-
...option
|
|
8
|
-
});
|
|
9
|
-
result && console.log(result);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.error(`Command failed: ${error.message}`);
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const conicon = {
|
|
18
|
-
info: 'ℹ',
|
|
19
|
-
success: '✔',
|
|
20
|
-
warning: '⚠',
|
|
21
|
-
error: '✖',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const concolor = {
|
|
25
|
-
red: (str) => `\x1b[31m${str}\x1b[0m`,
|
|
26
|
-
green: (str) => `\x1b[32m${str}\x1b[0m`,
|
|
27
|
-
yellow: (str) => `\x1b[33m${str}\x1b[0m`,
|
|
28
|
-
blue: (str) => `\x1b[34m${str}\x1b[0m`,
|
|
29
|
-
bold: (str) => `\x1b[1m${str}\x1b[0m`,
|
|
30
|
-
dim: (str) => `\x1b[2m${str}\x1b[0m`,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const logger = {
|
|
35
|
-
log: (message, prefix, icon, color) => {
|
|
36
|
-
let _color = concolor[color] || concolor.reset;
|
|
37
|
-
let _icon = conicon[icon] || '';
|
|
38
|
-
prefix = prefix ? _color(concolor.bold(prefix)) : "";
|
|
39
|
-
console.log(`${_icon ? _color(_icon) + " " : ""}${prefix} ${message}`);
|
|
40
|
-
},
|
|
41
|
-
info: (message, prefix = 'INFO', icon = true) => {
|
|
42
|
-
logger.log(message, prefix, icon ? 'info' : '', 'blue');
|
|
43
|
-
},
|
|
44
|
-
success: (message, prefix = 'SUCCESS:', icon = true) => {
|
|
45
|
-
logger.log(message, prefix, icon ? 'success' : '', 'green');
|
|
46
|
-
},
|
|
47
|
-
warning: (message, prefix = 'WARNING:', icon = true) => {
|
|
48
|
-
logger.log(message, prefix, icon ? 'warning' : '', 'yellow');
|
|
49
|
-
},
|
|
50
|
-
error: (message, prefix = 'ERROR:', icon = true) => {
|
|
51
|
-
logger.log(message, prefix, icon ? 'error' : '', 'red');
|
|
52
|
-
}
|
|
1
|
+
import child_process from 'child_process'
|
|
2
|
+
export const execSync = (command, option = {}) => {
|
|
3
|
+
try {
|
|
4
|
+
const result = child_process.execSync(command, {
|
|
5
|
+
encoding: "utf-8",
|
|
6
|
+
stdio: 'inherit',
|
|
7
|
+
...option
|
|
8
|
+
});
|
|
9
|
+
result && console.log(result);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(`Command failed: ${error.message}`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export const conicon = {
|
|
18
|
+
info: 'ℹ',
|
|
19
|
+
success: '✔',
|
|
20
|
+
warning: '⚠',
|
|
21
|
+
error: '✖',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const concolor = {
|
|
25
|
+
red: (str) => `\x1b[31m${str}\x1b[0m`,
|
|
26
|
+
green: (str) => `\x1b[32m${str}\x1b[0m`,
|
|
27
|
+
yellow: (str) => `\x1b[33m${str}\x1b[0m`,
|
|
28
|
+
blue: (str) => `\x1b[34m${str}\x1b[0m`,
|
|
29
|
+
bold: (str) => `\x1b[1m${str}\x1b[0m`,
|
|
30
|
+
dim: (str) => `\x1b[2m${str}\x1b[0m`,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export const logger = {
|
|
35
|
+
log: (message, prefix, icon, color) => {
|
|
36
|
+
let _color = concolor[color] || concolor.reset;
|
|
37
|
+
let _icon = conicon[icon] || '';
|
|
38
|
+
prefix = prefix ? _color(concolor.bold(prefix)) : "";
|
|
39
|
+
console.log(`${_icon ? _color(_icon) + " " : ""}${prefix} ${message}`);
|
|
40
|
+
},
|
|
41
|
+
info: (message, prefix = 'INFO', icon = true) => {
|
|
42
|
+
logger.log(message, prefix, icon ? 'info' : '', 'blue');
|
|
43
|
+
},
|
|
44
|
+
success: (message, prefix = 'SUCCESS:', icon = true) => {
|
|
45
|
+
logger.log(message, prefix, icon ? 'success' : '', 'green');
|
|
46
|
+
},
|
|
47
|
+
warning: (message, prefix = 'WARNING:', icon = true) => {
|
|
48
|
+
logger.log(message, prefix, icon ? 'warning' : '', 'yellow');
|
|
49
|
+
},
|
|
50
|
+
error: (message, prefix = 'ERROR:', icon = true) => {
|
|
51
|
+
logger.log(message, prefix, icon ? 'error' : '', 'red');
|
|
52
|
+
}
|
|
53
53
|
};
|
package/src/index.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
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 release from "./actions/release/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
|
-
.option("-p, --port <port>", "Port to run the server", 3000)
|
|
21
|
-
.description("Start the server")
|
|
22
|
-
.action(start);
|
|
23
|
-
|
|
24
|
-
program
|
|
25
|
-
.command("build")
|
|
26
|
-
.description("Build the project")
|
|
27
|
-
.option("-f, --format <format>", "Output format (cjs, esm, both)", "both")
|
|
28
|
-
.option("-b, --bundle <bundle>", "Bundle the project", false)
|
|
29
|
-
.option("-m, --minify <minify>", "Minify the output", false)
|
|
30
|
-
.option("-s, --sourcemap <sourcemap>", "Generate sourcemaps", true)
|
|
31
|
-
.option("-d, --declaration <declaration>", "Generate TypeScript declaration files", true)
|
|
32
|
-
.action(build);
|
|
33
|
-
|
|
34
|
-
program
|
|
35
|
-
.command("release")
|
|
36
|
-
.description("Release it to the npm repository")
|
|
37
|
-
.action(release);
|
|
38
|
-
|
|
39
|
-
program.parse();
|
|
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 release from "./actions/release/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
|
+
.option("-p, --port <port>", "Port to run the server", 3000)
|
|
21
|
+
.description("Start the server")
|
|
22
|
+
.action(start);
|
|
23
|
+
|
|
24
|
+
program
|
|
25
|
+
.command("build")
|
|
26
|
+
.description("Build the project")
|
|
27
|
+
.option("-f, --format <format>", "Output format (cjs, esm, both)", "both")
|
|
28
|
+
.option("-b, --bundle <bundle>", "Bundle the project", false)
|
|
29
|
+
.option("-m, --minify <minify>", "Minify the output", false)
|
|
30
|
+
.option("-s, --sourcemap <sourcemap>", "Generate sourcemaps", true)
|
|
31
|
+
.option("-d, --declaration <declaration>", "Generate TypeScript declaration files", true)
|
|
32
|
+
.action(build);
|
|
33
|
+
|
|
34
|
+
program
|
|
35
|
+
.command("release")
|
|
36
|
+
.description("Release it to the npm repository")
|
|
37
|
+
.action(release);
|
|
38
|
+
|
|
39
|
+
program.parse();
|