frgen 0.2.8 → 0.3.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/README.md +64 -2
- package/lib/make_controller.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
### Generator
|
|
2
|
+
|
|
3
|
+
#### Resource
|
|
4
|
+
- make:resource "className" "tableName"
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npx frgen make:resource UserResource users
|
|
8
|
+
```
|
|
9
|
+
- shema --schema=schemaName
|
|
10
|
+
```bash
|
|
11
|
+
npx frgen make:resource UserResource users --schema=other_schema
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
#### Controller
|
|
15
|
+
- make:controller "className" "tableName"
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx frgen make:controller UserController users --prisma
|
|
19
|
+
```
|
|
20
|
+
- shema --schema=schemaName
|
|
21
|
+
```bash
|
|
22
|
+
npx frgen make:controller UserController users --schema=other_schema --prisma
|
|
23
|
+
```
|
|
24
|
+
- path --path=/directory/.../target
|
|
25
|
+
```bash
|
|
26
|
+
npx frgen make:controller UserController users --path=/directory/.../target --prisma
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Service
|
|
30
|
+
- make:service "ServiceName" "tableName"
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx frgen make:service UserService users --prisma
|
|
34
|
+
```
|
|
35
|
+
- shema --schema=schemaName
|
|
36
|
+
```bash
|
|
37
|
+
npx frgen make:service UserService users --schema=other_schema --prisma
|
|
38
|
+
```
|
|
39
|
+
- path --path=/directory/.../target
|
|
40
|
+
```bash
|
|
41
|
+
npx frgen make:service UserService users --path=/directory/.../target --prisma
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Validation
|
|
45
|
+
- make:validation "ValidationName" "tableName"
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx frgen make:validation UserValidation users
|
|
49
|
+
```
|
|
50
|
+
- shema --schema=schemaName
|
|
51
|
+
```bash
|
|
52
|
+
npx frgen make:validation UserValidation users --schema=other_schema
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### ALL
|
|
56
|
+
- make:crud "className" "tableName"
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx frgen make:crud --prisma
|
|
60
|
+
```
|
|
61
|
+
- shema --schema=schemaName
|
|
62
|
+
```bash
|
|
63
|
+
npx frgen make:crud --schema=other_schema --prisma
|
|
64
|
+
```
|
|
2
65
|
|
|
3
|
-
Generator CRUD
|
package/lib/make_controller.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("./_virtual/_rollupPluginBabelHelpers.js"),n=require("fs"),r=require("path"),t=require("./utils.js"),
|
|
2
|
+
"use strict";var e=require("./_virtual/_rollupPluginBabelHelpers.js"),n=require("fs"),r=require("path"),t=require("./utils.js"),o=require("./make_resource.js"),a=require("./make_validation.js"),c=require("./make_service.js"),s=function(){var s=e.asyncToGenerator(e.regeneratorRuntime().mark((function s(i,l,u,d){var p,m,x,v,h,q,f,R,y,w,C,g,S,j,P=arguments;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return p=P.length>4&&void 0!==P[4]?P[4]:"public",m=P.length>5&&void 0!==P[5]&&P[5],e.prev=2,i||(console.error("class name undefined"),process.exit(1)),l||(console.error("table name undefined"),process.exit(1)),x=i.replace(/Controller$/,""),v=t.capitalize(t.toCamelCase(t.removePluralSuffix(l))),h=t.capitalize(t.toCamelCase(t.removePluralSuffix(l))),q=x,f=t.capitalize(t.toCamelCase(t.removePluralSuffix(l))),R=t.toCamelCase(t.removePluralSuffix(l)),y="".concat(q,"Controller.ts"),w=r.join(process.cwd(),"src","app","http","controller",y),u&&"default"!==u&&("/"!==u.charAt(u.length-1)&&(u+="/"),w=r.join(process.cwd(),"src",u,y)),C="\n const validated = await req.validation(".concat(R,"Schema, {\n context: { method: req.method },\n });\n "),g="\n const validated = await req.validation(".concat(R,"Schema);\n "),S='\nimport { NextFunction, Request, Response } from "express";\nimport { Controller, Get, Post, Put, Delete } from "frexp/lib/Decorator";\nimport { getPaginate, getDetail, handleCreate, handleUpdate, handleDelete} from "@service/'.concat(h,'Service";\nimport ').concat(v,'Resource from "@resource/').concat(v,'Resource";\nimport { ').concat(R,'Schema } from "@validation/').concat(f,'Validation";\n\n@Controller("/').concat(t.toKebabCase(x),'")\nexport class ').concat(q,'Controller {\n\n @Get("/")\n async index(req: Request, res: Response, next: NextFunction){\n try {\n const results = await getPaginate(req);\n res.json(').concat(v,'Resource.paginate(results));\n } catch (error) {\n next(error);\n }\n };\n\n @Get("/:id")\n async view(req: Request, res: Response, next: NextFunction){\n try {\n const model = await getDetail(+req.params.id)\n res.json(new ').concat(v,'Resource(model, true));\n } catch (error) {\n next(error);\n }\n };\n\n @Post("/")\n async create(req: Request, res: Response, next: NextFunction){\n try {\n ').concat(g,"\n const model = await handleCreate(").concat(""===g?"req.body":"validated",");\n res.json(new ").concat(v,'Resource(model, true));\n } catch (error) {\n next(error);\n }\n };\n\n @Put("/")\n async update(req: Request, res: Response, next: NextFunction){\n try {\n ').concat(C,"\n const model = await handleUpdate(").concat(""===C?"req.body":"validated",");\n res.json(new ").concat(v,'Resource(model, true));\n } catch (error) {\n next(error);\n }\n };\n\n @Delete("/:id")\n async destroy(req: Request, res: Response, next: NextFunction){\n try {\n await handleDelete(+req.params.id)\n res.sendStatus(204);\n } catch (error) {\n next(error);\n }\n };\n}\n'),j=r.dirname(w),n.existsSync(j)||n.mkdirSync(j,{recursive:!0}),n.writeFile(w,S,(function(e){e?console.error("err: ",e):console.log("File ".concat(y," has been created"))})),e.next=22,o("".concat(v,"Resource"),l,d,p);case 22:return e.next=24,a("".concat(f,"Validation"),l,d,p);case 24:return e.next=26,c("".concat(h,"Service"),l,void 0,m);case 26:e.next=31;break;case 28:e.prev=28,e.t0=e.catch(2),console.error("err::",e.t0);case 31:return e.prev=31,e.finish(31);case 33:case"end":return e.stop()}}),s,null,[[2,28,31,33]])})));return function(e,n,r,t){return s.apply(this,arguments)}}();module.exports=s;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frgen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "helper generator",
|
|
5
5
|
"main": "lib/",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/fajarrh
|
|
17
|
+
"url": "git+https://github.com/fajarrh/EPP-Starter.git"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"express",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"author": "fajarrizkyhidayat",
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"bugs": {
|
|
31
|
-
"url": "https://github.com/fajarrh
|
|
31
|
+
"url": "https://github.com/fajarrh/EPP-Starter/issues"
|
|
32
32
|
},
|
|
33
|
-
"homepage": "https://
|
|
33
|
+
"homepage": "https://github.com/fajarrh/EPP-Starter",
|
|
34
34
|
"files": [
|
|
35
35
|
"lib/**/*"
|
|
36
36
|
],
|