@elysiumjs/styx 0.3.0 → 0.5.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.
- package/README.md +25 -14
- package/package.json +11 -12
- package/src/commands/make_command.ts +172 -0
- package/src/commands/make_controller.ts +277 -0
- package/src/commands/make_job.ts +183 -0
- package/src/commands/make_middleware.ts +143 -0
- package/src/commands/make_model.ts +205 -0
- package/src/commands/make_repository.ts +225 -0
- package/src/commands/make_service.ts +201 -0
- package/src/commands/make_validator.ts +147 -0
- package/src/commands/migration_generate.ts +80 -0
- package/src/commands/migration_run.ts +153 -0
- package/src/commands/module_new.ts +112 -0
- package/src/commands/module_rename.ts +78 -0
- package/src/config.ts +101 -0
- package/src/styx.ts +54 -0
- package/src/utils.ts +148 -0
- package/stubs/validator.stub +30 -0
- package/styx.js +60 -60
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import type { PromptObject } from 'prompts';
|
|
16
|
+
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
import { Command, CommandArgumentType } from '@elysiumjs/core';
|
|
20
|
+
import prompts from 'prompts';
|
|
21
|
+
import { snake } from 'radash';
|
|
22
|
+
import formatter from 'string-template';
|
|
23
|
+
|
|
24
|
+
import { getModulePath, parseProjectConfig } from '../config';
|
|
25
|
+
import { getRootPath } from '../utils';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Maker class for creating Elysium.js jobs.
|
|
29
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
30
|
+
*/
|
|
31
|
+
export class MakeJobCommand extends Command {
|
|
32
|
+
public static readonly command: string = 'make:job';
|
|
33
|
+
public static readonly description: string = 'Creates a new job.';
|
|
34
|
+
|
|
35
|
+
@Command.arg({
|
|
36
|
+
description: 'The name of the job to create',
|
|
37
|
+
type: CommandArgumentType.STRING
|
|
38
|
+
})
|
|
39
|
+
private name?: string;
|
|
40
|
+
|
|
41
|
+
@Command.arg({
|
|
42
|
+
description: 'The module where the job will be created',
|
|
43
|
+
type: CommandArgumentType.STRING
|
|
44
|
+
})
|
|
45
|
+
private module?: string;
|
|
46
|
+
|
|
47
|
+
@Command.arg({
|
|
48
|
+
description: 'The alias of the job to create',
|
|
49
|
+
type: CommandArgumentType.STRING
|
|
50
|
+
})
|
|
51
|
+
private alias?: string;
|
|
52
|
+
|
|
53
|
+
@Command.arg({
|
|
54
|
+
description: 'The name of the queue where the job will be dispatched',
|
|
55
|
+
type: CommandArgumentType.STRING,
|
|
56
|
+
default: 'default'
|
|
57
|
+
})
|
|
58
|
+
private queue: string = 'default';
|
|
59
|
+
|
|
60
|
+
public async run(): Promise<void> {
|
|
61
|
+
if (!this.name) {
|
|
62
|
+
return this.setup();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const config = await parseProjectConfig();
|
|
66
|
+
|
|
67
|
+
const answers: Record<string, any> = {
|
|
68
|
+
module: this.module,
|
|
69
|
+
name: this.name,
|
|
70
|
+
alias: this.alias,
|
|
71
|
+
queue: this.queue ?? 'default'
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (!answers.module && !config.mono) {
|
|
75
|
+
const module = await prompts({
|
|
76
|
+
type: 'select',
|
|
77
|
+
name: 'module',
|
|
78
|
+
message: 'Module:',
|
|
79
|
+
choices: Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
80
|
+
title: moduleName,
|
|
81
|
+
value: moduleName
|
|
82
|
+
}))
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
answers.module = module.module;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return this.build(answers);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private async setup(): Promise<void> {
|
|
92
|
+
const config = await parseProjectConfig();
|
|
93
|
+
|
|
94
|
+
const items: PromptObject[] = [
|
|
95
|
+
{
|
|
96
|
+
type() {
|
|
97
|
+
return config.mono ? null : 'select';
|
|
98
|
+
},
|
|
99
|
+
name: 'module',
|
|
100
|
+
message: 'Module:',
|
|
101
|
+
choices() {
|
|
102
|
+
return Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
103
|
+
title: moduleName,
|
|
104
|
+
value: moduleName
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'text',
|
|
110
|
+
name: 'name',
|
|
111
|
+
message: 'Job Name:',
|
|
112
|
+
initial: 'SendEmailJob',
|
|
113
|
+
validate(value: string) {
|
|
114
|
+
if (value.length < 1) {
|
|
115
|
+
return 'Job name cannot be empty';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: 'text',
|
|
123
|
+
name: 'alias',
|
|
124
|
+
message: 'Job Alias:',
|
|
125
|
+
initial(_, values) {
|
|
126
|
+
return values.name;
|
|
127
|
+
},
|
|
128
|
+
validate(value: string) {
|
|
129
|
+
if (value.length < 1) {
|
|
130
|
+
return 'Job alias cannot be empty';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: 'text',
|
|
138
|
+
name: 'queue',
|
|
139
|
+
message: 'Job Queue:',
|
|
140
|
+
initial: 'default'
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
const answers = await prompts(items, {
|
|
145
|
+
onCancel: () => {
|
|
146
|
+
this.error('Operation cancelled.');
|
|
147
|
+
process.exit(0);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return this.build(answers);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async build(answers: Record<string, any>): Promise<void> {
|
|
155
|
+
if (!answers.name) {
|
|
156
|
+
this.error('Operation cancelled.');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!answers.name.endsWith('Job')) {
|
|
161
|
+
answers.name += 'Job';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!answers.alias) {
|
|
165
|
+
answers.alias = answers.name;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Get stub file
|
|
169
|
+
const stubFile = Bun.file(join(getRootPath(), 'stubs/job.stub'));
|
|
170
|
+
|
|
171
|
+
// Format the stub content
|
|
172
|
+
const stub = formatter(await stubFile.text(), answers);
|
|
173
|
+
|
|
174
|
+
const path = answers.module ? await getModulePath(answers.module) : './src';
|
|
175
|
+
|
|
176
|
+
// Write to file
|
|
177
|
+
const name = snake(answers.name.replace('Job', ''));
|
|
178
|
+
const file = Bun.file(`${path}/jobs/${name}.job.ts`);
|
|
179
|
+
await file.write(stub);
|
|
180
|
+
|
|
181
|
+
this.success(`Job ${this.bold(file.name!)} created successfully.`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import type { PromptObject } from 'prompts';
|
|
16
|
+
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
import { Command, CommandArgumentType } from '@elysiumjs/core';
|
|
20
|
+
import prompts from 'prompts';
|
|
21
|
+
import { snake } from 'radash';
|
|
22
|
+
import formatter from 'string-template';
|
|
23
|
+
|
|
24
|
+
import { getModulePath, parseProjectConfig } from '../config';
|
|
25
|
+
import { getRootPath } from '../utils';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Maker class for creating Elysium.js middlewares.
|
|
29
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
30
|
+
*/
|
|
31
|
+
export class MakeMiddlewareCommand extends Command {
|
|
32
|
+
public static readonly command: string = 'make:middleware';
|
|
33
|
+
public static readonly description: string = 'Creates a new middleware.';
|
|
34
|
+
|
|
35
|
+
@Command.arg({
|
|
36
|
+
description: 'The name of the middleware to create',
|
|
37
|
+
type: CommandArgumentType.STRING
|
|
38
|
+
})
|
|
39
|
+
private name?: string;
|
|
40
|
+
|
|
41
|
+
@Command.arg({
|
|
42
|
+
description: 'The module where the middleware will be created',
|
|
43
|
+
type: CommandArgumentType.STRING
|
|
44
|
+
})
|
|
45
|
+
private module?: string;
|
|
46
|
+
|
|
47
|
+
public async run(): Promise<void> {
|
|
48
|
+
if (!this.name) {
|
|
49
|
+
return this.setup();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const config = await parseProjectConfig();
|
|
53
|
+
|
|
54
|
+
const answers: Record<string, any> = {
|
|
55
|
+
module: this.module,
|
|
56
|
+
name: this.name
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (!answers.module && !config.mono) {
|
|
60
|
+
const module = await prompts({
|
|
61
|
+
type: 'select',
|
|
62
|
+
name: 'module',
|
|
63
|
+
message: 'Module:',
|
|
64
|
+
choices: Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
65
|
+
title: moduleName,
|
|
66
|
+
value: moduleName
|
|
67
|
+
}))
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
answers.module = module.module;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return this.build(answers);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private async setup(): Promise<void> {
|
|
77
|
+
const config = await parseProjectConfig();
|
|
78
|
+
|
|
79
|
+
const items: PromptObject[] = [
|
|
80
|
+
{
|
|
81
|
+
type() {
|
|
82
|
+
return config.mono ? null : 'select';
|
|
83
|
+
},
|
|
84
|
+
name: 'module',
|
|
85
|
+
message: 'Module:',
|
|
86
|
+
choices() {
|
|
87
|
+
return Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
88
|
+
title: moduleName,
|
|
89
|
+
value: moduleName
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
type: 'text',
|
|
95
|
+
name: 'name',
|
|
96
|
+
message: 'Middleware Name:',
|
|
97
|
+
initial: 'AuthMiddleware',
|
|
98
|
+
validate(value: string) {
|
|
99
|
+
if (value.length < 1) {
|
|
100
|
+
return 'Middleware name cannot be empty';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
const answers = await prompts(items, {
|
|
109
|
+
onCancel: () => {
|
|
110
|
+
this.error('Operation cancelled.');
|
|
111
|
+
process.exit(0);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return this.build(answers);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private async build(answers: Record<string, any>): Promise<void> {
|
|
119
|
+
if (!answers.name) {
|
|
120
|
+
this.error('Operation cancelled.');
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!answers.name.endsWith('Middleware')) {
|
|
125
|
+
answers.name += 'Middleware';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Get stub file
|
|
129
|
+
const stubFile = Bun.file(join(getRootPath(), 'stubs/middleware.stub'));
|
|
130
|
+
|
|
131
|
+
// Format the stub content
|
|
132
|
+
const stub = formatter(await stubFile.text(), answers);
|
|
133
|
+
|
|
134
|
+
const path = answers.module ? await getModulePath(answers.module) : './src';
|
|
135
|
+
|
|
136
|
+
// Write to file
|
|
137
|
+
const name = snake(answers.name.replace('Middleware', ''));
|
|
138
|
+
const file = Bun.file(`${path}/middlewares/${name}.middleware.ts`);
|
|
139
|
+
await file.write(stub);
|
|
140
|
+
|
|
141
|
+
this.success(`Middleware ${this.bold(file.name!)} created successfully.`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import type { PromptObject } from 'prompts';
|
|
16
|
+
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
import { Command, CommandArgumentType } from '@elysiumjs/core';
|
|
20
|
+
import prompts from 'prompts';
|
|
21
|
+
import { pascal, snake, trim } from 'radash';
|
|
22
|
+
import formatter from 'string-template';
|
|
23
|
+
|
|
24
|
+
import { getModulePath, parseProjectConfig } from '../config';
|
|
25
|
+
import { getRootPath } from '../utils';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Maker command for creating Elysium.js models.
|
|
29
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
30
|
+
*/
|
|
31
|
+
export class MakeModelCommand extends Command {
|
|
32
|
+
public static readonly command: string = 'make:model';
|
|
33
|
+
public static readonly description: string = 'Creates a new model.';
|
|
34
|
+
|
|
35
|
+
@Command.arg({
|
|
36
|
+
description: 'The name of the model to create',
|
|
37
|
+
type: CommandArgumentType.STRING
|
|
38
|
+
})
|
|
39
|
+
private name?: string;
|
|
40
|
+
|
|
41
|
+
@Command.arg({
|
|
42
|
+
description: 'The module where the model will be created',
|
|
43
|
+
type: CommandArgumentType.STRING
|
|
44
|
+
})
|
|
45
|
+
private module?: string;
|
|
46
|
+
|
|
47
|
+
@Command.arg({
|
|
48
|
+
name: 'table',
|
|
49
|
+
description: 'The name of the table wrapped by the model',
|
|
50
|
+
type: CommandArgumentType.STRING
|
|
51
|
+
})
|
|
52
|
+
private tableName?: string;
|
|
53
|
+
|
|
54
|
+
@Command.arg({
|
|
55
|
+
name: 'support-tenancy',
|
|
56
|
+
description: 'Support tenancy',
|
|
57
|
+
type: CommandArgumentType.BOOLEAN,
|
|
58
|
+
default: false
|
|
59
|
+
})
|
|
60
|
+
private supportTenancy: boolean = false;
|
|
61
|
+
|
|
62
|
+
public async run(): Promise<void> {
|
|
63
|
+
if (!this.name || !this.tableName) {
|
|
64
|
+
return this.setup();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const config = await parseProjectConfig();
|
|
68
|
+
|
|
69
|
+
const answers: Record<string, any> = {
|
|
70
|
+
module: this.module,
|
|
71
|
+
table: this.tableName,
|
|
72
|
+
name: this.name,
|
|
73
|
+
supportTenancy: this.supportTenancy
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (!answers.module && !config.mono) {
|
|
77
|
+
const module = await prompts(
|
|
78
|
+
{
|
|
79
|
+
type: 'select',
|
|
80
|
+
name: 'module',
|
|
81
|
+
message: 'Module:',
|
|
82
|
+
choices: Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
83
|
+
title: moduleName,
|
|
84
|
+
value: moduleName
|
|
85
|
+
}))
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
onCancel: () => process.exit(1)
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
answers.module = module.module;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!answers.name) {
|
|
96
|
+
answers.name = trim(pascal(answers.table), 's');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
answers.canonicalName = answers.name;
|
|
100
|
+
|
|
101
|
+
return this.build(answers);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private async setup(): Promise<void> {
|
|
105
|
+
const config = await parseProjectConfig();
|
|
106
|
+
|
|
107
|
+
const items: PromptObject[] = [
|
|
108
|
+
{
|
|
109
|
+
type() {
|
|
110
|
+
return config.mono ? null : 'select';
|
|
111
|
+
},
|
|
112
|
+
name: 'module',
|
|
113
|
+
message: 'Module:',
|
|
114
|
+
choices() {
|
|
115
|
+
return Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
116
|
+
title: moduleName,
|
|
117
|
+
value: moduleName
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: 'text',
|
|
123
|
+
name: 'table',
|
|
124
|
+
message: 'Table Name:',
|
|
125
|
+
initial: 'users',
|
|
126
|
+
validate(value: string) {
|
|
127
|
+
if (value.length < 1) {
|
|
128
|
+
return 'Table name cannot be empty';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: 'text',
|
|
136
|
+
name: 'name',
|
|
137
|
+
message: 'Model Name:',
|
|
138
|
+
initial(_, values) {
|
|
139
|
+
return trim(pascal(values.table), 's');
|
|
140
|
+
},
|
|
141
|
+
validate(value: string) {
|
|
142
|
+
if (value.length < 1) {
|
|
143
|
+
return 'Model name cannot be empty';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
type: 'select',
|
|
151
|
+
name: 'supportTenancy',
|
|
152
|
+
message: 'Support Tenancy:',
|
|
153
|
+
choices: [
|
|
154
|
+
{
|
|
155
|
+
title: 'Yes',
|
|
156
|
+
value: true,
|
|
157
|
+
description: 'The model supports multi-tenancy.'
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
title: 'No',
|
|
161
|
+
value: false,
|
|
162
|
+
description: 'The model does not support multi-tenancy.'
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
const answers = await prompts(items, {
|
|
169
|
+
onCancel: () => {
|
|
170
|
+
this.error('Operation cancelled.');
|
|
171
|
+
process.exit(0);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return this.build(answers);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private async build(answers: Record<string, any>): Promise<void> {
|
|
179
|
+
if (!answers.name) {
|
|
180
|
+
this.error('Operation cancelled.');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!answers.name.endsWith('Model')) {
|
|
185
|
+
answers.name += 'Model';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
answers.canonicalName = answers.name.replace('Model', '');
|
|
189
|
+
|
|
190
|
+
// Get stub file
|
|
191
|
+
const stubFile = Bun.file(join(getRootPath(), 'stubs/model.stub'));
|
|
192
|
+
|
|
193
|
+
// Format the stub content
|
|
194
|
+
const stub = formatter(await stubFile.text(), answers);
|
|
195
|
+
|
|
196
|
+
const path = answers.module ? await getModulePath(answers.module) : './src';
|
|
197
|
+
|
|
198
|
+
// Write to file
|
|
199
|
+
const name = snake(answers.name.replace('Model', ''));
|
|
200
|
+
const file = Bun.file(`${path}/models/${name}.model.ts`);
|
|
201
|
+
await file.write(stub);
|
|
202
|
+
|
|
203
|
+
this.success(`Model ${this.bold(file.name!)} created successfully.`);
|
|
204
|
+
}
|
|
205
|
+
}
|