pwi-plata-type 0.2.13 → 0.2.14
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/bin/extras/plata-build-tool.ts +150 -0
- package/bin/extras/plata-create-tools.ts +3 -3
- package/bin/plata-build.ts +144 -0
- package/bin/plata-swagger-gen.ts +8 -13
- package/bin/plata.ts +2 -2
- package/libs/cluster.ts +3 -5
- package/libs/env.ts +1 -1
- package/libs/model.ts +4 -4
- package/libs/routes.ts +5 -7
- package/libs/swagger.ts +2 -3
- package/libs/tools.ts +7 -11
- package/package.json +1 -1
- package/templates/postinstall/api/_install.mjs +1 -0
- package/templates/postinstall/api/tsconfig.json +8 -8
- package/templates/postinstall/lib/tsconfig.json +8 -8
- package/tsconfig.json +8 -8
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { PlataResultado, PlataDirs, PlataFiles, PlataError } from '../../libs/tools.js';
|
|
5
|
+
|
|
6
|
+
export namespace tools {
|
|
7
|
+
export interface ProcessExit {
|
|
8
|
+
exitCode: number,
|
|
9
|
+
stdout: string,
|
|
10
|
+
stderr: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function runIn(command: string, args: string[], cwd: string,): Promise<PlataResultado<ProcessExit>> {
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
try {
|
|
16
|
+
const p = spawn(command, args, {
|
|
17
|
+
cwd: cwd
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
let stdout, stderr = ''
|
|
21
|
+
|
|
22
|
+
p.stdout.on('data', (data) => {
|
|
23
|
+
stdout += `${data}\n`
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
p.stderr.on('data', (data) => {
|
|
27
|
+
stderr += `${data}\n`
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
p.on('close', (code) => {
|
|
31
|
+
return resolve({
|
|
32
|
+
exitCode: code ?? 999,
|
|
33
|
+
stdout: stdout,
|
|
34
|
+
stderr: stderr,
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return resolve({
|
|
39
|
+
errorID: 'PBEBT0001',
|
|
40
|
+
msg: [ 'Erro ao rodar o comando no projeto:', command, ...args ].join(' '),
|
|
41
|
+
error: e
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function runInProject(command: string, args: string[], folder?: string): Promise<PlataResultado<ProcessExit>> {
|
|
48
|
+
return runIn(
|
|
49
|
+
command,
|
|
50
|
+
args,
|
|
51
|
+
path.join(PlataDirs.getProjectDir(), folder ?? '')
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getProjectJson(): any {
|
|
56
|
+
return PlataDirs.ProjectJson
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function getPlataJson(): any {
|
|
60
|
+
return PlataFiles.readJsonSync(path.join(
|
|
61
|
+
PlataDirs.getPlataDir(),
|
|
62
|
+
'package.json'
|
|
63
|
+
))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getBuildFolder(): string {
|
|
67
|
+
return path.join(PlataDirs.getProjectDir(), 'build')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function getBuildPlataFolder(plataName: string): string {
|
|
71
|
+
return path.join(getBuildFolder(), 'node_modules', plataName)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function doError(error: PlataError): any {
|
|
75
|
+
console.log(error.errorID)
|
|
76
|
+
console.log(error.msg)
|
|
77
|
+
if (error.error) {
|
|
78
|
+
throw error.error
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function copyFolder(folder: string, destination: string): Promise<PlataResultado<string>> {
|
|
85
|
+
return new Promise(resolve => {
|
|
86
|
+
const p = path.join(destination, path.basename(folder))
|
|
87
|
+
fs.cp(folder, p, { recursive: true, errorOnExist: false },(err) => {
|
|
88
|
+
if (err !== null) {
|
|
89
|
+
return resolve({
|
|
90
|
+
errorID: 'PBEBT0002',
|
|
91
|
+
msg: `Erro ao copiar a pasta ${folder} para ${p}`,
|
|
92
|
+
error: err
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return resolve(p)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function copyFolderIfExits(folder: string, destination: string): Promise<PlataResultado<string>> {
|
|
102
|
+
try {
|
|
103
|
+
if (fs.existsSync(folder)) {
|
|
104
|
+
return copyFolder(folder, destination)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return ''
|
|
108
|
+
} catch(e) {
|
|
109
|
+
return {
|
|
110
|
+
errorID: 'PBEBT0003',
|
|
111
|
+
msg: `Erro ao checar se a pasta ${folder} existe`,
|
|
112
|
+
error: e
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function saveJson(folder: string, file: string, content: any): Promise<PlataResultado<string>> {
|
|
118
|
+
return new Promise(resolve => {
|
|
119
|
+
const p = path.join(folder, file)
|
|
120
|
+
fs.writeFile(p, JSON.stringify(content, null, 4), err => {
|
|
121
|
+
if (err !== null) {
|
|
122
|
+
return resolve({
|
|
123
|
+
errorID: 'PBEBT0004',
|
|
124
|
+
msg: `Erro salvar o arquivo ${p}`,
|
|
125
|
+
error: err
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return resolve(p)
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function createFolderIfNotExists(...folder: string[]): Promise<PlataResultado<string>> {
|
|
135
|
+
try {
|
|
136
|
+
const p = path.join(...folder)
|
|
137
|
+
if (!fs.existsSync(p)) {
|
|
138
|
+
fs.mkdirSync(p, { recursive: true })
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return p
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return {
|
|
144
|
+
errorID: 'PBEBT0005',
|
|
145
|
+
msg: `Ao criar a pasta ${folder}`,
|
|
146
|
+
error: e
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -3,8 +3,8 @@ import path from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
import { PlataDirs, PlataFiles } from '../../libs/tools.js'
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
export
|
|
6
|
+
export namespace tools {
|
|
7
|
+
export namespace files {
|
|
8
8
|
export async function mkdirIfNotExists(dir: string) {
|
|
9
9
|
try {
|
|
10
10
|
const p = path.resolve(dir)
|
|
@@ -80,7 +80,7 @@ export module tools {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
export
|
|
83
|
+
export namespace args {
|
|
84
84
|
export type argsCallBack = (command: string, args: string[]) => Promise<string[]>
|
|
85
85
|
|
|
86
86
|
export async function forEachArg(callback: argsCallBack) {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { tools } from './extras/plata-build-tool.js'
|
|
2
|
+
import { PlataResultado, PlataDirs } from '../libs/tools.js'
|
|
3
|
+
|
|
4
|
+
const main = async () => {
|
|
5
|
+
// Prepara o JSONs
|
|
6
|
+
const projectJson = tools.getProjectJson()
|
|
7
|
+
const plataJson = tools.getPlataJson()
|
|
8
|
+
|
|
9
|
+
plataJson.main = 'index.js'
|
|
10
|
+
|
|
11
|
+
projectJson.plata_no_setup = "true"
|
|
12
|
+
projectJson.dependencies = { ...projectJson.dependencies, ...plataJson.dependencies }
|
|
13
|
+
|
|
14
|
+
for (const dependencia in projectJson.dependencies) {
|
|
15
|
+
switch (dependencia) {
|
|
16
|
+
case 'ts-jest':
|
|
17
|
+
delete projectJson.dependencies['ts-jest']
|
|
18
|
+
break
|
|
19
|
+
case 'ts-node':
|
|
20
|
+
delete projectJson.dependencies['ts-node']
|
|
21
|
+
break
|
|
22
|
+
case plataJson.name:
|
|
23
|
+
delete projectJson.dependencies[plataJson.name]
|
|
24
|
+
break
|
|
25
|
+
default:
|
|
26
|
+
if (/^@types/.test(dependencia)) {
|
|
27
|
+
delete projectJson.dependencies[dependencia]
|
|
28
|
+
}
|
|
29
|
+
break
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
projectJson.scripts = {
|
|
34
|
+
start: `node ./node_modules/${plataJson.name}/bin/plata`,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Faz a manipulação dos arquivos para deixar certinho
|
|
38
|
+
const buildFolder = tools.getBuildFolder()
|
|
39
|
+
|
|
40
|
+
// Copia a pasta da plata compilada para fora da node_modules
|
|
41
|
+
|
|
42
|
+
const plataTmpFolder = await tools.copyFolder(
|
|
43
|
+
tools.getBuildPlataFolder(plataJson.name),
|
|
44
|
+
buildFolder
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if (plataTmpFolder.errorID !== undefined) {
|
|
48
|
+
return tools.doError(plataTmpFolder)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Salva os packages.json
|
|
52
|
+
{
|
|
53
|
+
const promises: Promise<PlataResultado<unknown>>[] = []
|
|
54
|
+
|
|
55
|
+
promises.push(tools.saveJson(
|
|
56
|
+
buildFolder,
|
|
57
|
+
'package.json',
|
|
58
|
+
projectJson
|
|
59
|
+
))
|
|
60
|
+
|
|
61
|
+
promises.push(tools.saveJson(
|
|
62
|
+
plataTmpFolder,
|
|
63
|
+
'package.json',
|
|
64
|
+
plataJson
|
|
65
|
+
))
|
|
66
|
+
|
|
67
|
+
const resultado = await Promise.all(promises)
|
|
68
|
+
|
|
69
|
+
for (const r of resultado) {
|
|
70
|
+
if (r.errorID !== undefined) {
|
|
71
|
+
return tools.doError(r)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Instala as dependencias
|
|
77
|
+
{
|
|
78
|
+
const install = await tools.runIn('npm', ['i'], buildFolder)
|
|
79
|
+
|
|
80
|
+
if (install.errorID !== undefined) {
|
|
81
|
+
return tools.doError(install)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (install.exitCode !== 0) {
|
|
85
|
+
return tools.doError({
|
|
86
|
+
errorID: 'PBB0002',
|
|
87
|
+
msg: `out:\n${install.stdout}\n err:\n${install.stderr}\n`
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Copia as pastas:
|
|
93
|
+
// plata compilada => node_modules
|
|
94
|
+
// env => projeto compilado
|
|
95
|
+
// swagger => projeto compilado
|
|
96
|
+
{
|
|
97
|
+
const promises: Promise<PlataResultado<unknown>>[] = []
|
|
98
|
+
|
|
99
|
+
promises.push(tools.copyFolder(
|
|
100
|
+
plataTmpFolder,
|
|
101
|
+
tools.getBuildPlataFolder('')
|
|
102
|
+
))
|
|
103
|
+
|
|
104
|
+
promises.push(tools.copyFolder(
|
|
105
|
+
PlataDirs.getProjectEnvFileDir(''),
|
|
106
|
+
buildFolder
|
|
107
|
+
))
|
|
108
|
+
|
|
109
|
+
promises.push(tools.copyFolderIfExits(
|
|
110
|
+
PlataDirs.getProjectDirSwagger(),
|
|
111
|
+
buildFolder
|
|
112
|
+
))
|
|
113
|
+
|
|
114
|
+
const resultado = await Promise.all(promises)
|
|
115
|
+
|
|
116
|
+
for (const r of resultado) {
|
|
117
|
+
if (r.errorID !== undefined) {
|
|
118
|
+
return tools.doError(r)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Cria as pasta caso ela não exista
|
|
124
|
+
{
|
|
125
|
+
const promises: Promise<PlataResultado<unknown>>[] = []
|
|
126
|
+
|
|
127
|
+
promises.push(tools.createFolderIfNotExists(buildFolder, 'clusters'))
|
|
128
|
+
promises.push(tools.createFolderIfNotExists(buildFolder, 'models'))
|
|
129
|
+
promises.push(tools.createFolderIfNotExists(buildFolder, 'routes'))
|
|
130
|
+
|
|
131
|
+
const resultado = await Promise.all(promises)
|
|
132
|
+
|
|
133
|
+
for (const r of resultado) {
|
|
134
|
+
if (r.errorID !== undefined) {
|
|
135
|
+
return tools.doError(r)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log('Projeto compilado')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
main()
|
package/bin/plata-swagger-gen.ts
CHANGED
|
@@ -46,9 +46,7 @@ function fromTemplateJson(file: string): PlataResultado<any> {
|
|
|
46
46
|
try {
|
|
47
47
|
const p = path.resolve(file)
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return j
|
|
49
|
+
return JSON.parse(fs.readFileSync(p).toString())
|
|
52
50
|
} catch (e) {
|
|
53
51
|
return {
|
|
54
52
|
errorID: 'PBSW0001',
|
|
@@ -111,25 +109,23 @@ async function dumpRotas(): Promise<dumpRoute[]> {
|
|
|
111
109
|
const rotas = await loadExpressRoutes()
|
|
112
110
|
const rotasMetodos: dumpRoute[] = []
|
|
113
111
|
const regex = /[:|?](.*?)\//g
|
|
114
|
-
for (
|
|
115
|
-
const r = rotas[i]
|
|
112
|
+
for (const r of rotas) {
|
|
116
113
|
const expressRouter = await r.exports()
|
|
117
114
|
|
|
118
115
|
if (expressRouter.swaggerHide) {
|
|
119
116
|
continue
|
|
120
117
|
}
|
|
121
118
|
|
|
122
|
-
for (
|
|
123
|
-
|
|
119
|
+
for (const layer of expressRouter.stack) {
|
|
120
|
+
if (layer.route === undefined) continue
|
|
121
|
+
|
|
124
122
|
const httpLayerRoute = path.normalize(`${r.httpRoute}/${layer.route.path}/`)
|
|
125
123
|
|
|
126
124
|
for (const metodo in layer.route.methods) {
|
|
127
125
|
const urlParms = httpLayerRoute.match(regex) ?? []
|
|
128
126
|
const routeParams: dumpParameter[] = []
|
|
129
127
|
|
|
130
|
-
for (
|
|
131
|
-
const p = urlParms[k];
|
|
132
|
-
|
|
128
|
+
for (const p of urlParms) {
|
|
133
129
|
routeParams.push({
|
|
134
130
|
name: p.slice(1, -1),
|
|
135
131
|
required: p[0] === ':',
|
|
@@ -142,7 +138,7 @@ async function dumpRotas(): Promise<dumpRoute[]> {
|
|
|
142
138
|
httpRoute: httpLayerRoute.replace(regex, '{$1}/'),
|
|
143
139
|
params: routeParams,
|
|
144
140
|
metodo,
|
|
145
|
-
})
|
|
141
|
+
})
|
|
146
142
|
}
|
|
147
143
|
}
|
|
148
144
|
}
|
|
@@ -157,8 +153,7 @@ const main = async () => {
|
|
|
157
153
|
{
|
|
158
154
|
const pathSwaggerRotas = PlataDirs.getProjectDirSwaggerRotas()
|
|
159
155
|
|
|
160
|
-
for (
|
|
161
|
-
const r = rotas[i];
|
|
156
|
+
for (const r of rotas) {
|
|
162
157
|
// https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy
|
|
163
158
|
const f = JSON.parse(JSON.stringify(files))
|
|
164
159
|
|
package/bin/plata.ts
CHANGED
|
@@ -25,7 +25,7 @@ const main = async () => {
|
|
|
25
25
|
|
|
26
26
|
clusterLib.run({
|
|
27
27
|
name: '_plata_express',
|
|
28
|
-
onStart: async () => {},
|
|
28
|
+
onStart: async () => { /*****/ },
|
|
29
29
|
env: process.env.ENV ?? 'prod'
|
|
30
30
|
})
|
|
31
31
|
|
|
@@ -58,7 +58,7 @@ const main = async () => {
|
|
|
58
58
|
|
|
59
59
|
app.use(process.env._PLATA_API_ROOT ?? '/api',await buildExpressRouter())
|
|
60
60
|
|
|
61
|
-
app.use((err,
|
|
61
|
+
app.use((err, _req, res, _next) => {
|
|
62
62
|
return res.status(500).json({
|
|
63
63
|
errorId: 'B00000',
|
|
64
64
|
error: 'Erro interno da aplicação',
|
package/libs/cluster.ts
CHANGED
|
@@ -135,9 +135,7 @@ export class PlataClusterManager {
|
|
|
135
135
|
|
|
136
136
|
const promisesClusters: any[] = []
|
|
137
137
|
|
|
138
|
-
for (
|
|
139
|
-
const r = required[i];
|
|
140
|
-
|
|
138
|
+
for (const r of required) {
|
|
141
139
|
if (r.errorID !== undefined) {
|
|
142
140
|
console.log(required)
|
|
143
141
|
process.exit(1)
|
|
@@ -162,13 +160,13 @@ export class PlataClusterManager {
|
|
|
162
160
|
})
|
|
163
161
|
|
|
164
162
|
if (file !== null) {
|
|
165
|
-
const config: PlataClusterWorkerConfig = (await import(`file:///${file}`.replace(/\\/g, '/'))
|
|
163
|
+
const config: PlataClusterWorkerConfig = (await import(`file:///${file}`.replace(/\\/g, '/'))).default
|
|
166
164
|
|
|
167
165
|
await config.onStart()
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
|
|
171
|
-
private async _clusterMsgServer(
|
|
169
|
+
private async _clusterMsgServer(_worker: typeCluster.Worker, msg: PlataClusterMsg) {
|
|
172
170
|
if (msg.name !== '_plata') {
|
|
173
171
|
// TODO :::
|
|
174
172
|
} else {
|
package/libs/env.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface EnvConfig {
|
|
|
6
6
|
|
|
7
7
|
export async function loadEnvProjectFile() {
|
|
8
8
|
const config = process.env['ENV'] === undefined ?
|
|
9
|
-
(await import(PlataDirs.getProjectConfigFileDir('env.js'))
|
|
9
|
+
(await import(PlataDirs.getProjectConfigFileDir('env.js'))).default as EnvConfig
|
|
10
10
|
: { env: process.env['ENV'] }
|
|
11
11
|
|
|
12
12
|
return PlataFiles.readFileAsync(
|
package/libs/model.ts
CHANGED
|
@@ -32,9 +32,9 @@ export class Model {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export async function _validaCampo(value: any,
|
|
36
|
-
for (
|
|
37
|
-
const result = await pipeline
|
|
35
|
+
export async function _validaCampo(value: any, pipelines: ModelValicacaoPrimitivo[], name: string): Promise<PlataError | null> {
|
|
36
|
+
for (const pipeline of pipelines) {
|
|
37
|
+
const result = await pipeline(name, value)
|
|
38
38
|
|
|
39
39
|
if (result.error !== undefined) {
|
|
40
40
|
return result.error
|
|
@@ -332,7 +332,7 @@ export function isArray(tamanhoMaximo?: number): ModelValicacaoPrimitivo {
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
export function Optional(): ModelValicacaoPrimitivo {
|
|
335
|
-
return async (
|
|
335
|
+
return async (_nome: string, valor: any) => {
|
|
336
336
|
if (!valor) {
|
|
337
337
|
return { continua: false }
|
|
338
338
|
}
|
package/libs/routes.ts
CHANGED
|
@@ -31,7 +31,7 @@ export async function loadExpressRoutes(): Promise<PlataRequiredRoute[]> {
|
|
|
31
31
|
}
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
throw
|
|
34
|
+
throw routes
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
let r = (routes as PlataRequiredRoute[])
|
|
@@ -57,7 +57,7 @@ export async function loadExpressRoutes(): Promise<PlataRequiredRoute[]> {
|
|
|
57
57
|
return r
|
|
58
58
|
} else {
|
|
59
59
|
console.log(routes)
|
|
60
|
-
throw
|
|
60
|
+
throw routes
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -67,9 +67,7 @@ export async function buildExpressRouter(): Promise<Router> {
|
|
|
67
67
|
|
|
68
68
|
const routes = await loadExpressRoutes()
|
|
69
69
|
|
|
70
|
-
for (
|
|
71
|
-
const r = routes[i];
|
|
72
|
-
|
|
70
|
+
for (const r of routes) {
|
|
73
71
|
router.use(r.httpRoute, await r.exports())
|
|
74
72
|
}
|
|
75
73
|
|
|
@@ -112,13 +110,13 @@ export function PlataRoute(r: PlataRequestHandler): express.RequestHandler {
|
|
|
112
110
|
}
|
|
113
111
|
|
|
114
112
|
aRes.json = (body) => {
|
|
115
|
-
(async () => { aRes._onResponseEvent(aReq, body, undefined, undefined) })
|
|
113
|
+
(async () => { aRes._onResponseEvent(aReq, body, undefined, undefined) })()
|
|
116
114
|
|
|
117
115
|
return aRes._oldJson(body)
|
|
118
116
|
}
|
|
119
117
|
|
|
120
118
|
aRes.error = (error, nodeError) => {
|
|
121
|
-
(async () => { aRes._onResponseEvent(aReq, undefined, error, nodeError) })
|
|
119
|
+
(async () => { aRes._onResponseEvent(aReq, undefined, error, nodeError) })()
|
|
122
120
|
|
|
123
121
|
return aRes._oldJson(error)
|
|
124
122
|
}
|
package/libs/swagger.ts
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path'
|
|
|
4
4
|
import { _Router } from './routes.js';
|
|
5
5
|
import { PlataFiles, PlataDirs } from "./tools.js";
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export namespace PlataSwagger {
|
|
8
8
|
export async function swagger(): Promise<_Router> {
|
|
9
9
|
const router = Router() as _Router
|
|
10
10
|
router.swaggerHide = true
|
|
@@ -27,8 +27,7 @@ export module PlataSwagger {
|
|
|
27
27
|
{
|
|
28
28
|
const routes = await PlataFiles.findFiles([PlataDirs.getProjectDirSwaggerRotas()], 'header.json')
|
|
29
29
|
|
|
30
|
-
for (
|
|
31
|
-
const route = routes[i];
|
|
30
|
+
for (const route of routes) {
|
|
32
31
|
|
|
33
32
|
const docPath = path.normalize(path.dirname(route))
|
|
34
33
|
const metodo = path.normalize(path.basename(docPath))
|
package/libs/tools.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface PlataError {
|
|
|
13
13
|
|
|
14
14
|
export type PlataResultado<T> = (T & { errorID?: undefined }) | PlataError
|
|
15
15
|
|
|
16
|
-
export
|
|
16
|
+
export namespace PlataDirs {
|
|
17
17
|
export function getProjectDir(): string {
|
|
18
18
|
return path.resolve('.')
|
|
19
19
|
}
|
|
@@ -74,7 +74,7 @@ export module PlataDirs {
|
|
|
74
74
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export
|
|
77
|
+
export namespace PlataFiles {
|
|
78
78
|
export type readLineCallback = (line: string) => Promise<void>
|
|
79
79
|
|
|
80
80
|
export type readLineCallbackSync = (line: string) => string
|
|
@@ -129,9 +129,7 @@ export module PlataFiles {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
export async function findFile(folders: string[], file: string): Promise<string | null> {
|
|
132
|
-
for (
|
|
133
|
-
const folder = folders[i];
|
|
134
|
-
|
|
132
|
+
for (const folder of folders) {
|
|
135
133
|
const f = glob.sync(`${folder.replace(/\\/g, '/')}/**/${file}`)[0]
|
|
136
134
|
|
|
137
135
|
if (f !== undefined) {
|
|
@@ -145,9 +143,7 @@ export module PlataFiles {
|
|
|
145
143
|
export async function findFiles(folders: string[], file: string): Promise<string[]> {
|
|
146
144
|
const files: string[] = []
|
|
147
145
|
|
|
148
|
-
for (
|
|
149
|
-
const folder = folders[i]
|
|
150
|
-
|
|
146
|
+
for (const folder of folders) {
|
|
151
147
|
files.push(...glob.sync(`${folder.replace(/\\/g, '/')}/**/${file}`))
|
|
152
148
|
}
|
|
153
149
|
|
|
@@ -187,7 +183,7 @@ export module PlataFiles {
|
|
|
187
183
|
}
|
|
188
184
|
}
|
|
189
185
|
|
|
190
|
-
export
|
|
186
|
+
export namespace PlataRequire {
|
|
191
187
|
export type Required<Type> = PlataResultado<RequiredInterface<Type>>
|
|
192
188
|
export interface RequiredInterface<Type> {
|
|
193
189
|
filePath: string,
|
|
@@ -211,7 +207,7 @@ export module PlataRequire {
|
|
|
211
207
|
return {
|
|
212
208
|
filePath: p,
|
|
213
209
|
name: path.basename(p).replace('.ts', '').replace('.js', ''),
|
|
214
|
-
exports:
|
|
210
|
+
exports: e.default as Type
|
|
215
211
|
}
|
|
216
212
|
}
|
|
217
213
|
|
|
@@ -239,7 +235,7 @@ export module PlataRequire {
|
|
|
239
235
|
}
|
|
240
236
|
}
|
|
241
237
|
|
|
242
|
-
export
|
|
238
|
+
export namespace PlataExtra {
|
|
243
239
|
export function Sleep(ms: number) {
|
|
244
240
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
245
241
|
}
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ export async function install({ dirs, projectPackageJson }) {
|
|
|
21
21
|
projectPackageJson.type = "module"
|
|
22
22
|
projectPackageJson.scripts = new Object(null)
|
|
23
23
|
projectPackageJson.scripts.start = `ts-node --transpile-only --esm ./node_modules/${projectPackageJson.plata_name}/bin/plata`
|
|
24
|
+
projectPackageJson.scripts.build = `npx tsc && ts-node --transpile-only --esm ./node_modules/${projectPackageJson.plata_name}/bin/plata-build --`
|
|
24
25
|
projectPackageJson.scripts.create = `ts-node --transpile-only --esm ./node_modules/${projectPackageJson.plata_name}/bin/plata-create --`
|
|
25
26
|
projectPackageJson.scripts.dev = "npx nodemon -e '.js,.mjs,.json,.ts' --exec 'npm start'"
|
|
26
27
|
projectPackageJson.scripts['swagger:gen'] = `ts-node --transpile-only --esm ./node_modules/${projectPackageJson.plata_name}/bin/plata-swagger-gen`
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"strictNullChecks": true,
|
|
4
4
|
"module": "es2022",
|
|
5
5
|
"target": "es2022",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
6
|
+
"declaration": false,
|
|
7
|
+
"sourceMap": false,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"outDir": "build",
|
|
10
|
+
"moduleResolution": "node"
|
|
10
11
|
},
|
|
11
12
|
"include": [
|
|
12
|
-
"
|
|
13
|
+
"./**/*.ts",
|
|
14
|
+
"node_modules/pwi-plata*/**/*.ts"
|
|
13
15
|
]
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
16
|
+
}
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"strictNullChecks": true,
|
|
4
4
|
"module": "es2022",
|
|
5
5
|
"target": "es2022",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
6
|
+
"declaration": false,
|
|
7
|
+
"sourceMap": false,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"outDir": "build",
|
|
10
|
+
"moduleResolution": "node"
|
|
10
11
|
},
|
|
11
12
|
"include": [
|
|
12
|
-
"
|
|
13
|
+
"./**/*.ts",
|
|
14
|
+
"node_modules/pwi-plata*/**/*.ts"
|
|
13
15
|
]
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
16
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"strictNullChecks": true,
|
|
4
4
|
"module": "es2022",
|
|
5
5
|
"target": "es2022",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
6
|
+
"declaration": false,
|
|
7
|
+
"sourceMap": false,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"outDir": "build",
|
|
10
|
+
"moduleResolution": "node"
|
|
10
11
|
},
|
|
11
12
|
"include": [
|
|
12
|
-
"
|
|
13
|
+
"./**/*.ts",
|
|
14
|
+
"node_modules/pwi-plata*/**/*.ts"
|
|
13
15
|
]
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
16
|
+
}
|