@ciderjs/gasnuki 0.2.3 → 0.2.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # gasnuki
2
2
 
3
- [![Test Coverage](https://img.shields.io/badge/test%20coverage-93.43%25-brightgreen)](https://github.com/luthpg/gasnuki)
3
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-87.76%25-green)](https://github.com/luthpg/gasnuki)
4
4
  [![License](https://img.shields.io/badge/license-ISC-blue.svg)](LICENSE)
5
5
  [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
6
6
  [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](https://github.com/luthpg/gasnuki/issues)
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ciderjs/gasnuki
2
2
 
3
- [![Test Coverage](https://img.shields.io/badge/test%20coverage-93.43%25-brightgreen)](https://github.com/luthpg/gasnuki)
3
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-87.76%25-green)](https://github.com/luthpg/gasnuki)
4
4
  [![License](https://img.shields.io/badge/license-ISC-blue.svg)](LICENSE)
5
5
  [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
6
6
  [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](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.s61ETQvI.cjs');
6
+ const index = require('./shared/gasnuki.CYh0jbl5.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.3";
27
+ const version = "0.2.4";
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.y-_vxcPh.mjs';
4
+ import { l as loadConfig, g as generateTypes } from './shared/gasnuki.DvpVGJ1U.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.3";
11
+ const version = "0.2.4";
12
12
 
13
13
  const parseArgs = async (command) => {
14
14
  const cliOpts = command.opts();
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('node:path');
4
4
  require('chokidar');
5
5
  require('consola');
6
- const index = require('./shared/gasnuki.s61ETQvI.cjs');
6
+ const index = require('./shared/gasnuki.CYh0jbl5.cjs');
7
7
  require('node:fs');
8
8
  require('ts-morph');
9
9
  require('jiti');
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.y-_vxcPh.mjs';
4
+ export { d as defineConfig, g as generateTypes } from './shared/gasnuki.DvpVGJ1U.mjs';
5
5
  import 'node:fs';
6
6
  import 'ts-morph';
7
7
  import 'jiti';
@@ -74,6 +74,14 @@ const getInterfaceMethodDefinition_ = (name, node) => {
74
74
  }
75
75
  return `${jsDocString}${name}${typeParamsString}(${parameters}): ${returnType};`;
76
76
  };
77
+ const SIMPLE_TRIGGER_FUNCTION_NAMES = [
78
+ "onOpen",
79
+ "onEdit",
80
+ "onInstall",
81
+ "onSelectionChange",
82
+ "doGet",
83
+ "doPost"
84
+ ];
77
85
  const generateAppsScriptTypes = async ({
78
86
  project: projectPath,
79
87
  srcDir,
@@ -95,9 +103,32 @@ const generateAppsScriptTypes = async ({
95
103
  );
96
104
  const methodDefinitions = [];
97
105
  const globalTypeDefinitions = [];
106
+ const importStatements = /* @__PURE__ */ new Set();
98
107
  const sourceFiles = project.getSourceFiles();
99
108
  consola.consola.info(`Found ${sourceFiles.length} source file(s).`);
100
109
  for (const sourceFile of sourceFiles) {
110
+ const importDeclarations = sourceFile.getImportDeclarations?.();
111
+ if (importDeclarations != null && importDeclarations.length > 0) {
112
+ for (const importDeclaration of importDeclarations) {
113
+ const moduleSpecifier = importDeclaration.getModuleSpecifierSourceFile();
114
+ if (moduleSpecifier) {
115
+ const importedFilePath = moduleSpecifier.getFilePath();
116
+ let relativePath = path__namespace.relative(path__namespace.dirname(absoluteOutputFile), importedFilePath).replace(/\\/g, "/");
117
+ relativePath = relativePath.replace(/\.(ts|tsx|d\.ts)$/, "");
118
+ if (!relativePath.startsWith(".") && !relativePath.startsWith("..")) {
119
+ relativePath = `./${relativePath}`;
120
+ }
121
+ const originalText = importDeclaration.getText();
122
+ const newImportText = originalText.replace(
123
+ importDeclaration.getModuleSpecifierValue(),
124
+ relativePath
125
+ );
126
+ importStatements.add(newImportText);
127
+ } else {
128
+ importStatements.add(importDeclaration.getText());
129
+ }
130
+ }
131
+ }
101
132
  for (const iface of sourceFile.getInterfaces()) {
102
133
  const name = iface?.getName?.();
103
134
  if (name == null || name.endsWith("_")) {
@@ -120,7 +151,7 @@ const generateAppsScriptTypes = async ({
120
151
  for (const funcDecl of sourceFile.getFunctions()) {
121
152
  if (!funcDecl.isAmbient()) {
122
153
  const name = funcDecl.getName();
123
- if (name != null && !name.endsWith("_")) {
154
+ if (name != null && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
124
155
  methodDefinitions.push(getInterfaceMethodDefinition_(name, funcDecl));
125
156
  }
126
157
  }
@@ -130,7 +161,7 @@ const generateAppsScriptTypes = async ({
130
161
  for (const varDecl of varStmt.getDeclarations()) {
131
162
  const initializer = varDecl.getInitializer();
132
163
  const varName = varDecl.getName();
133
- if (initializer != null && (initializer.getKind() === tsMorph.SyntaxKind.ArrowFunction || initializer.getKind() === tsMorph.SyntaxKind.FunctionExpression) && !varName.endsWith("_")) {
164
+ if (initializer != null && (initializer.getKind() === tsMorph.SyntaxKind.ArrowFunction || initializer.getKind() === tsMorph.SyntaxKind.FunctionExpression) && !varName.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(varName)) {
134
165
  methodDefinitions.push(
135
166
  getInterfaceMethodDefinition_(
136
167
  varName,
@@ -150,6 +181,11 @@ const generateAppsScriptTypes = async ({
150
181
  let outputContent = `// Auto-generated by ${generatorName}
151
182
  // Do NOT edit this file manually.
152
183
  `;
184
+ if (importStatements.size > 0) {
185
+ outputContent += `${[...importStatements].join("\n")}
186
+
187
+ `;
188
+ }
153
189
  if (globalTypeDefinitions.length > 0) {
154
190
  outputContent += `${globalTypeDefinitions.join("\n\n")}
155
191
 
@@ -167,7 +203,7 @@ ${formattedMethods}
167
203
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
168
204
  );
169
205
  } else {
170
- outputContent = "export type ServerScripts = {}\n";
206
+ outputContent += "export type ServerScripts = {}\n";
171
207
  consola.consola.info(
172
208
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (no functions found).`
173
209
  );
@@ -56,6 +56,14 @@ const getInterfaceMethodDefinition_ = (name, node) => {
56
56
  }
57
57
  return `${jsDocString}${name}${typeParamsString}(${parameters}): ${returnType};`;
58
58
  };
59
+ const SIMPLE_TRIGGER_FUNCTION_NAMES = [
60
+ "onOpen",
61
+ "onEdit",
62
+ "onInstall",
63
+ "onSelectionChange",
64
+ "doGet",
65
+ "doPost"
66
+ ];
59
67
  const generateAppsScriptTypes = async ({
60
68
  project: projectPath,
61
69
  srcDir,
@@ -77,9 +85,32 @@ const generateAppsScriptTypes = async ({
77
85
  );
78
86
  const methodDefinitions = [];
79
87
  const globalTypeDefinitions = [];
88
+ const importStatements = /* @__PURE__ */ new Set();
80
89
  const sourceFiles = project.getSourceFiles();
81
90
  consola.info(`Found ${sourceFiles.length} source file(s).`);
82
91
  for (const sourceFile of sourceFiles) {
92
+ const importDeclarations = sourceFile.getImportDeclarations?.();
93
+ if (importDeclarations != null && importDeclarations.length > 0) {
94
+ for (const importDeclaration of importDeclarations) {
95
+ const moduleSpecifier = importDeclaration.getModuleSpecifierSourceFile();
96
+ if (moduleSpecifier) {
97
+ const importedFilePath = moduleSpecifier.getFilePath();
98
+ let relativePath = path.relative(path.dirname(absoluteOutputFile), importedFilePath).replace(/\\/g, "/");
99
+ relativePath = relativePath.replace(/\.(ts|tsx|d\.ts)$/, "");
100
+ if (!relativePath.startsWith(".") && !relativePath.startsWith("..")) {
101
+ relativePath = `./${relativePath}`;
102
+ }
103
+ const originalText = importDeclaration.getText();
104
+ const newImportText = originalText.replace(
105
+ importDeclaration.getModuleSpecifierValue(),
106
+ relativePath
107
+ );
108
+ importStatements.add(newImportText);
109
+ } else {
110
+ importStatements.add(importDeclaration.getText());
111
+ }
112
+ }
113
+ }
83
114
  for (const iface of sourceFile.getInterfaces()) {
84
115
  const name = iface?.getName?.();
85
116
  if (name == null || name.endsWith("_")) {
@@ -102,7 +133,7 @@ const generateAppsScriptTypes = async ({
102
133
  for (const funcDecl of sourceFile.getFunctions()) {
103
134
  if (!funcDecl.isAmbient()) {
104
135
  const name = funcDecl.getName();
105
- if (name != null && !name.endsWith("_")) {
136
+ if (name != null && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
106
137
  methodDefinitions.push(getInterfaceMethodDefinition_(name, funcDecl));
107
138
  }
108
139
  }
@@ -112,7 +143,7 @@ const generateAppsScriptTypes = async ({
112
143
  for (const varDecl of varStmt.getDeclarations()) {
113
144
  const initializer = varDecl.getInitializer();
114
145
  const varName = varDecl.getName();
115
- if (initializer != null && (initializer.getKind() === SyntaxKind.ArrowFunction || initializer.getKind() === SyntaxKind.FunctionExpression) && !varName.endsWith("_")) {
146
+ if (initializer != null && (initializer.getKind() === SyntaxKind.ArrowFunction || initializer.getKind() === SyntaxKind.FunctionExpression) && !varName.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(varName)) {
116
147
  methodDefinitions.push(
117
148
  getInterfaceMethodDefinition_(
118
149
  varName,
@@ -132,6 +163,11 @@ const generateAppsScriptTypes = async ({
132
163
  let outputContent = `// Auto-generated by ${generatorName}
133
164
  // Do NOT edit this file manually.
134
165
  `;
166
+ if (importStatements.size > 0) {
167
+ outputContent += `${[...importStatements].join("\n")}
168
+
169
+ `;
170
+ }
135
171
  if (globalTypeDefinitions.length > 0) {
136
172
  outputContent += `${globalTypeDefinitions.join("\n\n")}
137
173
 
@@ -149,7 +185,7 @@ ${formattedMethods}
149
185
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
150
186
  );
151
187
  } else {
152
- outputContent = "export type ServerScripts = {}\n";
188
+ outputContent += "export type ServerScripts = {}\n";
153
189
  consola.info(
154
190
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (no functions found).`
155
191
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciderjs/gasnuki",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Type definitions and utilities for Google Apps Script client-side API",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",