@mainset/cli 0.1.0 → 0.1.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.
@@ -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(async (options) => {
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)
@@ -26,9 +26,9 @@ function registerNodePackageCommand(program) {
26
26
  execPurgeDist();
27
27
  // Step 2: build source code
28
28
  console.log('\nšŸ“¦ Compiling Source Code with Rslib ...');
29
- await execRslibCLICommand(`build --config ${rslibConfigPath}`);
29
+ execRslibCLICommand(`build --config ${rslibConfigPath}`);
30
30
  // Step 3: build type only
31
- await execTypeScriptCompileTypeOnly();
31
+ execTypeScriptCompileTypeOnly();
32
32
  console.log('\nāœ… Build completed successfully\n');
33
33
  }
34
34
  catch (error) {
@@ -42,14 +42,9 @@ function registerNodePackageCommand(program) {
42
42
  // Step 1: purge dist folder
43
43
  execPurgeDist();
44
44
  // Step 2: watch source code
45
- await runRslibCLICommand([
46
- 'build',
47
- '--config',
48
- rslibConfigPath,
49
- '--watch',
50
- ]);
45
+ runRslibCLICommand(['build', '--config', rslibConfigPath, '--watch']);
51
46
  // Step 3: watch type only
52
- await runTypeScriptCompileTypeOnly();
47
+ runTypeScriptCompileTypeOnly();
53
48
  }
54
49
  catch (error) {
55
50
  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
- async function getRslibCLICommandPath() {
4
- const rslibCLICommandPath = await resolveHostPackageBinForCLICommandPath('@mainset/builder-rslib', '@rslib/core', 'rslib');
3
+ function getRslibCLICommandPath() {
4
+ const rslibCLICommandPath = resolveHostPackageBinForCLICommandPath('@mainset/builder-rslib', 'rslib');
5
5
  return rslibCLICommandPath;
6
6
  }
7
- async function execRslibCLICommand(command) {
8
- const rslibCLICommandPath = await getRslibCLICommandPath();
9
- return execImmediateCommand(`node ${rslibCLICommandPath} ${command}`);
7
+ function execRslibCLICommand(command) {
8
+ const rslibCLICommandPath = getRslibCLICommandPath();
9
+ return execImmediateCommand(`${rslibCLICommandPath} ${command}`);
10
10
  }
11
- async function runRslibCLICommand(commandParams) {
12
- const rslibCLICommandPath = await getRslibCLICommandPath();
13
- return runStreamingCommand('node', [rslibCLICommandPath, ...commandParams]);
11
+ function runRslibCLICommand(commandParams) {
12
+ const rslibCLICommandPath = getRslibCLICommandPath();
13
+ return runStreamingCommand(rslibCLICommandPath, [...commandParams]);
14
14
  }
15
15
  export { execRslibCLICommand, runRslibCLICommand };
@@ -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
- async function getTscCLICommandPath() {
5
- const tscCLICommandPath = await resolveHostPackageBinForCLICommandPath('@mainset/dev-stack-fe', 'typescript', 'tsc');
4
+ function getTscCLICommandPath() {
5
+ const tscCLICommandPath = resolveHostPackageBinForCLICommandPath('@mainset/dev-stack-fe', 'tsc');
6
6
  return tscCLICommandPath;
7
7
  }
8
8
  // Source code
9
- async function execTypeScriptCompileSourceCode({ configPath, }) {
10
- const tscCLICommandPath = await getTscCLICommandPath();
9
+ function execTypeScriptCompileSourceCode({ configPath, }) {
10
+ const tscCLICommandPath = getTscCLICommandPath();
11
11
  console.log('\nšŸ“¦ Compiling Source Code with TypeScript ...');
12
- execImmediateCommand(`node ${tscCLICommandPath} --project ${configPath}`);
12
+ execImmediateCommand(`${tscCLICommandPath} --project ${configPath}`);
13
13
  }
14
- async function runTypeScriptCompileSourceCode({ configPath, }) {
15
- const tscCLICommandPath = await getTscCLICommandPath();
14
+ function runTypeScriptCompileSourceCode({ configPath, }) {
15
+ const tscCLICommandPath = getTscCLICommandPath();
16
16
  console.log('\nšŸ“ Compiling .d.ts Types in watch mode ...');
17
- runStreamingCommand('node', [
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
- async function execTypeScriptCompileTypeOnly() {
26
+ function execTypeScriptCompileTypeOnly() {
32
27
  const { configPath } = getTypeScriptTypeOnlyConfigPath();
33
- const tscCLICommandPath = await getTscCLICommandPath();
28
+ const tscCLICommandPath = getTscCLICommandPath();
34
29
  console.log('\nšŸ“ Compiling .d.ts Types in build mode ...');
35
- execImmediateCommand(`node ${tscCLICommandPath} --project ${configPath}`);
30
+ execImmediateCommand(`${tscCLICommandPath} --project ${configPath}`);
36
31
  }
37
- async function runTypeScriptCompileTypeOnly() {
32
+ function runTypeScriptCompileTypeOnly() {
38
33
  const { configPath } = getTypeScriptTypeOnlyConfigPath();
39
- const tscCLICommandPath = await getTscCLICommandPath();
34
+ const tscCLICommandPath = getTscCLICommandPath();
40
35
  console.log('\nšŸ“ Compiling .d.ts Types in watch mode ...');
41
- runStreamingCommand('node', [
42
- tscCLICommandPath,
43
- '--project',
44
- configPath,
45
- '--watch',
46
- ]);
36
+ runStreamingCommand(tscCLICommandPath, ['--project', configPath, '--watch']);
47
37
  }
48
38
  export { execTypeScriptCompileSourceCode, execTypeScriptCompileTypeOnly, runTypeScriptCompileSourceCode, runTypeScriptCompileTypeOnly, };
@@ -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(async (options) => {
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') {
@@ -19,11 +19,11 @@ function registerSourceCodeCommand(program) {
19
19
  // Step 1: purge dist folder
20
20
  execPurgeDist();
21
21
  // Step 2: compile source code
22
- await execTypeScriptCompileSourceCode({
22
+ execTypeScriptCompileSourceCode({
23
23
  configPath: typeScriptSourceCodeConfigPath,
24
24
  });
25
25
  // Step 3: compile type only
26
- await execTypeScriptCompileTypeOnly();
26
+ execTypeScriptCompileTypeOnly();
27
27
  console.log('\nāœ… Build completed successfully\n');
28
28
  }
29
29
  catch (error) {
@@ -37,11 +37,11 @@ function registerSourceCodeCommand(program) {
37
37
  // Step 1: purge dist folder
38
38
  execPurgeDist();
39
39
  // Step 2: watch source code
40
- await runTypeScriptCompileSourceCode({
40
+ runTypeScriptCompileSourceCode({
41
41
  configPath: typeScriptSourceCodeConfigPath,
42
42
  });
43
43
  // Step 3: watch type only
44
- await runTypeScriptCompileTypeOnly();
44
+ runTypeScriptCompileTypeOnly();
45
45
  }
46
46
  catch (error) {
47
47
  initProcessCatchErrorLogger('source-code', error, 'watch');
@@ -15,11 +15,11 @@ 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(async (options) => {
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
21
  // Webpack paths
22
- const webpackCLICommandPath = await resolveHostPackageBinForCLICommandPath('@mainset/bundler-webpack', 'webpack', 'webpack');
22
+ const webpackCLICommandPath = resolveHostPackageBinForCLICommandPath('@mainset/bundler-webpack', 'webpack');
23
23
  const webpackSSRConfigPath = fs.existsSync(customWebpackConfigPath)
24
24
  ? customWebpackConfigPath
25
25
  : path.resolve(runtimePathById.root, 'node_modules', '@mainset/bundler-webpack/dist/esm/webpack-config/webapp.ssr.config.mjs');
@@ -34,10 +34,10 @@ function registerWebAppCommand(program) {
34
34
  execPurgeDist();
35
35
  // Step 2: build:ssr-webapp source code
36
36
  console.log('\nšŸ“¦ Compiling SSR WebApp with Webpack ...');
37
- execImmediateCommand(`node ${webpackCLICommandPath} --config ${webpackSSRConfigPath}`);
37
+ execImmediateCommand(`${webpackCLICommandPath} --config ${webpackSSRConfigPath}`);
38
38
  // Step 3: build:ssr-server source code
39
39
  console.log('\nšŸ“¦ Compiling SSR Server with Rslib ...');
40
- await execRslibCLICommand(`build --config ${rslibSSRConfigPath}`);
40
+ execRslibCLICommand(`build --config ${rslibSSRConfigPath}`);
41
41
  console.log('\nāœ… SSR Build completed successfully\n');
42
42
  }
43
43
  else {
@@ -49,7 +49,7 @@ function registerWebAppCommand(program) {
49
49
  execPurgeDist();
50
50
  // Step 2: build:csr-webapp source code
51
51
  console.log('\nšŸ“¦ Compiling CSR WebApp with Webpack ...');
52
- execImmediateCommand(`node ${webpackCLICommandPath} --config ${webpackCSRConfigPath}`);
52
+ execImmediateCommand(`${webpackCLICommandPath} --config ${webpackCSRConfigPath}`);
53
53
  console.log('\nāœ… CSR Build completed successfully\n');
54
54
  }
55
55
  }
@@ -66,15 +66,14 @@ function registerWebAppCommand(program) {
66
66
  const ssrServerEntryPath = path.resolve(runtimePathById.msCLISrc, '../services/ssr-server/ssr-server.mjs');
67
67
  const ssrServerConfigCompiledPath = path.resolve(runtimePathById.dist, './private/ssr-server.config.mjs');
68
68
  // Step 1: watch:ssr-server start ssr server
69
- await runRslibCLICommand([
69
+ runRslibCLICommand([
70
70
  'build',
71
71
  '--config',
72
72
  rslibSSRConfigPath,
73
73
  '--watch',
74
74
  ]);
75
75
  // Step 2: watch:ssr-webapp source code of web app
76
- runStreamingCommand('node', [
77
- webpackCLICommandPath,
76
+ runStreamingCommand(webpackCLICommandPath, [
78
77
  '--config',
79
78
  webpackSSRConfigPath,
80
79
  '--watch',
@@ -89,13 +88,12 @@ function registerWebAppCommand(program) {
89
88
  }
90
89
  else {
91
90
  // ========== [Serve] CSR mode ==========
92
- const webpackDevServerCLICommandPath = await resolveHostPackageBinForCLICommandPath('@mainset/bundler-webpack', 'webpack-dev-server');
93
91
  const webpackDevServerConfigPath = fs.existsSync(customWebpackConfigPath)
94
92
  ? customWebpackConfigPath
95
93
  : path.resolve(runtimePathById.root, 'node_modules', '@mainset/bundler-webpack/dist/esm/webpack-config/dev-server.csr.config.mjs');
96
94
  // Step 1: watch:csr-server / start:csr-server source code
97
- runStreamingCommand('node', [
98
- webpackDevServerCLICommandPath,
95
+ runStreamingCommand(webpackCLICommandPath, [
96
+ 'serve',
99
97
  '--config',
100
98
  webpackDevServerConfigPath,
101
99
  '--open',
@@ -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 isNodeModulesDeepNested = fs.existsSync(hostPackageNodeModulesPath);
7
- return isNodeModulesDeepNested // Pnpm uses such a structure
8
- ? path.join(hostPackageNodeModulesPath, dependencyPackageName)
9
- : path.join(runtimePathById.root, 'node_modules', dependencyPackageName);
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
- async function resolveHostPackageBinForCLICommandPath(hostPackageName, dependencyPackageName, cliCommandName) {
14
+ function resolveHostPackageBinForCLICommandPath(hostPackageName,
15
+ // dependencyPackageName: string,
16
+ cliCommandName) {
17
+ /* Previous implementation
12
18
  // Pnpm node_modules structure
13
- const dependencyPackageNodeModulesPath = resolveHostPackageNodeModulesPath(hostPackageName, dependencyPackageName);
14
- const packageJson = await import(path.join(dependencyPackageNodeModulesPath, 'package.json'), { with: { type: 'json' } });
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
- ? packageJson.default.bin[cliCommandName]
17
- : packageJson.default.bin;
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
- async startListening() {
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' } });
@@ -1,3 +1,3 @@
1
- declare function execRslibCLICommand(command: string): Promise<void>;
2
- declare function runRslibCLICommand(commandParams: string[]): Promise<void>;
1
+ declare function execRslibCLICommand(command: string): void;
2
+ declare function runRslibCLICommand(commandParams: string[]): void;
3
3
  export { execRslibCLICommand, runRslibCLICommand };
@@ -1,9 +1,9 @@
1
1
  declare function execTypeScriptCompileSourceCode({ configPath, }: {
2
2
  configPath: string;
3
- }): Promise<void>;
3
+ }): void;
4
4
  declare function runTypeScriptCompileSourceCode({ configPath, }: {
5
5
  configPath: string;
6
- }): Promise<void>;
7
- declare function execTypeScriptCompileTypeOnly(): Promise<void>;
8
- declare function runTypeScriptCompileTypeOnly(): Promise<void>;
6
+ }): void;
7
+ declare function execTypeScriptCompileTypeOnly(): void;
8
+ declare function runTypeScriptCompileTypeOnly(): void;
9
9
  export { execTypeScriptCompileSourceCode, execTypeScriptCompileTypeOnly, runTypeScriptCompileSourceCode, runTypeScriptCompileTypeOnly, };
@@ -1,3 +1,3 @@
1
1
  declare function resolveHostPackageNodeModulesPath(hostPackageName: string, dependencyPackageName: string): string;
2
- declare function resolveHostPackageBinForCLICommandPath(hostPackageName: string, dependencyPackageName: string, cliCommandName?: string): Promise<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(): Promise<void>;
15
+ startListening(): void;
16
16
  }
17
17
  export { ExpressBaseApp };
18
18
  export type { ExpressBaseAppConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mainset/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.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.0"
45
+ "@mainset/dev-stack-fe": "^0.1.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "@mainset/dev-stack-fe": "0.1.0"
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",