@magek/cli 0.0.1
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/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/dist/commands/add/projection.js +51 -0
- package/dist/commands/add/reducer.js +52 -0
- package/dist/commands/build.js +35 -0
- package/dist/commands/clean.js +35 -0
- package/dist/commands/deploy.js +47 -0
- package/dist/commands/new/command.js +71 -0
- package/dist/commands/new/entity.js +84 -0
- package/dist/commands/new/event-handler.js +73 -0
- package/dist/commands/new/event.js +65 -0
- package/dist/commands/new/query.js +71 -0
- package/dist/commands/new/read-model.js +85 -0
- package/dist/commands/new/scheduled-command.js +60 -0
- package/dist/commands/new/type.js +53 -0
- package/dist/commands/nuke.js +63 -0
- package/dist/commands/start.js +52 -0
- package/dist/commands/stub/publish.js +44 -0
- package/dist/commands/synth.js +45 -0
- package/dist/common/base-command.js +18 -0
- package/dist/common/brand.js +38 -0
- package/dist/common/errors.js +24 -0
- package/dist/common/filenames.js +45 -0
- package/dist/common/provider.js +2 -0
- package/dist/common/sandbox.js +45 -0
- package/dist/common/script.js +102 -0
- package/dist/hooks/command_not_found/custom-parse.js +40 -0
- package/dist/index.js +4 -0
- package/dist/services/config-service.js +76 -0
- package/dist/services/environment.js +22 -0
- package/dist/services/file-system/index.js +12 -0
- package/dist/services/file-system/live.impl.js +26 -0
- package/dist/services/generator/target/index.js +5 -0
- package/dist/services/generator/target/parsing.js +64 -0
- package/dist/services/generator/target/types.js +2 -0
- package/dist/services/generator.js +40 -0
- package/dist/services/logger.js +23 -0
- package/dist/services/method-generator.js +81 -0
- package/dist/services/package-manager/common.js +74 -0
- package/dist/services/package-manager/index.js +21 -0
- package/dist/services/package-manager/live.impl.js +35 -0
- package/dist/services/package-manager/npm.impl.js +8 -0
- package/dist/services/package-manager/pnpm.impl.js +8 -0
- package/dist/services/package-manager/rush.impl.js +50 -0
- package/dist/services/package-manager/yarn.impl.js +8 -0
- package/dist/services/process/index.js +12 -0
- package/dist/services/process/live.impl.js +30 -0
- package/dist/services/project-checker.js +152 -0
- package/dist/services/provider-service.js +53 -0
- package/dist/services/semver.js +29 -0
- package/dist/services/stub-publisher.js +42 -0
- package/dist/services/user-prompt.js +31 -0
- package/dist/templates/command.stub +17 -0
- package/dist/templates/entity.stub +22 -0
- package/dist/templates/event-handler.stub +8 -0
- package/dist/templates/event.stub +16 -0
- package/dist/templates/query.stub +17 -0
- package/dist/templates/read-model.stub +24 -0
- package/dist/templates/scheduled-command.stub +13 -0
- package/dist/templates/type.stub +7 -0
- package/package.json +91 -0
|
@@ -0,0 +1,85 @@
|
|
|
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 script_js_1 = require("../../common/script.js");
|
|
7
|
+
const brand_js_1 = tslib_1.__importDefault(require("../../common/brand.js"));
|
|
8
|
+
const index_js_1 = require("../../services/generator/target/index.js");
|
|
9
|
+
const path = tslib_1.__importStar(require("path"));
|
|
10
|
+
const generator_js_1 = require("../../services/generator.js");
|
|
11
|
+
const project_checker_js_1 = require("../../services/project-checker.js");
|
|
12
|
+
const filenames_js_1 = require("../../common/filenames.js");
|
|
13
|
+
class ReadModel extends base_command_js_1.default {
|
|
14
|
+
async run() {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const { args, flags } = await this.parse(ReadModel);
|
|
17
|
+
try {
|
|
18
|
+
const fields = (_a = flags.fields) !== null && _a !== void 0 ? _a : [];
|
|
19
|
+
const projections = (_b = flags.projects) !== null && _b !== void 0 ? _b : [];
|
|
20
|
+
if (!args.readModelName)
|
|
21
|
+
throw "You haven't provided a read model name, but it is required, run with --help for usage";
|
|
22
|
+
return run(args.readModelName, fields, projections);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error(error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
ReadModel.description = 'create a new read model';
|
|
30
|
+
ReadModel.flags = {
|
|
31
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
32
|
+
fields: core_1.Flags.string({
|
|
33
|
+
char: 'f',
|
|
34
|
+
description: 'fields that this read model will contain',
|
|
35
|
+
multiple: true,
|
|
36
|
+
}),
|
|
37
|
+
projects: core_1.Flags.string({
|
|
38
|
+
char: 'p',
|
|
39
|
+
description: 'entities that this read model will project to build its state',
|
|
40
|
+
multiple: true,
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
ReadModel.args = {
|
|
44
|
+
readModelName: core_1.Args.string(),
|
|
45
|
+
};
|
|
46
|
+
exports.default = ReadModel;
|
|
47
|
+
const run = async (name, rawFields, rawProjections) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:read-model')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name), (0, index_js_1.parseFields)(rawFields), (0, index_js_1.parseProjections)(rawProjections)))
|
|
48
|
+
.step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
|
|
49
|
+
.step('Creating new read model', generateReadModel)
|
|
50
|
+
.info('Read model generated!')
|
|
51
|
+
.done();
|
|
52
|
+
function generateImports(info) {
|
|
53
|
+
const eventsImports = info.projections.map((projection) => {
|
|
54
|
+
const fileName = (0, filenames_js_1.classNameToFileName)(projection.entityName);
|
|
55
|
+
return {
|
|
56
|
+
packagePath: `../entities/${fileName}`,
|
|
57
|
+
commaSeparatedComponents: projection.entityName,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
const coreComponents = ['ReadModel'];
|
|
61
|
+
if (info.projections.length > 0) {
|
|
62
|
+
coreComponents.push('Projects');
|
|
63
|
+
}
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
packagePath: '@magek/core',
|
|
67
|
+
commaSeparatedComponents: coreComponents.join(', '),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
packagePath: '@magek/common',
|
|
71
|
+
commaSeparatedComponents: info.projections.length > 0 ? 'UUID, ProjectionResult' : 'UUID',
|
|
72
|
+
},
|
|
73
|
+
...eventsImports,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
const generateReadModel = (info) => (0, generator_js_1.generate)({
|
|
77
|
+
name: info.name,
|
|
78
|
+
extension: '.ts',
|
|
79
|
+
placementDir: path.join('src', 'read-models'),
|
|
80
|
+
template: (0, generator_js_1.template)('read-model'),
|
|
81
|
+
info: {
|
|
82
|
+
imports: generateImports(info),
|
|
83
|
+
...info,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
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 script_js_1 = require("../../common/script.js");
|
|
7
|
+
const brand_js_1 = tslib_1.__importDefault(require("../../common/brand.js"));
|
|
8
|
+
const generator_js_1 = require("../../services/generator.js");
|
|
9
|
+
const index_js_1 = require("../../services/generator/target/index.js");
|
|
10
|
+
const path = tslib_1.__importStar(require("path"));
|
|
11
|
+
const project_checker_js_1 = require("../../services/project-checker.js");
|
|
12
|
+
class ScheduledCommand extends base_command_js_1.default {
|
|
13
|
+
async run() {
|
|
14
|
+
const { args } = await this.parse(ScheduledCommand);
|
|
15
|
+
try {
|
|
16
|
+
if (!args.scheduledCommandName)
|
|
17
|
+
throw "You haven't provided a scheduled command name, but it is required, run with --help for usage";
|
|
18
|
+
return run(args.scheduledCommandName);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
ScheduledCommand.description = "generate new scheduled command, write 'magek new:scheduled-command -h' to see options";
|
|
26
|
+
ScheduledCommand.flags = {
|
|
27
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
28
|
+
};
|
|
29
|
+
ScheduledCommand.args = {
|
|
30
|
+
scheduledCommandName: core_1.Args.string(),
|
|
31
|
+
};
|
|
32
|
+
exports.default = ScheduledCommand;
|
|
33
|
+
const run = async (name) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:scheduled-command')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name)))
|
|
34
|
+
.step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
|
|
35
|
+
.step('Creating new scheduled command', generateScheduledCommand)
|
|
36
|
+
.info('Scheduled command generated!')
|
|
37
|
+
.done();
|
|
38
|
+
function generateImports() {
|
|
39
|
+
const componentsFromMagekTypes = ['Register'];
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
packagePath: '@magek/core',
|
|
43
|
+
commaSeparatedComponents: 'ScheduledCommand',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
packagePath: '@magek/common',
|
|
47
|
+
commaSeparatedComponents: componentsFromMagekTypes.join(', '),
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
const generateScheduledCommand = (info) => (0, generator_js_1.generate)({
|
|
52
|
+
name: info.name,
|
|
53
|
+
extension: '.ts',
|
|
54
|
+
placementDir: path.join('src', 'scheduled-commands'),
|
|
55
|
+
template: (0, generator_js_1.template)('scheduled-command'),
|
|
56
|
+
info: {
|
|
57
|
+
imports: generateImports(),
|
|
58
|
+
...info,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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 script_js_1 = require("../../common/script.js");
|
|
7
|
+
const brand_js_1 = tslib_1.__importDefault(require("../../common/brand.js"));
|
|
8
|
+
const index_js_1 = require("../../services/generator/target/index.js");
|
|
9
|
+
const generator_js_1 = require("../../services/generator.js");
|
|
10
|
+
const path = tslib_1.__importStar(require("path"));
|
|
11
|
+
const project_checker_js_1 = require("../../services/project-checker.js");
|
|
12
|
+
class Type extends base_command_js_1.default {
|
|
13
|
+
async run() {
|
|
14
|
+
const { args, flags } = await this.parse(Type);
|
|
15
|
+
try {
|
|
16
|
+
const fields = flags.fields || [];
|
|
17
|
+
if (!args.typeName)
|
|
18
|
+
throw "You haven't provided a type name, but it is required, run with --help for usage";
|
|
19
|
+
return run(args.typeName, fields);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
Type.description = 'create a new type';
|
|
27
|
+
Type.flags = {
|
|
28
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
29
|
+
fields: core_1.Flags.string({
|
|
30
|
+
char: 'f',
|
|
31
|
+
description: 'field that this type will contain',
|
|
32
|
+
multiple: true,
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
Type.args = {
|
|
36
|
+
typeName: core_1.Args.string(),
|
|
37
|
+
};
|
|
38
|
+
exports.default = Type;
|
|
39
|
+
const run = async (name, rawFields) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:type')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name), (0, index_js_1.parseFields)(rawFields)))
|
|
40
|
+
.step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
|
|
41
|
+
.step('Creating new type', generateType)
|
|
42
|
+
.info('Type generated!')
|
|
43
|
+
.done();
|
|
44
|
+
const generateType = (info) => (0, generator_js_1.generate)({
|
|
45
|
+
name: info.name,
|
|
46
|
+
extension: '.ts',
|
|
47
|
+
placementDir: path.join('src', 'common'),
|
|
48
|
+
template: (0, generator_js_1.template)('type'),
|
|
49
|
+
info: {
|
|
50
|
+
imports: [],
|
|
51
|
+
...info,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
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;
|
|
@@ -0,0 +1,52 @@
|
|
|
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;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 script_js_1 = require("../../common/script.js");
|
|
7
|
+
const brand_js_1 = tslib_1.__importDefault(require("../../common/brand.js"));
|
|
8
|
+
const stub_publisher_js_1 = require("../../services/stub-publisher.js");
|
|
9
|
+
const project_checker_js_1 = require("../../services/project-checker.js");
|
|
10
|
+
const user_prompt_js_1 = tslib_1.__importDefault(require("../../services/user-prompt.js"));
|
|
11
|
+
class Publish extends base_command_js_1.default {
|
|
12
|
+
async run() {
|
|
13
|
+
const { flags } = await this.parse(Publish);
|
|
14
|
+
const stubFolderExists = (0, stub_publisher_js_1.checkStubsFolderExists)();
|
|
15
|
+
if (!stubFolderExists) {
|
|
16
|
+
(0, stub_publisher_js_1.createStubsFolder)();
|
|
17
|
+
}
|
|
18
|
+
if (stubFolderExists && !flags.force) {
|
|
19
|
+
await user_prompt_js_1.default.confirmPrompt({
|
|
20
|
+
message: brand_js_1.default.dangerize('Stubs folder already exists. Do you want to overwrite it?'),
|
|
21
|
+
}).then((confirm) => {
|
|
22
|
+
if (!confirm) {
|
|
23
|
+
throw new Error(brand_js_1.default.dangerize('Stubs folder already exists. Use --force option to overwrite files in it'));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
await run();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
Publish.description = 'publish all resource template stubs that are available for customization';
|
|
31
|
+
Publish.usage = 'magek stub:publish --force';
|
|
32
|
+
Publish.examples = ['$ magek stub:publish --force', '$ magek stub:publish'];
|
|
33
|
+
Publish.flags = {
|
|
34
|
+
force: core_1.Flags.boolean({
|
|
35
|
+
char: 'f',
|
|
36
|
+
description: 'Overwrite any existing stub files',
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
exports.default = Publish;
|
|
40
|
+
const run = async () => script_js_1.Script.init(`magek ${brand_js_1.default.energize('stub:publish')} 🗄`, Promise.resolve(process.cwd()))
|
|
41
|
+
.step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
|
|
42
|
+
.step('Publishing stubs', stub_publisher_js_1.publishStubFiles)
|
|
43
|
+
.info('Resource template stubs published!')
|
|
44
|
+
.done();
|
|
@@ -0,0 +1,45 @@
|
|
|
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;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const project_checker_js_1 = require("../services/project-checker.js");
|
|
5
|
+
const logger_js_1 = require("../services/logger.js");
|
|
6
|
+
class BaseCommand extends core_1.Command {
|
|
7
|
+
async init() {
|
|
8
|
+
await (0, project_checker_js_1.checkCurrentDirMagekVersion)(this.config.version);
|
|
9
|
+
}
|
|
10
|
+
async catch(fullError) {
|
|
11
|
+
const errorMessage = fullError.message.split('\n')[0].replace('Error:', '');
|
|
12
|
+
const logRefMessage = '\n(You can see the full error logs in ./errors.log)';
|
|
13
|
+
const errorForFile = `\nmagek ${this.id} ${this.argv.join(' ')}\n${fullError.message}`;
|
|
14
|
+
(0, logger_js_1.appendOnErrorsFile)(errorForFile);
|
|
15
|
+
return super.catch(new Error(errorMessage + logRefMessage));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = BaseCommand;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
|
+
/**
|
|
6
|
+
* Class to output text with proper Magek brand colors
|
|
7
|
+
*/
|
|
8
|
+
class Brand {
|
|
9
|
+
/**
|
|
10
|
+
* Apply a dangerous feeling (red) to some text
|
|
11
|
+
* @param text
|
|
12
|
+
*/
|
|
13
|
+
static dangerize(text) {
|
|
14
|
+
return chalk_1.default.hex('#FA6E59')(text);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Apply a mellancholic blue color to some text
|
|
18
|
+
* @param text
|
|
19
|
+
*/
|
|
20
|
+
static mellancholize(text) {
|
|
21
|
+
return chalk_1.default.hex('#4797D8')(text);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Apply a nice canary yellow tone to some text
|
|
25
|
+
* @param text
|
|
26
|
+
*/
|
|
27
|
+
static canarize(text) {
|
|
28
|
+
return chalk_1.default.hex('#FFD243')(text);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Apply an energic orange tone to some text
|
|
32
|
+
* @param text
|
|
33
|
+
*/
|
|
34
|
+
static energize(text) {
|
|
35
|
+
return chalk_1.default.hex('#FF8D40')(text);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = Brand;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unknownToError = exports.guardError = void 0;
|
|
4
|
+
exports.wrapExecError = wrapExecError;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const brand_js_1 = tslib_1.__importDefault(require("./brand.js"));
|
|
7
|
+
/**
|
|
8
|
+
* Builds an error extracting its message from the "stdout" and "stderr" properties if present
|
|
9
|
+
* @param e
|
|
10
|
+
* @param prefix
|
|
11
|
+
*/
|
|
12
|
+
function wrapExecError(e, prefix) {
|
|
13
|
+
const { stdout, stderr } = e;
|
|
14
|
+
return new Error(brand_js_1.default.dangerize(prefix) + '\n' + stdout + stderr);
|
|
15
|
+
}
|
|
16
|
+
const guardError = (prefix) => (err) => {
|
|
17
|
+
return new Error(brand_js_1.default.dangerize(`[${err.name}] ${prefix}:`) + '\n' + err.message);
|
|
18
|
+
};
|
|
19
|
+
exports.guardError = guardError;
|
|
20
|
+
/**
|
|
21
|
+
* Converts an unknown value to an Error. If it's not an error already, it will be stringified.
|
|
22
|
+
*/
|
|
23
|
+
const unknownToError = (reason) => reason instanceof Error ? reason : new Error(JSON.stringify(reason));
|
|
24
|
+
exports.unknownToError = unknownToError;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkResourceNameIsValid = exports.fileNameWithExtension = exports.classNameToFileName = exports.filenames = exports.titleCaseString = void 0;
|
|
4
|
+
exports.formatResourceName = formatResourceName;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const inflected = tslib_1.__importStar(require("inflected"));
|
|
7
|
+
const classNameToFileNameImpl = (name) => inflected.dasherize(inflected.underscore(name));
|
|
8
|
+
const fileNameWithExtensionImpl = (name, extension = 'ts') => (classNameToFileNameImpl(name) + '.' + extension).toLowerCase();
|
|
9
|
+
const checkResourceNameIsValidImpl = (name) => {
|
|
10
|
+
if (!hasValidResourceName(name))
|
|
11
|
+
throw new Error(`'${name}' is not valid resource name. Please use PascalCase name with valid characters.`);
|
|
12
|
+
};
|
|
13
|
+
function hasValidResourceName(name) {
|
|
14
|
+
const resourceName = formatResourceName(name);
|
|
15
|
+
return resourceName === name;
|
|
16
|
+
}
|
|
17
|
+
function formatResourceName(name) {
|
|
18
|
+
const resourceName = name
|
|
19
|
+
.replace(/^[\d-]|[#$-/:-?{-~!"^_`[\]]/g, ' ')
|
|
20
|
+
.replace(/\s+/g, ' ')
|
|
21
|
+
.trim();
|
|
22
|
+
if (resourceName === '')
|
|
23
|
+
return null;
|
|
24
|
+
if (resourceName.length === 1)
|
|
25
|
+
return resourceName.toLocaleUpperCase();
|
|
26
|
+
const match = resourceName.match(/[a-zA-Z\d]+/g);
|
|
27
|
+
if (match)
|
|
28
|
+
return match.map(exports.titleCaseString).join('');
|
|
29
|
+
return resourceName;
|
|
30
|
+
}
|
|
31
|
+
const titleCaseString = (value) => value[0].toLocaleUpperCase() + value.slice(1);
|
|
32
|
+
exports.titleCaseString = titleCaseString;
|
|
33
|
+
exports.filenames = {
|
|
34
|
+
classNameToFileName: classNameToFileNameImpl,
|
|
35
|
+
fileNameWithExtension: fileNameWithExtensionImpl,
|
|
36
|
+
checkResourceNameIsValid: checkResourceNameIsValidImpl,
|
|
37
|
+
formatResourceName,
|
|
38
|
+
titleCaseString: exports.titleCaseString,
|
|
39
|
+
};
|
|
40
|
+
const classNameToFileName = (...args) => exports.filenames.classNameToFileName(...args);
|
|
41
|
+
exports.classNameToFileName = classNameToFileName;
|
|
42
|
+
const fileNameWithExtension = (...args) => exports.filenames.fileNameWithExtension(...args);
|
|
43
|
+
exports.fileNameWithExtension = fileNameWithExtension;
|
|
44
|
+
const checkResourceNameIsValid = (...args) => exports.filenames.checkResourceNameIsValid(...args);
|
|
45
|
+
exports.checkResourceNameIsValid = checkResourceNameIsValid;
|
|
@@ -0,0 +1,45 @@
|
|
|
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;
|