@ciderjs/gasnuki 0.1.1 → 0.1.2

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/dist/cli.cjs CHANGED
@@ -9,7 +9,7 @@ require('consola');
9
9
  require('node:fs');
10
10
  require('ts-morph');
11
11
 
12
- const version = "0.1.1";
12
+ const version = "0.1.2";
13
13
 
14
14
  const parseArgs = async (command) => {
15
15
  const { project, srcDir, outDir, outputFile, watch } = command.opts();
package/dist/cli.mjs CHANGED
@@ -7,7 +7,7 @@ import 'consola';
7
7
  import 'node:fs';
8
8
  import 'ts-morph';
9
9
 
10
- const version = "0.1.1";
10
+ const version = "0.1.2";
11
11
 
12
12
  const parseArgs = async (command) => {
13
13
  const { project, srcDir, outDir, outputFile, watch } = command.opts();
package/dist/index.cjs CHANGED
@@ -23,6 +23,8 @@ const chokidar__namespace = /*#__PURE__*/_interopNamespaceCompat(chokidar);
23
23
  const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
24
24
 
25
25
  const getInterfaceMethodDefinition_ = (name, node) => {
26
+ const typeParameters = node.getTypeParameters?.() ?? [];
27
+ const typeParamsString = typeParameters.length > 0 ? `<${typeParameters.map((tp) => tp.getText()).join(", ")}>` : "";
26
28
  const parameters = node.getParameters().map((param) => {
27
29
  const paramName = param.getName();
28
30
  const type = param.getTypeNode()?.getText() ?? param.getType().getText(node) ?? "any";
@@ -67,7 +69,7 @@ const getInterfaceMethodDefinition_ = (name, node) => {
67
69
  }
68
70
  }
69
71
  }
70
- return `${jsDocString}${name}(${parameters}): ${returnType};`;
72
+ return `${jsDocString}${name}${typeParamsString}(${parameters}): ${returnType};`;
71
73
  };
72
74
  const generateAppsScriptTypes = async ({
73
75
  project: projectPath,
@@ -82,17 +84,30 @@ const generateAppsScriptTypes = async ({
82
84
  consola.consola.info(` AppsScript Source Directory: ${absoluteSrcDir}`);
83
85
  consola.consola.info(` Output File: ${absoluteOutputFile}`);
84
86
  const project = new tsMorph.Project({
85
- tsConfigFilePath: path__namespace.resolve(projectPath, "tsconfig.json")
87
+ tsConfigFilePath: path__namespace.resolve(projectPath, "tsconfig.json"),
88
+ skipAddingFilesFromTsConfig: true
86
89
  });
87
90
  project.addSourceFilesAtPaths(
88
91
  path__namespace.join(absoluteSrcDir, "**/*.ts").replace(/\\/g, "/")
89
92
  );
90
93
  const methodDefinitions = [];
94
+ const globalTypeDefinitions = [];
91
95
  const sourceFiles = project.getSourceFiles();
92
96
  consola.consola.info(`Found ${sourceFiles.length} source file(s).`);
93
97
  for (const sourceFile of sourceFiles) {
98
+ for (const iface of sourceFile.getInterfaces()) {
99
+ globalTypeDefinitions.push(iface.getText());
100
+ }
101
+ for (const typeAlias of sourceFile.getTypeAliases()) {
102
+ globalTypeDefinitions.push(typeAlias.getText());
103
+ }
104
+ for (const statement of sourceFile.getStatements()) {
105
+ if (statement.getKind() === tsMorph.SyntaxKind.ModuleDeclaration) {
106
+ globalTypeDefinitions.push(statement.getText());
107
+ }
108
+ }
94
109
  for (const funcDecl of sourceFile.getFunctions()) {
95
- if (!funcDecl.isExported() && !funcDecl.isAmbient()) {
110
+ if (!funcDecl.isAmbient()) {
96
111
  const name = funcDecl.getName();
97
112
  if (name != null) {
98
113
  methodDefinitions.push(getInterfaceMethodDefinition_(name, funcDecl));
@@ -100,7 +115,7 @@ const generateAppsScriptTypes = async ({
100
115
  }
101
116
  }
102
117
  for (const varStmt of sourceFile.getVariableStatements()) {
103
- if (!varStmt.isExported() && !varStmt.isAmbient()) {
118
+ if (!varStmt.isAmbient()) {
104
119
  for (const varDecl of varStmt.getDeclarations()) {
105
120
  const initializer = varDecl.getInitializer();
106
121
  const varName = varDecl.getName();
@@ -124,6 +139,11 @@ const generateAppsScriptTypes = async ({
124
139
  let outputContent = `// Auto-generated by ${generatorName}
125
140
  // Do NOT edit this file manually.
126
141
  `;
142
+ if (globalTypeDefinitions.length > 0) {
143
+ outputContent += `${globalTypeDefinitions.join("\n\n")}
144
+
145
+ `;
146
+ }
127
147
  if (methodDefinitions.length > 0) {
128
148
  const formattedMethods = methodDefinitions.map(
129
149
  (method) => method.split("\n").map((line) => ` ${line}`).join("\n")
@@ -133,7 +153,7 @@ ${formattedMethods}
133
153
  }
134
154
  `;
135
155
  consola.consola.info(
136
- `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s)).`
156
+ `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
137
157
  );
138
158
  } else {
139
159
  outputContent = "export interface ServerScripts {}\n";
package/dist/index.mjs CHANGED
@@ -5,6 +5,8 @@ import * as fs from 'node:fs';
5
5
  import { Project, SyntaxKind } from 'ts-morph';
6
6
 
7
7
  const getInterfaceMethodDefinition_ = (name, node) => {
8
+ const typeParameters = node.getTypeParameters?.() ?? [];
9
+ const typeParamsString = typeParameters.length > 0 ? `<${typeParameters.map((tp) => tp.getText()).join(", ")}>` : "";
8
10
  const parameters = node.getParameters().map((param) => {
9
11
  const paramName = param.getName();
10
12
  const type = param.getTypeNode()?.getText() ?? param.getType().getText(node) ?? "any";
@@ -49,7 +51,7 @@ const getInterfaceMethodDefinition_ = (name, node) => {
49
51
  }
50
52
  }
51
53
  }
52
- return `${jsDocString}${name}(${parameters}): ${returnType};`;
54
+ return `${jsDocString}${name}${typeParamsString}(${parameters}): ${returnType};`;
53
55
  };
54
56
  const generateAppsScriptTypes = async ({
55
57
  project: projectPath,
@@ -64,17 +66,30 @@ const generateAppsScriptTypes = async ({
64
66
  consola.info(` AppsScript Source Directory: ${absoluteSrcDir}`);
65
67
  consola.info(` Output File: ${absoluteOutputFile}`);
66
68
  const project = new Project({
67
- tsConfigFilePath: path.resolve(projectPath, "tsconfig.json")
69
+ tsConfigFilePath: path.resolve(projectPath, "tsconfig.json"),
70
+ skipAddingFilesFromTsConfig: true
68
71
  });
69
72
  project.addSourceFilesAtPaths(
70
73
  path.join(absoluteSrcDir, "**/*.ts").replace(/\\/g, "/")
71
74
  );
72
75
  const methodDefinitions = [];
76
+ const globalTypeDefinitions = [];
73
77
  const sourceFiles = project.getSourceFiles();
74
78
  consola.info(`Found ${sourceFiles.length} source file(s).`);
75
79
  for (const sourceFile of sourceFiles) {
80
+ for (const iface of sourceFile.getInterfaces()) {
81
+ globalTypeDefinitions.push(iface.getText());
82
+ }
83
+ for (const typeAlias of sourceFile.getTypeAliases()) {
84
+ globalTypeDefinitions.push(typeAlias.getText());
85
+ }
86
+ for (const statement of sourceFile.getStatements()) {
87
+ if (statement.getKind() === SyntaxKind.ModuleDeclaration) {
88
+ globalTypeDefinitions.push(statement.getText());
89
+ }
90
+ }
76
91
  for (const funcDecl of sourceFile.getFunctions()) {
77
- if (!funcDecl.isExported() && !funcDecl.isAmbient()) {
92
+ if (!funcDecl.isAmbient()) {
78
93
  const name = funcDecl.getName();
79
94
  if (name != null) {
80
95
  methodDefinitions.push(getInterfaceMethodDefinition_(name, funcDecl));
@@ -82,7 +97,7 @@ const generateAppsScriptTypes = async ({
82
97
  }
83
98
  }
84
99
  for (const varStmt of sourceFile.getVariableStatements()) {
85
- if (!varStmt.isExported() && !varStmt.isAmbient()) {
100
+ if (!varStmt.isAmbient()) {
86
101
  for (const varDecl of varStmt.getDeclarations()) {
87
102
  const initializer = varDecl.getInitializer();
88
103
  const varName = varDecl.getName();
@@ -106,6 +121,11 @@ const generateAppsScriptTypes = async ({
106
121
  let outputContent = `// Auto-generated by ${generatorName}
107
122
  // Do NOT edit this file manually.
108
123
  `;
124
+ if (globalTypeDefinitions.length > 0) {
125
+ outputContent += `${globalTypeDefinitions.join("\n\n")}
126
+
127
+ `;
128
+ }
109
129
  if (methodDefinitions.length > 0) {
110
130
  const formattedMethods = methodDefinitions.map(
111
131
  (method) => method.split("\n").map((line) => ` ${line}`).join("\n")
@@ -115,7 +135,7 @@ ${formattedMethods}
115
135
  }
116
136
  `;
117
137
  consola.info(
118
- `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s)).`
138
+ `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
119
139
  );
120
140
  } else {
121
141
  outputContent = "export interface ServerScripts {}\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciderjs/gasnuki",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",