pwi-plata-type 0.2.2 → 0.2.5
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.
|
@@ -8,7 +8,7 @@ export async function h() {
|
|
|
8
8
|
|
|
9
9
|
switch (command) {
|
|
10
10
|
case 'lib':
|
|
11
|
-
const nameLib = args.shift()
|
|
11
|
+
const nameLib = `${args.shift()}`
|
|
12
12
|
promises.push(tools.files.deployFileToProject(
|
|
13
13
|
'configs',
|
|
14
14
|
'config',
|
|
@@ -24,7 +24,7 @@ export async function h() {
|
|
|
24
24
|
).finally(() => console.log(`Lib ${nameLib.toLowerCase()} criada`)))
|
|
25
25
|
break;
|
|
26
26
|
case 'config':
|
|
27
|
-
const nameConfig = args.shift()
|
|
27
|
+
const nameConfig = `${args.shift()}`
|
|
28
28
|
promises.push(tools.files.deployFileToProject(
|
|
29
29
|
'configs',
|
|
30
30
|
'config',
|
|
@@ -45,14 +45,14 @@ export async function h() {
|
|
|
45
45
|
routeFilePath,
|
|
46
46
|
'route',
|
|
47
47
|
`${routeFileName}.ts`,
|
|
48
|
-
{}
|
|
48
|
+
{ PlataName: `${PlataDirs.ProjectJson.plata_name}` }
|
|
49
49
|
).finally(() => console.log(
|
|
50
50
|
`Rota ${routeFilePath}/${routeFileName === 'index' ? '' : routeFileName} criada`
|
|
51
51
|
)))
|
|
52
52
|
|
|
53
53
|
break;
|
|
54
54
|
case 'model':
|
|
55
|
-
const modelName = args.shift()
|
|
55
|
+
const modelName = `${args.shift()}`
|
|
56
56
|
const plataName = PlataDirs.ProjectJson.plata_name
|
|
57
57
|
|
|
58
58
|
promises.push(tools.files.deployFileToProject(
|
package/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as PlataCluster from './libs/cluster.js'
|
|
2
2
|
import * as PlataEnv from './libs/env.js'
|
|
3
3
|
import * as PlataRoutes from './libs/routes.js'
|
|
4
|
+
import { PlataRoute } from './libs/routes.js'
|
|
4
5
|
import * as PlataTools from './libs/tools.js'
|
|
5
6
|
import * as PlataModels from './libs/model.js'
|
|
6
7
|
|
|
@@ -10,4 +11,5 @@ export {
|
|
|
10
11
|
PlataRoutes,
|
|
11
12
|
PlataTools,
|
|
12
13
|
PlataModels,
|
|
14
|
+
PlataRoute,
|
|
13
15
|
}
|
package/libs/routes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlataDirs, PlataRequire } from "./tools.js";
|
|
2
|
-
import express, {
|
|
2
|
+
import express, { Router } from "express";
|
|
3
3
|
|
|
4
4
|
export type PlataRouter = () => Router
|
|
5
5
|
|
|
@@ -31,4 +31,24 @@ export async function loadExpressRoutes(): Promise<Router> {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
return router
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type PlataRequest = express.Request & { user: any, extras: any }
|
|
37
|
+
|
|
38
|
+
export type PlataRequestHandler = (req: PlataRequest, res: express.Response, next: express.NextFunction) => Promise<any>
|
|
39
|
+
|
|
40
|
+
export function PlataRoute(r: PlataRequestHandler): express.RequestHandler {
|
|
41
|
+
return async (req, res, next) => {
|
|
42
|
+
const aReq = req as any
|
|
43
|
+
|
|
44
|
+
if (aReq.user === undefined) {
|
|
45
|
+
aReq.user = new Object(null)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (aReq.extras === undefined) {
|
|
49
|
+
aReq.extras = new Object(null)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return r(aReq, res, next)
|
|
53
|
+
}
|
|
34
54
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
|
-
import * as ç__Name__
|
|
3
|
-
const ç__Name__çConfig = ç__Name__çConfigImport.default as unknown as typeof ç__Name__çConfigImport
|
|
2
|
+
import * as ç__Name__çConfig from '../configs/ç__name__ç.js'
|
|
4
3
|
|
|
5
4
|
export class ç__Name__ç {
|
|
6
|
-
constructor(config: typeof ç__Name__çConfig) {
|
|
5
|
+
constructor(config: typeof ç__Name__çConfig.default) {
|
|
7
6
|
|
|
8
7
|
}
|
|
9
8
|
}
|
|
@@ -12,7 +11,7 @@ export function getç__Name__ç(): ç__Name__ç {
|
|
|
12
11
|
const p = process as any
|
|
13
12
|
|
|
14
13
|
if (p._plata._libç__Name__ç === undefined) {
|
|
15
|
-
p._plata._libç__Name__ç = new ç__Name__ç(ç__Name__çConfig)
|
|
14
|
+
p._plata._libç__Name__ç = new ç__Name__ç(ç__Name__çConfig.default)
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
return p._plata._libç__Name__ç
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
1
2
|
import { Router } from 'express'
|
|
3
|
+
import { PlataRoute } from 'ç__PlataName__ç'
|
|
2
4
|
|
|
3
5
|
export default (): Router => {
|
|
4
6
|
const router = Router()
|
|
5
7
|
|
|
6
|
-
router.get('/', (req, res) => {
|
|
8
|
+
router.get('/', PlataRoute(async (req, res) => {
|
|
7
9
|
return res.status(200).json({})
|
|
8
|
-
})
|
|
10
|
+
}))
|
|
9
11
|
|
|
10
12
|
return router
|
|
11
13
|
}
|
|
@@ -21,7 +21,7 @@ export async function install({ dirs, projectPackageJson }) {
|
|
|
21
21
|
projectPackageJson.scripts = new Object(null)
|
|
22
22
|
projectPackageJson.scripts.dev = "ts-node"
|
|
23
23
|
projectPackageJson.scripts.postinstall = "node postinstall.js"
|
|
24
|
-
projectPackageJson.scripts.create =
|
|
24
|
+
projectPackageJson.scripts.create = `ts-node --transpile-only --esm ./node_modules/${projectPackageJson.plata_name}/bin/plata-create --`
|
|
25
25
|
projectPackageJson.main = undefined
|
|
26
26
|
|
|
27
27
|
await Promise.all(promises)
|