@mbc-cqrs-serverless/cli 0.1.24-beta.0 → 0.1.25-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.
@@ -32,7 +32,7 @@ async function newAction(name = '', options, command) {
32
32
  const destDir = path_1.default.join(process.cwd(), projectName);
33
33
  console.log('Generating MBC cqrs serverless application in', destDir);
34
34
  (0, fs_1.mkdirSync)(destDir, { recursive: true });
35
- (0, fs_1.cpSync)(path_1.default.join(__dirname, '../../templates'), destDir, { recursive: true });
35
+ useTemplate(destDir);
36
36
  usePackageVersion(destDir, packageVersion, projectName);
37
37
  const gitignore = path_1.default.join(destDir, 'gitignore');
38
38
  (0, fs_1.copyFileSync)(gitignore, path_1.default.join(destDir, '.gitignore'));
@@ -48,6 +48,26 @@ async function newAction(name = '', options, command) {
48
48
  console.log(logs.toString());
49
49
  }
50
50
  exports.default = newAction;
51
+ function useTemplate(destDir) {
52
+ if (isLatestCli()) {
53
+ (0, fs_1.cpSync)(path_1.default.join(__dirname, '../../templates'), destDir, {
54
+ recursive: true,
55
+ });
56
+ }
57
+ else {
58
+ (0, child_process_1.execSync)('npm i @mbc-cqrs-serverless/cli', { cwd: destDir });
59
+ (0, fs_1.cpSync)(path_1.default.join(destDir, 'node_modules/@mbc-cqrs-serverless/cli/templates'), destDir, { recursive: true });
60
+ (0, fs_1.rmSync)(path_1.default.join(destDir, 'node_modules'), {
61
+ recursive: true,
62
+ });
63
+ }
64
+ }
65
+ function isLatestCli() {
66
+ const latestVersion = getPackageVersion('@mbc-cqrs-serverless/cli', true)[0];
67
+ const packageJson = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(__dirname, '../../package.json')).toString());
68
+ const curVersion = packageJson.version;
69
+ return latestVersion === curVersion;
70
+ }
51
71
  function usePackageVersion(destDir, packageVersion, projectName) {
52
72
  const packageJson = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(__dirname, '../../package.json')).toString());
53
73
  const fname = path_1.default.join(destDir, 'package.json');
@@ -73,6 +93,7 @@ function getPackageVersion(packageName, isLatest = false) {
73
93
  exports.exportsForTesting = {
74
94
  usePackageVersion,
75
95
  getPackageVersion,
96
+ isLatestCli,
76
97
  };
77
98
  if (process.env.NODE_ENV !== 'test') {
78
99
  exports.exportsForTesting = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbc-cqrs-serverless/cli",
3
- "version": "0.1.24-beta.0",
3
+ "version": "0.1.25-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": "4329f4e6d5993db9e3ad8edd5aab40542e5b9156"
52
+ "gitHead": "7c50d386295bdd70d6db5d325e6892f0cb4d9f62"
53
53
  }