-
Notifications
You must be signed in to change notification settings - Fork 10
/
artisan.ts
144 lines (128 loc) · 4.25 KB
/
artisan.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import yargs, { Arguments, option } from 'yargs';
import { MigrationTemplate } from './code_templates/MigrationTemplate';
import { ApiTemplate } from './code_templates/ApiTemplate';
import { ModelTemplate } from './code_templates/ModelTemplate';
import { RepositoryTemplate } from './code_templates/RepositoryTemplate';
import { ServiceTemplate } from './code_templates/ServiceTemplate';
import { CronTemplate } from './code_templates/CronTemplate';
import { EventTemplate } from './code_templates/EventTemplate';
import { DocsTemplate } from './code_templates/DocsTemplate';
import { SocketTemplate } from './code_templates/SocketTemplate';
const commands = yargs(process.argv.slice(2)).options({
docs: {
type: 'boolean',
default: false,
describe: '',
},
});
try {
commands.command(
'make:migration <table>',
'Create a migration file',
() => {},
(argv: Arguments) => {
console.log('EXECUTING', argv);
const template = new MigrationTemplate(<string>argv.table);
template.generate();
console.log('Migration file successfully created');
},
);
commands.command(
'make:api <name>',
'Create a new api handler',
() => {},
(argv: Arguments) => {
const template = new ApiTemplate(<string>argv.name);
template.generate();
console.log('API Handler successfully created');
},
);
commands.command(
'make:model <name> <table_name>',
'Create a model class',
() => {},
async (argv: Arguments) => {
let type = 'mysql';
if (argv.mongo) {
type = 'mongo';
} else if (argv.postgre) {
type = 'postgre';
}
const template = new ModelTemplate(<string>argv.name, <string>argv.table_name, type);
await template.generate();
console.log('Model successfully created');
},
);
commands.command(
'make:repository <name> <table_name>',
'Create a repository class',
() => {},
async (argv: Arguments) => {
let type = 'mysql';
if (argv.mongo) {
type = 'mongo';
} else if (argv.postgre) {
type = 'postgre';
}
const repository = new RepositoryTemplate(<string>argv.name, type);
repository.generate();
const template = new ModelTemplate(<string>argv.name, <string>argv.table_name, type);
await template.generate();
console.log('Repository successfully created');
},
);
commands.command(
'make:service <name>',
'Create a service class',
() => {},
(argv: Arguments) => {
const service = new ServiceTemplate(<string>argv.name);
service.generate();
console.log('Service successfully created');
},
);
commands.command(
'make:doc <name>',
'Create a doc',
() => {},
(argv: Arguments) => {
const service = new DocsTemplate(<string>argv.name);
service.generate();
console.log('Docs successfully created');
},
);
commands.command(
'make:event <name>',
'Create a new event',
() => {},
(argv: Arguments) => {
const template = new EventTemplate(<string>argv.name);
template.generate();
console.log('Event successfully created');
},
);
commands.command(
'make:socket <name>',
'Create a new socket event',
() => {},
(argv: Arguments) => {
const template = new SocketTemplate(<string>argv.name);
template.generate();
console.log('Socket event successfully created');
},
);
commands.command(
'make:cron <name>',
'Create a cron class',
() => {},
(argv: Arguments) => {
const cron = new CronTemplate(<string>argv.name);
cron.generate();
console.log('Cron successfully created');
},
);
commands.strictCommands();
commands.argv;
} catch (e: any) {
console.error('\x1b[33m%s\x1b[0m', e.message);
}