Skip to content

Commit 0a46666

Browse files
author
svolkov
committed
docs: add changes to next release in CHANGELOG; refactor(internal): test scripts
1 parent 2d02a8e commit 0a46666

File tree

6 files changed

+84
-59
lines changed

6 files changed

+84
-59
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# next release
22
Features:
3-
- Api module description from schema info
4-
![api description](./assets/changelog_assets/api-module-description.jpg)
5-
3+
- Api module description from schema info
4+
![api description](./assets/changelog_assets/api-module-description.jpg)
5+
- Generate API types declarations (CLI flag `--route-types`)
6+
- Ability to not generate clint API class (CLI flag `--no-client`)
7+
Internal:
8+
- refactored generate and validate test scripts
69

710
# 1.2.6
811
Fixes: create api without `-o` option (use default `./` output)

tests/generate.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
1-
const fs = require("fs");
21
const path = require("path");
2+
const createSchemasInfos = require("./utils/createSchemaInfos")
33
const { generateApi } = require('../src');
44

5-
const createSchemasInfos = (pathToSchemas) =>
6-
(fs.readdirSync(pathToSchemas) || [])
7-
.reduce((schemas, fileName) => ([
8-
...schemas,
9-
{
10-
absolutePath: path.resolve(pathToSchemas, fileName),
11-
schemaFileName: fileName,
12-
apiFileName: fileName.replace(/.(yaml|json|yml)/g, '.ts'),
13-
}
14-
]), [])
5+
const schemas = [
6+
...createSchemasInfos({
7+
absolutePathToSchemas: path.resolve(__dirname, "./schemas/v2.0"),
8+
absoluteOutputPath: path.resolve(__dirname, "./generated/v2.0")
9+
}),
10+
...createSchemasInfos({
11+
absolutePathToSchemas: path.resolve(__dirname, "./schemas/v3.0"),
12+
absoluteOutputPath: path.resolve(__dirname, "./generated/v3.0")
13+
}),
14+
]
1515

16-
const v2Schemas = createSchemasInfos(path.resolve(__dirname, "./schemas/v2.0"));
17-
const v3Schemas = createSchemasInfos(path.resolve(__dirname, "./schemas/v3.0"));
18-
19-
v2Schemas.forEach(({
16+
schemas.forEach(({
2017
absolutePath,
2118
apiFileName,
19+
outputPath,
2220
}) => {
2321
generateApi({
2422
name: apiFileName,
2523
input: absolutePath,
26-
output: path.resolve(__dirname, "./generated/v2.0/")
24+
output: outputPath,
2725
});
2826
})
29-
30-
v3Schemas.forEach(({
31-
absolutePath,
32-
apiFileName,
33-
}) => {
34-
generateApi({
35-
name: apiFileName,
36-
input: absolutePath,
37-
output: path.resolve(__dirname, "./generated/v3.0/")
38-
});
39-
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const fs = require("fs");
2+
const { resolve } = require("path");
3+
4+
module.exports = (pathToApis) =>
5+
(fs.readdirSync(pathToApis) || [])
6+
.map(fileName => resolve(pathToApis, fileName))

tests/utils/createSchemaInfos.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
module.exports = ({
5+
absolutePathToSchemas,
6+
absoluteOutputPath,
7+
}) => {
8+
return (fs.readdirSync(absolutePathToSchemas) || [])
9+
.reduce((schemas, fileName) => ([
10+
...schemas,
11+
{
12+
absolutePath: path.resolve(absolutePathToSchemas, fileName),
13+
schemaFileName: fileName,
14+
apiFileName: fileName.replace(/.(yaml|json|yml)/g, '.ts'),
15+
outputPath: absoluteOutputPath
16+
}
17+
]), [])
18+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const { relative } = require("path");
2+
const tsc = require("typescript");
3+
4+
const compilerOptions = {
5+
noEmitOnError: true,
6+
noImplicitAny: false,
7+
target: tsc.ScriptTarget.ES5, module: tsc.ModuleKind.CommonJS
8+
}
9+
10+
module.exports = (path) => {
11+
process.stdout.write(`validating ${relative('', path)}: `)
12+
13+
var program = tsc.createProgram([path], compilerOptions);
14+
var emitResult = program.emit(void 0, void 0, void 0, true)
15+
16+
var allDiagnostics = emitResult.diagnostics;
17+
18+
allDiagnostics.forEach(({
19+
messageText,
20+
file,
21+
start,
22+
}) => {
23+
var message = tsc.flattenDiagnosticMessageText(messageText, '\n');
24+
if (!file) {
25+
console.error(message);
26+
return;
27+
}
28+
var { line, character } = file.getLineAndCharacterOfPosition(start);
29+
console.error(`${file.fileName} (${line + 1},${character + 1}): ${message}`);
30+
});
31+
32+
process.stdout.write(`errors ${allDiagnostics.length}\r\n`)
33+
34+
return allDiagnostics
35+
}

tests/validate.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
const fs = require("fs");
2-
const { resolve, relative } = require("path");
3-
const tsc = require("typescript");
4-
5-
const createGeneratedApiInfos = (pathToApis) =>
6-
(fs.readdirSync(pathToApis) || [])
7-
.map(fileName => resolve(pathToApis, fileName))
1+
const { resolve } = require("path");
2+
const createGeneratedApiInfos = require("./utils/createGeneratedApiInfos");
3+
const validateGeneratedModule = require("./utils/validateGeneratedModule");
84

95
const v2ApiPaths = createGeneratedApiInfos(resolve(__dirname, "./generated/v2.0"));
106
const v3ApiPaths = createGeneratedApiInfos(resolve(__dirname, "./generated/v3.0"));
@@ -15,30 +11,10 @@ let hasErrors = false;
1511
...v2ApiPaths,
1612
...v3ApiPaths,
1713
].forEach(path => {
18-
process.stdout.write(`validating ${relative('', path)}: `)
19-
var program = tsc.createProgram([path], {
20-
noEmitOnError: true,
21-
noImplicitAny: false,
22-
target: tsc.ScriptTarget.ES5, module: tsc.ModuleKind.CommonJS
23-
});
24-
var emitResult = program.emit(void 0, void 0, void 0, true)
25-
26-
var allDiagnostics = emitResult.diagnostics;
27-
28-
allDiagnostics.forEach(diagnostic => {
29-
var message = tsc.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
30-
if (!diagnostic.file) {
31-
console.error(message);
32-
return;
33-
}
34-
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
35-
console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
36-
});
37-
38-
process.stdout.write(`errors ${emitResult.diagnostics.length}\r\n`)
14+
const diagnostics = validateGeneratedModule(path)
3915

4016
if (!hasErrors) {
41-
hasErrors = !!emitResult.diagnostics.length
17+
hasErrors = !!diagnostics.length
4218
}
4319
})
4420

0 commit comments

Comments
 (0)