Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeGen
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Coscine
backend
scripts
CodeGen
Commits
be371a20
Commit
be371a20
authored
Sep 13, 2021
by
Benedikt Heinrichs
Browse files
Options
Downloads
Patches
Plain Diff
Also generate index file
parent
986652ba
No related branches found
No related tags found
1 merge request
!1
New: Create a Api Client Script
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/CodeGen/Program.cs
+19
-0
19 additions, 0 deletions
src/CodeGen/Program.cs
with
19 additions
and
0 deletions
src/CodeGen/Program.cs
+
19
−
0
View file @
be371a20
...
@@ -58,10 +58,13 @@ namespace Coscine.CodeGen
...
@@ -58,10 +58,13 @@ namespace Coscine.CodeGen
}
}
var
combinationFile
=
outputPath
+
"/apis.ts"
;
var
combinationFile
=
outputPath
+
"/apis.ts"
;
var
indexFile
=
outputPath
+
"/index.ts"
;
var
combinationFileImports
=
new
List
<
string
>();
var
combinationFileImports
=
new
List
<
string
>();
var
combinationFileExports
=
new
List
<
string
>();
var
combinationFileExports
=
new
List
<
string
>();
var
concreteApiNames
=
new
List
<
string
>();
var
first
=
true
;
var
first
=
true
;
var
apiRegex
=
new
Regex
(
"(?<= )(.*?)(?= extends BaseAPI)"
);
var
apiRegex
=
new
Regex
(
"(?<= )(.*?)(?= extends BaseAPI)"
);
...
@@ -81,6 +84,7 @@ namespace Coscine.CodeGen
...
@@ -81,6 +84,7 @@ namespace Coscine.CodeGen
foreach
(
var
apiImplementation
in
apiImplementations
)
foreach
(
var
apiImplementation
in
apiImplementations
)
{
{
var
concreteApiName
=
apiImplementation
.
ToString
().
Replace
(
"class "
,
""
);
var
concreteApiName
=
apiImplementation
.
ToString
().
Replace
(
"class "
,
""
);
concreteApiNames
.
Add
(
concreteApiName
);
combinationFileImports
.
Add
(
$"import
{{
{
concreteApiName
}
Factory
}}
from './
{
directoryName
}
/api';"
);
combinationFileImports
.
Add
(
$"import
{{
{
concreteApiName
}
Factory
}}
from './
{
directoryName
}
/api';"
);
if
(
first
)
if
(
first
)
{
{
...
@@ -92,6 +96,7 @@ namespace Coscine.CodeGen
...
@@ -92,6 +96,7 @@ namespace Coscine.CodeGen
}
}
combinationFileExports
.
Sort
();
combinationFileExports
.
Sort
();
concreteApiNames
.
Sort
();
var
combinationFileText
=
"import { AxiosInstance } from 'axios';\n\n"
;
var
combinationFileText
=
"import { AxiosInstance } from 'axios';\n\n"
;
combinationFileText
+=
string
.
Join
(
'\n'
,
combinationFileImports
);
combinationFileText
+=
string
.
Join
(
'\n'
,
combinationFileImports
);
...
@@ -126,6 +131,20 @@ const getHostName = () => {
...
@@ -126,6 +131,20 @@ const getHostName = () => {
combinationFileText
+=
"\n };\n};\n\nexport default implementations;\n"
;
combinationFileText
+=
"\n };\n};\n\nexport default implementations;\n"
;
await
File
.
WriteAllTextAsync
(
combinationFile
,
combinationFileText
);
await
File
.
WriteAllTextAsync
(
combinationFile
,
combinationFileText
);
var
indexFileText
=
@"import implementations from './apis';
import instance from './axios-basic';
const apis = implementations(instance);
"
;
foreach
(
var
concreteApiName
in
concreteApiNames
)
{
indexFileText
+=
$"export const
{
concreteApiName
}
= apis.
{
concreteApiName
}
;\n"
;
}
indexFileText
+=
"\nexport default apis;\n"
;
await
File
.
WriteAllTextAsync
(
indexFile
,
indexFileText
);
}
}
private
static
Task
ExecuteCommand
(
string
command
)
private
static
Task
ExecuteCommand
(
string
command
)
...
...
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