Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alex Quispe
doc-generator
Commits
3b1d6433
Commit
3b1d6433
authored
Oct 23, 2018
by
Alex Quispe
Browse files
Mensajes informativos optimizados.
parent
2b76a46c
Changes
1
Hide whitespace changes
Inline
Side-by-side
class/ApidocGenerator.js
View file @
3b1d6433
...
...
@@ -40,6 +40,7 @@ class ApidocGenerator {
}
static
scaffold
(
app
)
{
console
.
log
(
'
Apidoc Scaffolding ...
'
)
_crearCarpetaSiNoExiste
(
ApidocGenerator
.
SRC_PATH
)
const
ROUTES
=
_getRoutes
(
app
)
const
archivosVerificados
=
[]
...
...
@@ -54,12 +55,13 @@ class ApidocGenerator {
_crearContenidoSiNoExiste
(
filePath
,
routeInfo
)
})
})
console
.
log
(
'
\n
Scaffold ok :)
\n
'
)
console
.
log
(
'
\n
\
x1b[32minfo:
\
x1b[0m
Scaffold ok :)
\n
'
)
process
.
exit
(
0
)
}
static
async
create
(
filesName
)
{
console
.
log
(
'
Construyendo apidoc ...
'
)
const
archivosConError
=
[]
if
(
!
util
.
isDir
(
ApidocGenerator
.
BUILD_PATH
))
util
.
mkdir
(
ApidocGenerator
.
BUILD_PATH
)
const
outputRoutesPath
=
path
.
resolve
(
ApidocGenerator
.
BUILD_PATH
,
'
routes
'
)
...
...
@@ -68,7 +70,7 @@ class ApidocGenerator {
filesName
=
filesName
||
util
.
toArray
(
util
.
find
(
ApidocGenerator
.
SRC_PATH
,
'
.js
'
),
'
fileName
'
)
for
(
let
i
in
filesName
)
{
const
fileName
=
filesName
[
i
]
const
fileName
=
`
${
filesName
[
i
]
}
.js`
const
filePath
=
path
.
resolve
(
ApidocGenerator
.
SRC_PATH
,
fileName
)
console
.
log
(
`\n Procesando archivo "
${
filePath
.
replace
(
process
.
cwd
(),
''
)}
" ...\n`
)
const
dirname
=
path
.
dirname
(
filePath
)
...
...
@@ -77,7 +79,12 @@ class ApidocGenerator {
util
.
mkdir
(
outputDirPath
)
ApidocGenerator
.
GROUP_FILE
=
_toWords
(
fileName
)
ApidocGenerator
.
OUTPUT_TEMP_PATH
=
outputDirPath
await
require
(
filePath
)()
try
{
await
require
(
filePath
)()
}
catch
(
e
)
{
archivosConError
.
push
(
filePath
)
console
.
log
(
` \x1b[31mError:\x1b[0m
${
e
.
message
}
`
)
}
}
// Unión de ficheros y construcción del apidoc
...
...
@@ -89,6 +96,14 @@ class ApidocGenerator {
util
.
removeFile
(
path
.
resolve
(
ApidocGenerator
.
BUILD_PATH
,
'
apidoc.js
'
))
util
.
removeFile
(
path
.
resolve
(
ApidocGenerator
.
BUILD_PATH
,
'
swagger.json
'
))
if
(
archivosConError
.
length
>
0
)
{
console
.
log
(
'
\n
\
x1b[32minfo:
\
x1b[0m Apidoc generado <<< SIN DATOS >>> :)
\n
'
)
console
.
log
(
'
Los siguientes archivos, no pudieron ser procesados:
\n
'
)
console
.
log
(
archivosConError
)
console
.
log
(
'
\n
Verifique que el servicio a documentar se encuentre activo.
'
)
return
}
console
.
log
(
'
\n
\
x1b[32minfo:
\
x1b[0m Apidoc generado exitosamente :)
\n
'
)
}
...
...
@@ -204,7 +219,7 @@ class ApidocGenerator {
content
=
{
"
swagger
"
:
"
2.0
"
,
"
info
"
:
{
"
description
"
:
``
,
"
description
"
:
ApidocGenerator
.
DESCRIPTION
,
"
version
"
:
"
1.0.0
"
,
"
title
"
:
"
Apidoc
"
,
},
...
...
@@ -249,6 +264,7 @@ ApidocGenerator.SRC_PATH = path.resolve(process.cwd(), `src`)
ApidocGenerator
.
BUILD_PATH
=
path
.
resolve
(
process
.
cwd
(),
`build`
)
ApidocGenerator
.
API_URL
=
'
http://localhost:4000
'
ApidocGenerator
.
REDIRECT_PATH
=
'
/apidoc
'
ApidocGenerator
.
DESCRIPTION
=
''
function
_toWords
(
text
)
{
text
=
_
.
replace
(
text
,
/-/g
,
'
'
)
...
...
@@ -345,9 +361,9 @@ function _request (method, uri, body, headers) {
return
request
(
options
,
(
error
,
response
,
body
)
=>
{
if
(
error
)
{
if
(
error
.
code
===
'
ECONNREFUSED
'
)
{
console
.
log
(
'
El servicio a documentar no se encuentra disponible :(
\n
'
)
console
.
log
(
'
\
x1b[31mError:
\
x1b[0m
El servicio a documentar no se encuentra disponible :(
\n
'
)
}
console
.
log
(
error
);
return
reject
(
error
)
return
reject
(
error
)
}
const
CODE
=
response
.
statusCode
try
{
if
(
typeof
body
===
'
string
'
)
body
=
JSON
.
parse
(
body
)
}
catch
(
e
)
{}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment