@coast/core-api-types 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/scripts/generateTypes.js +14 -3
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Description
|
|
2
|
+
This project contains script and skeleton package.json to support generating and publishing an npm package for all types in `@coast/core-models`
|
|
3
|
+
|
|
4
|
+
# Commands
|
|
5
|
+
### Generate types
|
|
6
|
+
- `yarn clean` (optional) cleans generated + compiled files
|
|
7
|
+
- `yarn generate` copies files from core-models and turns them into interfaces without dependencies
|
|
8
|
+
### Build
|
|
9
|
+
- `yarn build` compiles ts files into dist
|
|
10
|
+
### Version
|
|
11
|
+
- `yarn version --patch`
|
|
12
|
+
- `patch`
|
|
13
|
+
- `minor`
|
|
14
|
+
- `major`
|
|
15
|
+
### Publish
|
|
16
|
+
- `npm login` if not logged in
|
|
17
|
+
- `yarn publish`
|
|
18
|
+
|
|
19
|
+
|
|
@@ -24,6 +24,7 @@ const project = new ts_morph_1.Project({
|
|
|
24
24
|
});
|
|
25
25
|
console.log(`Processing project with ${project.getSourceFiles().length} files`);
|
|
26
26
|
project.getSourceFiles().forEach((sourceFile) => processFile(sourceFile));
|
|
27
|
+
project.saveSync();
|
|
27
28
|
function copyCoreModels() {
|
|
28
29
|
const sourceDir = path_1.default.resolve(__dirname, '../../../core-models/src');
|
|
29
30
|
const destDir = path_1.default.resolve(__dirname, '../models');
|
|
@@ -56,7 +57,6 @@ function processFile(sourceFile) {
|
|
|
56
57
|
sourceFile.fixMissingImports();
|
|
57
58
|
sourceFile.organizeImports();
|
|
58
59
|
sourceFile.formatText();
|
|
59
|
-
project.saveSync();
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
console.log(`Ignoring file: ${filePath}`);
|
|
@@ -115,7 +115,7 @@ function makeInterface(sourceFile, classDeclaration) {
|
|
|
115
115
|
}
|
|
116
116
|
function getAllExtends(classDeclaration) {
|
|
117
117
|
const extendsTexts = classDeclaration.getImplements().map((implement) => implement.getText());
|
|
118
|
-
const extendsExpression = classDeclaration
|
|
118
|
+
const extendsExpression = cleanseMappedTypeCasting(classDeclaration);
|
|
119
119
|
if (extendsExpression !== undefined) {
|
|
120
120
|
const callExpression = extendsExpression.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
121
121
|
if (extendsContainsNestJSMappedType(callExpression)) {
|
|
@@ -128,6 +128,18 @@ function getAllExtends(classDeclaration) {
|
|
|
128
128
|
}
|
|
129
129
|
return extendsTexts.length > 0 ? extendsTexts : null;
|
|
130
130
|
}
|
|
131
|
+
function cleanseMappedTypeCasting(classDeclaration) {
|
|
132
|
+
const extendsExpression = classDeclaration.getExtends();
|
|
133
|
+
extendsExpression?.forEachDescendant((descendant) => {
|
|
134
|
+
if (descendant.getKind() === ts_morph_1.SyntaxKind.AsExpression) {
|
|
135
|
+
const desiredExpression = descendant.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
|
|
136
|
+
if (desiredExpression !== undefined) {
|
|
137
|
+
descendant.replaceWithText(desiredExpression.getText());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return extendsExpression;
|
|
142
|
+
}
|
|
131
143
|
function extendsContainsNestJSMappedType(extendsExpression) {
|
|
132
144
|
return extendsExpression !== undefined && mappedTypeUtilityTypeMap[extendsExpression.getExpression().getText()] !== undefined;
|
|
133
145
|
}
|
|
@@ -164,7 +176,6 @@ function getDefaultMappedType(mappedType, baseTypeText, callExpression) {
|
|
|
164
176
|
?.getElements()
|
|
165
177
|
.map((element) => element.getText())
|
|
166
178
|
.join(' | ');
|
|
167
|
-
console.log({ omitOrPickTypeArgument, isUndefined: omitOrPickTypeArgument === undefined });
|
|
168
179
|
if (omitOrPickTypeArgument !== undefined && omitOrPickTypeArgument !== '') {
|
|
169
180
|
return `${utilityType}<${baseTypeText}, ${omitOrPickTypeArgument}>`;
|
|
170
181
|
}
|