@mbc-cqrs-serverless/cli 0.1.21-beta.0 → 0.1.22-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.
package/README.md CHANGED
@@ -1,6 +1,34 @@
1
1
  ![MBC CQRS serverless framework](https://mbc-net.github.io/mbc-cqrs-serverless-doc/img/mbc-cqrs-serverless.png)
2
2
  # MBC CQRS serverless framework CLI package
3
3
 
4
+ ## Description
5
+
6
+ The MBC CLI is a command-line interface tool that helps you to initialize your mbc-cqrs-serverless applications.
7
+
8
+ ## Installation
9
+
10
+ To install `mbc`, run:
11
+
12
+ ```bash
13
+ npm install -g @mbc-cqrs-serverless/cli
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### `mbc new|n [projectName@version]`
19
+
20
+ There are 3 usages for the new command:
21
+
22
+ - `mbc new`
23
+ - Creates a new project in the current folder using a default name with the latest framework version.
24
+ - `mbc new [projectName]`
25
+ - Creates a new project in the `projectName` folder using the latest framework version.
26
+ - `mbc new [projectName@version]`
27
+ - If the specified version exists, the CLI uses that exact version.
28
+ - If the provided version is a prefix, the CLI uses the latest version matching that prefix.
29
+ - If no matching version is found, the CLI logs an error and provides a list of available versions for the user.
30
+
31
+
4
32
  ## Documentation
5
33
 
6
34
  Visit https://mbc-net.github.io/mbc-cqrs-serverless-doc/ to view the full documentation.
@@ -8,12 +8,32 @@ const child_process_1 = require("child_process");
8
8
  const fs_1 = require("fs");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  async function newAction(name = '', options, command) {
11
- console.log(`Executing command '${command.name()}' for application '${name}' with options '${JSON.stringify(options)}'`);
12
- const destDir = path_1.default.join(process.cwd(), name);
11
+ const [projectName, version = 'latest'] = name.split('@');
12
+ console.log(`Executing command '${command.name()}' for application '${projectName}' with options '${JSON.stringify(options)}'`);
13
+ let packageVersion;
14
+ if (version === 'latest') {
15
+ packageVersion = `^${getPackageVersion('@mbc-cqrs-serverless/core', true)[0]}`;
16
+ }
17
+ else {
18
+ const versions = getPackageVersion('@mbc-cqrs-serverless/core');
19
+ const regex = new RegExp(`^${version}(?![0-9]).*$`);
20
+ const matchVersions = versions.filter((v) => regex.test(v));
21
+ if (versions.includes(version)) {
22
+ packageVersion = version;
23
+ }
24
+ else if (matchVersions.length !== 0) {
25
+ packageVersion = `^${matchVersions.at(-1)}`;
26
+ }
27
+ else {
28
+ console.log('The specified package version does not exist. Please chose a valid version!\n', versions);
29
+ return;
30
+ }
31
+ }
32
+ const destDir = path_1.default.join(process.cwd(), projectName);
13
33
  console.log('Generating MBC cqrs serverless application in', destDir);
14
34
  (0, fs_1.mkdirSync)(destDir, { recursive: true });
15
35
  (0, fs_1.cpSync)(path_1.default.join(__dirname, '../../templates'), destDir, { recursive: true });
16
- useLatestPackageVersion(destDir, name);
36
+ usePackageVersion(destDir, packageVersion, projectName);
17
37
  const gitignore = path_1.default.join(destDir, 'gitignore');
18
38
  (0, fs_1.copyFileSync)(gitignore, path_1.default.join(destDir, '.gitignore'));
19
39
  (0, fs_1.unlinkSync)(gitignore);
@@ -25,21 +45,31 @@ async function newAction(name = '', options, command) {
25
45
  console.log(logs.toString());
26
46
  }
27
47
  exports.default = newAction;
28
- function useLatestPackageVersion(destDir, name) {
48
+ function usePackageVersion(destDir, packageVersion, projectName) {
29
49
  const packageJson = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(__dirname, '../../package.json')).toString());
30
50
  const fname = path_1.default.join(destDir, 'package.json');
31
51
  const tplPackageJson = JSON.parse((0, fs_1.readFileSync)(fname).toString());
32
- if (name) {
33
- tplPackageJson.name = name;
52
+ if (projectName) {
53
+ tplPackageJson.name = projectName;
34
54
  }
35
- tplPackageJson.dependencies['@mbc-cqrs-serverless/core'] =
36
- packageJson.devDependencies['@mbc-cqrs-serverless/core'];
55
+ tplPackageJson.dependencies['@mbc-cqrs-serverless/core'] = packageVersion;
37
56
  tplPackageJson.devDependencies['@mbc-cqrs-serverless/cli'] =
38
57
  packageJson.version;
39
58
  (0, fs_1.writeFileSync)(fname, JSON.stringify(tplPackageJson, null, 2));
40
59
  }
60
+ function getPackageVersion(packageName, isLatest = false) {
61
+ if (isLatest) {
62
+ const latestVersion = (0, child_process_1.execSync)(`npm view ${packageName} dist-tags.latest`)
63
+ .toString()
64
+ .trim();
65
+ return [latestVersion];
66
+ }
67
+ const versions = JSON.parse((0, child_process_1.execSync)(`npm view ${packageName} versions --json`).toString());
68
+ return versions;
69
+ }
41
70
  exports.exportsForTesting = {
42
- useLatestPackageVersion,
71
+ usePackageVersion,
72
+ getPackageVersion,
43
73
  };
44
74
  if (process.env.NODE_ENV !== 'test') {
45
75
  exports.exportsForTesting = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbc-cqrs-serverless/cli",
3
- "version": "0.1.21-beta.0",
3
+ "version": "0.1.22-beta.0",
4
4
  "description": "a CLI to get started with MBC CQRS serverless framework",
5
5
  "keywords": [
6
6
  "mbc",
@@ -47,8 +47,7 @@
47
47
  "rimraf": "^5.0.5"
48
48
  },
49
49
  "devDependencies": {
50
- "@faker-js/faker": "^8.3.1",
51
- "@mbc-cqrs-serverless/core": "^0.1.21-beta.0"
50
+ "@faker-js/faker": "^8.3.1"
52
51
  },
53
- "gitHead": "163e71ab47e27863f7bfd24f8c59f19e1e330e23"
52
+ "gitHead": "2801b6700640df7bb9d82e1e686b4017dd5b176b"
54
53
  }