@mainset/cli 0.1.0 โ 0.2.0-rc.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/dist/esm/commands/node-package.mjs +8 -8
- package/dist/esm/commands/process-runner-chunks/rslib.chunk.mjs +9 -9
- package/dist/esm/commands/process-runner-chunks/system.chunk.mjs +2 -2
- package/dist/esm/commands/process-runner-chunks/typescript.chunk.mjs +15 -25
- package/dist/esm/commands/source-code.mjs +8 -8
- package/dist/esm/commands/web-app.mjs +76 -45
- package/dist/esm/runtime/resolve-host-package.mjs +32 -9
- package/dist/esm/services/express-base-app/express-base-app.mjs +1 -1
- package/dist/esm/utils/process-runner/process-runner.mjs +37 -1
- package/dist/types/commands/process-runner-chunks/rslib.chunk.d.mts +3 -3
- package/dist/types/commands/process-runner-chunks/system.chunk.d.mts +2 -2
- package/dist/types/commands/process-runner-chunks/typescript.chunk.d.mts +7 -7
- package/dist/types/runtime/resolve-host-package.d.mts +1 -1
- package/dist/types/services/express-base-app/express-base-app.d.mts +1 -1
- package/dist/types/utils/process-runner/process-runner.d.mts +13 -2
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { runtimePathById } from '../runtime/index.mjs';
|
|
4
4
|
import { consoleColorize, initProcessCatchErrorLogger, } from '../utils/index.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { execImmediatePurgeDist, execImmediateRslibCLICommand, execImmediateTypeScriptCompileTypeOnly, runStreamingRslibCLICommand, runStreamingTypeScriptCompileTypeOnly, } from './process-runner-chunks/index.mjs';
|
|
6
6
|
function registerNodePackageCommand(program) {
|
|
7
7
|
program
|
|
8
8
|
.command('node-package')
|
|
@@ -10,7 +10,7 @@ function registerNodePackageCommand(program) {
|
|
|
10
10
|
.requiredOption('-e, --exec <type>', 'Execution mode: build or watch')
|
|
11
11
|
// .option('-b, --builder <builder>', 'Builder tool (default: rslib)', 'rslib')
|
|
12
12
|
.option('-c, --config <path>', 'Path to config file', './rslib.config.mts')
|
|
13
|
-
.action(
|
|
13
|
+
.action((options) => {
|
|
14
14
|
// Step 0: determinate command params
|
|
15
15
|
const customRslibConfigPath = path.resolve(runtimePathById.root, options.config);
|
|
16
16
|
const rslibConfigPath = fs.existsSync(customRslibConfigPath)
|
|
@@ -23,12 +23,12 @@ function registerNodePackageCommand(program) {
|
|
|
23
23
|
console.log('\n๐๏ธ [mainset cli] node-package: build');
|
|
24
24
|
try {
|
|
25
25
|
// Step 1: purge dist folder
|
|
26
|
-
|
|
26
|
+
execImmediatePurgeDist();
|
|
27
27
|
// Step 2: build source code
|
|
28
28
|
console.log('\n๐ฆ Compiling Source Code with Rslib ...');
|
|
29
|
-
|
|
29
|
+
execImmediateRslibCLICommand(`build --config ${rslibConfigPath}`);
|
|
30
30
|
// Step 3: build type only
|
|
31
|
-
|
|
31
|
+
execImmediateTypeScriptCompileTypeOnly();
|
|
32
32
|
console.log('\nโ
Build completed successfully\n');
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
@@ -40,16 +40,16 @@ function registerNodePackageCommand(program) {
|
|
|
40
40
|
console.log('\n๐๏ธ [mainset cli] node-package: watch');
|
|
41
41
|
try {
|
|
42
42
|
// Step 1: purge dist folder
|
|
43
|
-
|
|
43
|
+
execImmediatePurgeDist();
|
|
44
44
|
// Step 2: watch source code
|
|
45
|
-
|
|
45
|
+
runStreamingRslibCLICommand([
|
|
46
46
|
'build',
|
|
47
47
|
'--config',
|
|
48
48
|
rslibConfigPath,
|
|
49
49
|
'--watch',
|
|
50
50
|
]);
|
|
51
51
|
// Step 3: watch type only
|
|
52
|
-
|
|
52
|
+
runStreamingTypeScriptCompileTypeOnly();
|
|
53
53
|
}
|
|
54
54
|
catch (error) {
|
|
55
55
|
initProcessCatchErrorLogger('node-package', error, 'watch');
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { resolveHostPackageBinForCLICommandPath } from '../../runtime/index.mjs';
|
|
2
2
|
import { execImmediateCommand, runStreamingCommand, } from '../../utils/index.mjs';
|
|
3
|
-
|
|
4
|
-
const rslibCLICommandPath =
|
|
3
|
+
function getRslibCLICommandPath() {
|
|
4
|
+
const rslibCLICommandPath = resolveHostPackageBinForCLICommandPath('@mainset/builder-rslib', 'rslib');
|
|
5
5
|
return rslibCLICommandPath;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
const rslibCLICommandPath =
|
|
9
|
-
return execImmediateCommand(
|
|
7
|
+
function execImmediateRslibCLICommand(command) {
|
|
8
|
+
const rslibCLICommandPath = getRslibCLICommandPath();
|
|
9
|
+
return execImmediateCommand(`${rslibCLICommandPath} ${command}`);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
const rslibCLICommandPath =
|
|
13
|
-
return runStreamingCommand(
|
|
11
|
+
function runStreamingRslibCLICommand(commandParams) {
|
|
12
|
+
const rslibCLICommandPath = getRslibCLICommandPath();
|
|
13
|
+
return runStreamingCommand(rslibCLICommandPath, [...commandParams]);
|
|
14
14
|
}
|
|
15
|
-
export {
|
|
15
|
+
export { execImmediateRslibCLICommand, runStreamingRslibCLICommand };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { runtimePathById } from '../../runtime/index.mjs';
|
|
2
2
|
import { execImmediateCommand } from '../../utils/index.mjs';
|
|
3
3
|
// Cleanup
|
|
4
|
-
function
|
|
4
|
+
function execImmediatePurgeDist() {
|
|
5
5
|
console.log('๐งน Cleaning dist folder ...');
|
|
6
6
|
execImmediateCommand(`rm -rf ${runtimePathById.dist}`);
|
|
7
7
|
}
|
|
8
|
-
export {
|
|
8
|
+
export { execImmediatePurgeDist };
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { resolveHostPackageBinForCLICommandPath, runtimePathById, } from '../../runtime/index.mjs';
|
|
3
3
|
import { execImmediateCommand, runStreamingCommand, } from '../../utils/index.mjs';
|
|
4
|
-
|
|
5
|
-
const tscCLICommandPath =
|
|
4
|
+
function getTscCLICommandPath() {
|
|
5
|
+
const tscCLICommandPath = resolveHostPackageBinForCLICommandPath('@mainset/dev-stack-fe', 'tsc');
|
|
6
6
|
return tscCLICommandPath;
|
|
7
7
|
}
|
|
8
8
|
// Source code
|
|
9
|
-
|
|
10
|
-
const tscCLICommandPath =
|
|
9
|
+
function execImmediateTypeScriptCompileSourceCode({ configPath, }) {
|
|
10
|
+
const tscCLICommandPath = getTscCLICommandPath();
|
|
11
11
|
console.log('\n๐ฆ Compiling Source Code with TypeScript ...');
|
|
12
|
-
execImmediateCommand(
|
|
12
|
+
execImmediateCommand(`${tscCLICommandPath} --project ${configPath}`);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
const tscCLICommandPath =
|
|
14
|
+
function runStreamingTypeScriptCompileSourceCode({ configPath, }) {
|
|
15
|
+
const tscCLICommandPath = getTscCLICommandPath();
|
|
16
16
|
console.log('\n๐ Compiling .d.ts Types in watch mode ...');
|
|
17
|
-
runStreamingCommand('
|
|
18
|
-
tscCLICommandPath,
|
|
19
|
-
'--project',
|
|
20
|
-
configPath,
|
|
21
|
-
'--watch',
|
|
22
|
-
]);
|
|
17
|
+
runStreamingCommand(tscCLICommandPath, ['--project', configPath, '--watch']);
|
|
23
18
|
}
|
|
24
19
|
// Type only
|
|
25
20
|
function getTypeScriptTypeOnlyConfigPath() {
|
|
@@ -28,21 +23,16 @@ function getTypeScriptTypeOnlyConfigPath() {
|
|
|
28
23
|
configPath: customTypeScriptTypeOnlyConfigPath,
|
|
29
24
|
};
|
|
30
25
|
}
|
|
31
|
-
|
|
26
|
+
function execImmediateTypeScriptCompileTypeOnly() {
|
|
32
27
|
const { configPath } = getTypeScriptTypeOnlyConfigPath();
|
|
33
|
-
const tscCLICommandPath =
|
|
28
|
+
const tscCLICommandPath = getTscCLICommandPath();
|
|
34
29
|
console.log('\n๐ Compiling .d.ts Types in build mode ...');
|
|
35
|
-
execImmediateCommand(
|
|
30
|
+
execImmediateCommand(`${tscCLICommandPath} --project ${configPath}`);
|
|
36
31
|
}
|
|
37
|
-
|
|
32
|
+
function runStreamingTypeScriptCompileTypeOnly() {
|
|
38
33
|
const { configPath } = getTypeScriptTypeOnlyConfigPath();
|
|
39
|
-
const tscCLICommandPath =
|
|
34
|
+
const tscCLICommandPath = getTscCLICommandPath();
|
|
40
35
|
console.log('\n๐ Compiling .d.ts Types in watch mode ...');
|
|
41
|
-
runStreamingCommand('
|
|
42
|
-
tscCLICommandPath,
|
|
43
|
-
'--project',
|
|
44
|
-
configPath,
|
|
45
|
-
'--watch',
|
|
46
|
-
]);
|
|
36
|
+
runStreamingCommand(tscCLICommandPath, ['--project', configPath, '--watch']);
|
|
47
37
|
}
|
|
48
|
-
export {
|
|
38
|
+
export { execImmediateTypeScriptCompileSourceCode, execImmediateTypeScriptCompileTypeOnly, runStreamingTypeScriptCompileSourceCode, runStreamingTypeScriptCompileTypeOnly, };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { runtimePathById } from '../runtime/index.mjs';
|
|
3
3
|
import { consoleColorize, initProcessCatchErrorLogger, } from '../utils/index.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { execImmediatePurgeDist, execImmediateTypeScriptCompileSourceCode, execImmediateTypeScriptCompileTypeOnly, runStreamingTypeScriptCompileSourceCode, runStreamingTypeScriptCompileTypeOnly, } from './process-runner-chunks/index.mjs';
|
|
5
5
|
function registerSourceCodeCommand(program) {
|
|
6
6
|
program
|
|
7
7
|
.command('source-code')
|
|
@@ -9,7 +9,7 @@ function registerSourceCodeCommand(program) {
|
|
|
9
9
|
.requiredOption('-e, --exec <type>', 'Execution mode: compile or watch')
|
|
10
10
|
// .option('-b, --builder <builder>', 'Compiler tool (default: tsc)', 'tsc')
|
|
11
11
|
.option('-c, --config <path>', 'Path to config file', './tsconfig.json')
|
|
12
|
-
.action(
|
|
12
|
+
.action((options) => {
|
|
13
13
|
// Step 0: determinate command params
|
|
14
14
|
const typeScriptSourceCodeConfigPath = path.join(runtimePathById.root, options.config);
|
|
15
15
|
if (options.exec === 'compile') {
|
|
@@ -17,13 +17,13 @@ function registerSourceCodeCommand(program) {
|
|
|
17
17
|
console.log('\n๐๏ธ [mainset cli] source-code: compile');
|
|
18
18
|
try {
|
|
19
19
|
// Step 1: purge dist folder
|
|
20
|
-
|
|
20
|
+
execImmediatePurgeDist();
|
|
21
21
|
// Step 2: compile source code
|
|
22
|
-
|
|
22
|
+
execImmediateTypeScriptCompileSourceCode({
|
|
23
23
|
configPath: typeScriptSourceCodeConfigPath,
|
|
24
24
|
});
|
|
25
25
|
// Step 3: compile type only
|
|
26
|
-
|
|
26
|
+
execImmediateTypeScriptCompileTypeOnly();
|
|
27
27
|
console.log('\nโ
Build completed successfully\n');
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
@@ -35,13 +35,13 @@ function registerSourceCodeCommand(program) {
|
|
|
35
35
|
console.log('\n๐๏ธ [mainset cli] source-code: watch');
|
|
36
36
|
try {
|
|
37
37
|
// Step 1: purge dist folder
|
|
38
|
-
|
|
38
|
+
execImmediatePurgeDist();
|
|
39
39
|
// Step 2: watch source code
|
|
40
|
-
|
|
40
|
+
runStreamingTypeScriptCompileSourceCode({
|
|
41
41
|
configPath: typeScriptSourceCodeConfigPath,
|
|
42
42
|
});
|
|
43
43
|
// Step 3: watch type only
|
|
44
|
-
|
|
44
|
+
runStreamingTypeScriptCompileTypeOnly();
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
47
|
initProcessCatchErrorLogger('source-code', error, 'watch');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { resolveHostPackageBinForCLICommandPath, runtimePathById, } from '../runtime/index.mjs';
|
|
4
|
-
import { consoleColorize, execImmediateCommand, initProcessCatchErrorLogger, runStreamingCommand, } from '../utils/index.mjs';
|
|
5
|
-
import {
|
|
4
|
+
import { consoleColorize, execImmediateCommand, initProcessCatchErrorLogger, runStreamingCommand, runStreamingInSync, } from '../utils/index.mjs';
|
|
5
|
+
import { execImmediatePurgeDist } from './process-runner-chunks/index.mjs';
|
|
6
6
|
function registerWebAppCommand(program) {
|
|
7
7
|
program
|
|
8
8
|
.command('web-app')
|
|
@@ -15,15 +15,25 @@ function registerWebAppCommand(program) {
|
|
|
15
15
|
// )
|
|
16
16
|
.option('-c, --config <path>', 'Path to config file')
|
|
17
17
|
.option('--serveMode <mode>', 'Serve mode: ssr or csr (default: ssr)', 'ssr')
|
|
18
|
-
.action(
|
|
18
|
+
.action((options) => {
|
|
19
19
|
// Step 0: determinate command params
|
|
20
20
|
const customWebpackConfigPath = path.resolve(runtimePathById.root, options.config || './config/webpack.config.mjs');
|
|
21
|
+
// SSR server path
|
|
22
|
+
const ssrServerEntryPath = path.resolve(runtimePathById.msCLISrc, '../services/ssr-server/ssr-server.mjs');
|
|
23
|
+
const ssrServerConfigCompiledPath = path.resolve(runtimePathById.dist, './private/ssr-server.config.mjs');
|
|
21
24
|
// Webpack paths
|
|
22
|
-
const webpackCLICommandPath =
|
|
25
|
+
const webpackCLICommandPath = resolveHostPackageBinForCLICommandPath('@mainset/bundler-webpack', 'webpack');
|
|
23
26
|
const webpackSSRConfigPath = fs.existsSync(customWebpackConfigPath)
|
|
24
27
|
? customWebpackConfigPath
|
|
25
28
|
: path.resolve(runtimePathById.root, 'node_modules', '@mainset/bundler-webpack/dist/esm/webpack-config/webapp.ssr.config.mjs');
|
|
26
|
-
|
|
29
|
+
/*
|
|
30
|
+
// Rslib paths
|
|
31
|
+
const rslibSSRConfigPath = path.resolve(
|
|
32
|
+
runtimePathById.root,
|
|
33
|
+
'node_modules',
|
|
34
|
+
'@mainset/builder-rslib/dist/esm/rslib.ssr-server.config.mjs',
|
|
35
|
+
);
|
|
36
|
+
*/
|
|
27
37
|
if (options.exec === 'build') {
|
|
28
38
|
// ========== Build mode ==========
|
|
29
39
|
console.log('\n๐๏ธ [mainset cli] web-app: build');
|
|
@@ -31,13 +41,15 @@ function registerWebAppCommand(program) {
|
|
|
31
41
|
if (options.serveMode === 'ssr') {
|
|
32
42
|
// ========== [Build] SSR mode ==========
|
|
33
43
|
// Step 1: purge dist folder
|
|
34
|
-
|
|
44
|
+
execImmediatePurgeDist();
|
|
35
45
|
// Step 2: build:ssr-webapp source code
|
|
36
46
|
console.log('\n๐ฆ Compiling SSR WebApp with Webpack ...');
|
|
37
|
-
execImmediateCommand(
|
|
47
|
+
execImmediateCommand(`${webpackCLICommandPath} --config ${webpackSSRConfigPath}`);
|
|
48
|
+
/*
|
|
38
49
|
// Step 3: build:ssr-server source code
|
|
39
50
|
console.log('\n๐ฆ Compiling SSR Server with Rslib ...');
|
|
40
|
-
|
|
51
|
+
execImmediateRslibCLICommand(`build --config ${rslibSSRConfigPath}`);
|
|
52
|
+
*/
|
|
41
53
|
console.log('\nโ
SSR Build completed successfully\n');
|
|
42
54
|
}
|
|
43
55
|
else {
|
|
@@ -46,10 +58,10 @@ function registerWebAppCommand(program) {
|
|
|
46
58
|
? customWebpackConfigPath
|
|
47
59
|
: path.resolve(runtimePathById.root, 'node_modules', '@mainset/bundler-webpack/dist/esm/webpack-config/webapp.csr.config.mjs');
|
|
48
60
|
// Step 1: purge dist folder
|
|
49
|
-
|
|
61
|
+
execImmediatePurgeDist();
|
|
50
62
|
// Step 2: build:csr-webapp source code
|
|
51
63
|
console.log('\n๐ฆ Compiling CSR WebApp with Webpack ...');
|
|
52
|
-
execImmediateCommand(
|
|
64
|
+
execImmediateCommand(`${webpackCLICommandPath} --config ${webpackCSRConfigPath}`);
|
|
53
65
|
console.log('\nโ
CSR Build completed successfully\n');
|
|
54
66
|
}
|
|
55
67
|
}
|
|
@@ -63,39 +75,45 @@ function registerWebAppCommand(program) {
|
|
|
63
75
|
try {
|
|
64
76
|
if (options.serveMode === 'ssr') {
|
|
65
77
|
// ========== [Serve] SSR mode ==========
|
|
66
|
-
|
|
67
|
-
const ssrServerConfigCompiledPath = path.resolve(runtimePathById.dist, './private/ssr-server.config.mjs');
|
|
78
|
+
/*
|
|
68
79
|
// Step 1: watch:ssr-server start ssr server
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
runStreamingRslibCLICommand([
|
|
81
|
+
'build',
|
|
82
|
+
'--config',
|
|
83
|
+
rslibSSRConfigPath,
|
|
84
|
+
'--watch',
|
|
74
85
|
]);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
*/
|
|
87
|
+
// NOTE: node SSR server requires webpack to compile web app files first
|
|
88
|
+
runStreamingInSync([
|
|
89
|
+
// Step 2: watch:ssr-webapp source code of web app
|
|
90
|
+
{
|
|
91
|
+
runCommand: () => runStreamingCommand(webpackCLICommandPath, [
|
|
92
|
+
'--config',
|
|
93
|
+
webpackSSRConfigPath,
|
|
94
|
+
'--watch',
|
|
95
|
+
]),
|
|
96
|
+
waitForOutput: 'compiled successfully',
|
|
97
|
+
},
|
|
98
|
+
// Step 3: start:ssr-server which is compiled web app and ssr-server code
|
|
99
|
+
{
|
|
100
|
+
runCommand: () => runStreamingCommand('node', [
|
|
101
|
+
'--watch', // Enable watch mode for {node}
|
|
102
|
+
ssrServerEntryPath,
|
|
103
|
+
'--ssrServerConfig',
|
|
104
|
+
ssrServerConfigCompiledPath,
|
|
105
|
+
]),
|
|
106
|
+
},
|
|
88
107
|
]);
|
|
89
108
|
}
|
|
90
109
|
else {
|
|
91
110
|
// ========== [Serve] CSR mode ==========
|
|
92
|
-
const webpackDevServerCLICommandPath = await resolveHostPackageBinForCLICommandPath('@mainset/bundler-webpack', 'webpack-dev-server');
|
|
93
111
|
const webpackDevServerConfigPath = fs.existsSync(customWebpackConfigPath)
|
|
94
112
|
? customWebpackConfigPath
|
|
95
113
|
: path.resolve(runtimePathById.root, 'node_modules', '@mainset/bundler-webpack/dist/esm/webpack-config/dev-server.csr.config.mjs');
|
|
96
114
|
// Step 1: watch:csr-server / start:csr-server source code
|
|
97
|
-
runStreamingCommand(
|
|
98
|
-
|
|
115
|
+
runStreamingCommand(webpackCLICommandPath, [
|
|
116
|
+
'serve',
|
|
99
117
|
'--config',
|
|
100
118
|
webpackDevServerConfigPath,
|
|
101
119
|
'--open',
|
|
@@ -110,18 +128,31 @@ function registerWebAppCommand(program) {
|
|
|
110
128
|
// ========== Serve static mode ==========
|
|
111
129
|
console.log('\n๐๏ธ [mainset cli] web-app: serve-static');
|
|
112
130
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
if (options.serveMode === 'ssr') {
|
|
132
|
+
// ========== [Serve Static] SSR mode ==========
|
|
133
|
+
// Step 1: start:ssr-server which is compiled web app and ssr-server code
|
|
134
|
+
runStreamingCommand('node', [
|
|
135
|
+
'--watch', // Enable watch mode for {node}
|
|
136
|
+
ssrServerEntryPath,
|
|
137
|
+
'--ssrServerConfig',
|
|
138
|
+
ssrServerConfigCompiledPath,
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// ========== [Serve Static] CSR mode ==========
|
|
143
|
+
// Step 1: determinate command params
|
|
144
|
+
const serverEntryPath = path.resolve(runtimePathById.msCLISrc, '../services/serve-static/serve-static.mjs');
|
|
145
|
+
const customServeStaticConfigPath = path.resolve(runtimePathById.root, options.config || './config/serve-static.config.json');
|
|
146
|
+
const serveStaticConfigPath = fs.existsSync(customServeStaticConfigPath)
|
|
147
|
+
? customServeStaticConfigPath
|
|
148
|
+
: path.resolve(runtimePathById.msCLISrc, '../services/express-base-app/express-base-app.config.json');
|
|
149
|
+
// Step 2: serve static compiled files
|
|
150
|
+
runStreamingCommand('node', [
|
|
151
|
+
serverEntryPath,
|
|
152
|
+
'--serveStaticConfig',
|
|
153
|
+
serveStaticConfigPath,
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
125
156
|
}
|
|
126
157
|
catch (error) {
|
|
127
158
|
initProcessCatchErrorLogger('web-app', error, 'serve-static');
|
|
@@ -3,18 +3,41 @@ import path from 'path';
|
|
|
3
3
|
import { runtimePathById } from './path.mjs';
|
|
4
4
|
function resolveHostPackageNodeModulesPath(hostPackageName, dependencyPackageName) {
|
|
5
5
|
const hostPackageNodeModulesPath = path.resolve(runtimePathById.root, `node_modules/${hostPackageName}/node_modules`);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const hostPackageDependencyPackagePath = path.join(hostPackageNodeModulesPath, dependencyPackageName);
|
|
7
|
+
const isNodeModulesLinkedOrWorkspace = fs.existsSync(hostPackageDependencyPackagePath);
|
|
8
|
+
// If the package is linked or part of a workspace, return the full path
|
|
9
|
+
// Otherwise, return just the package name (for packages installed from the registry)
|
|
10
|
+
return isNodeModulesLinkedOrWorkspace
|
|
11
|
+
? hostPackageDependencyPackagePath
|
|
12
|
+
: dependencyPackageName;
|
|
10
13
|
}
|
|
11
|
-
|
|
14
|
+
function resolveHostPackageBinForCLICommandPath(hostPackageName,
|
|
15
|
+
// dependencyPackageName: string,
|
|
16
|
+
cliCommandName) {
|
|
17
|
+
/* Previous implementation
|
|
12
18
|
// Pnpm node_modules structure
|
|
13
|
-
const dependencyPackageNodeModulesPath = resolveHostPackageNodeModulesPath(
|
|
14
|
-
|
|
19
|
+
const dependencyPackageNodeModulesPath = resolveHostPackageNodeModulesPath(
|
|
20
|
+
hostPackageName,
|
|
21
|
+
dependencyPackageName,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const packageJson = await import(
|
|
25
|
+
path.join(dependencyPackageNodeModulesPath, 'package.json'),
|
|
26
|
+
{ with: { type: 'json' } }
|
|
27
|
+
);
|
|
28
|
+
|
|
15
29
|
const binPath = cliCommandName
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
? packageJson.default.bin[cliCommandName]
|
|
31
|
+
: packageJson.default.bin;
|
|
32
|
+
|
|
18
33
|
return path.join(dependencyPackageNodeModulesPath, binPath);
|
|
34
|
+
*/
|
|
35
|
+
// installed from the registry
|
|
36
|
+
const dependencyPackageNodeModulesPath = path.resolve(runtimePathById.root, `node_modules/.bin/${cliCommandName}`);
|
|
37
|
+
// linked / workspace:^ package
|
|
38
|
+
const dependencyWorkspacePackageNodeModulesPath = path.resolve(runtimePathById.root, `node_modules/${hostPackageName}/node_modules/.bin/${cliCommandName}`);
|
|
39
|
+
return fs.existsSync(dependencyPackageNodeModulesPath)
|
|
40
|
+
? dependencyPackageNodeModulesPath
|
|
41
|
+
: dependencyWorkspacePackageNodeModulesPath;
|
|
19
42
|
}
|
|
20
43
|
export { resolveHostPackageBinForCLICommandPath, resolveHostPackageNodeModulesPath, };
|
|
@@ -27,7 +27,7 @@ class ExpressBaseApp {
|
|
|
27
27
|
// app.use('/api-boilerplate', createProxyMiddleware(proxyConfig['/api-boilerplate/']));
|
|
28
28
|
// }
|
|
29
29
|
// ========== Public ==========
|
|
30
|
-
|
|
30
|
+
startListening() {
|
|
31
31
|
this.app.listen(this.listenPort, async () => {
|
|
32
32
|
var _a;
|
|
33
33
|
const packageJson = await import(path.resolve(runtimePathById.root, 'package.json'), { with: { type: 'json' } });
|
|
@@ -48,9 +48,45 @@ function runStreamingCommand(command, args) {
|
|
|
48
48
|
// 2. rm -rf ./node_modules
|
|
49
49
|
processManager.trackProcess(child);
|
|
50
50
|
child.on('exit', (code) => process.exit(code !== null && code !== void 0 ? code : 1));
|
|
51
|
+
// NOTE: return isn't required, but it uses in combination with {runStreamingInSync} func
|
|
52
|
+
return child;
|
|
51
53
|
}
|
|
52
54
|
catch (error) {
|
|
53
55
|
initProcessCatchErrorLogger('runStreamingCommand', error);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Runs a streaming command in sync mode.
|
|
60
|
+
* This is a placeholder function and does not execute any command.
|
|
61
|
+
* It is used to maintain compatibility with the existing code structure.
|
|
62
|
+
*
|
|
63
|
+
* Example: runStreamingInSync([{ runCommand: () => runStreamingCommand(), waitForOutput: 'compiled successfully' }]);
|
|
64
|
+
*/
|
|
65
|
+
async function runStreamingInSync(streamings) {
|
|
66
|
+
for (const streaming of streamings) {
|
|
67
|
+
// eslint-disable-next-line no-await-in-loop
|
|
68
|
+
await new Promise((resolve, reject) => {
|
|
69
|
+
const child = streaming.runCommand();
|
|
70
|
+
if (!child) {
|
|
71
|
+
reject(new Error('[mainset cli][runStreamingInSync] Previous command failed, aborting sequence.'));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (streaming.waitForOutput && child.stdout) {
|
|
75
|
+
child.stdout.on('data', (data) => {
|
|
76
|
+
const text = data.toString();
|
|
77
|
+
if (text.includes(streaming.waitForOutput)) {
|
|
78
|
+
resolve();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
resolve();
|
|
84
|
+
}
|
|
85
|
+
child.on('error', reject);
|
|
86
|
+
}).catch((err) => {
|
|
87
|
+
// Stop further execution if a command fails
|
|
88
|
+
throw err;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export { execImmediateCommand, initProcessCatchErrorLogger, runStreamingCommand, runStreamingInSync, };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function
|
|
2
|
-
declare function
|
|
3
|
-
export {
|
|
1
|
+
declare function execImmediateRslibCLICommand(command: string): void;
|
|
2
|
+
declare function runStreamingRslibCLICommand(commandParams: string[]): import("child_process").ChildProcess | undefined;
|
|
3
|
+
export { execImmediateRslibCLICommand, runStreamingRslibCLICommand };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function
|
|
2
|
-
export {
|
|
1
|
+
declare function execImmediatePurgeDist(): void;
|
|
2
|
+
export { execImmediatePurgeDist };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
declare function
|
|
1
|
+
declare function execImmediateTypeScriptCompileSourceCode({ configPath, }: {
|
|
2
2
|
configPath: string;
|
|
3
|
-
}):
|
|
4
|
-
declare function
|
|
3
|
+
}): void;
|
|
4
|
+
declare function runStreamingTypeScriptCompileSourceCode({ configPath, }: {
|
|
5
5
|
configPath: string;
|
|
6
|
-
}):
|
|
7
|
-
declare function
|
|
8
|
-
declare function
|
|
9
|
-
export {
|
|
6
|
+
}): void;
|
|
7
|
+
declare function execImmediateTypeScriptCompileTypeOnly(): void;
|
|
8
|
+
declare function runStreamingTypeScriptCompileTypeOnly(): void;
|
|
9
|
+
export { execImmediateTypeScriptCompileSourceCode, execImmediateTypeScriptCompileTypeOnly, runStreamingTypeScriptCompileSourceCode, runStreamingTypeScriptCompileTypeOnly, };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
declare function resolveHostPackageNodeModulesPath(hostPackageName: string, dependencyPackageName: string): string;
|
|
2
|
-
declare function resolveHostPackageBinForCLICommandPath(hostPackageName: string,
|
|
2
|
+
declare function resolveHostPackageBinForCLICommandPath(hostPackageName: string, cliCommandName: string): string;
|
|
3
3
|
export { resolveHostPackageBinForCLICommandPath, resolveHostPackageNodeModulesPath, };
|
|
@@ -12,7 +12,7 @@ declare class ExpressBaseApp {
|
|
|
12
12
|
readonly app: Express;
|
|
13
13
|
constructor(customExpressConfig?: Partial<ExpressBaseAppConfig>);
|
|
14
14
|
private appUseStatic;
|
|
15
|
-
startListening():
|
|
15
|
+
startListening(): void;
|
|
16
16
|
}
|
|
17
17
|
export { ExpressBaseApp };
|
|
18
18
|
export type { ExpressBaseAppConfig };
|
|
@@ -12,5 +12,16 @@ declare function execImmediateCommand(fullCommandString: string): void;
|
|
|
12
12
|
*
|
|
13
13
|
* Example: runStreamingCommand('rspack', ['serve', '--config', './config/rspack.config.ts']);
|
|
14
14
|
*/
|
|
15
|
-
declare function runStreamingCommand(command: string, args: string[]):
|
|
16
|
-
|
|
15
|
+
declare function runStreamingCommand(command: string, args: string[]): import("child_process").ChildProcess | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Runs a streaming command in sync mode.
|
|
18
|
+
* This is a placeholder function and does not execute any command.
|
|
19
|
+
* It is used to maintain compatibility with the existing code structure.
|
|
20
|
+
*
|
|
21
|
+
* Example: runStreamingInSync([{ runCommand: () => runStreamingCommand(), waitForOutput: 'compiled successfully' }]);
|
|
22
|
+
*/
|
|
23
|
+
declare function runStreamingInSync(streamings: {
|
|
24
|
+
runCommand: () => ReturnType<typeof runStreamingCommand>;
|
|
25
|
+
waitForOutput?: string;
|
|
26
|
+
}[]): Promise<void>;
|
|
27
|
+
export { execImmediateCommand, initProcessCatchErrorLogger, runStreamingCommand, runStreamingInSync, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainset/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc.1",
|
|
4
4
|
"description": "A unified CLI tool for accelerating development, based on mainset vision of front-end infrastructure",
|
|
5
5
|
"homepage": "https://github.com/mainset/dev-stack-fe/tree/main/packages/cli",
|
|
6
6
|
"bugs": {
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@types/cors": "^2.8.19",
|
|
43
43
|
"@types/express": "^5.0.3",
|
|
44
44
|
"@types/node": "^24.0.3",
|
|
45
|
-
"@mainset/dev-stack-fe": "^0.1.
|
|
45
|
+
"@mainset/dev-stack-fe": "^0.1.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@mainset/dev-stack-fe": "0.1.
|
|
48
|
+
"@mainset/dev-stack-fe": "^0.1.1"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build:source": "node ./node_modules/@mainset/dev-stack-fe/node_modules/typescript/bin/tsc --project ./tsconfig.json",
|