@magek/cli 0.0.6 → 0.0.8

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.
@@ -9,6 +9,27 @@ const brand_js_1 = tslib_1.__importDefault(require("../../common/brand.js"));
9
9
  const project_checker_js_1 = require("../../services/project-checker.js");
10
10
  const method_generator_js_1 = require("../../services/method-generator.js");
11
11
  class Projection extends base_command_js_1.default {
12
+ static description = 'add new projection to read model';
13
+ static usage = 'projection --read-model ReadModel --entity Entity:id';
14
+ static examples = [
15
+ '$ magek add:projection --read-model PostReadModel --entity Post:id',
16
+ '$ magek add:projection --read-model CommentReadModel --entity Comment:id',
17
+ ];
18
+ static flags = {
19
+ help: core_1.Flags.help({ char: 'h' }),
20
+ 'read-model': core_1.Flags.string({
21
+ description: 'read-model name',
22
+ required: true,
23
+ multiple: false,
24
+ dependsOn: ['entity'],
25
+ }),
26
+ entity: core_1.Flags.string({
27
+ description: 'an entity name',
28
+ required: true,
29
+ multiple: false,
30
+ dependsOn: ['read-model'],
31
+ }),
32
+ };
12
33
  async run() {
13
34
  const { flags } = await this.parse(Projection);
14
35
  const readModel = flags['read-model'];
@@ -16,27 +37,6 @@ class Projection extends base_command_js_1.default {
16
37
  return run(readModel, entity);
17
38
  }
18
39
  }
19
- Projection.description = 'add new projection to read model';
20
- Projection.usage = 'projection --read-model ReadModel --entity Entity:id';
21
- Projection.examples = [
22
- '$ magek add:projection --read-model PostReadModel --entity Post:id',
23
- '$ magek add:projection --read-model CommentReadModel --entity Comment:id',
24
- ];
25
- Projection.flags = {
26
- help: core_1.Flags.help({ char: 'h' }),
27
- 'read-model': core_1.Flags.string({
28
- description: 'read-model name',
29
- required: true,
30
- multiple: false,
31
- dependsOn: ['entity'],
32
- }),
33
- entity: core_1.Flags.string({
34
- description: 'an entity name',
35
- required: true,
36
- multiple: false,
37
- dependsOn: ['read-model'],
38
- }),
39
- };
40
40
  exports.default = Projection;
41
41
  const run = async (rawReadModel, rawProjection) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('add:projection')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(rawReadModel), (0, index_js_1.parseProjectionField)(rawProjection)))
42
42
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -9,6 +9,27 @@ const brand_js_1 = tslib_1.__importDefault(require("../../common/brand.js"));
9
9
  const project_checker_js_1 = require("../../services/project-checker.js");
10
10
  const method_generator_js_1 = require("../../services/method-generator.js");
11
11
  class Reducer extends base_command_js_1.default {
12
+ static description = 'add new reducer to entity';
13
+ static usage = 'reducer --entity Entity --event Event';
14
+ static examples = [
15
+ '$ magek add:reducer --entity Post --event PostCreated',
16
+ '$ magek add:reducer --entity Comment --event CommentUpdated CommentVoted',
17
+ ];
18
+ static flags = {
19
+ help: core_1.Flags.help({ char: 'h' }),
20
+ entity: core_1.Flags.string({
21
+ description: 'an entity name',
22
+ required: true,
23
+ multiple: false,
24
+ dependsOn: ['event'],
25
+ }),
26
+ event: core_1.Flags.string({
27
+ description: 'an event name',
28
+ required: true,
29
+ multiple: true,
30
+ dependsOn: ['entity'],
31
+ }),
32
+ };
12
33
  async run() {
13
34
  const { flags } = await this.parse(Reducer);
14
35
  const entity = flags.entity;
@@ -16,27 +37,6 @@ class Reducer extends base_command_js_1.default {
16
37
  return run(entity, events);
17
38
  }
18
39
  }
19
- Reducer.description = 'add new reducer to entity';
20
- Reducer.usage = 'reducer --entity Entity --event Event';
21
- Reducer.examples = [
22
- '$ magek add:reducer --entity Post --event PostCreated',
23
- '$ magek add:reducer --entity Comment --event CommentUpdated CommentVoted',
24
- ];
25
- Reducer.flags = {
26
- help: core_1.Flags.help({ char: 'h' }),
27
- entity: core_1.Flags.string({
28
- description: 'an entity name',
29
- required: true,
30
- multiple: false,
31
- dependsOn: ['event'],
32
- }),
33
- event: core_1.Flags.string({
34
- description: 'an event name',
35
- required: true,
36
- multiple: true,
37
- dependsOn: ['entity'],
38
- }),
39
- };
40
40
  exports.default = Reducer;
41
41
  const pluralize = (word, count) => (count === 1 ? word : `${word}s`);
42
42
  const run = async (rawEntity, rawEvents) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('add:reducer')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(rawEntity), (0, index_js_1.parseReaction)(rawEvents)))
@@ -13,6 +13,14 @@ const runTasks = async (clean) => script_js_1.Script.init(`magek ${brand_js_1.de
13
13
  .info('Clean complete!')
14
14
  .done();
15
15
  class Clean extends base_command_js_1.default {
16
+ static description = 'Clean the current application as configured in your `index.ts` file.';
17
+ static flags = {
18
+ help: core_1.Flags.help({ char: 'h' }),
19
+ verbose: core_1.Flags.boolean({
20
+ description: 'display full error messages',
21
+ default: false,
22
+ }),
23
+ };
16
24
  async run() {
17
25
  await runTasks((ctx) => (0, config_service_js_1.cleanProject)(process.cwd()));
18
26
  }
@@ -24,12 +32,4 @@ class Clean extends base_command_js_1.default {
24
32
  return super.catch(fullError);
25
33
  }
26
34
  }
27
- Clean.description = 'Clean the current application as configured in your `index.ts` file.';
28
- Clean.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
35
  exports.default = Clean;
@@ -10,6 +10,18 @@ const index_js_1 = require("../../services/generator/target/index.js");
10
10
  const path = tslib_1.__importStar(require("path"));
11
11
  const project_checker_js_1 = require("../../services/project-checker.js");
12
12
  class Command extends base_command_js_1.default {
13
+ static description = "Generate new resource, write 'magek new' to see options";
14
+ static flags = {
15
+ help: core_1.Flags.help({ char: 'h' }),
16
+ fields: core_1.Flags.string({
17
+ char: 'f',
18
+ description: 'Field that this command will contain',
19
+ multiple: true,
20
+ }),
21
+ };
22
+ static args = {
23
+ commandName: core_1.Args.string(),
24
+ };
13
25
  async run() {
14
26
  const { args, flags } = await this.parse(Command);
15
27
  try {
@@ -23,18 +35,6 @@ class Command extends base_command_js_1.default {
23
35
  }
24
36
  }
25
37
  }
26
- Command.description = "Generate new resource, write 'magek new' to see options";
27
- Command.flags = {
28
- help: core_1.Flags.help({ char: 'h' }),
29
- fields: core_1.Flags.string({
30
- char: 'f',
31
- description: 'Field that this command will contain',
32
- multiple: true,
33
- }),
34
- };
35
- Command.args = {
36
- commandName: core_1.Args.string(),
37
- };
38
38
  exports.default = Command;
39
39
  const run = async (name, rawFields) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:command')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name), (0, index_js_1.parseFields)(rawFields)))
40
40
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -11,6 +11,23 @@ const generator_js_1 = require("../../services/generator.js");
11
11
  const project_checker_js_1 = require("../../services/project-checker.js");
12
12
  const filenames_js_1 = require("../../common/filenames.js");
13
13
  class Entity extends base_command_js_1.default {
14
+ static description = 'create a new entity';
15
+ static flags = {
16
+ help: core_1.Flags.help({ char: 'h' }),
17
+ fields: core_1.Flags.string({
18
+ char: 'f',
19
+ description: 'fields that this entity will contain',
20
+ multiple: true,
21
+ }),
22
+ reduces: core_1.Flags.string({
23
+ char: 'r',
24
+ description: 'events that this entity will reduce to build its state',
25
+ multiple: true,
26
+ }),
27
+ };
28
+ static args = {
29
+ entityName: core_1.Args.string(),
30
+ };
14
31
  async run() {
15
32
  const { args, flags } = await this.parse(Entity);
16
33
  try {
@@ -25,23 +42,6 @@ class Entity extends base_command_js_1.default {
25
42
  }
26
43
  }
27
44
  }
28
- Entity.description = 'create a new entity';
29
- Entity.flags = {
30
- help: core_1.Flags.help({ char: 'h' }),
31
- fields: core_1.Flags.string({
32
- char: 'f',
33
- description: 'fields that this entity will contain',
34
- multiple: true,
35
- }),
36
- reduces: core_1.Flags.string({
37
- char: 'r',
38
- description: 'events that this entity will reduce to build its state',
39
- multiple: true,
40
- }),
41
- };
42
- Entity.args = {
43
- entityName: core_1.Args.string(),
44
- };
45
45
  exports.default = Entity;
46
46
  const run = async (name, rawFields, rawEvents) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:entity')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name), (0, index_js_1.parseFields)(rawFields), (0, index_js_1.parseReaction)(rawEvents)))
47
47
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -11,6 +11,18 @@ const generator_js_1 = require("../../services/generator.js");
11
11
  const path = tslib_1.__importStar(require("path"));
12
12
  const filenames_js_1 = require("../../common/filenames.js");
13
13
  class EventHandler extends base_command_js_1.default {
14
+ static description = 'create a new event handler';
15
+ static flags = {
16
+ help: core_1.Flags.help({ char: 'h' }),
17
+ event: core_1.Flags.string({
18
+ char: 'e',
19
+ description: 'event that this event handler with handle',
20
+ multiple: false,
21
+ }),
22
+ };
23
+ static args = {
24
+ eventHandlerName: core_1.Args.string(),
25
+ };
14
26
  async run() {
15
27
  const { args, flags } = await this.parse(EventHandler);
16
28
  try {
@@ -26,18 +38,6 @@ class EventHandler extends base_command_js_1.default {
26
38
  }
27
39
  }
28
40
  }
29
- EventHandler.description = 'create a new event handler';
30
- EventHandler.flags = {
31
- help: core_1.Flags.help({ char: 'h' }),
32
- event: core_1.Flags.string({
33
- char: 'e',
34
- description: 'event that this event handler with handle',
35
- multiple: false,
36
- }),
37
- };
38
- EventHandler.args = {
39
- eventHandlerName: core_1.Args.string(),
40
- };
41
41
  exports.default = EventHandler;
42
42
  const run = async (name, eventName) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:event-handler')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name), (0, index_js_1.parseEvent)(eventName)))
43
43
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -10,6 +10,18 @@ const generator_js_1 = require("../../services/generator.js");
10
10
  const path = tslib_1.__importStar(require("path"));
11
11
  const project_checker_js_1 = require("../../services/project-checker.js");
12
12
  class Event extends base_command_js_1.default {
13
+ static description = 'create a new event';
14
+ static flags = {
15
+ help: core_1.Flags.help({ char: 'h' }),
16
+ fields: core_1.Flags.string({
17
+ char: 'f',
18
+ description: 'field that this event will contain',
19
+ multiple: true,
20
+ }),
21
+ };
22
+ static args = {
23
+ eventName: core_1.Args.string(),
24
+ };
13
25
  async run() {
14
26
  const { args, flags } = await this.parse(Event);
15
27
  try {
@@ -23,18 +35,6 @@ class Event extends base_command_js_1.default {
23
35
  }
24
36
  }
25
37
  }
26
- Event.description = 'create a new event';
27
- Event.flags = {
28
- help: core_1.Flags.help({ char: 'h' }),
29
- fields: core_1.Flags.string({
30
- char: 'f',
31
- description: 'field that this event will contain',
32
- multiple: true,
33
- }),
34
- };
35
- Event.args = {
36
- eventName: core_1.Args.string(),
37
- };
38
38
  exports.default = Event;
39
39
  const run = async (name, rawFields) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:event')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name), (0, index_js_1.parseFields)(rawFields)))
40
40
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -10,6 +10,18 @@ const index_js_1 = require("../../services/generator/target/index.js");
10
10
  const path = tslib_1.__importStar(require("path"));
11
11
  const project_checker_js_1 = require("../../services/project-checker.js");
12
12
  class Query extends base_command_js_1.default {
13
+ static description = "generate new query resource, write 'magek new' to see options";
14
+ static flags = {
15
+ help: core_1.Flags.help({ char: 'h' }),
16
+ fields: core_1.Flags.string({
17
+ char: 'f',
18
+ description: 'field list that this query will contain',
19
+ multiple: true,
20
+ }),
21
+ };
22
+ static args = {
23
+ queryName: core_1.Args.string(),
24
+ };
13
25
  async run() {
14
26
  const { args, flags } = await this.parse(Query);
15
27
  try {
@@ -23,18 +35,6 @@ class Query extends base_command_js_1.default {
23
35
  }
24
36
  }
25
37
  }
26
- Query.description = "generate new query resource, write 'magek new' to see options";
27
- Query.flags = {
28
- help: core_1.Flags.help({ char: 'h' }),
29
- fields: core_1.Flags.string({
30
- char: 'f',
31
- description: 'field list that this query will contain',
32
- multiple: true,
33
- }),
34
- };
35
- Query.args = {
36
- queryName: core_1.Args.string(),
37
- };
38
38
  exports.default = Query;
39
39
  const run = async (name, rawFields) => script_js_1.Script.init(`magek ${brand_js_1.default.energize('new:query')} 🚧`, (0, index_js_1.joinParsers)((0, index_js_1.parseName)(name), (0, index_js_1.parseFields)(rawFields)))
40
40
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -54,7 +54,7 @@ function generateImports(info) {
54
54
  return [
55
55
  {
56
56
  packagePath: '@magek/core',
57
- commaSeparatedComponents: 'Query',
57
+ commaSeparatedComponents: 'Query, returns',
58
58
  },
59
59
  {
60
60
  packagePath: '@magek/common',
@@ -11,12 +11,28 @@ const generator_js_1 = require("../../services/generator.js");
11
11
  const project_checker_js_1 = require("../../services/project-checker.js");
12
12
  const filenames_js_1 = require("../../common/filenames.js");
13
13
  class ReadModel extends base_command_js_1.default {
14
+ static description = 'create a new read model';
15
+ static flags = {
16
+ help: core_1.Flags.help({ char: 'h' }),
17
+ fields: core_1.Flags.string({
18
+ char: 'f',
19
+ description: 'fields that this read model will contain',
20
+ multiple: true,
21
+ }),
22
+ projects: core_1.Flags.string({
23
+ char: 'p',
24
+ description: 'entities that this read model will project to build its state',
25
+ multiple: true,
26
+ }),
27
+ };
28
+ static args = {
29
+ readModelName: core_1.Args.string(),
30
+ };
14
31
  async run() {
15
- var _a, _b;
16
32
  const { args, flags } = await this.parse(ReadModel);
17
33
  try {
18
- const fields = (_a = flags.fields) !== null && _a !== void 0 ? _a : [];
19
- const projections = (_b = flags.projects) !== null && _b !== void 0 ? _b : [];
34
+ const fields = flags.fields ?? [];
35
+ const projections = flags.projects ?? [];
20
36
  if (!args.readModelName)
21
37
  throw "You haven't provided a read model name, but it is required, run with --help for usage";
22
38
  return run(args.readModelName, fields, projections);
@@ -26,23 +42,6 @@ class ReadModel extends base_command_js_1.default {
26
42
  }
27
43
  }
28
44
  }
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
45
  exports.default = ReadModel;
47
46
  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
47
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -10,6 +10,13 @@ const index_js_1 = require("../../services/generator/target/index.js");
10
10
  const path = tslib_1.__importStar(require("path"));
11
11
  const project_checker_js_1 = require("../../services/project-checker.js");
12
12
  class ScheduledCommand extends base_command_js_1.default {
13
+ static description = "generate new scheduled command, write 'magek new:scheduled-command -h' to see options";
14
+ static flags = {
15
+ help: core_1.Flags.help({ char: 'h' }),
16
+ };
17
+ static args = {
18
+ scheduledCommandName: core_1.Args.string(),
19
+ };
13
20
  async run() {
14
21
  const { args } = await this.parse(ScheduledCommand);
15
22
  try {
@@ -22,13 +29,6 @@ class ScheduledCommand extends base_command_js_1.default {
22
29
  }
23
30
  }
24
31
  }
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
32
  exports.default = ScheduledCommand;
33
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
34
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -10,6 +10,18 @@ const generator_js_1 = require("../../services/generator.js");
10
10
  const path = tslib_1.__importStar(require("path"));
11
11
  const project_checker_js_1 = require("../../services/project-checker.js");
12
12
  class Type extends base_command_js_1.default {
13
+ static description = 'create a new type';
14
+ static flags = {
15
+ help: core_1.Flags.help({ char: 'h' }),
16
+ fields: core_1.Flags.string({
17
+ char: 'f',
18
+ description: 'field that this type will contain',
19
+ multiple: true,
20
+ }),
21
+ };
22
+ static args = {
23
+ typeName: core_1.Args.string(),
24
+ };
13
25
  async run() {
14
26
  const { args, flags } = await this.parse(Type);
15
27
  try {
@@ -23,18 +35,6 @@ class Type extends base_command_js_1.default {
23
35
  }
24
36
  }
25
37
  }
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
38
  exports.default = Type;
39
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
40
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -9,6 +9,15 @@ const stub_publisher_js_1 = require("../../services/stub-publisher.js");
9
9
  const project_checker_js_1 = require("../../services/project-checker.js");
10
10
  const user_prompt_js_1 = tslib_1.__importDefault(require("../../services/user-prompt.js"));
11
11
  class Publish extends base_command_js_1.default {
12
+ static description = 'publish all resource template stubs that are available for customization';
13
+ static usage = 'magek stub:publish --force';
14
+ static examples = ['$ magek stub:publish --force', '$ magek stub:publish'];
15
+ static flags = {
16
+ force: core_1.Flags.boolean({
17
+ char: 'f',
18
+ description: 'Overwrite any existing stub files',
19
+ }),
20
+ };
12
21
  async run() {
13
22
  const { flags } = await this.parse(Publish);
14
23
  const stubFolderExists = (0, stub_publisher_js_1.checkStubsFolderExists)();
@@ -27,15 +36,6 @@ class Publish extends base_command_js_1.default {
27
36
  await run();
28
37
  }
29
38
  }
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
39
  exports.default = Publish;
40
40
  const run = async () => script_js_1.Script.init(`magek ${brand_js_1.default.energize('stub:publish')} 🗄`, Promise.resolve(process.cwd()))
41
41
  .step('Verifying project', project_checker_js_1.checkCurrentDirIsAMagekProject)
@@ -14,60 +14,72 @@ const brand_js_1 = tslib_1.__importDefault(require("./brand.js"));
14
14
  * implicitly, and makes it available for all of the steps that define this process.
15
15
  */
16
16
  class Script {
17
+ contextResolver;
18
+ errorHandlers;
19
+ action;
17
20
  constructor(contextResolver, errorHandlers, action) {
18
- /**
19
- * Method that eases the creation of steps. It accepts a message to be shown in the spinner and a
20
- * function that receives the context and the input from the previous step.
21
- * From this function you must return a Promise that resolves with the value that you want to pass to the next step (if any)
22
- *
23
- * @param message Message to initialize the spinner
24
- * @param action Function that receives the config object and performs an action
25
- */
26
- this.step = (message, action) => new Script(this.contextResolver, this.errorHandlers, (0, pipeable_js_1.pipe)(this.action, (0, ReaderTaskEither_js_1.chain)(() => (0, ReaderTaskEither_js_1.ask)()), (0, ReaderTaskEither_js_1.chain)((ctx) => (0, ReaderTaskEither_js_1.fromTaskEither)((0, TaskEither_js_1.tryCatch)(async () => {
27
- Script.logger.start(message);
28
- await action(ctx);
29
- Script.logger.succeed(message);
30
- }, (err) => {
31
- Script.logger.fail(message);
32
- return err;
33
- })))));
34
- /**
35
- * Function to determine next action depending on passed boolean condition
36
- * If condition is true, step will be skipped and info action will be called.
37
- * Otherwise, step method will be called as usual.
38
- *
39
- * @param skipCondition When true, the action is skipped
40
- * @param message Message to initialize the spinner
41
- * @param action Function that receives the config object and performs an action
42
- */
43
- this.optionalStep = (skipCondition, message, action) => {
44
- if (skipCondition)
45
- return this.info(brand_js_1.default.mellancholize(`Skipping: ${message}`));
46
- return this.step(message, action);
47
- };
48
- /**
49
- * Convenience method to generate a step that just prints a message with a small blue `i` character in front of it.
50
- *
51
- * @param message Message to be shown in the CLI
52
- */
53
- this.info = (message) => new Script(this.contextResolver, this.errorHandlers, (0, pipeable_js_1.pipe)(this.action, (0, ReaderTaskEither_js_1.chain)(() => (0, ReaderTaskEither_js_1.rightIO)(() => {
54
- Script.logger.info(message);
55
- }))));
56
- /**
57
- * Add a handler to catch a specific type of errors
58
- *
59
- * @param errorType the kind of errors that the handler will catch
60
- * @param handler handler for the errors
61
- */
62
- this.catch = (errorType, handler) => {
63
- const newHandlers = { ...this.errorHandlers };
64
- newHandlers[errorType] = handler;
65
- return new Script(this.contextResolver, newHandlers, this.action);
66
- };
67
21
  this.contextResolver = contextResolver;
68
22
  this.errorHandlers = errorHandlers;
69
23
  this.action = action;
70
24
  }
25
+ /**
26
+ * Convenience function to print a welcome message and initialize the context of the script
27
+ *
28
+ * @param initialMessage The message to show in the console
29
+ * @param contextResolver A promise that fulfills into a valid context object
30
+ */
31
+ static init = (initialMessage, contextResolver) => new Script(contextResolver, {}, (0, ReaderTaskEither_js_1.rightIO)(() => {
32
+ Script.logger.info(initialMessage);
33
+ }));
34
+ /**
35
+ * Method that eases the creation of steps. It accepts a message to be shown in the spinner and a
36
+ * function that receives the context and the input from the previous step.
37
+ * From this function you must return a Promise that resolves with the value that you want to pass to the next step (if any)
38
+ *
39
+ * @param message Message to initialize the spinner
40
+ * @param action Function that receives the config object and performs an action
41
+ */
42
+ step = (message, action) => new Script(this.contextResolver, this.errorHandlers, (0, pipeable_js_1.pipe)(this.action, (0, ReaderTaskEither_js_1.chain)(() => (0, ReaderTaskEither_js_1.ask)()), (0, ReaderTaskEither_js_1.chain)((ctx) => (0, ReaderTaskEither_js_1.fromTaskEither)((0, TaskEither_js_1.tryCatch)(async () => {
43
+ Script.logger.start(message);
44
+ await action(ctx);
45
+ Script.logger.succeed(message);
46
+ }, (err) => {
47
+ Script.logger.fail(message);
48
+ return err;
49
+ })))));
50
+ /**
51
+ * Function to determine next action depending on passed boolean condition
52
+ * If condition is true, step will be skipped and info action will be called.
53
+ * Otherwise, step method will be called as usual.
54
+ *
55
+ * @param skipCondition When true, the action is skipped
56
+ * @param message Message to initialize the spinner
57
+ * @param action Function that receives the config object and performs an action
58
+ */
59
+ optionalStep = (skipCondition, message, action) => {
60
+ if (skipCondition)
61
+ return this.info(brand_js_1.default.mellancholize(`Skipping: ${message}`));
62
+ return this.step(message, action);
63
+ };
64
+ /**
65
+ * Convenience method to generate a step that just prints a message with a small blue `i` character in front of it.
66
+ *
67
+ * @param message Message to be shown in the CLI
68
+ */
69
+ info = (message) => new Script(this.contextResolver, this.errorHandlers, (0, pipeable_js_1.pipe)(this.action, (0, ReaderTaskEither_js_1.chain)(() => (0, ReaderTaskEither_js_1.rightIO)(() => {
70
+ Script.logger.info(message);
71
+ }))));
72
+ /**
73
+ * Add a handler to catch a specific type of errors
74
+ *
75
+ * @param errorType the kind of errors that the handler will catch
76
+ * @param handler handler for the errors
77
+ */
78
+ catch = (errorType, handler) => {
79
+ const newHandlers = { ...this.errorHandlers };
80
+ newHandlers[errorType] = handler;
81
+ return new Script(this.contextResolver, newHandlers, this.action);
82
+ };
71
83
  /**
72
84
  * Function to finish the script,
73
85
  * it will handle any error in between that might happen in
@@ -88,15 +100,6 @@ class Script {
88
100
  throw new Error(handler(error));
89
101
  }
90
102
  }
103
+ static logger = logger_js_1.oraLogger;
91
104
  }
92
105
  exports.Script = Script;
93
- /**
94
- * Convenience function to print a welcome message and initialize the context of the script
95
- *
96
- * @param initialMessage The message to show in the console
97
- * @param contextResolver A promise that fulfills into a valid context object
98
- */
99
- Script.init = (initialMessage, contextResolver) => new Script(contextResolver, {}, (0, ReaderTaskEither_js_1.rightIO)(() => {
100
- Script.logger.info(initialMessage);
101
- }));
102
- Script.logger = logger_js_1.oraLogger;
@@ -17,14 +17,13 @@ const extractEnvironmentArg = () => {
17
17
  return environment;
18
18
  };
19
19
  const hook = async function (opts) {
20
- var _a;
21
20
  // ensure opts.argv is argv without the environment
22
21
  process.env['MAGEK_CLI_HOOK'] = 'true';
23
22
  if (opts.id === '-e') {
24
23
  opts.id = '';
25
- opts.argv = ['-e', ...((_a = opts.argv) !== null && _a !== void 0 ? _a : [])];
24
+ opts.argv = ['-e', ...(opts.argv ?? [])];
26
25
  }
27
- const firstArgs = process.argv.filter((arg) => { var _a; return !((_a = opts.argv) === null || _a === void 0 ? void 0 : _a.includes(arg)); });
26
+ const firstArgs = process.argv.filter((arg) => !opts.argv?.includes(arg));
28
27
  const environment = extractEnvironmentArg();
29
28
  opts.argv = process.argv.filter((arg) => !firstArgs.includes(arg));
30
29
  const cwd = process.cwd();
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileSystemError = void 0;
4
4
  class FileSystemError extends Error {
5
+ cause;
6
+ _tag = 'FileSystemError';
5
7
  constructor(message, cause) {
6
8
  super(message);
7
9
  this.cause = cause;
8
- this._tag = 'FileSystemError';
9
10
  this.name = 'FileSystemError';
10
11
  }
11
12
  }
@@ -2,19 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RunScriptError = exports.InstallDependenciesError = void 0;
4
4
  class InstallDependenciesError extends Error {
5
+ cause;
6
+ _tag = 'InstallDependenciesError';
5
7
  constructor(message, cause) {
6
8
  super(message);
7
9
  this.cause = cause;
8
- this._tag = 'InstallDependenciesError';
9
10
  this.name = 'InstallDependenciesError';
10
11
  }
11
12
  }
12
13
  exports.InstallDependenciesError = InstallDependenciesError;
13
14
  class RunScriptError extends Error {
15
+ cause;
16
+ _tag = 'RunScriptError';
14
17
  constructor(message, cause) {
15
18
  super(message);
16
19
  this.cause = cause;
17
- this._tag = 'RunScriptError';
18
20
  this.name = 'RunScriptError';
19
21
  }
20
22
  }
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProcessError = void 0;
4
4
  class ProcessError extends Error {
5
+ cause;
6
+ _tag = 'ProcessError';
5
7
  constructor(message, cause) {
6
8
  super(message);
7
9
  this.cause = cause;
8
- this._tag = 'ProcessError';
9
10
  this.name = 'ProcessError';
10
11
  }
11
12
  }
@@ -87,6 +87,9 @@ async function getMagekVersion(projectPath) {
87
87
  }
88
88
  }
89
89
  class HigherCliVersionError extends Error {
90
+ cliVersion;
91
+ projectVersion;
92
+ section;
90
93
  constructor(cliVersion, projectVersion, section) {
91
94
  super(`CLI version ${cliVersion} is higher than your project Magek version ${projectVersion} in the '${section}' section. Please upgrade your project Magek dependencies.`);
92
95
  this.cliVersion = cliVersion;
@@ -95,6 +98,9 @@ class HigherCliVersionError extends Error {
95
98
  }
96
99
  }
97
100
  class LowerCliVersionError extends Error {
101
+ cliVersion;
102
+ projectVersion;
103
+ section;
98
104
  constructor(cliVersion, projectVersion, section) {
99
105
  super(`CLI version ${cliVersion} is lower than your project Magek version ${projectVersion}. Please upgrade your @magek/cli to the same version with "npm install -g @magek/cli@${projectVersion}"`);
100
106
  this.cliVersion = cliVersion;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class Semver {
4
+ versionParts;
4
5
  constructor(semverString) {
5
6
  this.versionParts = semverString.split('.').map((v) => parseInt(v, 10));
6
7
  if (this.versionParts.length !== 3) {
@@ -7,7 +7,7 @@ import { {{commaSeparatedComponents}} } from '{{{packagePath}}}'
7
7
  })
8
8
  export class {{{ name }}} {
9
9
  {{#fields}}
10
- @Field()
10
+ @field()
11
11
  readonly {{{name}}}!: {{{type}}}
12
12
 
13
13
  {{/fields}}
@@ -4,16 +4,16 @@ import { {{commaSeparatedComponents}} } from '{{{packagePath}}}'
4
4
 
5
5
  @Entity
6
6
  export class {{{name}}} {
7
- @Field(type => UUID)
7
+ @field(type => UUID)
8
8
  public id!: UUID
9
9
 
10
10
  {{#fields}}
11
- @Field()
11
+ @field()
12
12
  readonly {{{name}}}!: {{{type}}}
13
13
 
14
14
  {{/fields}}
15
15
  {{#events}}
16
- @Reduces({{{eventName}}})
16
+ @reduces({{{eventName}}})
17
17
  public static reduce{{{eventName}}}(event: {{{eventName}}}, current{{{name}}}?: {{{name}}}): {{{name}}} {
18
18
  return /* NEW {{name}} HERE */
19
19
  }
@@ -5,7 +5,7 @@ import { {{commaSeparatedComponents}} } from '{{{packagePath}}}'
5
5
  @Event
6
6
  export class {{{ name }}} {
7
7
  {{#fields}}
8
- @Field()
8
+ @field()
9
9
  public readonly {{{name}}}!: {{{type}}}
10
10
 
11
11
  {{/fields}}
@@ -7,10 +7,11 @@ import { {{commaSeparatedComponents}} } from '{{{packagePath}}}'
7
7
  })
8
8
  export class {{{ name }}} {
9
9
  {{#fields}}
10
- @Field()
10
+ @field()
11
11
  readonly {{{name}}}!: {{{type}}}
12
12
 
13
13
  {{/fields}}
14
+ @returns(type => String)
14
15
  public static async handle(query: {{{ name }}}, queryInfo?: QueryInfo): Promise<string> {
15
16
  /* YOUR CODE HERE */
16
17
  }
@@ -6,16 +6,16 @@ import { {{commaSeparatedComponents}} } from '{{{packagePath}}}'
6
6
  authorize: // Specify authorized roles here. Use 'all' to authorize anyone
7
7
  })
8
8
  export class {{{name}}} {
9
- @Field(type => UUID)
9
+ @field(type => UUID)
10
10
  public id!: UUID
11
11
 
12
12
  {{#fields}}
13
- @Field()
13
+ @field()
14
14
  readonly {{{name}}}!: {{{type}}}
15
15
 
16
16
  {{/fields}}
17
17
  {{#projections}}
18
- @Projects({{{entityName}}}, "{{{entityId}}}")
18
+ @projects({{{entityName}}}, "{{{entityId}}}")
19
19
  public static project{{{entityName}}}(entity: {{{entityName}}}, current{{{name}}}?: {{{name}}}): ProjectionResult<{{{name}}}> {
20
20
  return /* NEW {{name}} HERE */
21
21
  }
@@ -4,7 +4,7 @@ import { {{commaSeparatedComponents}} } from '{{{packagePath}}}'
4
4
 
5
5
  export class {{{ name }}} {
6
6
  {{#fields}}
7
- @Field()
7
+ @field()
8
8
  public {{{name}}}!: {{{type}}}
9
9
 
10
10
  {{/fields}}
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.6",
4
+ "version": "0.0.8",
5
5
  "author": "Boosterin Labs SLU",
6
6
  "homepage": "https://magek.ai",
7
7
  "publishConfig": {
@@ -12,24 +12,24 @@
12
12
  },
13
13
  "bugs": "https://github.com/theam/magek/issues",
14
14
  "dependencies": {
15
- "@magek/common": "^0.0.6",
15
+ "@magek/common": "^0.0.8",
16
16
  "@oclif/core": "4.8.0",
17
- "@oclif/plugin-help": "6.2.36",
18
- "@oclif/plugin-plugins": "5.4.54",
17
+ "@oclif/plugin-help": "6.2.37",
18
+ "@oclif/plugin-plugins": "5.4.55",
19
19
  "chalk": "5.6.2",
20
20
  "execa": "9.6.1",
21
21
  "fp-ts": "2.16.11",
22
22
  "fs-extra": "11.3.3",
23
23
  "inflected": "2.1.0",
24
- "inquirer": "13.2.0",
24
+ "inquirer": "13.2.2",
25
25
  "mustache": "4.2.0",
26
26
  "ora": "9.1.0",
27
27
  "ts-morph": "27.0.2",
28
28
  "tslib": "2.8.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@magek/eslint-config": "^0.0.6",
32
- "@oclif/test": "4.1.15",
31
+ "@magek/eslint-config": "^0.0.8",
32
+ "@oclif/test": "4.1.16",
33
33
  "@types/chai": "5.2.3",
34
34
  "@types/chai-as-promised": "8.0.2",
35
35
  "@types/fs-extra": "11.0.4",