Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
cdf328dc
Unverified
Commit
cdf328dc
authored
3 years ago
by
Gabriel-Ladzaretti
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
docs: Prettify JSON output for default objects in docs (#16015)
parent
96dc2e34
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/docs/config.ts
+77
-8
77 additions, 8 deletions
tools/docs/config.ts
with
77 additions
and
8 deletions
tools/docs/config.ts
+
77
−
8
View file @
cdf328dc
import
table
from
'
markdown-table
'
;
import
stringify
from
'
json-stringify-pretty-compact
'
;
import
{
getOptions
}
from
'
../../lib/config/options
'
;
import
{
getCliName
}
from
'
../../lib/workers/global/config/parse/cli
'
;
import
{
getEnvName
}
from
'
../../lib/workers/global/config/parse/env
'
;
...
...
@@ -6,6 +6,75 @@ import { readFile, updateFile } from '../utils';
const
options
=
getOptions
();
/**
* Merge string arrays one by one
* Example: let arr1 = ['a','b','c'], arr2 = ['1','2','3','4','5']
* merge(arr1,arr2) = ['a','1','b','2','c','3','4','5']
* @param array1
* @param array2
*/
function
merge
(
array1
:
string
[],
array2
:
string
[]):
string
[]
{
const
arr1
=
[...
array1
];
const
arr2
=
[...
array2
];
const
merged
:
string
[]
=
[];
for
(
const
str1
of
arr1
)
{
merged
.
push
(
str1
);
const
str2
=
arr2
.
pop
();
if
(
str2
!==
undefined
)
{
merged
.
push
(
str2
);
}
}
return
merged
.
concat
(
arr2
);
}
function
indent
(
strings
:
TemplateStringsArray
,
...
keys
:
(
string
|
number
|
boolean
)[]
):
string
{
const
indent
=
'
'
;
const
strs
=
[...
strings
];
let
amount
=
0
;
// validate input
if
(
typeof
keys
[
0
]
===
'
number
'
&&
strings
[
0
]
===
''
)
{
amount
=
keys
.
shift
()
as
number
;
strs
.
shift
();
}
return
indent
.
repeat
(
amount
)
+
merge
(
strs
,
keys
.
map
(
String
)).
join
(
''
);
}
function
buildHtmlTable
(
data
:
string
[][]):
string
{
// skip empty tables
if
(
data
.
length
<
2
)
{
return
''
;
}
let
table
=
`<table>\n`
;
for
(
const
[
i
,
row
]
of
data
.
entries
())
{
if
(
i
===
0
)
{
table
+=
indent
`
${
1
}
<thead>\n`
;
}
if
(
i
===
1
)
{
table
+=
indent
`
${
1
}
</thead>\n`
+
indent
`
${
1
}
<tbody>\n`
;
}
table
+=
indent
`
${
2
}
<tr>\n`
;
for
(
const
col
of
row
)
{
if
(
i
===
0
)
{
table
+=
indent
`
${
3
}
<th>
${
col
}
</th>\n`
;
continue
;
}
table
+=
indent
`
${
3
}
<td>
${
col
}
`
+
(
`
${
col
}
`
.
endsWith
(
'
\n
'
)
?
indent
`
${
3
}
`
:
''
)
+
`</td>\n`
;
}
table
+=
indent
`
${
2
}
</tr>\n`
;
}
table
+=
indent
`
${
1
}
</tbody>\n</table>\n`
;
return
table
;
}
function
genTable
(
obj
:
[
string
,
string
][],
type
:
string
,
def
:
any
):
string
{
const
data
=
[[
'
Name
'
,
'
Value
'
]];
const
name
=
obj
[
0
][
1
];
...
...
@@ -33,14 +102,14 @@ function genTable(obj: [string, string][], type: string, def: any): string {
name
!==
'
prBody
'
)
)
{
if
(
type
===
'
string
'
&&
el
[
0
]
===
'
default
'
)
{
el
[
1
]
=
`
\`
"
${
el
[
1
]}
"
\`
`
;
el
[
1
]
=
`
<code>
"
${
el
[
1
]}
"
</code>
`
;
}
if
(
(
type
===
'
boolean
'
&&
el
[
0
]
===
'
default
'
)
||
el
[
0
]
===
'
cli
'
||
el
[
0
]
===
'
env
'
)
{
el
[
1
]
=
`
\`
${
el
[
1
]}
\`
`
;
el
[
1
]
=
`
<code>
${
el
[
1
]}
</code>
`
;
}
if
(
type
===
'
string
'
&&
el
[
0
]
===
'
default
'
&&
el
[
1
].
length
>
200
)
{
el
[
1
]
=
`[template]`
;
...
...
@@ -51,7 +120,7 @@ function genTable(obj: [string, string][], type: string, def: any): string {
if
(
Object
.
keys
(
el
[
1
]
??
[]).
length
===
0
)
{
return
;
}
el
[
1
]
=
`
\
`
${
JSON
.
stringify
(
el
[
1
])}
\`
`
;
el
[
1
]
=
`\
n
\`\`\`
json\n
${
stringify
(
el
[
1
],
{
indent
:
2
})}
\n
\`\`\`
\n
`
;
}
data
.
push
(
el
);
}
...
...
@@ -61,15 +130,15 @@ function genTable(obj: [string, string][], type: string, def: any): string {
data
.
push
([
'
default
'
,
'
`[]`
'
]);
}
if
(
type
===
'
string
'
&&
def
===
undefined
)
{
data
.
push
([
'
default
'
,
'
`null`
'
]);
data
.
push
([
'
default
'
,
'
<code>null</code>
'
]);
}
if
(
type
===
'
boolean
'
&&
def
===
undefined
)
{
data
.
push
([
'
default
'
,
'
`true`
'
]);
data
.
push
([
'
default
'
,
'
<code>true</code>
'
]);
}
if
(
type
===
'
boolean
'
&&
def
===
null
)
{
data
.
push
([
'
default
'
,
'
`null`
'
]);
data
.
push
([
'
default
'
,
'
<code>null</code>
'
]);
}
return
t
able
(
data
);
return
buildHtmlT
able
(
data
);
}
export
async
function
generateConfig
(
dist
:
string
,
bot
=
false
):
Promise
<
void
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment