@mbc-cqrs-serverless/cli 0.1.33-beta.0 → 0.1.35-beta.0

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.
@@ -7,22 +7,23 @@ exports.exportsForTesting = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const fs_1 = require("fs");
9
9
  const path_1 = __importDefault(require("path"));
10
+ /* eslint-disable no-console */
10
11
  async function newAction(name = '', options, command) {
11
12
  const [projectName, version = 'latest'] = name.split('@');
12
13
  console.log(`Executing command '${command.name()}' for application '${projectName}' with options '${JSON.stringify(options)}'`);
13
14
  let packageVersion;
14
15
  if (version === 'latest') {
15
- packageVersion = `^${getPackageVersion('@mbc-cqrs-serverless/core', true)[0]}`;
16
+ packageVersion = `^${getPackageVersion('@mbc-cqrs-serverless/core', true)[0]}`; // use the latest patch and minor versions
16
17
  }
17
18
  else {
18
19
  const versions = getPackageVersion('@mbc-cqrs-serverless/core');
19
- const regex = new RegExp(`^${version}(?![0-9]).*$`);
20
+ const regex = new RegExp(`^${version}(?![0-9]).*$`); // start with version and not directly follow by a digit
20
21
  const matchVersions = versions.filter((v) => regex.test(v));
21
22
  if (versions.includes(version)) {
22
- packageVersion = version;
23
+ packageVersion = version; // specific version
23
24
  }
24
25
  else if (matchVersions.length !== 0) {
25
- packageVersion = `^${matchVersions.at(-1)}`;
26
+ packageVersion = `^${matchVersions.at(-1)}`; // use the patch and minor versions
26
27
  }
27
28
  else {
28
29
  console.log('The specified package version does not exist. Please chose a valid version!\n', versions);
@@ -34,15 +35,20 @@ async function newAction(name = '', options, command) {
34
35
  (0, fs_1.mkdirSync)(destDir, { recursive: true });
35
36
  useTemplate(destDir);
36
37
  usePackageVersion(destDir, packageVersion, projectName);
38
+ // mv gitignore .gitignore
37
39
  const gitignore = path_1.default.join(destDir, 'gitignore');
38
40
  (0, fs_1.copyFileSync)(gitignore, path_1.default.join(destDir, '.gitignore'));
39
41
  (0, fs_1.unlinkSync)(gitignore);
42
+ // mv infra/gitignore infra/.gitignore
40
43
  const infraGitignore = path_1.default.join(destDir, 'infra/gitignore');
41
44
  (0, fs_1.copyFileSync)(infraGitignore, path_1.default.join(destDir, 'infra/.gitignore'));
42
45
  (0, fs_1.unlinkSync)(infraGitignore);
46
+ // cp .env.local .env
43
47
  (0, fs_1.copyFileSync)(path_1.default.join(destDir, '.env.local'), path_1.default.join(destDir, '.env'));
48
+ // git init
44
49
  let logs = (0, child_process_1.execSync)('git init', { cwd: destDir });
45
50
  console.log(logs.toString());
51
+ // npm install
46
52
  console.log('Installing packages in', destDir);
47
53
  logs = (0, child_process_1.execSync)('npm i', { cwd: destDir });
48
54
  console.log(logs.toString());
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable no-console */
3
4
  async function startAction() {
4
5
  console.log('startAction here');
6
+ // TODO
5
7
  }
6
8
  exports.default = startAction;
@@ -9,16 +9,19 @@ const path_1 = __importDefault(require("path"));
9
9
  const rimraf_1 = require("rimraf");
10
10
  const repoUrl = 'https://gitlab.com/mbc-net/common/mbc-cqrs-ui-common.git';
11
11
  const componentOptions = ['all', 'appsync', 'component'];
12
+ /* eslint-disable no-console */
12
13
  async function uiAction(options, command) {
13
14
  console.log(`Executing command '${command.name()}' for application with options '${JSON.stringify(options)}'`);
14
15
  const { branch, auth, component, pathDir, token = '' } = options;
15
16
  if (componentOptions.findIndex((optionName) => optionName === component) === -1) {
16
17
  console.error(`Please choose correct component options: ${componentOptions.join(', ')}`);
17
18
  }
19
+ // Check command run in base src
18
20
  if (!(0, fs_1.existsSync)(path_1.default.join(process.cwd(), 'tsconfig.json'))) {
19
21
  console.log('Please run command in base folder');
20
22
  return;
21
23
  }
24
+ // Check tsconfig.json contain path @ms
22
25
  const tsconfig = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(process.cwd(), 'tsconfig.json'), 'utf8'));
23
26
  if (tsconfig?.compilerOptions &&
24
27
  tsconfig?.compilerOptions?.paths &&
@@ -26,6 +29,7 @@ async function uiAction(options, command) {
26
29
  console.log('The project already contain mbc-cqrs-ui-common');
27
30
  return;
28
31
  }
32
+ // Copy source
29
33
  installTemplate({
30
34
  auth,
31
35
  token,
@@ -33,6 +37,7 @@ async function uiAction(options, command) {
33
37
  branch,
34
38
  component,
35
39
  });
40
+ // Modify tsconfig path alias
36
41
  if (!tsconfig?.compilerOptions) {
37
42
  tsconfig.compilerOptions = {};
38
43
  }
@@ -43,7 +48,9 @@ async function uiAction(options, command) {
43
48
  (0, fs_1.writeFileSync)(path_1.default.join(process.cwd(), 'tsconfig.json'), JSON.stringify(tsconfig, null, 2), {
44
49
  encoding: 'utf8',
45
50
  });
51
+ // Modify package.json
46
52
  modifyDependencies({ pathDir, component });
53
+ // npm install
47
54
  console.log('Installing packages');
48
55
  const logs = (0, child_process_1.execSync)('npm i');
49
56
  console.log(logs.toString());
@@ -57,11 +64,13 @@ const installTemplate = ({ auth, token, pathDir, branch, component, }) => {
57
64
  else if (auth === 'HTTPS - Token') {
58
65
  gitUrl = repoUrl.replace(/^https:\/\//, `https://${token}@`);
59
66
  }
67
+ // Copy source
60
68
  const destDir = path_1.default.join(process.cwd(), pathDir);
61
69
  console.log('Adding MBC common ui in', destDir);
62
70
  (0, fs_1.mkdirSync)(destDir, { recursive: true });
63
71
  const logs = (0, child_process_1.execSync)(`git clone --branch ${branch} ${gitUrl} ${destDir}`);
64
72
  console.log(logs.toString());
73
+ // remove .git
65
74
  (0, rimraf_1.rimrafSync)(`${destDir}/.git`);
66
75
  if (component === 'component') {
67
76
  (0, rimraf_1.rimrafSync)(`${destDir}/appsync`);
@@ -86,6 +95,7 @@ const modifyDependencies = ({ pathDir, component, }) => {
86
95
  (0, rimraf_1.rimrafSync)(`${destDir}/package.json`);
87
96
  };
88
97
  const getModifyPackage = ({ srcPackage, destPackage, component, }) => {
98
+ // modify dependencies
89
99
  if (srcPackage?.dependencies) {
90
100
  if (!destPackage.dependencies) {
91
101
  destPackage.dependencies = {};
@@ -7,6 +7,7 @@ function loadCommands(program) {
7
7
  (0, new_command_1.newCommand)(program);
8
8
  (0, start_command_1.startCommand)(program);
9
9
  (0, ui_command_1.uiCommand)(program);
10
+ // error handling
10
11
  program.on('command:*', () => {
11
12
  console.error(`\nInvalid command: '${program.args.join(' ')}'`);
12
13
  console.log(`See '--help' for a list of available commands.\n`);
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const commander_1 = require("commander");
8
8
  const commands_1 = __importDefault(require("./commands"));
9
9
  async function bootstrap() {
10
10
  const program = new commander_1.Command();
11
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
11
12
  program.version(require('../package.json').version);
12
13
  (0, commands_1.default)(program);
13
14
  await program.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbc-cqrs-serverless/cli",
3
- "version": "0.1.33-beta.0",
3
+ "version": "0.1.35-beta.0",
4
4
  "description": "a CLI to get started with MBC CQRS serverless framework",
5
5
  "keywords": [
6
6
  "mbc",
@@ -49,5 +49,5 @@
49
49
  "devDependencies": {
50
50
  "@faker-js/faker": "^8.3.1"
51
51
  },
52
- "gitHead": "cfe8a02acd7525b3404fba04952290d2c4b0509b"
52
+ "gitHead": "5cc39e994ca216b239768ba047a345a15011433e"
53
53
  }