@mbc-cqrs-serverless/cli 0.1.11-beta.0 → 0.1.13-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.
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.exportsForTesting = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const fs_1 = require("fs");
9
+ const path_1 = __importDefault(require("path"));
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);
13
+ console.log('Generating MBC cqrs serverless application in', destDir);
14
+ (0, fs_1.mkdirSync)(destDir, { recursive: true });
15
+ (0, fs_1.cpSync)(path_1.default.join(__dirname, '../../templates'), destDir, { recursive: true });
16
+ useLatestPackageVersion(destDir, name);
17
+ const gitignore = path_1.default.join(destDir, 'gitignore');
18
+ (0, fs_1.copyFileSync)(gitignore, path_1.default.join(destDir, '.gitignore'));
19
+ (0, fs_1.unlinkSync)(gitignore);
20
+ (0, fs_1.copyFileSync)(path_1.default.join(destDir, '.env.local'), path_1.default.join(destDir, '.env'));
21
+ let logs = (0, child_process_1.execSync)('git init', { cwd: destDir });
22
+ console.log(logs.toString());
23
+ console.log('Installing packages in', destDir);
24
+ logs = (0, child_process_1.execSync)('npm i', { cwd: destDir });
25
+ console.log(logs.toString());
26
+ }
27
+ exports.default = newAction;
28
+ function useLatestPackageVersion(destDir, name) {
29
+ const packageJson = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(__dirname, '../../package.json')).toString());
30
+ const fname = path_1.default.join(destDir, 'package.json');
31
+ const tplPackageJson = JSON.parse((0, fs_1.readFileSync)(fname).toString());
32
+ if (name) {
33
+ tplPackageJson.name = name;
34
+ }
35
+ tplPackageJson.dependencies['@mbc-cqrs-serverless/core'] =
36
+ packageJson.devDependencies['@mbc-cqrs-serverless/core'];
37
+ tplPackageJson.devDependencies['@mbc-cqrs-serverless/cli'] =
38
+ packageJson.version;
39
+ (0, fs_1.writeFileSync)(fname, JSON.stringify(tplPackageJson, null, 2));
40
+ }
41
+ exports.exportsForTesting = {
42
+ useLatestPackageVersion,
43
+ };
44
+ if (process.env.NODE_ENV !== 'test') {
45
+ exports.exportsForTesting = undefined;
46
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ async function startAction() {
4
+ console.log('startAction here');
5
+ }
6
+ exports.default = startAction;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const child_process_1 = require("child_process");
7
+ const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ const rimraf_1 = require("rimraf");
10
+ const repoUrl = 'https://gitlab.com/mbc-net/common/mbc-cqrs-ui-common.git';
11
+ const componentOptions = ['all', 'appsync', 'component'];
12
+ async function uiAction(options, command) {
13
+ console.log(`Executing command '${command.name()}' for application with options '${JSON.stringify(options)}'`);
14
+ const { branch, auth, component, pathDir, token = '' } = options;
15
+ if (componentOptions.findIndex((optionName) => optionName === component) === -1) {
16
+ console.error(`Please choose correct component options: ${componentOptions.join(', ')}`);
17
+ }
18
+ if (!(0, fs_1.existsSync)(path_1.default.join(process.cwd(), 'tsconfig.json'))) {
19
+ console.log('Please run command in base folder');
20
+ return;
21
+ }
22
+ const tsconfig = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(process.cwd(), 'tsconfig.json'), 'utf8'));
23
+ if (tsconfig?.compilerOptions &&
24
+ tsconfig?.compilerOptions?.paths &&
25
+ tsconfig?.compilerOptions?.paths.hasOwnProperty('@ms/*')) {
26
+ console.log('The project already contain mbc-cqrs-ui-common');
27
+ return;
28
+ }
29
+ installTemplate({
30
+ auth,
31
+ token,
32
+ pathDir,
33
+ branch,
34
+ component,
35
+ });
36
+ if (!tsconfig?.compilerOptions) {
37
+ tsconfig.compilerOptions = {};
38
+ }
39
+ if (!tsconfig?.compilerOptions?.paths) {
40
+ tsconfig.compilerOptions.paths = {};
41
+ }
42
+ tsconfig.compilerOptions.paths['@ms/*'] = [`./${pathDir}/*`];
43
+ (0, fs_1.writeFileSync)(path_1.default.join(process.cwd(), 'tsconfig.json'), JSON.stringify(tsconfig, null, 2), {
44
+ encoding: 'utf8',
45
+ });
46
+ modifyDependencies({ pathDir, component });
47
+ console.log('Installing packages');
48
+ const logs = (0, child_process_1.execSync)('npm i');
49
+ console.log(logs.toString());
50
+ }
51
+ exports.default = uiAction;
52
+ const installTemplate = ({ auth, token, pathDir, branch, component, }) => {
53
+ let gitUrl = repoUrl;
54
+ if (auth === 'SSH') {
55
+ gitUrl = 'git@gitlab.com:mbc-net/common/mbc-cqrs-ui-common.git';
56
+ }
57
+ else if (auth === 'HTTPS - Token') {
58
+ gitUrl = repoUrl.replace(/^https:\/\//, `https://${token}@`);
59
+ }
60
+ const destDir = path_1.default.join(process.cwd(), pathDir);
61
+ console.log('Adding MBC common ui in', destDir);
62
+ (0, fs_1.mkdirSync)(destDir, { recursive: true });
63
+ const logs = (0, child_process_1.execSync)(`git clone --branch ${branch} ${gitUrl} ${destDir}`);
64
+ console.log(logs.toString());
65
+ (0, rimraf_1.rimrafSync)(`${destDir}/.git`);
66
+ if (component === 'component') {
67
+ (0, rimraf_1.rimrafSync)(`${destDir}/appsync`);
68
+ }
69
+ else if (component === 'appsync') {
70
+ ;
71
+ ['components', 'lib', 'modules', 'styles', 'types'].forEach((name) => (0, rimraf_1.rimrafSync)(`${destDir}/${name}`));
72
+ }
73
+ };
74
+ const modifyDependencies = ({ pathDir, component, }) => {
75
+ const destDir = path_1.default.join(process.cwd(), pathDir);
76
+ const srcPackage = JSON.parse((0, fs_1.readFileSync)(`${destDir}/package.json`, 'utf8'));
77
+ const destPackage = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(process.cwd(), 'package.json'), 'utf8'));
78
+ const modifiedPackage = getModifyPackage({
79
+ srcPackage,
80
+ destPackage,
81
+ component,
82
+ });
83
+ (0, fs_1.writeFileSync)(path_1.default.join(process.cwd(), 'package.json'), JSON.stringify(modifiedPackage, null, 2), {
84
+ encoding: 'utf8',
85
+ });
86
+ (0, rimraf_1.rimrafSync)(`${destDir}/package.json`);
87
+ };
88
+ const getModifyPackage = ({ srcPackage, destPackage, component, }) => {
89
+ if (srcPackage?.dependencies) {
90
+ if (!destPackage.dependencies) {
91
+ destPackage.dependencies = {};
92
+ }
93
+ for (const key of Object.keys(srcPackage.dependencies)) {
94
+ if (!destPackage.dependencies[key]) {
95
+ if (component === 'component' && key === 'aws-amplify')
96
+ continue;
97
+ if (component === 'appsync' && key !== 'aws-amplify')
98
+ continue;
99
+ destPackage.dependencies[key] = srcPackage.dependencies[key];
100
+ }
101
+ }
102
+ }
103
+ return destPackage;
104
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const new_command_1 = require("./new.command");
4
+ const start_command_1 = require("./start.command");
5
+ const ui_command_1 = require("./ui.command");
6
+ function loadCommands(program) {
7
+ (0, new_command_1.newCommand)(program);
8
+ (0, start_command_1.startCommand)(program);
9
+ (0, ui_command_1.uiCommand)(program);
10
+ program.on('command:*', () => {
11
+ console.error(`\nInvalid command: '${program.args.join(' ')}'`);
12
+ console.log(`See '--help' for a list of available commands.\n`);
13
+ program.outputHelp();
14
+ });
15
+ }
16
+ exports.default = loadCommands;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.newCommand = void 0;
7
+ const new_action_1 = __importDefault(require("../actions/new.action"));
8
+ function newCommand(program) {
9
+ program
10
+ .command('new [name]')
11
+ .alias('n')
12
+ .description('Generate a new CQRS application using the MBC CQRS serverless framework')
13
+ .action(new_action_1.default);
14
+ }
15
+ exports.newCommand = newCommand;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.startCommand = void 0;
7
+ const start_action_1 = __importDefault(require("../actions/start.action"));
8
+ function startCommand(program) {
9
+ program
10
+ .command('start')
11
+ .alias('s')
12
+ .description('Start application with serverless framework')
13
+ .action(start_action_1.default);
14
+ }
15
+ exports.startCommand = startCommand;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.uiCommand = void 0;
7
+ const ui_action_1 = __importDefault(require("../actions/ui.action"));
8
+ function uiCommand(program) {
9
+ program
10
+ .command('ui-common')
11
+ .alias('ui')
12
+ .description('add mbc-cqrs-ui-common components to your project.')
13
+ .requiredOption('-p, --pathDir <string>', 'The place of common-ui')
14
+ .option('-b, --branch <string>', 'The branch name', 'main')
15
+ .option('--auth <string>', 'The auth method (HTTPS - Token, SSH)', 'SSH')
16
+ .option('--token <string>', 'The token with format: tokenId:tokenPassword')
17
+ .option('-c, --component <string>', 'Component to install (all, appsync, component)', 'all')
18
+ .option('--alias', 'The alias to common-ui')
19
+ .action(ui_action_1.default);
20
+ }
21
+ exports.uiCommand = uiCommand;
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = require("commander");
8
+ const commands_1 = __importDefault(require("./commands"));
9
+ async function bootstrap() {
10
+ const program = new commander_1.Command();
11
+ program.version(require('../package.json').version);
12
+ (0, commands_1.default)(program);
13
+ await program.parseAsync(process.argv);
14
+ if (!process.argv.slice(2).length) {
15
+ program.outputHelp();
16
+ }
17
+ }
18
+ bootstrap();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbc-cqrs-serverless/cli",
3
- "version": "0.1.11-beta.0",
3
+ "version": "0.1.13-beta.0",
4
4
  "description": "a CLI to get started with MBC CQRS serverless framework",
5
5
  "bin": {
6
6
  "mbc": "./dist/index.js"
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@faker-js/faker": "^8.3.1",
36
- "@mbc-cqrs-serverless/core": "^0.1.11-beta.0"
36
+ "@mbc-cqrs-serverless/core": "^0.1.13-beta.0"
37
37
  },
38
- "gitHead": "870fd6950e38a93552e82b6b3f2dc58376c9e431"
38
+ "gitHead": "f2c68c27fb59d27c13cbf04f4ba706e9687606f7"
39
39
  }