@mikemajesty/microservice-crud 6.1.7 → 6.1.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.
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { getCoreSingleEntity } from './templates/core-sigle/entity/entity';
|
|
2
|
+
import { getCoreSingleRepository } from './templates/core-sigle/repository/repository';
|
|
3
|
+
import { getCoreSingleUsecaseCreate } from './templates/core-sigle/use-cases/usecase';
|
|
1
4
|
import { getIndexInfra } from './templates/infra';
|
|
2
5
|
import { getAdapterInfra } from './templates/infra/adapter';
|
|
3
6
|
import { getModuleInfa } from './templates/infra/module';
|
|
@@ -174,6 +177,45 @@ const createCore = async (name) => {
|
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
179
|
|
|
180
|
+
const createCoreSingle = async (name) => {
|
|
181
|
+
name = getName(name);
|
|
182
|
+
const dirRoot = `${__dirname}/scafold/core-single/${name}`
|
|
183
|
+
try {
|
|
184
|
+
if (fs.existsSync(dirRoot)) {
|
|
185
|
+
fs.rmSync(dirRoot, { recursive: true });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
fs.mkdirSync(dirRoot)
|
|
189
|
+
|
|
190
|
+
const usecasePath = `${dirRoot}/use-cases`
|
|
191
|
+
|
|
192
|
+
fs.mkdirSync(usecasePath)
|
|
193
|
+
|
|
194
|
+
fs.writeFileSync(`${usecasePath}/${name}-rename.ts`, getCoreSingleUsecaseCreate(name))
|
|
195
|
+
|
|
196
|
+
const repositoryPath = `${dirRoot}/repository`
|
|
197
|
+
|
|
198
|
+
fs.mkdirSync(repositoryPath)
|
|
199
|
+
|
|
200
|
+
fs.writeFileSync(`${repositoryPath}/${name}.ts`, getCoreSingleRepository(name))
|
|
201
|
+
|
|
202
|
+
const entityPath = `${dirRoot}/entity`
|
|
203
|
+
|
|
204
|
+
fs.mkdirSync(entityPath)
|
|
205
|
+
|
|
206
|
+
fs.writeFileSync(`${entityPath}/${name}.ts`, getCoreSingleEntity(name))
|
|
207
|
+
|
|
208
|
+
return `${name}`
|
|
209
|
+
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.log('error', error)
|
|
212
|
+
if (fs.existsSync(dirRoot)) {
|
|
213
|
+
fs.rmSync(dirRoot, { recursive: true });
|
|
214
|
+
}
|
|
215
|
+
return `${name}`
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
177
219
|
const createPostgresCrud = async (name) => {
|
|
178
220
|
name = getName(name);
|
|
179
221
|
|
|
@@ -270,6 +312,7 @@ export const parseArgumentsInoOptions = async (input) => {
|
|
|
270
312
|
libCreate: input.type === 'lib' ? await createLib(input.name) : false,
|
|
271
313
|
infraCreate: input.type === 'infra' ? await createInfra(input.name) : false,
|
|
272
314
|
moduleCreate: input.type === 'module' ? await createModule(input.name) : false,
|
|
315
|
+
coreCreate: input.type === 'core' ? await createCoreSingle(input.name) : false,
|
|
273
316
|
}
|
|
274
317
|
}
|
|
275
318
|
|
|
@@ -277,7 +320,7 @@ export async function cli(args) {
|
|
|
277
320
|
|
|
278
321
|
console.log(bold(green('Selecting template...')))
|
|
279
322
|
const cli = await cliSelect({
|
|
280
|
-
values: [bold('POSTGRES:CRUD'), bold('MONGO:CRUD'), bold('LIB'), bold('INFRA'), bold('MODULE')],
|
|
323
|
+
values: [bold('POSTGRES:CRUD'), bold('MONGO:CRUD'), bold('LIB'), bold('INFRA'), bold('MODULE'), bold('CORE')],
|
|
281
324
|
valueRenderer: (value, selected) => {
|
|
282
325
|
if (selected) {
|
|
283
326
|
return value;
|
|
@@ -287,7 +330,7 @@ export async function cli(args) {
|
|
|
287
330
|
},
|
|
288
331
|
})
|
|
289
332
|
|
|
290
|
-
const mapSelectType = { 0: 'postgres:crud', 1: 'mongo:crud', 2: "lib", 3: "infra", 4: "module" }[cli.id]
|
|
333
|
+
const mapSelectType = { 0: 'postgres:crud', 1: 'mongo:crud', 2: "lib", 3: "infra", 4: "module", 5: "core" }[cli.id]
|
|
291
334
|
const userInput = { name: undefined, type: undefined }
|
|
292
335
|
|
|
293
336
|
userInput.type = mapSelectType
|
|
@@ -331,6 +374,10 @@ export async function cli(args) {
|
|
|
331
374
|
if (userInput.type === 'module') {
|
|
332
375
|
paths.push(path.resolve(`${__dirname}/../src/scafold/module/`, options[key]))
|
|
333
376
|
}
|
|
377
|
+
|
|
378
|
+
if (userInput.type === 'core') {
|
|
379
|
+
paths.push(path.resolve(`${__dirname}/../src/scafold/core-single/`, options[key]))
|
|
380
|
+
}
|
|
334
381
|
}
|
|
335
382
|
}
|
|
336
383
|
|
|
@@ -360,6 +407,9 @@ export async function cli(args) {
|
|
|
360
407
|
}
|
|
361
408
|
});
|
|
362
409
|
|
|
410
|
+
if (!src) {
|
|
411
|
+
throw new Error('project destiny not found')
|
|
412
|
+
}
|
|
363
413
|
|
|
364
414
|
// CREATE CRUD
|
|
365
415
|
fs.readdir(src, function (err, folders) {
|
|
@@ -393,6 +443,16 @@ export async function cli(args) {
|
|
|
393
443
|
continue
|
|
394
444
|
}
|
|
395
445
|
|
|
446
|
+
if (userInput.type === 'core') {
|
|
447
|
+
const source = `${src}/${folder}`;
|
|
448
|
+
const destination = `${dest}/src/core/${options.coreCreate}/${folder}`.replace('\n', '');
|
|
449
|
+
fse.copySync(source, destination, { overwrite: true });
|
|
450
|
+
if (fs.existsSync(source)) {
|
|
451
|
+
fs.rmSync(source, { recursive: true });
|
|
452
|
+
}
|
|
453
|
+
continue
|
|
454
|
+
}
|
|
455
|
+
|
|
396
456
|
if (userInput.type === 'lib') {
|
|
397
457
|
const source = `${src}/${folder}`;
|
|
398
458
|
const destination = `${dest}/src/libs/${options.libCreate}/${folder}`.replace('\n', '');
|
|
@@ -470,6 +530,6 @@ export async function cli(args) {
|
|
|
470
530
|
|
|
471
531
|
const getName = (name) => {
|
|
472
532
|
if (!name) throw new Error('--name is required');
|
|
473
|
-
name = String(name).trim().replace(" ", "").toLowerCase();
|
|
533
|
+
name = String(name).trim().replace(" ", "").replace("_", "-").toLowerCase();
|
|
474
534
|
return name;
|
|
475
535
|
}
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const { dashToPascal } = require("../../../textUtils")
|
|
2
|
+
|
|
3
|
+
const getCoreSingleEntity = (name) => `import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
import { BaseEntity } from '@/utils/entity';
|
|
6
|
+
|
|
7
|
+
const ID = z.string().uuid();
|
|
8
|
+
const Name = z.string().min(1).max(200).trim();
|
|
9
|
+
const CreatedAt = z.date().nullish();
|
|
10
|
+
const UpdatedAt = z.date().nullish();
|
|
11
|
+
const DeletedAt = z.date().nullish();
|
|
12
|
+
|
|
13
|
+
export const ${dashToPascal(name)}EntitySchema = z.object({
|
|
14
|
+
id: ID,
|
|
15
|
+
name: Name,
|
|
16
|
+
createdAt: CreatedAt,
|
|
17
|
+
updatedAt: UpdatedAt,
|
|
18
|
+
deletedAt: DeletedAt
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
type ${dashToPascal(name)} = z.infer<typeof ${dashToPascal(name)}EntitySchema>;
|
|
22
|
+
|
|
23
|
+
export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>(${dashToPascal(name)}EntitySchema) {
|
|
24
|
+
name!: string;
|
|
25
|
+
|
|
26
|
+
constructor(entity: ${dashToPascal(name)}) {
|
|
27
|
+
super();
|
|
28
|
+
Object.assign(this, this.validate(entity));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
getCoreSingleEntity
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { dashToPascal } = require("../../../textUtils")
|
|
2
|
+
|
|
3
|
+
const getCoreSingleRepository = (name) => `import { IRepository } from '@/infra/repository';
|
|
4
|
+
|
|
5
|
+
import { ${dashToPascal(name)}Entity } from '../entity/${name}';
|
|
6
|
+
|
|
7
|
+
export abstract class I${dashToPascal(name)}Repository extends IRepository<${dashToPascal(name)}Entity> {}
|
|
8
|
+
`
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
getCoreSingleRepository
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { dashToPascal } = require("../../../textUtils")
|
|
2
|
+
|
|
3
|
+
const getCoreSingleUsecaseCreate = (name) => `import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
6
|
+
import { IUsecase } from '@/utils/usecase';
|
|
7
|
+
|
|
8
|
+
export const ${dashToPascal(name)}RenameSchema = z.object({ id: z.string() });
|
|
9
|
+
|
|
10
|
+
export class ${dashToPascal(name)}RenameUsecase implements IUsecase {
|
|
11
|
+
@ValidateSchema(${dashToPascal(name)}RenameSchema)
|
|
12
|
+
async execute(input: ${dashToPascal(name)}RenameUseCaseInput): Promise<${dashToPascal(name)}RenameUseCaseOutput> {
|
|
13
|
+
return input;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ${dashToPascal(name)}RenameUseCaseInput = z.infer<typeof ${dashToPascal(name)}RenameSchema>;
|
|
18
|
+
export type ${dashToPascal(name)}RenameUseCaseOutput = ${dashToPascal(name)}RenameUseCaseInput;
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
getCoreSingleUsecaseCreate
|
|
23
|
+
}
|