@mainset/cli 0.1.1 โ†’ 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.
@@ -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 { execPurgeDist, execRslibCLICommand, execTypeScriptCompileTypeOnly, runRslibCLICommand, runTypeScriptCompileTypeOnly, } from './process-runner-chunks/index.mjs';
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')
@@ -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
- execPurgeDist();
26
+ execImmediatePurgeDist();
27
27
  // Step 2: build source code
28
28
  console.log('\n๐Ÿ“ฆ Compiling Source Code with Rslib ...');
29
- execRslibCLICommand(`build --config ${rslibConfigPath}`);
29
+ execImmediateRslibCLICommand(`build --config ${rslibConfigPath}`);
30
30
  // Step 3: build type only
31
- execTypeScriptCompileTypeOnly();
31
+ execImmediateTypeScriptCompileTypeOnly();
32
32
  console.log('\nโœ… Build completed successfully\n');
33
33
  }
34
34
  catch (error) {
@@ -40,11 +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
- execPurgeDist();
43
+ execImmediatePurgeDist();
44
44
  // Step 2: watch source code
45
- runRslibCLICommand(['build', '--config', rslibConfigPath, '--watch']);
45
+ runStreamingRslibCLICommand([
46
+ 'build',
47
+ '--config',
48
+ rslibConfigPath,
49
+ '--watch',
50
+ ]);
46
51
  // Step 3: watch type only
47
- runTypeScriptCompileTypeOnly();
52
+ runStreamingTypeScriptCompileTypeOnly();
48
53
  }
49
54
  catch (error) {
50
55
  initProcessCatchErrorLogger('node-package', error, 'watch');
@@ -4,12 +4,12 @@ function getRslibCLICommandPath() {
4
4
  const rslibCLICommandPath = resolveHostPackageBinForCLICommandPath('@mainset/builder-rslib', 'rslib');
5
5
  return rslibCLICommandPath;
6
6
  }
7
- function execRslibCLICommand(command) {
7
+ function execImmediateRslibCLICommand(command) {
8
8
  const rslibCLICommandPath = getRslibCLICommandPath();
9
9
  return execImmediateCommand(`${rslibCLICommandPath} ${command}`);
10
10
  }
11
- function runRslibCLICommand(commandParams) {
11
+ function runStreamingRslibCLICommand(commandParams) {
12
12
  const rslibCLICommandPath = getRslibCLICommandPath();
13
13
  return runStreamingCommand(rslibCLICommandPath, [...commandParams]);
14
14
  }
15
- export { execRslibCLICommand, runRslibCLICommand };
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 execPurgeDist() {
4
+ function execImmediatePurgeDist() {
5
5
  console.log('๐Ÿงน Cleaning dist folder ...');
6
6
  execImmediateCommand(`rm -rf ${runtimePathById.dist}`);
7
7
  }
8
- export { execPurgeDist };
8
+ export { execImmediatePurgeDist };
@@ -6,12 +6,12 @@ function getTscCLICommandPath() {
6
6
  return tscCLICommandPath;
7
7
  }
8
8
  // Source code
9
- function execTypeScriptCompileSourceCode({ configPath, }) {
9
+ function execImmediateTypeScriptCompileSourceCode({ configPath, }) {
10
10
  const tscCLICommandPath = getTscCLICommandPath();
11
11
  console.log('\n๐Ÿ“ฆ Compiling Source Code with TypeScript ...');
12
12
  execImmediateCommand(`${tscCLICommandPath} --project ${configPath}`);
13
13
  }
14
- function runTypeScriptCompileSourceCode({ configPath, }) {
14
+ function runStreamingTypeScriptCompileSourceCode({ configPath, }) {
15
15
  const tscCLICommandPath = getTscCLICommandPath();
16
16
  console.log('\n๐Ÿ“ Compiling .d.ts Types in watch mode ...');
17
17
  runStreamingCommand(tscCLICommandPath, ['--project', configPath, '--watch']);
@@ -23,16 +23,16 @@ function getTypeScriptTypeOnlyConfigPath() {
23
23
  configPath: customTypeScriptTypeOnlyConfigPath,
24
24
  };
25
25
  }
26
- function execTypeScriptCompileTypeOnly() {
26
+ function execImmediateTypeScriptCompileTypeOnly() {
27
27
  const { configPath } = getTypeScriptTypeOnlyConfigPath();
28
28
  const tscCLICommandPath = getTscCLICommandPath();
29
29
  console.log('\n๐Ÿ“ Compiling .d.ts Types in build mode ...');
30
30
  execImmediateCommand(`${tscCLICommandPath} --project ${configPath}`);
31
31
  }
32
- function runTypeScriptCompileTypeOnly() {
32
+ function runStreamingTypeScriptCompileTypeOnly() {
33
33
  const { configPath } = getTypeScriptTypeOnlyConfigPath();
34
34
  const tscCLICommandPath = getTscCLICommandPath();
35
35
  console.log('\n๐Ÿ“ Compiling .d.ts Types in watch mode ...');
36
36
  runStreamingCommand(tscCLICommandPath, ['--project', configPath, '--watch']);
37
37
  }
38
- export { execTypeScriptCompileSourceCode, execTypeScriptCompileTypeOnly, runTypeScriptCompileSourceCode, runTypeScriptCompileTypeOnly, };
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 { execPurgeDist, execTypeScriptCompileSourceCode, execTypeScriptCompileTypeOnly, runTypeScriptCompileSourceCode, runTypeScriptCompileTypeOnly, } from './process-runner-chunks/index.mjs';
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')
@@ -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
- execPurgeDist();
20
+ execImmediatePurgeDist();
21
21
  // Step 2: compile source code
22
- execTypeScriptCompileSourceCode({
22
+ execImmediateTypeScriptCompileSourceCode({
23
23
  configPath: typeScriptSourceCodeConfigPath,
24
24
  });
25
25
  // Step 3: compile type only
26
- execTypeScriptCompileTypeOnly();
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
- execPurgeDist();
38
+ execImmediatePurgeDist();
39
39
  // Step 2: watch source code
40
- runTypeScriptCompileSourceCode({
40
+ runStreamingTypeScriptCompileSourceCode({
41
41
  configPath: typeScriptSourceCodeConfigPath,
42
42
  });
43
43
  // Step 3: watch type only
44
- runTypeScriptCompileTypeOnly();
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 { execPurgeDist, execRslibCLICommand, runRslibCLICommand, } from './process-runner-chunks/index.mjs';
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')
@@ -18,12 +18,22 @@ function registerWebAppCommand(program) {
18
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
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
- const rslibSSRConfigPath = path.resolve(runtimePathById.root, 'node_modules', '@mainset/builder-rslib/dist/esm/rslib.ssr-server.config.mjs');
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
- execPurgeDist();
44
+ execImmediatePurgeDist();
35
45
  // Step 2: build:ssr-webapp source code
36
46
  console.log('\n๐Ÿ“ฆ Compiling SSR WebApp with Webpack ...');
37
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
- execRslibCLICommand(`build --config ${rslibSSRConfigPath}`);
51
+ execImmediateRslibCLICommand(`build --config ${rslibSSRConfigPath}`);
52
+ */
41
53
  console.log('\nโœ… SSR Build completed successfully\n');
42
54
  }
43
55
  else {
@@ -46,7 +58,7 @@ 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
- execPurgeDist();
61
+ execImmediatePurgeDist();
50
62
  // Step 2: build:csr-webapp source code
51
63
  console.log('\n๐Ÿ“ฆ Compiling CSR WebApp with Webpack ...');
52
64
  execImmediateCommand(`${webpackCLICommandPath} --config ${webpackCSRConfigPath}`);
@@ -63,27 +75,35 @@ function registerWebAppCommand(program) {
63
75
  try {
64
76
  if (options.serveMode === 'ssr') {
65
77
  // ========== [Serve] SSR mode ==========
66
- const ssrServerEntryPath = path.resolve(runtimePathById.msCLISrc, '../services/ssr-server/ssr-server.mjs');
67
- const ssrServerConfigCompiledPath = path.resolve(runtimePathById.dist, './private/ssr-server.config.mjs');
78
+ /*
68
79
  // Step 1: watch:ssr-server start ssr server
69
- runRslibCLICommand([
70
- 'build',
71
- '--config',
72
- rslibSSRConfigPath,
73
- '--watch',
80
+ runStreamingRslibCLICommand([
81
+ 'build',
82
+ '--config',
83
+ rslibSSRConfigPath,
84
+ '--watch',
74
85
  ]);
75
- // Step 2: watch:ssr-webapp source code of web app
76
- runStreamingCommand(webpackCLICommandPath, [
77
- '--config',
78
- webpackSSRConfigPath,
79
- '--watch',
80
- ]);
81
- // Step 3: start:ssr-server which is compiled web app and ssr-server code
82
- runStreamingCommand('node', [
83
- '--watch', // Enable watch mode for {node}
84
- ssrServerEntryPath,
85
- '--ssrServerConfig',
86
- ssrServerConfigCompiledPath,
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
+ },
87
107
  ]);
88
108
  }
89
109
  else {
@@ -108,18 +128,31 @@ function registerWebAppCommand(program) {
108
128
  // ========== Serve static mode ==========
109
129
  console.log('\n๐Ÿ—๏ธ [mainset cli] web-app: serve-static');
110
130
  try {
111
- // Step 1: determinate command params
112
- const serverEntryPath = path.resolve(runtimePathById.msCLISrc, '../services/serve-static/serve-static.mjs');
113
- const customServeStaticConfigPath = path.resolve(runtimePathById.root, options.config || './config/serve-static.config.json');
114
- const serveStaticConfigPath = fs.existsSync(customServeStaticConfigPath)
115
- ? customServeStaticConfigPath
116
- : path.resolve(runtimePathById.msCLISrc, '../services/express-base-app/express-base-app.config.json');
117
- // Step 2: serve static compiled files
118
- runStreamingCommand('node', [
119
- serverEntryPath,
120
- '--serveStaticConfig',
121
- serveStaticConfigPath,
122
- ]);
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
+ }
123
156
  }
124
157
  catch (error) {
125
158
  initProcessCatchErrorLogger('web-app', error, 'serve-static');
@@ -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
- export { execImmediateCommand, initProcessCatchErrorLogger, runStreamingCommand, };
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 execRslibCLICommand(command: string): void;
2
- declare function runRslibCLICommand(commandParams: string[]): void;
3
- export { execRslibCLICommand, runRslibCLICommand };
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 execPurgeDist(): void;
2
- export { execPurgeDist };
1
+ declare function execImmediatePurgeDist(): void;
2
+ export { execImmediatePurgeDist };
@@ -1,9 +1,9 @@
1
- declare function execTypeScriptCompileSourceCode({ configPath, }: {
1
+ declare function execImmediateTypeScriptCompileSourceCode({ configPath, }: {
2
2
  configPath: string;
3
3
  }): void;
4
- declare function runTypeScriptCompileSourceCode({ configPath, }: {
4
+ declare function runStreamingTypeScriptCompileSourceCode({ configPath, }: {
5
5
  configPath: string;
6
6
  }): void;
7
- declare function execTypeScriptCompileTypeOnly(): void;
8
- declare function runTypeScriptCompileTypeOnly(): void;
9
- export { execTypeScriptCompileSourceCode, execTypeScriptCompileTypeOnly, runTypeScriptCompileSourceCode, runTypeScriptCompileTypeOnly, };
7
+ declare function execImmediateTypeScriptCompileTypeOnly(): void;
8
+ declare function runStreamingTypeScriptCompileTypeOnly(): void;
9
+ export { execImmediateTypeScriptCompileSourceCode, execImmediateTypeScriptCompileTypeOnly, runStreamingTypeScriptCompileSourceCode, runStreamingTypeScriptCompileTypeOnly, };
@@ -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[]): void;
16
- export { execImmediateCommand, initProcessCatchErrorLogger, runStreamingCommand, };
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.1.1",
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": {