@elysiumjs/styx 0.5.0 → 0.6.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/package.json +5 -4
- package/styx.js +62 -60
- package/src/commands/make_command.ts +0 -172
- package/src/commands/make_controller.ts +0 -277
- package/src/commands/make_job.ts +0 -183
- package/src/commands/make_middleware.ts +0 -143
- package/src/commands/make_model.ts +0 -205
- package/src/commands/make_repository.ts +0 -225
- package/src/commands/make_service.ts +0 -201
- package/src/commands/make_validator.ts +0 -147
- package/src/commands/migration_generate.ts +0 -80
- package/src/commands/migration_run.ts +0 -153
- package/src/commands/module_new.ts +0 -112
- package/src/commands/module_rename.ts +0 -78
- package/src/config.ts +0 -101
- package/src/styx.ts +0 -54
- package/src/utils.ts +0 -148
|
@@ -1,143 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
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 command for creating Elysium repositories.
|
|
29
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
30
|
-
*/
|
|
31
|
-
export class MakeRepositoryCommand extends Command {
|
|
32
|
-
public static readonly command: string = 'make:repository';
|
|
33
|
-
public static readonly description: string = 'Creates a new repository.';
|
|
34
|
-
|
|
35
|
-
@Command.arg({
|
|
36
|
-
description: 'The name of the repository to create',
|
|
37
|
-
type: CommandArgumentType.STRING
|
|
38
|
-
})
|
|
39
|
-
private name?: string;
|
|
40
|
-
|
|
41
|
-
@Command.arg({
|
|
42
|
-
description: 'The module where the repository will be created',
|
|
43
|
-
type: CommandArgumentType.STRING
|
|
44
|
-
})
|
|
45
|
-
private module?: string;
|
|
46
|
-
|
|
47
|
-
@Command.arg({
|
|
48
|
-
description: 'The alias of the repository to create',
|
|
49
|
-
type: CommandArgumentType.STRING
|
|
50
|
-
})
|
|
51
|
-
private alias?: string;
|
|
52
|
-
|
|
53
|
-
@Command.arg({
|
|
54
|
-
description: 'The model used by the repository',
|
|
55
|
-
type: CommandArgumentType.STRING
|
|
56
|
-
})
|
|
57
|
-
private model?: string;
|
|
58
|
-
|
|
59
|
-
@Command.arg({
|
|
60
|
-
description: 'Create a factory repository',
|
|
61
|
-
type: CommandArgumentType.BOOLEAN,
|
|
62
|
-
default: false
|
|
63
|
-
})
|
|
64
|
-
private factory: boolean = false;
|
|
65
|
-
|
|
66
|
-
@Command.arg({
|
|
67
|
-
description: 'Create a singleton repository',
|
|
68
|
-
type: CommandArgumentType.BOOLEAN,
|
|
69
|
-
default: false
|
|
70
|
-
})
|
|
71
|
-
private singleton: boolean = false;
|
|
72
|
-
|
|
73
|
-
public async run(): Promise<void> {
|
|
74
|
-
if (!this.name) {
|
|
75
|
-
return this.setup();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const config = await parseProjectConfig();
|
|
79
|
-
|
|
80
|
-
const answers: Record<string, any> = {
|
|
81
|
-
module: this.module,
|
|
82
|
-
name: this.name,
|
|
83
|
-
alias: this.alias,
|
|
84
|
-
scope: this.factory ? 'FACTORY' : this.singleton ? 'SINGLETON' : 'SINGLETON',
|
|
85
|
-
model: this.model
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (!answers.module && !config.mono) {
|
|
89
|
-
const module = await prompts({
|
|
90
|
-
type: 'select',
|
|
91
|
-
name: 'module',
|
|
92
|
-
message: 'Module:',
|
|
93
|
-
choices: Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
94
|
-
title: moduleName,
|
|
95
|
-
value: moduleName
|
|
96
|
-
}))
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
answers.module = module.module;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return this.build(answers);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private async setup(): Promise<void> {
|
|
106
|
-
const config = await parseProjectConfig();
|
|
107
|
-
|
|
108
|
-
const items: PromptObject[] = [
|
|
109
|
-
{
|
|
110
|
-
type() {
|
|
111
|
-
return config.mono ? null : 'select';
|
|
112
|
-
},
|
|
113
|
-
name: 'module',
|
|
114
|
-
message: 'Module:',
|
|
115
|
-
choices() {
|
|
116
|
-
return Object.keys(config.modules ?? {}).map((moduleName) => ({
|
|
117
|
-
title: moduleName,
|
|
118
|
-
value: moduleName
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
type: 'text',
|
|
124
|
-
name: 'name',
|
|
125
|
-
message: 'Repository Name:',
|
|
126
|
-
initial: 'UserRepository',
|
|
127
|
-
validate(value: string) {
|
|
128
|
-
if (value.length < 1) {
|
|
129
|
-
return 'Repository name cannot be empty';
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
type: 'text',
|
|
137
|
-
name: 'model',
|
|
138
|
-
message: 'Model Name:',
|
|
139
|
-
initial: 'UserModel',
|
|
140
|
-
validate(value: string) {
|
|
141
|
-
if (value.length < 1) {
|
|
142
|
-
return 'Model name cannot be empty';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
type: 'text',
|
|
150
|
-
name: 'alias',
|
|
151
|
-
message: 'Repository Alias:',
|
|
152
|
-
initial(_, values) {
|
|
153
|
-
return values.name;
|
|
154
|
-
},
|
|
155
|
-
validate(value: string) {
|
|
156
|
-
if (value.length < 1) {
|
|
157
|
-
return 'Repository alias cannot be empty';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
type: 'select',
|
|
165
|
-
name: 'scope',
|
|
166
|
-
message: 'Repository Scope:',
|
|
167
|
-
choices: [
|
|
168
|
-
{
|
|
169
|
-
title: 'SINGLETON',
|
|
170
|
-
value: 'SINGLETON',
|
|
171
|
-
description: 'A single instance of the repository is created.'
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
title: 'FACTORY',
|
|
175
|
-
value: 'FACTORY',
|
|
176
|
-
description: 'A new instance of the repository is created each time it is injected.'
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
}
|
|
180
|
-
];
|
|
181
|
-
|
|
182
|
-
const answers = await prompts(items, {
|
|
183
|
-
onCancel: () => {
|
|
184
|
-
this.error('Operation cancelled.');
|
|
185
|
-
process.exit(0);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
return this.build(answers);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private async build(answers: Record<string, any>): Promise<void> {
|
|
193
|
-
if (!answers.name) {
|
|
194
|
-
this.error('Operation cancelled.');
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!answers.name.endsWith('Repository')) {
|
|
199
|
-
answers.name += 'Repository';
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (!answers.alias) {
|
|
203
|
-
answers.alias = answers.name;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Get stub file
|
|
207
|
-
const stubFile = Bun.file(join(getRootPath(), 'stubs/repository.stub'));
|
|
208
|
-
|
|
209
|
-
// Format the stub content
|
|
210
|
-
const stub = formatter(await stubFile.text(), {
|
|
211
|
-
...answers,
|
|
212
|
-
module: answers.module ?? 'root',
|
|
213
|
-
model_name: snake(answers.model.replace('Model', ''))
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const path = answers.module ? await getModulePath(answers.module) : './src';
|
|
217
|
-
|
|
218
|
-
// Write to file
|
|
219
|
-
const name = snake(answers.name.replace('Repository', ''));
|
|
220
|
-
const file = Bun.file(`${path}/repositories/${name}.repository.ts`);
|
|
221
|
-
await file.write(stub);
|
|
222
|
-
|
|
223
|
-
this.success(`Repository ${this.bold(file.name!)} created successfully.`);
|
|
224
|
-
}
|
|
225
|
-
}
|