@ciderjs/gasnuki 0.2.5 → 0.2.6
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.ja.md +1 -1
- package/README.md +1 -1
- package/dist/cli.cjs +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{gasnuki.Ce9vzQ2b.cjs → gasnuki.DH8w-v3n.cjs} +125 -59
- package/dist/shared/{gasnuki.DJCCMztm.mjs → gasnuki.DgQBiLxg.mjs} +125 -59
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# gasnuki
|
|
2
2
|
|
|
3
|
-
[](https://github.com/luthpg/gasnuki)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
6
6
|
[](https://github.com/luthpg/gasnuki/issues)
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ciderjs/gasnuki
|
|
2
2
|
|
|
3
|
-
[](https://github.com/luthpg/gasnuki)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
6
6
|
[](https://github.com/luthpg/gasnuki/issues)
|
package/dist/cli.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const commander = require('commander');
|
|
6
|
-
const index = require('./shared/gasnuki.
|
|
6
|
+
const index = require('./shared/gasnuki.DH8w-v3n.cjs');
|
|
7
7
|
require('chokidar');
|
|
8
8
|
require('consola');
|
|
9
9
|
require('node:fs');
|
|
@@ -24,7 +24,7 @@ function _interopNamespaceCompat(e) {
|
|
|
24
24
|
|
|
25
25
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
26
26
|
|
|
27
|
-
const version = "0.2.
|
|
27
|
+
const version = "0.2.6";
|
|
28
28
|
|
|
29
29
|
const parseArgs = async (command) => {
|
|
30
30
|
const cliOpts = command.opts();
|
package/dist/cli.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
-
import { l as loadConfig, g as generateTypes } from './shared/gasnuki.
|
|
4
|
+
import { l as loadConfig, g as generateTypes } from './shared/gasnuki.DgQBiLxg.mjs';
|
|
5
5
|
import 'chokidar';
|
|
6
6
|
import 'consola';
|
|
7
7
|
import 'node:fs';
|
|
8
8
|
import 'ts-morph';
|
|
9
9
|
import 'jiti';
|
|
10
10
|
|
|
11
|
-
const version = "0.2.
|
|
11
|
+
const version = "0.2.6";
|
|
12
12
|
|
|
13
13
|
const parseArgs = async (command) => {
|
|
14
14
|
const cliOpts = command.opts();
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'node:path';
|
|
2
2
|
import 'chokidar';
|
|
3
3
|
import 'consola';
|
|
4
|
-
export { d as defineConfig, g as generateTypes } from './shared/gasnuki.
|
|
4
|
+
export { d as defineConfig, g as generateTypes } from './shared/gasnuki.DgQBiLxg.mjs';
|
|
5
5
|
import 'node:fs';
|
|
6
6
|
import 'ts-morph';
|
|
7
7
|
import 'jiti';
|
|
@@ -92,86 +92,147 @@ const generateAppsScriptTypes = async ({
|
|
|
92
92
|
const sourceFiles = project.getSourceFiles();
|
|
93
93
|
consola.consola.info(`Found ${sourceFiles.length} source file(s).`);
|
|
94
94
|
const methodDefinitions = [];
|
|
95
|
-
const
|
|
96
|
-
const
|
|
95
|
+
const exportedDeclarations = [];
|
|
96
|
+
const exportedDeclarationNames = /* @__PURE__ */ new Set();
|
|
97
|
+
const exportedFunctions = [];
|
|
97
98
|
for (const sourceFile of sourceFiles) {
|
|
98
99
|
for (const iface of sourceFile.getInterfaces()) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
localDeclarationNames.add(name);
|
|
100
|
+
if (iface.isExported() && !iface.getName()?.endsWith("_")) {
|
|
101
|
+
exportedDeclarations.push(iface);
|
|
102
|
+
exportedDeclarationNames.add(iface.getName());
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
for (const typeAlias of sourceFile.getTypeAliases()) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
localDeclarationNames.add(name);
|
|
106
|
+
if (typeAlias.isExported() && !typeAlias.getName().endsWith("_")) {
|
|
107
|
+
exportedDeclarations.push(typeAlias);
|
|
108
|
+
exportedDeclarationNames.add(typeAlias.getName());
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
for (const func of sourceFile.getFunctions()) {
|
|
113
112
|
const name = func.getName();
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
if (func.isExported() && name && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
|
|
114
|
+
exportedDeclarations.push(func);
|
|
115
|
+
exportedDeclarationNames.add(name);
|
|
117
116
|
methodDefinitions.push(getInterfaceMethodDefinition_(name, func));
|
|
117
|
+
exportedFunctions.push(func);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
for (const varStmt of sourceFile.getVariableStatements()) {
|
|
121
|
-
if (varStmt.
|
|
121
|
+
if (!varStmt.isExported()) continue;
|
|
122
122
|
for (const varDecl of varStmt.getDeclarations()) {
|
|
123
123
|
const name = varDecl.getName();
|
|
124
124
|
const initializer = varDecl.getInitializer();
|
|
125
125
|
if (!name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name) && initializer && (initializer.getKind() === tsMorph.SyntaxKind.ArrowFunction || initializer.getKind() === tsMorph.SyntaxKind.FunctionExpression)) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
initializer
|
|
132
|
-
)
|
|
133
|
-
);
|
|
126
|
+
const funcExpr = initializer;
|
|
127
|
+
exportedDeclarations.push(varDecl);
|
|
128
|
+
exportedDeclarationNames.add(name);
|
|
129
|
+
methodDefinitions.push(getInterfaceMethodDefinition_(name, funcExpr));
|
|
130
|
+
exportedFunctions.push(funcExpr);
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
}
|
|
135
|
+
const collectSymbolsFromType = (type, foundSymbols) => {
|
|
136
|
+
const symbol = type.getAliasSymbol() ?? type.getSymbol();
|
|
137
|
+
if (symbol && !foundSymbols.has(symbol)) {
|
|
138
|
+
foundSymbols.add(symbol);
|
|
139
|
+
if (type.isObject()) {
|
|
140
|
+
for (const prop of type.getProperties()) {
|
|
141
|
+
const propDecl = prop.getDeclarations()[0];
|
|
142
|
+
if (propDecl) {
|
|
143
|
+
collectSymbolsFromType(propDecl.getType(), foundSymbols);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const typeArg of type.getTypeArguments()) {
|
|
149
|
+
collectSymbolsFromType(typeArg, foundSymbols);
|
|
150
|
+
}
|
|
151
|
+
if (type.isUnion()) {
|
|
152
|
+
for (const unionType of type.getUnionTypes()) {
|
|
153
|
+
collectSymbolsFromType(unionType, foundSymbols);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (type.isIntersection()) {
|
|
157
|
+
for (const intersectionType of type.getIntersectionTypes()) {
|
|
158
|
+
collectSymbolsFromType(intersectionType, foundSymbols);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const returnValueSymbols = /* @__PURE__ */ new Set();
|
|
163
|
+
for (const func of exportedFunctions) {
|
|
164
|
+
collectSymbolsFromType(func.getReturnType(), returnValueSymbols);
|
|
165
|
+
}
|
|
138
166
|
const importsMap = /* @__PURE__ */ new Map();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
167
|
+
const inlineDefinitions = /* @__PURE__ */ new Map();
|
|
168
|
+
const symbolsToProcess = /* @__PURE__ */ new Set();
|
|
169
|
+
const processedSymbols = /* @__PURE__ */ new Set();
|
|
170
|
+
for (const decl of exportedDeclarations) {
|
|
171
|
+
for (const descendant of decl.getDescendantsOfKind(
|
|
172
|
+
tsMorph.SyntaxKind.TypeReference
|
|
173
|
+
)) {
|
|
142
174
|
const symbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
|
|
143
175
|
if (symbol) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
symbolsToProcess.add(symbol);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
while (symbolsToProcess.size > 0) {
|
|
181
|
+
const symbol = symbolsToProcess.values().next().value;
|
|
182
|
+
if (!symbol) continue;
|
|
183
|
+
symbolsToProcess.delete(symbol);
|
|
184
|
+
const symbolName = symbol.getName();
|
|
185
|
+
if (processedSymbols.has(symbolName) || exportedDeclarationNames.has(symbolName) || symbolName === "__type") {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const symbolFlags = symbol.getFlags();
|
|
189
|
+
if (symbolFlags & tsMorph.SymbolFlags.TypeParameter) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const declaration = symbol.getDeclarations()[0];
|
|
193
|
+
if (!declaration) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const sourceFile = declaration.getSourceFile();
|
|
197
|
+
if (sourceFile.getFilePath().includes("node_modules")) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
processedSymbols.add(symbolName);
|
|
201
|
+
const isLocalDefinition = declaration.getParent()?.getKind() !== tsMorph.SyntaxKind.SourceFile;
|
|
202
|
+
if (isLocalDefinition) {
|
|
203
|
+
if (returnValueSymbols.has(symbol)) {
|
|
204
|
+
const declText = declaration.getText();
|
|
205
|
+
inlineDefinitions.set(symbolName, declText);
|
|
206
|
+
const tempSourceFile = project.createSourceFile(
|
|
207
|
+
`__temp_${symbolName}.ts`,
|
|
208
|
+
declText
|
|
209
|
+
);
|
|
210
|
+
for (const descendant of tempSourceFile.getDescendantsOfKind(
|
|
211
|
+
tsMorph.SyntaxKind.TypeReference
|
|
212
|
+
)) {
|
|
213
|
+
const newSymbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
|
|
214
|
+
if (newSymbol) {
|
|
215
|
+
symbolsToProcess.add(newSymbol);
|
|
171
216
|
}
|
|
172
|
-
importsMap.get(modulePath)?.add(symbolName);
|
|
173
217
|
}
|
|
218
|
+
tempSourceFile.delete();
|
|
174
219
|
}
|
|
220
|
+
} else {
|
|
221
|
+
let modulePath = path__namespace.relative(absoluteOutDir, sourceFile.getFilePath()).replace(/\\/g, "/");
|
|
222
|
+
modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
|
|
223
|
+
if (modulePath.endsWith("/index")) {
|
|
224
|
+
modulePath = modulePath.slice(0, -6);
|
|
225
|
+
}
|
|
226
|
+
if (modulePath === "index" || modulePath === "") {
|
|
227
|
+
modulePath = ".";
|
|
228
|
+
}
|
|
229
|
+
if (!modulePath.startsWith(".")) {
|
|
230
|
+
modulePath = `./${modulePath}`;
|
|
231
|
+
}
|
|
232
|
+
if (!importsMap.has(modulePath)) {
|
|
233
|
+
importsMap.set(modulePath, /* @__PURE__ */ new Set());
|
|
234
|
+
}
|
|
235
|
+
importsMap.get(modulePath)?.add(symbolName);
|
|
175
236
|
}
|
|
176
237
|
}
|
|
177
238
|
if (!fs__namespace.existsSync(absoluteOutDir)) {
|
|
@@ -199,11 +260,16 @@ const generateAppsScriptTypes = async ({
|
|
|
199
260
|
|
|
200
261
|
`;
|
|
201
262
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
263
|
+
if (inlineDefinitions.size > 0) {
|
|
264
|
+
outputContent += `${[...inlineDefinitions.values()].join("\n\n")}
|
|
265
|
+
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
const exportedTypeDefinitions = exportedDeclarations.filter(
|
|
269
|
+
(d) => d.getKind() === tsMorph.SyntaxKind.InterfaceDeclaration || d.getKind() === tsMorph.SyntaxKind.TypeAliasDeclaration
|
|
270
|
+
).map((decl) => decl.getText());
|
|
271
|
+
if (exportedTypeDefinitions.length > 0) {
|
|
272
|
+
outputContent += `${exportedTypeDefinitions.join("\n\n")}
|
|
207
273
|
|
|
208
274
|
`;
|
|
209
275
|
}
|
|
@@ -216,7 +282,7 @@ ${formattedMethods}
|
|
|
216
282
|
}
|
|
217
283
|
`;
|
|
218
284
|
consola.consola.info(
|
|
219
|
-
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${
|
|
285
|
+
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${exportedTypeDefinitions.length + inlineDefinitions.size} type(s)).`
|
|
220
286
|
);
|
|
221
287
|
} else {
|
|
222
288
|
outputContent += "export type ServerScripts = {}\n";
|
|
@@ -74,86 +74,147 @@ const generateAppsScriptTypes = async ({
|
|
|
74
74
|
const sourceFiles = project.getSourceFiles();
|
|
75
75
|
consola.info(`Found ${sourceFiles.length} source file(s).`);
|
|
76
76
|
const methodDefinitions = [];
|
|
77
|
-
const
|
|
78
|
-
const
|
|
77
|
+
const exportedDeclarations = [];
|
|
78
|
+
const exportedDeclarationNames = /* @__PURE__ */ new Set();
|
|
79
|
+
const exportedFunctions = [];
|
|
79
80
|
for (const sourceFile of sourceFiles) {
|
|
80
81
|
for (const iface of sourceFile.getInterfaces()) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
localDeclarationNames.add(name);
|
|
82
|
+
if (iface.isExported() && !iface.getName()?.endsWith("_")) {
|
|
83
|
+
exportedDeclarations.push(iface);
|
|
84
|
+
exportedDeclarationNames.add(iface.getName());
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
for (const typeAlias of sourceFile.getTypeAliases()) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
localDeclarationNames.add(name);
|
|
88
|
+
if (typeAlias.isExported() && !typeAlias.getName().endsWith("_")) {
|
|
89
|
+
exportedDeclarations.push(typeAlias);
|
|
90
|
+
exportedDeclarationNames.add(typeAlias.getName());
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
for (const func of sourceFile.getFunctions()) {
|
|
95
94
|
const name = func.getName();
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if (func.isExported() && name && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
|
|
96
|
+
exportedDeclarations.push(func);
|
|
97
|
+
exportedDeclarationNames.add(name);
|
|
99
98
|
methodDefinitions.push(getInterfaceMethodDefinition_(name, func));
|
|
99
|
+
exportedFunctions.push(func);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
for (const varStmt of sourceFile.getVariableStatements()) {
|
|
103
|
-
if (varStmt.
|
|
103
|
+
if (!varStmt.isExported()) continue;
|
|
104
104
|
for (const varDecl of varStmt.getDeclarations()) {
|
|
105
105
|
const name = varDecl.getName();
|
|
106
106
|
const initializer = varDecl.getInitializer();
|
|
107
107
|
if (!name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name) && initializer && (initializer.getKind() === SyntaxKind.ArrowFunction || initializer.getKind() === SyntaxKind.FunctionExpression)) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
initializer
|
|
114
|
-
)
|
|
115
|
-
);
|
|
108
|
+
const funcExpr = initializer;
|
|
109
|
+
exportedDeclarations.push(varDecl);
|
|
110
|
+
exportedDeclarationNames.add(name);
|
|
111
|
+
methodDefinitions.push(getInterfaceMethodDefinition_(name, funcExpr));
|
|
112
|
+
exportedFunctions.push(funcExpr);
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
}
|
|
117
|
+
const collectSymbolsFromType = (type, foundSymbols) => {
|
|
118
|
+
const symbol = type.getAliasSymbol() ?? type.getSymbol();
|
|
119
|
+
if (symbol && !foundSymbols.has(symbol)) {
|
|
120
|
+
foundSymbols.add(symbol);
|
|
121
|
+
if (type.isObject()) {
|
|
122
|
+
for (const prop of type.getProperties()) {
|
|
123
|
+
const propDecl = prop.getDeclarations()[0];
|
|
124
|
+
if (propDecl) {
|
|
125
|
+
collectSymbolsFromType(propDecl.getType(), foundSymbols);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (const typeArg of type.getTypeArguments()) {
|
|
131
|
+
collectSymbolsFromType(typeArg, foundSymbols);
|
|
132
|
+
}
|
|
133
|
+
if (type.isUnion()) {
|
|
134
|
+
for (const unionType of type.getUnionTypes()) {
|
|
135
|
+
collectSymbolsFromType(unionType, foundSymbols);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (type.isIntersection()) {
|
|
139
|
+
for (const intersectionType of type.getIntersectionTypes()) {
|
|
140
|
+
collectSymbolsFromType(intersectionType, foundSymbols);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const returnValueSymbols = /* @__PURE__ */ new Set();
|
|
145
|
+
for (const func of exportedFunctions) {
|
|
146
|
+
collectSymbolsFromType(func.getReturnType(), returnValueSymbols);
|
|
147
|
+
}
|
|
120
148
|
const importsMap = /* @__PURE__ */ new Map();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
149
|
+
const inlineDefinitions = /* @__PURE__ */ new Map();
|
|
150
|
+
const symbolsToProcess = /* @__PURE__ */ new Set();
|
|
151
|
+
const processedSymbols = /* @__PURE__ */ new Set();
|
|
152
|
+
for (const decl of exportedDeclarations) {
|
|
153
|
+
for (const descendant of decl.getDescendantsOfKind(
|
|
154
|
+
SyntaxKind.TypeReference
|
|
155
|
+
)) {
|
|
124
156
|
const symbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
|
|
125
157
|
if (symbol) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
symbolsToProcess.add(symbol);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
while (symbolsToProcess.size > 0) {
|
|
163
|
+
const symbol = symbolsToProcess.values().next().value;
|
|
164
|
+
if (!symbol) continue;
|
|
165
|
+
symbolsToProcess.delete(symbol);
|
|
166
|
+
const symbolName = symbol.getName();
|
|
167
|
+
if (processedSymbols.has(symbolName) || exportedDeclarationNames.has(symbolName) || symbolName === "__type") {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const symbolFlags = symbol.getFlags();
|
|
171
|
+
if (symbolFlags & SymbolFlags.TypeParameter) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const declaration = symbol.getDeclarations()[0];
|
|
175
|
+
if (!declaration) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const sourceFile = declaration.getSourceFile();
|
|
179
|
+
if (sourceFile.getFilePath().includes("node_modules")) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
processedSymbols.add(symbolName);
|
|
183
|
+
const isLocalDefinition = declaration.getParent()?.getKind() !== SyntaxKind.SourceFile;
|
|
184
|
+
if (isLocalDefinition) {
|
|
185
|
+
if (returnValueSymbols.has(symbol)) {
|
|
186
|
+
const declText = declaration.getText();
|
|
187
|
+
inlineDefinitions.set(symbolName, declText);
|
|
188
|
+
const tempSourceFile = project.createSourceFile(
|
|
189
|
+
`__temp_${symbolName}.ts`,
|
|
190
|
+
declText
|
|
191
|
+
);
|
|
192
|
+
for (const descendant of tempSourceFile.getDescendantsOfKind(
|
|
193
|
+
SyntaxKind.TypeReference
|
|
194
|
+
)) {
|
|
195
|
+
const newSymbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
|
|
196
|
+
if (newSymbol) {
|
|
197
|
+
symbolsToProcess.add(newSymbol);
|
|
153
198
|
}
|
|
154
|
-
importsMap.get(modulePath)?.add(symbolName);
|
|
155
199
|
}
|
|
200
|
+
tempSourceFile.delete();
|
|
156
201
|
}
|
|
202
|
+
} else {
|
|
203
|
+
let modulePath = path.relative(absoluteOutDir, sourceFile.getFilePath()).replace(/\\/g, "/");
|
|
204
|
+
modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
|
|
205
|
+
if (modulePath.endsWith("/index")) {
|
|
206
|
+
modulePath = modulePath.slice(0, -6);
|
|
207
|
+
}
|
|
208
|
+
if (modulePath === "index" || modulePath === "") {
|
|
209
|
+
modulePath = ".";
|
|
210
|
+
}
|
|
211
|
+
if (!modulePath.startsWith(".")) {
|
|
212
|
+
modulePath = `./${modulePath}`;
|
|
213
|
+
}
|
|
214
|
+
if (!importsMap.has(modulePath)) {
|
|
215
|
+
importsMap.set(modulePath, /* @__PURE__ */ new Set());
|
|
216
|
+
}
|
|
217
|
+
importsMap.get(modulePath)?.add(symbolName);
|
|
157
218
|
}
|
|
158
219
|
}
|
|
159
220
|
if (!fs.existsSync(absoluteOutDir)) {
|
|
@@ -181,11 +242,16 @@ const generateAppsScriptTypes = async ({
|
|
|
181
242
|
|
|
182
243
|
`;
|
|
183
244
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
245
|
+
if (inlineDefinitions.size > 0) {
|
|
246
|
+
outputContent += `${[...inlineDefinitions.values()].join("\n\n")}
|
|
247
|
+
|
|
248
|
+
`;
|
|
249
|
+
}
|
|
250
|
+
const exportedTypeDefinitions = exportedDeclarations.filter(
|
|
251
|
+
(d) => d.getKind() === SyntaxKind.InterfaceDeclaration || d.getKind() === SyntaxKind.TypeAliasDeclaration
|
|
252
|
+
).map((decl) => decl.getText());
|
|
253
|
+
if (exportedTypeDefinitions.length > 0) {
|
|
254
|
+
outputContent += `${exportedTypeDefinitions.join("\n\n")}
|
|
189
255
|
|
|
190
256
|
`;
|
|
191
257
|
}
|
|
@@ -198,7 +264,7 @@ ${formattedMethods}
|
|
|
198
264
|
}
|
|
199
265
|
`;
|
|
200
266
|
consola.info(
|
|
201
|
-
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${
|
|
267
|
+
`Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${exportedTypeDefinitions.length + inlineDefinitions.size} type(s)).`
|
|
202
268
|
);
|
|
203
269
|
} else {
|
|
204
270
|
outputContent += "export type ServerScripts = {}\n";
|