@magek/cli 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magek/cli",
3
3
  "description": "CLI of the Magek Framework, the next level of abstraction for cloud-native applications",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "author": "Boosterin Labs SLU",
6
6
  "homepage": "https://magek.ai",
7
7
  "publishConfig": {
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "bugs": "https://github.com/theam/magek/issues",
14
14
  "dependencies": {
15
- "@magek/core": "^0.0.1",
16
- "@magek/common": "^0.0.1",
15
+ "@magek/core": "^0.0.2",
16
+ "@magek/common": "^0.0.2",
17
17
  "@oclif/core": "4.8.0",
18
18
  "@oclif/plugin-help": "6.2.36",
19
19
  "chalk": "5.6.2",
@@ -28,7 +28,7 @@
28
28
  "tslib": "2.8.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@magek/eslint-config": "^0.0.1",
31
+ "@magek/eslint-config": "^0.0.2",
32
32
  "@oclif/test": "4.1.15",
33
33
  "@types/chai": "5.2.3",
34
34
  "@types/chai-as-promised": "8.0.2",
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
5
- const base_command_js_1 = tslib_1.__importDefault(require("../common/base-command.js"));
6
- const config_service_js_1 = require("../services/config-service.js");
7
- const project_checker_js_1 = require("../services/project-checker.js");
8
- const script_js_1 = require("../common/script.js");
9
- const brand_js_1 = tslib_1.__importDefault(require("../common/brand.js"));
10
- const runTasks = async (compileAndLoad) => script_js_1.Script.init(`magek ${brand_js_1.default.dangerize('build')} 🚀`, Promise.resolve(process.cwd()))
11
- .step('Checking project structure', project_checker_js_1.checkCurrentDirIsAMagekProject)
12
- .step('Building project', compileAndLoad)
13
- .info('Build complete!')
14
- .done();
15
- class Build extends base_command_js_1.default {
16
- async run() {
17
- await runTasks((ctx) => (0, config_service_js_1.compileProject)(process.cwd()));
18
- }
19
- async catch(fullError) {
20
- const { flags: { verbose }, } = await this.parse(Build);
21
- if (verbose) {
22
- console.error(fullError.message);
23
- }
24
- return super.catch(fullError);
25
- }
26
- }
27
- Build.description = 'Build the current application as configured in your `index.ts` file.';
28
- Build.flags = {
29
- help: core_1.Flags.help({ char: 'h' }),
30
- verbose: core_1.Flags.boolean({
31
- description: 'display full error messages',
32
- default: false,
33
- }),
34
- };
35
- exports.default = Build;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTasks = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@oclif/core");
6
- const base_command_js_1 = tslib_1.__importDefault(require("../common/base-command.js"));
7
- const provider_service_js_1 = require("../services/provider-service.js");
8
- const config_service_js_1 = require("../services/config-service.js");
9
- const script_js_1 = require("../common/script.js");
10
- const brand_js_1 = tslib_1.__importDefault(require("../common/brand.js"));
11
- const logger_js_1 = require("../services/logger.js");
12
- const environment_js_1 = require("../services/environment.js");
13
- const runTasks = async (compileAndLoad, deployer) => script_js_1.Script.init(`boost ${brand_js_1.default.dangerize('deploy')} [${(0, environment_js_1.currentEnvironment)()}] 🚀`, compileAndLoad)
14
- .step('Deploying', (config) => deployer(config))
15
- .step('Cleaning up deployment files', config_service_js_1.cleanDeploymentSandbox)
16
- .info('Deployment complete!')
17
- .done();
18
- exports.runTasks = runTasks;
19
- class Deploy extends base_command_js_1.default {
20
- async run() {
21
- const { flags } = await this.parse(Deploy);
22
- if ((0, environment_js_1.initializeEnvironment)(logger_js_1.logger, flags.environment)) {
23
- const deploymentProjectPath = await (0, config_service_js_1.createDeploymentSandbox)();
24
- await (0, exports.runTasks)((0, config_service_js_1.compileProjectAndLoadConfig)(deploymentProjectPath), provider_service_js_1.deployToCloudProvider);
25
- }
26
- }
27
- async catch(fullError) {
28
- const { flags: { verbose }, } = await this.parse(Deploy);
29
- if (verbose) {
30
- console.error(fullError.message);
31
- }
32
- return super.catch(fullError);
33
- }
34
- }
35
- Deploy.description = 'Deploy the current application as configured in your `index.ts` file.';
36
- Deploy.flags = {
37
- help: core_1.Flags.help({ char: 'h' }),
38
- environment: core_1.Flags.string({
39
- char: 'e',
40
- description: 'environment configuration to run',
41
- }),
42
- verbose: core_1.Flags.boolean({
43
- description: 'display full error messages',
44
- default: false,
45
- }),
46
- };
47
- exports.default = Deploy;
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTasks = void 0;
4
- exports.askToConfirmRemoval = askToConfirmRemoval;
5
- const tslib_1 = require("tslib");
6
- const core_1 = require("@oclif/core");
7
- const base_command_js_1 = tslib_1.__importDefault(require("../common/base-command.js"));
8
- const provider_service_js_1 = require("../services/provider-service.js");
9
- const config_service_js_1 = require("../services/config-service.js");
10
- const script_js_1 = require("../common/script.js");
11
- const brand_js_1 = tslib_1.__importDefault(require("../common/brand.js"));
12
- const user_prompt_js_1 = tslib_1.__importDefault(require("../services/user-prompt.js"));
13
- const logger_js_1 = require("../services/logger.js");
14
- const environment_js_1 = require("../services/environment.js");
15
- const runTasks = async (compileAndLoad, nuke) => script_js_1.Script.init(`boost ${brand_js_1.default.dangerize('nuke')} [${(0, environment_js_1.currentEnvironment)()}] 🧨`, compileAndLoad)
16
- .step('Removing', (config) => nuke(config))
17
- .info('Removal complete!')
18
- .done();
19
- exports.runTasks = runTasks;
20
- async function askToConfirmRemoval(prompter, force, config) {
21
- if (force)
22
- return config;
23
- const configuration = await config;
24
- const appName = await prompter.defaultOrPrompt(null, 'Please, enter the app name to confirm deletion of all resources:');
25
- if (appName == configuration.appName) {
26
- return configuration;
27
- }
28
- else {
29
- throw new Error('Wrong app name, stopping nuke!');
30
- }
31
- }
32
- class Nuke extends base_command_js_1.default {
33
- async run() {
34
- const { flags } = await this.parse(Nuke);
35
- if ((0, environment_js_1.initializeEnvironment)(logger_js_1.logger, flags.environment)) {
36
- await (0, exports.runTasks)(askToConfirmRemoval(new user_prompt_js_1.default(), flags.force, (0, config_service_js_1.compileProjectAndLoadConfig)(process.cwd())), provider_service_js_1.nukeCloudProviderResources);
37
- }
38
- }
39
- async catch(fullError) {
40
- const { flags: { verbose }, } = await this.parse(Nuke);
41
- if (verbose) {
42
- console.error(fullError.message);
43
- }
44
- return super.catch(fullError);
45
- }
46
- }
47
- Nuke.description = 'Remove all resources used by the current application as configured in your `index.ts` file.';
48
- Nuke.flags = {
49
- help: core_1.Flags.help({ char: 'h' }),
50
- environment: core_1.Flags.string({
51
- char: 'e',
52
- description: 'environment configuration to run',
53
- }),
54
- force: core_1.Flags.boolean({
55
- char: 'f',
56
- description: 'Run nuke without asking for confirmation. Be EXTRA CAUTIOUS with this option, all your application data will be irreversibly DELETED without confirmation.',
57
- }),
58
- verbose: core_1.Flags.boolean({
59
- description: 'display full error messages',
60
- default: false,
61
- }),
62
- };
63
- exports.default = Nuke;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTasks = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@oclif/core");
6
- const base_command_js_1 = tslib_1.__importDefault(require("../common/base-command.js"));
7
- const provider_service_js_1 = require("../services/provider-service.js");
8
- const config_service_js_1 = require("../services/config-service.js");
9
- const common_1 = require("@magek/common");
10
- const script_js_1 = require("../common/script.js");
11
- const brand_js_1 = tslib_1.__importDefault(require("../common/brand.js"));
12
- const logger_js_1 = require("../services/logger.js");
13
- const environment_js_1 = require("../services/environment.js");
14
- const process = tslib_1.__importStar(require("process"));
15
- const runTasks = async (port, loader, runner) => script_js_1.Script.init(`boost ${brand_js_1.default.canarize('debug')} [${(0, environment_js_1.currentEnvironment)()}] 🐛`, loader)
16
- .step(`Starting debug server on port ${port}`, runner)
17
- .done();
18
- exports.runTasks = runTasks;
19
- class Start extends base_command_js_1.default {
20
- async run() {
21
- const { flags } = await this.parse(Start);
22
- if ((0, environment_js_1.initializeEnvironment)(logger_js_1.logger, flags.environment)) {
23
- process.env[common_1.MAGEK_LOCAL_PORT] = flags.port ? flags.port.toString() : '3000';
24
- await (0, exports.runTasks)(flags.port, (0, config_service_js_1.compileProjectAndLoadConfig)(process.cwd()), provider_service_js_1.startProvider.bind(null, flags.port));
25
- }
26
- }
27
- async catch(fullError) {
28
- const { flags: { verbose }, } = await this.parse(Start);
29
- if (verbose) {
30
- console.error(fullError.message);
31
- }
32
- return super.catch(fullError);
33
- }
34
- }
35
- Start.description = 'Start local debug server.';
36
- Start.flags = {
37
- help: core_1.Flags.help({ char: 'h' }),
38
- port: core_1.Flags.integer({
39
- char: 'p',
40
- description: 'port to run the local runtime on',
41
- default: 3000,
42
- }),
43
- environment: core_1.Flags.string({
44
- char: 'e',
45
- description: 'environment configuration to run',
46
- }),
47
- verbose: core_1.Flags.boolean({
48
- description: 'display full error messages',
49
- default: false,
50
- }),
51
- };
52
- exports.default = Start;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
5
- const base_command_js_1 = tslib_1.__importDefault(require("../common/base-command.js"));
6
- const config_service_js_1 = require("../services/config-service.js");
7
- const script_js_1 = require("../common/script.js");
8
- const brand_js_1 = tslib_1.__importDefault(require("../common/brand.js"));
9
- const environment_js_1 = require("../services/environment.js");
10
- const logger_js_1 = require("../services/logger.js");
11
- const provider_service_js_1 = require("../services/provider-service.js");
12
- const runTasks = async (compileAndLoad, synther) => script_js_1.Script.init(`boost ${brand_js_1.default.dangerize('synth')} [${(0, environment_js_1.currentEnvironment)()}] 🚀`, compileAndLoad)
13
- .step('Synth', (config) => synther(config))
14
- .step('Cleaning up temporal files', config_service_js_1.cleanDeploymentSandbox)
15
- .info('Synth complete!')
16
- .done();
17
- class Synth extends base_command_js_1.default {
18
- async run() {
19
- const { flags } = await this.parse(Synth);
20
- if ((0, environment_js_1.initializeEnvironment)(logger_js_1.logger, flags.environment)) {
21
- const deploymentProjectPath = await (0, config_service_js_1.createDeploymentSandbox)();
22
- await runTasks((0, config_service_js_1.compileProjectAndLoadConfig)(deploymentProjectPath), provider_service_js_1.synthToProvider);
23
- }
24
- }
25
- async catch(fullError) {
26
- const { flags: { verbose }, } = await this.parse(Synth);
27
- if (verbose) {
28
- console.error(fullError.message);
29
- }
30
- return super.catch(fullError);
31
- }
32
- }
33
- Synth.description = 'Generate the required cloud templates to deploy your app manually.';
34
- Synth.flags = {
35
- help: core_1.Flags.help({ char: 'h' }),
36
- environment: core_1.Flags.string({
37
- char: 'e',
38
- description: 'environment configuration to run',
39
- }),
40
- verbose: core_1.Flags.boolean({
41
- description: 'display full error messages',
42
- default: false,
43
- }),
44
- };
45
- exports.default = Synth;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeSandboxProject = exports.createSandboxProject = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const fsExtra = tslib_1.__importStar(require("fs-extra"));
7
- const path = tslib_1.__importStar(require("path"));
8
- const copyFolder = (origin, destiny) => {
9
- fs.readdirSync(origin, { withFileTypes: true }).forEach((dirEnt) => {
10
- if (dirEnt.isFile()) {
11
- fsExtra.copySync(path.join(origin, dirEnt.name), path.join(destiny, dirEnt.name));
12
- }
13
- if (dirEnt.isDirectory()) {
14
- fs.mkdirSync(path.join(destiny, dirEnt.name), { recursive: true });
15
- copyFolder(path.join(origin, dirEnt.name), path.join(destiny, dirEnt.name));
16
- }
17
- });
18
- };
19
- const createSandboxProject = (sandboxPath, assets) => {
20
- fs.rmSync(sandboxPath, { recursive: true, force: true });
21
- fs.mkdirSync(sandboxPath, { recursive: true });
22
- copyFolder('src', path.join(sandboxPath, 'src'));
23
- const projectFiles = ['package.json', 'package-lock.json', 'tsconfig.json'];
24
- projectFiles.forEach((file) => {
25
- if (fsExtra.existsSync(file)) {
26
- fsExtra.copySync(file, path.join(sandboxPath, file));
27
- }
28
- });
29
- if (assets) {
30
- assets.forEach((asset) => {
31
- if (fs.statSync(asset).isDirectory()) {
32
- copyFolder(asset, path.join(sandboxPath, asset));
33
- }
34
- else {
35
- fsExtra.copySync(asset, path.join(sandboxPath, asset));
36
- }
37
- });
38
- }
39
- return sandboxPath;
40
- };
41
- exports.createSandboxProject = createSandboxProject;
42
- const removeSandboxProject = (sandboxPath) => {
43
- fs.rmSync(sandboxPath, { recursive: true, force: true });
44
- };
45
- exports.removeSandboxProject = removeSandboxProject;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startProvider = exports.nukeCloudProviderResources = exports.synthToProvider = exports.deployToCloudProvider = exports.providerService = void 0;
4
- exports.assertNameIsCorrect = assertNameIsCorrect;
5
- function assertNameIsCorrect(name) {
6
- // Current characters max length: 37
7
- // Lambda name limit is 64 characters
8
- // `-subscriptions-notifier` lambda is 23 characters
9
- // `-app` prefix is added to application stack
10
- // which is 64 - 23 - 4 = 37
11
- const maxProjectNameLength = 37;
12
- if (name.length > maxProjectNameLength)
13
- throw new ForbiddenProjectName(name, `be longer than ${maxProjectNameLength} characters`);
14
- if (name.includes(' '))
15
- throw new ForbiddenProjectName(name, 'contain spaces');
16
- if (name.toLowerCase() !== name)
17
- throw new ForbiddenProjectName(name, 'contain uppercase letters');
18
- if (name.includes('_'))
19
- throw new ForbiddenProjectName(name, 'contain underscore');
20
- }
21
- class ForbiddenProjectName extends Error {
22
- constructor(name, restrictionText) {
23
- super(`Project name cannot ${restrictionText}:\n\n Found: '${name}'`);
24
- this.name = name;
25
- this.restrictionText = restrictionText;
26
- }
27
- }
28
- function supportedInfrastructureMethodOrDie(methodName, config) {
29
- assertNameIsCorrect(config.appName);
30
- const method = config.provider.infrastructure()[methodName];
31
- if (!method) {
32
- throw new Error(`Attempted to perform the '${methodName}' operation with a provider that does not support this feature, please check your environment configuration.`);
33
- }
34
- return method;
35
- }
36
- const deployToCloudProviderImpl = (config) => supportedInfrastructureMethodOrDie('deploy', config)(config);
37
- const synthToProviderImpl = (config) => supportedInfrastructureMethodOrDie('synth', config)(config);
38
- const nukeCloudProviderResourcesImpl = (config) => supportedInfrastructureMethodOrDie('nuke', config)(config);
39
- const startProviderImpl = (port, config) => supportedInfrastructureMethodOrDie('start', config)(config, port);
40
- exports.providerService = {
41
- deployToCloudProvider: deployToCloudProviderImpl,
42
- synthToProvider: synthToProviderImpl,
43
- nukeCloudProviderResources: nukeCloudProviderResourcesImpl,
44
- startProvider: startProviderImpl,
45
- };
46
- const deployToCloudProvider = (...args) => exports.providerService.deployToCloudProvider(...args);
47
- exports.deployToCloudProvider = deployToCloudProvider;
48
- const synthToProvider = (...args) => exports.providerService.synthToProvider(...args);
49
- exports.synthToProvider = synthToProvider;
50
- const nukeCloudProviderResources = (...args) => exports.providerService.nukeCloudProviderResources(...args);
51
- exports.nukeCloudProviderResources = nukeCloudProviderResources;
52
- const startProvider = (...args) => exports.providerService.startProvider(...args);
53
- exports.startProvider = startProvider;