Skip to content

Commit 3bdb1c3

Browse files
authored
api(dotnet): generate api in a specific folder (#6708)
1 parent 7d0b4c2 commit 3bdb1c3

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

utils/doclint/generateDotnetApi.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ const customTypeNames = new Map([
4444
['File', 'FilePayload'],
4545
]);
4646

47-
const typesDir = process.argv[2] || path.join(__dirname, 'generate_types', 'csharp');
48-
const modelsDir = path.join(typesDir, 'Models');
49-
const enumsDir = path.join(typesDir, 'Enums');
50-
const optionsDir = path.join(typesDir, 'Options');
51-
const baseDir = path.join(typesDir, 'Base');
52-
53-
for (const dir of [typesDir, modelsDir, enumsDir, optionsDir, baseDir])
47+
const outputDir = process.argv[2] || path.join(__dirname, 'generate_types', 'csharp');
48+
const apiDir = path.join(outputDir, 'API', 'Generated');
49+
const optionsDir = path.join(outputDir, 'API', 'Generated', 'Options');
50+
const enumsDir = path.join(outputDir, 'API', 'Generated', 'Enums');
51+
const typesDir = path.join(outputDir, 'API', 'Generated', 'Types');
52+
const adaptersDir = path.join(outputDir, 'Generated', 'Adapters');
53+
54+
for (const dir of [apiDir, optionsDir, enumsDir, typesDir, adaptersDir])
5455
fs.mkdirSync(dir, { recursive: true });
5556

5657
const documentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'api'));
@@ -70,8 +71,7 @@ documentation.setLinkRenderer(item => {
7071
});
7172

7273
// get the template for a class
73-
const template = fs.readFileSync(path.join(__dirname, 'templates', 'interface.cs'), 'utf-8')
74-
.replace('[PW_TOOL_VERSION]', `${__filename.substring(path.join(__dirname, '..', '..').length).split(path.sep).join(path.posix.sep)}`);
74+
const template = fs.readFileSync(path.join(__dirname, 'templates', 'interface.cs'), 'utf-8');
7575

7676
// we have some "predefined" types, like the mixed state enum, that we can map in advance
7777
enumTypes.set("MixedState", ["On", "Off", "Mixed"]);
@@ -128,7 +128,7 @@ function writeFile(kind, name, spec, body, folder, extendsName = null) {
128128
out.push('}');
129129

130130
let content = template.replace('[CONTENT]', out.join(EOL));
131-
fs.writeFileSync(path.join(folder, name + '.generated.cs'), content);
131+
fs.writeFileSync(path.join(folder, name + '.cs'), content);
132132
}
133133

134134
/**
@@ -148,7 +148,7 @@ function renderClass(clazz) {
148148
name,
149149
clazz.spec,
150150
body,
151-
typesDir,
151+
apiDir,
152152
clazz.extends ? `I${toTitleCase(clazz.extends)}` : null);
153153
}
154154

@@ -180,7 +180,7 @@ function renderBaseClass(clazz) {
180180
name,
181181
[],
182182
body,
183-
baseDir,
183+
adaptersDir,
184184
null);
185185
}
186186

@@ -208,7 +208,7 @@ function renderModelType(name, type) {
208208
console.log(type);
209209
throw new Error(`Not sure what to do in this case.`);
210210
}
211-
writeFile('public partial class', name, null, body, modelsDir);
211+
writeFile('public partial class', name, null, body, typesDir);
212212
}
213213

214214
/**
@@ -261,7 +261,7 @@ for (let [name, literals] of enumTypes)
261261

262262
if (process.argv[3] !== "--skip-format") {
263263
// run the formatting tool for .net, to ensure the files are prepped
264-
execSync(`dotnet format -f "${typesDir}" --include-generated --fix-whitespace`);
264+
execSync(`dotnet format -f "${outputDir}" --include-generated --fix-whitespace`);
265265
}
266266

267267
/**

utils/doclint/templates/interface.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,8 @@
2020
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
23-
*
24-
*
25-
* ------------------------------------------------------------------------------
26-
* <auto-generated>
27-
* This code was generated by a tool at:
28-
* [PW_TOOL_VERSION]
29-
*
30-
* Changes to this file may cause incorrect behavior and will be lost if
31-
* the code is regenerated.
32-
* </auto-generated>
33-
* ------------------------------------------------------------------------------
3423
*/
24+
3525
using System;
3626
using System.Collections.Generic;
3727
using System.Drawing;

0 commit comments

Comments
 (0)