pwi-plata-type 0.3.17 → 0.4.0
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/__BUILD__/bin/extras/create-api-cli.js +96 -0
- package/__BUILD__/bin/extras/create-api-cli.js.map +1 -0
- package/__BUILD__/bin/extras/create-lib-cli.js +62 -0
- package/__BUILD__/bin/extras/create-lib-cli.js.map +1 -0
- package/__BUILD__/bin/extras/plata-create-tools.js +94 -0
- package/__BUILD__/bin/extras/plata-create-tools.js.map +1 -0
- package/__BUILD__/bin/plata-api.js +138 -0
- package/__BUILD__/bin/plata-api.js.map +1 -0
- package/__BUILD__/bin/plata-create.js +24 -0
- package/__BUILD__/bin/plata-create.js.map +1 -0
- package/__BUILD__/bin/plata-runtime.js +156 -0
- package/__BUILD__/bin/plata-runtime.js.map +1 -0
- package/__BUILD__/bin/plata-swagger.js +82 -0
- package/__BUILD__/bin/plata-swagger.js.map +1 -0
- package/__BUILD__/bin/runtime/_setupRuntime.js +43 -0
- package/__BUILD__/bin/runtime/_setupRuntime.js.map +1 -0
- package/__BUILD__/bin/runtime/class.js +18 -0
- package/__BUILD__/bin/runtime/class.js.map +1 -0
- package/__BUILD__/bin/runtime/dirs.js +16 -0
- package/__BUILD__/bin/runtime/dirs.js.map +1 -0
- package/__BUILD__/bin/runtime/promises.js +15 -0
- package/__BUILD__/bin/runtime/promises.js.map +1 -0
- package/__BUILD__/bin/runtime/require.js +88 -0
- package/__BUILD__/bin/runtime/require.js.map +1 -0
- package/__BUILD__/index.js +42 -0
- package/__BUILD__/index.js.map +1 -0
- package/__BUILD__/libs/axios.js +42 -0
- package/__BUILD__/libs/axios.js.map +1 -0
- package/__BUILD__/libs/cluster.js +160 -0
- package/__BUILD__/libs/cluster.js.map +1 -0
- package/__BUILD__/libs/fs.js +206 -0
- package/__BUILD__/libs/fs.js.map +1 -0
- package/__BUILD__/libs/model-validations.js +356 -0
- package/__BUILD__/libs/model-validations.js.map +1 -0
- package/__BUILD__/libs/model.js +185 -0
- package/__BUILD__/libs/model.js.map +1 -0
- package/__BUILD__/libs/router.js +127 -0
- package/__BUILD__/libs/router.js.map +1 -0
- package/__BUILD__/libs/swagger.js +64 -0
- package/__BUILD__/libs/swagger.js.map +1 -0
- package/__BUILD__/libs/tasks.js +134 -0
- package/__BUILD__/libs/tasks.js.map +1 -0
- package/__BUILD__/libs/tools.js +231 -0
- package/__BUILD__/libs/tools.js.map +1 -0
- package/__BUILD__/scripts/post-install/api.js +25 -0
- package/__BUILD__/scripts/post-install/api.js.map +1 -0
- package/__BUILD__/scripts/post-install/lib.js +25 -0
- package/__BUILD__/scripts/post-install/lib.js.map +1 -0
- package/__BUILD__/scripts/post-install.js +65 -0
- package/__BUILD__/scripts/post-install.js.map +1 -0
- package/__BUILD__/scripts/pre-test.js +25 -0
- package/__BUILD__/scripts/pre-test.js.map +1 -0
- package/package.json +18 -16
- package/src/@types/cluster.actions.d.ts +7 -0
- package/src/@types/cluster.d.ts +33 -0
- package/src/@types/create-cli.d.ts +9 -0
- package/src/@types/exported.d.ts +24 -0
- package/src/@types/global.d.ts +69 -0
- package/src/@types/model.d.ts +69 -0
- package/src/@types/router.d.ts +75 -0
- package/src/@types/swagger.d.ts +23 -0
- package/{bin/extras/plata-create-api.ts → src/bin/extras/create-api-cli.ts} +5 -6
- package/{bin/extras/plata-create-lib.ts → src/bin/extras/create-lib-cli.ts} +3 -4
- package/{bin → src/bin}/extras/plata-create-tools.ts +4 -4
- package/src/bin/plata-api.ts +172 -0
- package/src/bin/plata-create.ts +21 -0
- package/src/bin/plata-runtime.ts +188 -0
- package/src/bin/plata-swagger.ts +100 -0
- package/src/bin/runtime/_setupRuntime.ts +49 -0
- package/src/bin/runtime/_types.d.ts +4 -0
- package/src/bin/runtime/class.ts +21 -0
- package/src/bin/runtime/dirs.ts +26 -0
- package/src/bin/runtime/promises.ts +15 -0
- package/src/bin/runtime/require.ts +104 -0
- package/{index.ts → src/index.ts} +2 -4
- package/{libs → src/libs}/axios.ts +0 -0
- package/src/libs/cluster.ts +189 -0
- package/src/libs/fs.ts +382 -0
- package/{libs/model.ts → src/libs/model-validations.ts} +28 -262
- package/src/libs/model.ts +233 -0
- package/src/libs/router.ts +147 -0
- package/src/libs/swagger.ts +81 -0
- package/{libs → src/libs}/tasks.ts +0 -0
- package/{libs → src/libs}/tools.ts +3 -18
- package/src/scripts/post-install/api.ts +32 -0
- package/src/scripts/post-install/lib.ts +30 -0
- package/src/scripts/post-install.ts +65 -0
- package/src/scripts/pre-test.ts +34 -0
- package/src/tests/assets/config/test.txt +1 -0
- package/src/tests/config.test.ts +13 -0
- package/src/tests/model.test.ts +115 -0
- package/templates/create-cli/cluster.ts +7 -9
- package/templates/create-cli/config.ts +2 -8
- package/templates/create-cli/lib.ts +7 -17
- package/templates/create-cli/model.ts +10 -21
- package/templates/create-cli/route.ts +1 -3
- package/templates/postinstall/api/configs/env.ts +2 -8
- package/templates/postinstall/api/tsconfig.json +20 -37
- package/templates/postinstall/lib/postinstall-tools.mjs +1 -1
- package/templates/postinstall/lib/postinstall.js +1 -0
- package/templates/postinstall/lib/tsconfig.json +21 -38
- package/tsconfig.json +25 -37
- package/Dockerfile +0 -13
- package/bin/extras/plata-build-tool.ts +0 -151
- package/bin/plata-build.ts +0 -144
- package/bin/plata-create.ts +0 -28
- package/bin/plata-reload.ts +0 -13
- package/bin/plata-swagger-gen.ts +0 -183
- package/bin/plata.ts +0 -122
- package/libs/cluster.ts +0 -219
- package/libs/env.ts +0 -28
- package/libs/routes.ts +0 -275
- package/libs/swagger.ts +0 -79
- package/postinstall-tools.mjs +0 -115
- package/postinstall.mjs +0 -42
- package/templates/postinstall/api/_install.mjs +0 -34
- package/templates/postinstall/lib/_install.mjs +0 -30
package/libs/routes.ts
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { PlataDirs, PlataRequire, PlataError } from "./tools";
|
|
3
|
-
import express, { Router } from "express";
|
|
4
|
-
|
|
5
|
-
export const HttpMethodsArray = [
|
|
6
|
-
"all"
|
|
7
|
-
,"get"
|
|
8
|
-
,"post"
|
|
9
|
-
,"put"
|
|
10
|
-
,"delete"
|
|
11
|
-
,"patch"
|
|
12
|
-
,"options"
|
|
13
|
-
,"head"
|
|
14
|
-
,"checkout"
|
|
15
|
-
,"connect"
|
|
16
|
-
,"copy"
|
|
17
|
-
,"lock"
|
|
18
|
-
,"merge"
|
|
19
|
-
,"mkactivity"
|
|
20
|
-
,"mkcol"
|
|
21
|
-
,"move"
|
|
22
|
-
,"notify"
|
|
23
|
-
,"propfind"
|
|
24
|
-
,"proppatch"
|
|
25
|
-
,"purge"
|
|
26
|
-
,"report"
|
|
27
|
-
,"search"
|
|
28
|
-
,"subscribe"
|
|
29
|
-
,"trace"
|
|
30
|
-
,"unlock"
|
|
31
|
-
,"unsubscribe"
|
|
32
|
-
,"use"
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
export type HttpMethods =
|
|
36
|
-
"all"
|
|
37
|
-
| "get"
|
|
38
|
-
| "post"
|
|
39
|
-
| "put"
|
|
40
|
-
| "delete"
|
|
41
|
-
| "patch"
|
|
42
|
-
| "options"
|
|
43
|
-
| "head"
|
|
44
|
-
| "checkout"
|
|
45
|
-
| "connect"
|
|
46
|
-
| "copy"
|
|
47
|
-
| "lock"
|
|
48
|
-
| "merge"
|
|
49
|
-
| "mkactivity"
|
|
50
|
-
| "mkcol"
|
|
51
|
-
| "move"
|
|
52
|
-
| "notify"
|
|
53
|
-
| "propfind"
|
|
54
|
-
| "proppatch"
|
|
55
|
-
| "purge"
|
|
56
|
-
| "report"
|
|
57
|
-
| "search"
|
|
58
|
-
| "subscribe"
|
|
59
|
-
| "trace"
|
|
60
|
-
| "unlock"
|
|
61
|
-
| "unsubscribe"
|
|
62
|
-
| "use"
|
|
63
|
-
;
|
|
64
|
-
|
|
65
|
-
export type PlataRouterMethods = (
|
|
66
|
-
(path: string | PlataRequestHandler, ...handlers: PlataRequestHandler[]) => void | Promise<void>
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
export interface _PlataRoute {
|
|
70
|
-
path?: string,
|
|
71
|
-
method: HttpMethods
|
|
72
|
-
handlers: PlataRequestHandler[],
|
|
73
|
-
swaggerHide?: boolean
|
|
74
|
-
}
|
|
75
|
-
export interface PlataRouterExtras {
|
|
76
|
-
swaggerHide?: boolean
|
|
77
|
-
_routes?: _PlataRoute[]
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export type PlataRouter = PlataRouterExtras & {
|
|
81
|
-
[method in HttpMethods]: PlataRouterMethods
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type _Router = Router & PlataRouterExtras
|
|
85
|
-
|
|
86
|
-
export type PlataRouterBuilder = (r: PlataRouter) => PlataRouter | Promise<PlataRouter>
|
|
87
|
-
|
|
88
|
-
export type PlataRequest = express.Request & {
|
|
89
|
-
user: any,
|
|
90
|
-
extras: any,
|
|
91
|
-
_onResponse: PlataOnResponse[]
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export type PlataOnResponse = (req: PlataRequest, response?: any, error?: PlataError, nodeError?: any) => Promise<any>
|
|
95
|
-
export interface PlataResponse extends express.Response {
|
|
96
|
-
_oldJson(body?: any): this
|
|
97
|
-
_onResponseEvent(req: PlataRequest, response?: any, error?: PlataError, nodeError?: any): void
|
|
98
|
-
error(error: PlataError, nodeError?: any): this
|
|
99
|
-
addOnResponse(callback: PlataOnResponse): void
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface PlataRequiredRoute extends PlataRequire.RequiredInterface<PlataRouterBuilder> {
|
|
103
|
-
httpRoute: string
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function createPlataRouter(): any {
|
|
107
|
-
const router: any = new Object(null)
|
|
108
|
-
router._routes = []
|
|
109
|
-
|
|
110
|
-
for (let i = 0; i < HttpMethodsArray.length; i++) {
|
|
111
|
-
const method = HttpMethodsArray[i];
|
|
112
|
-
|
|
113
|
-
router[method] = (arg, ...args) => {
|
|
114
|
-
if (typeof arg === 'string') {
|
|
115
|
-
router._routes.push(
|
|
116
|
-
{
|
|
117
|
-
path: arg,
|
|
118
|
-
method: method,
|
|
119
|
-
handlers: args
|
|
120
|
-
|
|
121
|
-
} as _PlataRoute
|
|
122
|
-
)
|
|
123
|
-
} else {
|
|
124
|
-
router._routes.push(
|
|
125
|
-
{
|
|
126
|
-
method: method,
|
|
127
|
-
handlers: [].concat(arg, ...args)
|
|
128
|
-
} as _PlataRoute
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return router
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export type PlataRequestHandler = (req: PlataRequest, res: PlataResponse, next: express.NextFunction) => Promise<any>
|
|
138
|
-
|
|
139
|
-
export function PlataRoute(r: PlataRequestHandler): express.RequestHandler {
|
|
140
|
-
return async (req, res, next) => {
|
|
141
|
-
const aReq = req as any
|
|
142
|
-
|
|
143
|
-
if (aReq.user === undefined) {
|
|
144
|
-
aReq.user = new Object(null)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (aReq.extras === undefined) {
|
|
148
|
-
aReq.extras = new Object(null)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const aRes = res as any
|
|
152
|
-
|
|
153
|
-
if (aReq._onResponse === undefined) {
|
|
154
|
-
aReq._onResponse = []
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (aRes.addOnResponse === undefined) {
|
|
158
|
-
aRes.addOnResponse = (a) => {
|
|
159
|
-
aReq._onResponse.push(a)
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (aRes._oldJson === undefined) {
|
|
164
|
-
aRes._oldJson = aRes.json
|
|
165
|
-
|
|
166
|
-
aRes._onResponseEvent = (...a) => {
|
|
167
|
-
aReq._onResponse.forEach(r => {
|
|
168
|
-
try {
|
|
169
|
-
r(...a)
|
|
170
|
-
} catch (e) {}
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
aRes.json = (body) => {
|
|
175
|
-
(async () => { aRes._onResponseEvent(aReq, body, undefined, undefined) })()
|
|
176
|
-
|
|
177
|
-
return aRes._oldJson(body)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
aRes.error = (error, nodeError) => {
|
|
181
|
-
(async () => { aRes._onResponseEvent(aReq, undefined, error, nodeError) })()
|
|
182
|
-
|
|
183
|
-
return aRes._oldJson(error)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return r(aReq, aRes, next)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export async function loadExpressRoutes(): Promise<PlataRequiredRoute[]> {
|
|
193
|
-
const routes = await PlataRequire.requireFolderAsync<PlataRouterBuilder>(PlataDirs.getProjectRoutesDir())
|
|
194
|
-
|
|
195
|
-
if (routes.errorID === undefined) {
|
|
196
|
-
if (routes.findIndex(r => r.errorID !== undefined) !== -1) {
|
|
197
|
-
routes.forEach(r => {
|
|
198
|
-
if (r.errorID !== undefined) {
|
|
199
|
-
console.log(r)
|
|
200
|
-
}
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
throw routes
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
let r = (routes as PlataRequiredRoute[])
|
|
207
|
-
|
|
208
|
-
// Cria as rotas http no array
|
|
209
|
-
r = r.map(route => {
|
|
210
|
-
route.httpRoute = route.filePath
|
|
211
|
-
.replace(PlataDirs.getProjectRoutesDir(), '')
|
|
212
|
-
.replace(/\.ts|\.js$/, '')
|
|
213
|
-
.replace(/index/, '')
|
|
214
|
-
.replace(/\\/g, '/')
|
|
215
|
-
.replace(/\{(.*?)\}/g, ':$1')
|
|
216
|
-
.replace(/\[(.*?)\]/g, ':$1?')
|
|
217
|
-
;
|
|
218
|
-
|
|
219
|
-
return route
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
// coloca o index na frente de todas as rotas
|
|
223
|
-
r = r.sort((x,y) => {
|
|
224
|
-
if (x.name === 'index') {
|
|
225
|
-
if (y.name === 'index') {
|
|
226
|
-
return +(x.httpRoute.length > y.httpRoute.length)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return -1
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return +(x.name > y.name)
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
return r
|
|
236
|
-
} else {
|
|
237
|
-
console.log(routes)
|
|
238
|
-
throw routes
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export async function buildExpressRouter(): Promise<_Router> {
|
|
243
|
-
const router = Router() as _Router
|
|
244
|
-
router._routes = []
|
|
245
|
-
router.use(express.json({ limit: process.env._PLATA_API_JSON_SIZE ?? '100kb' }))
|
|
246
|
-
|
|
247
|
-
const routes = await loadExpressRoutes()
|
|
248
|
-
|
|
249
|
-
for (const r of routes) {
|
|
250
|
-
const pr = await r.exports(createPlataRouter())
|
|
251
|
-
|
|
252
|
-
pr._routes = pr._routes ?? []
|
|
253
|
-
|
|
254
|
-
for (let i = 0; i < pr._routes.length; i++) {
|
|
255
|
-
const prr = pr._routes[i];
|
|
256
|
-
|
|
257
|
-
let httpPath = r.httpRoute
|
|
258
|
-
|
|
259
|
-
if (prr.path !== undefined) {
|
|
260
|
-
httpPath = path.normalize(`${r.httpRoute}/${prr.path}`).replace(/\\/g, '/')
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
router[prr.method](httpPath, ...prr.handlers.map(PlataRoute))
|
|
264
|
-
|
|
265
|
-
router._routes.push({
|
|
266
|
-
path: httpPath,
|
|
267
|
-
method: prr.method,
|
|
268
|
-
handlers: [],
|
|
269
|
-
swaggerHide: prr.swaggerHide === undefined ? pr.swaggerHide : undefined
|
|
270
|
-
})
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return router
|
|
275
|
-
}
|
package/libs/swagger.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import swaggerUi from 'swagger-ui-express'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { PlataRouterBuilder, PlataRequestHandler } from './routes';
|
|
4
|
-
import { PlataFiles, PlataDirs } from "./tools";
|
|
5
|
-
|
|
6
|
-
export namespace PlataSwagger {
|
|
7
|
-
export const swagger: PlataRouterBuilder = async (router) => {
|
|
8
|
-
router.swaggerHide = true
|
|
9
|
-
|
|
10
|
-
if (process.env._plata_name === '_plata_express') {
|
|
11
|
-
router.use(
|
|
12
|
-
swaggerUi.serve as unknown as PlataRequestHandler,
|
|
13
|
-
swaggerUi.setup(
|
|
14
|
-
await _loadSwaggerConfig(),
|
|
15
|
-
{}
|
|
16
|
-
) as unknown as PlataRequestHandler
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return router
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function _loadSwaggerConfig(): Promise<any> {
|
|
24
|
-
const obj = PlataFiles.readJsonSync(path.join(PlataDirs.getProjectDirSwagger(), 'header.json'))
|
|
25
|
-
|
|
26
|
-
obj.paths = new Object(null)
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
const routes = await PlataFiles.findFiles([PlataDirs.getProjectDirSwaggerRotas()], 'header.json')
|
|
30
|
-
|
|
31
|
-
for (const route of routes) {
|
|
32
|
-
|
|
33
|
-
const docPath = path.normalize(path.dirname(route))
|
|
34
|
-
const metodo = path.normalize(path.basename(docPath))
|
|
35
|
-
const httpPath = path.normalize(
|
|
36
|
-
path.dirname(docPath.replace(PlataDirs.getProjectDirSwaggerRotas(), ''))
|
|
37
|
-
).replace(/\\/g, '/')
|
|
38
|
-
|
|
39
|
-
const header = PlataFiles.readJsonSync(path.join(docPath, 'header.json'))
|
|
40
|
-
const body = PlataFiles.readJsonSync(path.join(docPath, 'body.json'))
|
|
41
|
-
const response = PlataFiles.readJsonSync(path.join(docPath, 'response.json'))
|
|
42
|
-
|
|
43
|
-
if (obj.paths[httpPath] === undefined) {
|
|
44
|
-
obj.paths[httpPath] = new Object(null)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
obj.paths[httpPath][metodo] = { ...header, responses: response }
|
|
48
|
-
|
|
49
|
-
//https://bobbyhadz.com/blog/javascript-check-if-object-is-empty
|
|
50
|
-
if (Object.keys(body).length !== 0) {
|
|
51
|
-
if (!Array.isArray(obj.paths[httpPath][metodo].parameters)) {
|
|
52
|
-
obj.paths[httpPath][metodo].parameters = []
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const swaggerRouteBody = {
|
|
56
|
-
name: "body",
|
|
57
|
-
description: body.description,
|
|
58
|
-
in: "body",
|
|
59
|
-
schema: {
|
|
60
|
-
type: body.type ?? "object",
|
|
61
|
-
}
|
|
62
|
-
} as any
|
|
63
|
-
|
|
64
|
-
if (swaggerRouteBody.schema.type === 'array') {
|
|
65
|
-
swaggerRouteBody.schema.items = {
|
|
66
|
-
example: body.example
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
swaggerRouteBody.schema.properties = body.example
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
obj.paths[httpPath][metodo].parameters.push(swaggerRouteBody)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return obj
|
|
78
|
-
}
|
|
79
|
-
}
|
package/postinstall-tools.mjs
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
|
|
4
|
-
export function tools(dirs) {
|
|
5
|
-
const tools = new Object(null)
|
|
6
|
-
|
|
7
|
-
tools.mkdirIfNotExists = async (dir) => {
|
|
8
|
-
try {
|
|
9
|
-
const p = path.resolve(dir)
|
|
10
|
-
|
|
11
|
-
if (!fs.existsSync(p)) {
|
|
12
|
-
fs.mkdirSync(p, { resolve: true })
|
|
13
|
-
}
|
|
14
|
-
} catch (err) {
|
|
15
|
-
console.error(err)
|
|
16
|
-
process.exit(1)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
tools.copyFile = async (source, destination) => {
|
|
21
|
-
try {
|
|
22
|
-
const s = path.resolve(source)
|
|
23
|
-
const d = path.resolve(destination)
|
|
24
|
-
|
|
25
|
-
fs.copyFileSync(s, d)
|
|
26
|
-
} catch (err) {
|
|
27
|
-
console.error(err)
|
|
28
|
-
process.exit(1)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
tools.copyFileIfNotExists = async (source, destination) => {
|
|
33
|
-
try {
|
|
34
|
-
const s = path.resolve(source)
|
|
35
|
-
const d = path.resolve(destination)
|
|
36
|
-
|
|
37
|
-
if (!fs.existsSync(d)) {
|
|
38
|
-
tools.copyFile(s, d)
|
|
39
|
-
}
|
|
40
|
-
} catch (err) {
|
|
41
|
-
console.error(err)
|
|
42
|
-
process.exit(1)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
tools.forEachFileInFolder = async (folder, callback) => {
|
|
47
|
-
try {
|
|
48
|
-
const f = path.resolve(folder)
|
|
49
|
-
const files = fs.readdirSync(f)
|
|
50
|
-
|
|
51
|
-
const promises = []
|
|
52
|
-
|
|
53
|
-
files.forEach(file => {
|
|
54
|
-
const filePath = path.join(f, file)
|
|
55
|
-
|
|
56
|
-
promises.push(
|
|
57
|
-
(async () => callback(file, filePath))()
|
|
58
|
-
)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
await Promise.all(promises)
|
|
62
|
-
} catch (err) {
|
|
63
|
-
console.error(err)
|
|
64
|
-
process.exit(1)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
tools.createFolderProject = (async (folder) =>
|
|
69
|
-
tools.mkdirIfNotExists(path.join(dirs.projectDir, folder))
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
tools.copyFolderToProject = async (folder) => {
|
|
73
|
-
const templateFolder = path.join(dirs.templateDir, folder)
|
|
74
|
-
const destination = path.join(dirs.projectDir, folder)
|
|
75
|
-
|
|
76
|
-
await tools.mkdirIfNotExists(destination)
|
|
77
|
-
|
|
78
|
-
await tools.forEachFileInFolder(templateFolder, async (file, filePath) =>
|
|
79
|
-
tools.copyFileIfNotExists(
|
|
80
|
-
filePath,
|
|
81
|
-
path.join(destination, file)
|
|
82
|
-
)
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
tools.syncFolderProject = async (folder) => {
|
|
87
|
-
const templateFolder = path.join(dirs.templateDir, folder)
|
|
88
|
-
const destination = path.join(dirs.projectDir, folder)
|
|
89
|
-
|
|
90
|
-
await tools.mkdirIfNotExists(destination)
|
|
91
|
-
|
|
92
|
-
await tools.forEachFileInFolder(templateFolder, async (file, filePath) =>
|
|
93
|
-
tools.copyFile(
|
|
94
|
-
filePath,
|
|
95
|
-
path.join(destination, file)
|
|
96
|
-
)
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
tools.syncFileToProject = async (file) => {
|
|
101
|
-
const templateFile = path.join(dirs.templateDir, file)
|
|
102
|
-
const destination = path.join(dirs.projectDir, file)
|
|
103
|
-
|
|
104
|
-
await tools.copyFile(templateFile, destination)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
tools.copyFileToProject = async (file) => {
|
|
108
|
-
const templateFile = path.join(dirs.templateDir, file)
|
|
109
|
-
const destination = path.join(dirs.projectDir, file)
|
|
110
|
-
|
|
111
|
-
await tools.copyFileIfNotExists(templateFile, destination)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return tools
|
|
115
|
-
}
|
package/postinstall.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
|
|
4
|
-
const main = async () => {
|
|
5
|
-
const plataDir = path.resolve('.')
|
|
6
|
-
const templatesDir = path.resolve(plataDir, 'templates', 'postinstall')
|
|
7
|
-
const projectDir = path.resolve(plataDir, '..', '..')
|
|
8
|
-
let projectPackageJson = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json')).toString())
|
|
9
|
-
const plataPackageJson = JSON.parse(fs.readFileSync(path.join(plataDir, 'package.json')))
|
|
10
|
-
|
|
11
|
-
if (projectPackageJson.plata_no_setup !== undefined) {
|
|
12
|
-
process.exit(0)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
projectPackageJson.plata_type = projectPackageJson.plata_type ?? 'api'
|
|
16
|
-
projectPackageJson.plata_name = plataPackageJson.name
|
|
17
|
-
projectPackageJson.license = "UNLICENSED"
|
|
18
|
-
projectPackageJson['scripts_plata'] = projectPackageJson['scripts_plata'] ?? new Object(null)
|
|
19
|
-
|
|
20
|
-
// https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy
|
|
21
|
-
projectPackageJson.scripts = JSON.parse(JSON.stringify(projectPackageJson['scripts_plata']))
|
|
22
|
-
|
|
23
|
-
const templateDir = path.join(templatesDir, projectPackageJson.plata_type)
|
|
24
|
-
|
|
25
|
-
const { install } = await import(`file:///${path.join(templateDir, '_install.mjs')}`.replace(/\\/g, '/'))
|
|
26
|
-
|
|
27
|
-
projectPackageJson = await install({
|
|
28
|
-
dirs: {
|
|
29
|
-
plataDir,
|
|
30
|
-
templateDir,
|
|
31
|
-
projectDir,
|
|
32
|
-
},
|
|
33
|
-
projectPackageJson
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
fs.writeFileSync(
|
|
37
|
-
path.join(projectDir, 'package.json'),
|
|
38
|
-
JSON.stringify(projectPackageJson, null, 4)
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
main()
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
export async function install({ dirs, projectPackageJson }) {
|
|
4
|
-
const { tools } = await import(`file:///${path.resolve(dirs.plataDir, 'postinstall-tools.mjs')}`.replace(/\\/g, '/'))
|
|
5
|
-
const promises = []
|
|
6
|
-
|
|
7
|
-
const t = tools(dirs)
|
|
8
|
-
|
|
9
|
-
promises.push(t.createFolderProject('clusters'))
|
|
10
|
-
promises.push(t.createFolderProject('routes'))
|
|
11
|
-
promises.push(t.createFolderProject('libs'))
|
|
12
|
-
promises.push(t.createFolderProject('models'))
|
|
13
|
-
promises.push(t.createFolderProject('tasks'))
|
|
14
|
-
|
|
15
|
-
promises.push(t.copyFolderToProject('configs'))
|
|
16
|
-
promises.push(t.copyFolderToProject('envs'))
|
|
17
|
-
promises.push(t.syncFolderProject('.vscode'))
|
|
18
|
-
|
|
19
|
-
promises.push(t.copyFileToProject('Dockerfile'))
|
|
20
|
-
promises.push(t.syncFileToProject('tsconfig.json'))
|
|
21
|
-
|
|
22
|
-
projectPackageJson.scripts.start = `ts-node -P ./tsconfig.json ./node_modules/${projectPackageJson.plata_name}/bin/plata`
|
|
23
|
-
projectPackageJson.scripts.build = `npx tsc && ts-node -P ./tsconfig.json ./node_modules/${projectPackageJson.plata_name}/bin/plata-build --`
|
|
24
|
-
projectPackageJson.scripts.create = `ts-node -P ./tsconfig.json ./node_modules/${projectPackageJson.plata_name}/bin/plata-create --`
|
|
25
|
-
projectPackageJson.scripts.dev = "npx nodemon -e '.js,.mjs,.json,.ts' --exec npm run debug"
|
|
26
|
-
projectPackageJson.scripts.debug = `node --inspect -r ts-node/register ./node_modules/${projectPackageJson.plata_name}/bin/plata`
|
|
27
|
-
projectPackageJson.scripts['swagger:gen'] = `ts-node -P ./tsconfig.json ./node_modules/${projectPackageJson.plata_name}/bin/plata-swagger-gen`
|
|
28
|
-
projectPackageJson.scripts['plata:reload'] = `ts-node -P ./tsconfig.json ./node_modules/${projectPackageJson.plata_name}/bin/plata-reload.ts`
|
|
29
|
-
projectPackageJson.main = undefined
|
|
30
|
-
|
|
31
|
-
await Promise.all(promises)
|
|
32
|
-
|
|
33
|
-
return projectPackageJson
|
|
34
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
export async function install({ dirs, projectPackageJson }) {
|
|
4
|
-
const { tools } = await import(`file:///${path.resolve(dirs.plataDir, 'postinstall-tools.mjs')}`.replace(/\\/g, '/'))
|
|
5
|
-
const promises = []
|
|
6
|
-
|
|
7
|
-
const t = tools(dirs)
|
|
8
|
-
|
|
9
|
-
promises.push(t.createFolderProject('clusters'))
|
|
10
|
-
promises.push(t.createFolderProject('routes'))
|
|
11
|
-
promises.push(t.createFolderProject('libs'))
|
|
12
|
-
promises.push(t.createFolderProject('tasks'))
|
|
13
|
-
promises.push(t.createFolderProject('configs'))
|
|
14
|
-
promises.push(t.createFolderProject('bin'))
|
|
15
|
-
|
|
16
|
-
promises.push(t.syncFileToProject('postinstall.js'))
|
|
17
|
-
promises.push(t.syncFileToProject('postinstall-tools.mjs'))
|
|
18
|
-
promises.push(t.syncFileToProject('tsconfig.json'))
|
|
19
|
-
|
|
20
|
-
projectPackageJson.type = "module"
|
|
21
|
-
projectPackageJson.scripts.dev = "ts-node -P ./tsconfig.json"
|
|
22
|
-
projectPackageJson.scripts.postinstall = "node postinstall.js"
|
|
23
|
-
projectPackageJson.scripts.create = `ts-node -P ./tsconfig.json ./node_modules/${projectPackageJson.plata_name}/bin/plata-create --`
|
|
24
|
-
projectPackageJson.scripts['plata:reload'] = `ts-node -P ./tsconfig.json ./node_modules/${projectPackageJson.plata_name}/bin/plata-reload.ts`
|
|
25
|
-
projectPackageJson.main = undefined
|
|
26
|
-
|
|
27
|
-
await Promise.all(promises)
|
|
28
|
-
|
|
29
|
-
return projectPackageJson
|
|
30
|
-
}
|