@ciderjs/gasnuki 0.3.8 → 0.4.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.ja.md +1 -1
- package/README.md +1 -1
- package/dist/cli.cjs +4 -3
- package/dist/cli.mjs +4 -3
- package/dist/index.cjs +14 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +15 -4
- package/dist/shared/{gasnuki.BVdkJsiP.cjs → gasnuki.DfLTmLhN.cjs} +31 -1
- package/dist/shared/{gasnuki.Cd8JOTQ5.mjs → gasnuki.SJQVcSIQ.mjs} +30 -1
- package/dist/vite.cjs +2 -1
- package/dist/vite.mjs +2 -1
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @ciderjs/gasnuki
|
|
2
2
|
|
|
3
3
|
[](./README.md)
|
|
4
|
-
[](https://github.com/luthpg/gasnuki)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
7
7
|
[](https://github.com/luthpg/gasnuki/issues)
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @ciderjs/gasnuki
|
|
2
2
|
|
|
3
3
|
[](./README.ja.md)
|
|
4
|
-
[](https://github.com/luthpg/gasnuki)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
7
7
|
[](https://github.com/luthpg/gasnuki/issues)
|
package/dist/cli.cjs
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const commander = require('commander');
|
|
6
6
|
const index = require('./index.cjs');
|
|
7
|
-
const config = require('./shared/gasnuki.
|
|
7
|
+
const config = require('./shared/gasnuki.DfLTmLhN.cjs');
|
|
8
8
|
require('chokidar');
|
|
9
9
|
require('consola');
|
|
10
|
+
require('node:crypto');
|
|
10
11
|
require('node:fs');
|
|
11
12
|
require('ts-morph');
|
|
12
13
|
require('jiti');
|
|
@@ -25,7 +26,7 @@ function _interopNamespaceCompat(e) {
|
|
|
25
26
|
|
|
26
27
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
27
28
|
|
|
28
|
-
const version = "0.
|
|
29
|
+
const version = "0.4.0";
|
|
29
30
|
|
|
30
31
|
const parseArgs = async (command) => {
|
|
31
32
|
const cliOpts = command.opts();
|
|
@@ -69,7 +70,7 @@ const runCli = async () => {
|
|
|
69
70
|
"-o, --outDir <dir>",
|
|
70
71
|
"Output directory name (relative to project root)",
|
|
71
72
|
"types"
|
|
72
|
-
).option("-f, --outputFile <file>", "Output file name", "appsscript.ts").option("-w, --watch", "Watch for changes and re-generate types", false);
|
|
73
|
+
).option("-f, --outputFile <file>", "Output file name", "appsscript.ts").option("-w, --watch", "Watch for changes and re-generate types", false).option("--cache", "Enable checking generation cache", true).option("--no-cache", "Disable checking generation cache", true);
|
|
73
74
|
await program.parseAsync(process.argv);
|
|
74
75
|
};
|
|
75
76
|
const isMainModule = typeof require !== "undefined" && require.main === module;
|
package/dist/cli.mjs
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { generateTypes } from './index.mjs';
|
|
5
|
-
import { l as loadConfig } from './shared/gasnuki.
|
|
5
|
+
import { l as loadConfig } from './shared/gasnuki.SJQVcSIQ.mjs';
|
|
6
6
|
import 'chokidar';
|
|
7
7
|
import 'consola';
|
|
8
|
+
import 'node:crypto';
|
|
8
9
|
import 'node:fs';
|
|
9
10
|
import 'ts-morph';
|
|
10
11
|
import 'jiti';
|
|
11
12
|
|
|
12
|
-
const version = "0.
|
|
13
|
+
const version = "0.4.0";
|
|
13
14
|
|
|
14
15
|
const parseArgs = async (command) => {
|
|
15
16
|
const cliOpts = command.opts();
|
|
@@ -53,7 +54,7 @@ const runCli = async () => {
|
|
|
53
54
|
"-o, --outDir <dir>",
|
|
54
55
|
"Output directory name (relative to project root)",
|
|
55
56
|
"types"
|
|
56
|
-
).option("-f, --outputFile <file>", "Output file name", "appsscript.ts").option("-w, --watch", "Watch for changes and re-generate types", false);
|
|
57
|
+
).option("-f, --outputFile <file>", "Output file name", "appsscript.ts").option("-w, --watch", "Watch for changes and re-generate types", false).option("--cache", "Enable checking generation cache", true).option("--no-cache", "Disable checking generation cache", true);
|
|
57
58
|
await program.parseAsync(process.argv);
|
|
58
59
|
};
|
|
59
60
|
const isMainModule = typeof require !== "undefined" && require.main === module;
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const chokidar = require('chokidar');
|
|
5
5
|
const consola = require('consola');
|
|
6
|
-
const config = require('./shared/gasnuki.
|
|
6
|
+
const config = require('./shared/gasnuki.DfLTmLhN.cjs');
|
|
7
|
+
require('node:crypto');
|
|
7
8
|
require('node:fs');
|
|
8
9
|
require('ts-morph');
|
|
9
10
|
require('jiti');
|
|
@@ -28,13 +29,23 @@ const generateTypes = async ({
|
|
|
28
29
|
srcDir,
|
|
29
30
|
outDir,
|
|
30
31
|
outputFile,
|
|
31
|
-
watch
|
|
32
|
+
watch,
|
|
33
|
+
cache
|
|
32
34
|
}) => {
|
|
35
|
+
if (cache === false) {
|
|
36
|
+
consola.consola.info("Generation cache is disabled");
|
|
37
|
+
}
|
|
33
38
|
const runGeneration = async (triggeredBy) => {
|
|
34
39
|
const reason = triggeredBy ? ` (${triggeredBy})` : "";
|
|
35
40
|
consola.consola.info(`Generating AppsScript types${reason}...`);
|
|
36
41
|
try {
|
|
37
|
-
await config.generateAppsScriptTypes({
|
|
42
|
+
await config.generateAppsScriptTypes({
|
|
43
|
+
project,
|
|
44
|
+
srcDir,
|
|
45
|
+
outDir,
|
|
46
|
+
outputFile,
|
|
47
|
+
cache
|
|
48
|
+
});
|
|
38
49
|
consola.consola.info("Type generation complete.");
|
|
39
50
|
} catch (e) {
|
|
40
51
|
consola.consola.error(`Type generation failed: ${e.message}`, e);
|
package/dist/index.d.cts
CHANGED
|
@@ -16,8 +16,9 @@ interface GenerateOptions {
|
|
|
16
16
|
outDir: string;
|
|
17
17
|
outputFile: string;
|
|
18
18
|
watch: boolean;
|
|
19
|
+
cache?: boolean;
|
|
19
20
|
}
|
|
20
|
-
declare const generateTypes: ({ project, srcDir, outDir, outputFile, watch, }: GenerateOptions) => Promise<void>;
|
|
21
|
+
declare const generateTypes: ({ project, srcDir, outDir, outputFile, watch, cache, }: GenerateOptions) => Promise<void>;
|
|
21
22
|
|
|
22
23
|
export { defineConfig, generateTypes };
|
|
23
24
|
export type { GenerateOptions, UserConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -16,8 +16,9 @@ interface GenerateOptions {
|
|
|
16
16
|
outDir: string;
|
|
17
17
|
outputFile: string;
|
|
18
18
|
watch: boolean;
|
|
19
|
+
cache?: boolean;
|
|
19
20
|
}
|
|
20
|
-
declare const generateTypes: ({ project, srcDir, outDir, outputFile, watch, }: GenerateOptions) => Promise<void>;
|
|
21
|
+
declare const generateTypes: ({ project, srcDir, outDir, outputFile, watch, cache, }: GenerateOptions) => Promise<void>;
|
|
21
22
|
|
|
22
23
|
export { defineConfig, generateTypes };
|
|
23
24
|
export type { GenerateOptions, UserConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,8 +16,9 @@ interface GenerateOptions {
|
|
|
16
16
|
outDir: string;
|
|
17
17
|
outputFile: string;
|
|
18
18
|
watch: boolean;
|
|
19
|
+
cache?: boolean;
|
|
19
20
|
}
|
|
20
|
-
declare const generateTypes: ({ project, srcDir, outDir, outputFile, watch, }: GenerateOptions) => Promise<void>;
|
|
21
|
+
declare const generateTypes: ({ project, srcDir, outDir, outputFile, watch, cache, }: GenerateOptions) => Promise<void>;
|
|
21
22
|
|
|
22
23
|
export { defineConfig, generateTypes };
|
|
23
24
|
export type { GenerateOptions, UserConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as chokidar from 'chokidar';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
|
-
import { g as generateAppsScriptTypes } from './shared/gasnuki.
|
|
5
|
-
export { d as defineConfig } from './shared/gasnuki.
|
|
4
|
+
import { g as generateAppsScriptTypes } from './shared/gasnuki.SJQVcSIQ.mjs';
|
|
5
|
+
export { d as defineConfig } from './shared/gasnuki.SJQVcSIQ.mjs';
|
|
6
|
+
import 'node:crypto';
|
|
6
7
|
import 'node:fs';
|
|
7
8
|
import 'ts-morph';
|
|
8
9
|
import 'jiti';
|
|
@@ -12,13 +13,23 @@ const generateTypes = async ({
|
|
|
12
13
|
srcDir,
|
|
13
14
|
outDir,
|
|
14
15
|
outputFile,
|
|
15
|
-
watch
|
|
16
|
+
watch,
|
|
17
|
+
cache
|
|
16
18
|
}) => {
|
|
19
|
+
if (cache === false) {
|
|
20
|
+
consola.info("Generation cache is disabled");
|
|
21
|
+
}
|
|
17
22
|
const runGeneration = async (triggeredBy) => {
|
|
18
23
|
const reason = triggeredBy ? ` (${triggeredBy})` : "";
|
|
19
24
|
consola.info(`Generating AppsScript types${reason}...`);
|
|
20
25
|
try {
|
|
21
|
-
await generateAppsScriptTypes({
|
|
26
|
+
await generateAppsScriptTypes({
|
|
27
|
+
project,
|
|
28
|
+
srcDir,
|
|
29
|
+
outDir,
|
|
30
|
+
outputFile,
|
|
31
|
+
cache
|
|
32
|
+
});
|
|
22
33
|
consola.info("Type generation complete.");
|
|
23
34
|
} catch (e) {
|
|
24
35
|
consola.error(`Type generation failed: ${e.message}`, e);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const crypto = require('node:crypto');
|
|
3
4
|
const fs = require('node:fs');
|
|
4
5
|
const path = require('node:path');
|
|
5
6
|
const consola = require('consola');
|
|
@@ -18,11 +19,24 @@ function _interopNamespaceCompat(e) {
|
|
|
18
19
|
return n;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
const crypto__namespace = /*#__PURE__*/_interopNamespaceCompat(crypto);
|
|
21
23
|
const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
|
|
22
24
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
23
25
|
|
|
24
26
|
const text = "export type RemoveReturnType<T> = {\n [P in keyof T]: T[P] extends (...args: infer A) => any\n ? (...args: A) => void\n : T[P];\n};\n\ntype _AppsScriptRun = RemoveReturnType<ServerScripts> & {\n [key: string]: (...args: any[]) => any;\n withSuccessHandler: <T = string | number | boolean | undefined, U = any>(\n callback: (returnValues: T, userObject?: U) => void,\n ) => _AppsScriptRun;\n withFailureHandler: <U = any>(\n callback: (error: Error, userObject?: U) => void,\n ) => _AppsScriptRun;\n withUserObject: <U = any>(userObject: U) => _AppsScriptRun;\n};\n\ntype _AppsScriptHistoryFunction = (\n stateObject: object,\n params: object,\n hash: string,\n) => void;\n\ninterface _WebAppLocationType {\n hash: string;\n parameter: Record<string, string>;\n parameters: Record<string, string[]>;\n}\n\nexport declare interface GoogleClientSideApi {\n script: {\n run: _AppsScriptRun;\n url: {\n getLocation: (callback: (location: _WebAppLocationType) => void) => void;\n };\n history: {\n push: _AppsScriptHistoryFunction;\n replace: _AppsScriptHistoryFunction;\n setChangeHandler: (\n callback: (e: { state: object; location: _WebAppLocationType }) => void,\n ) => void;\n };\n };\n}\n\ndeclare global {\n const google: GoogleClientSideApi;\n}\n";
|
|
25
27
|
|
|
28
|
+
const generationCache = /* @__PURE__ */ new Map();
|
|
29
|
+
const computeSourceHash = (sourceFiles) => {
|
|
30
|
+
const hash = crypto__namespace.createHash("md5");
|
|
31
|
+
const sortedFiles = [...sourceFiles].sort(
|
|
32
|
+
(a, b) => a.getFilePath().localeCompare(b.getFilePath())
|
|
33
|
+
);
|
|
34
|
+
for (const file of sortedFiles) {
|
|
35
|
+
hash.update(file.getFilePath());
|
|
36
|
+
hash.update(file.getFullText());
|
|
37
|
+
}
|
|
38
|
+
return hash.digest("hex");
|
|
39
|
+
};
|
|
26
40
|
const getInterfaceMethodDefinition_ = (name, node) => {
|
|
27
41
|
const typeParameters = node.getTypeParameters?.() ?? [];
|
|
28
42
|
const typeParamsString = typeParameters.length > 0 ? `<${typeParameters.map((tp) => tp.getText()).join(", ")}>` : "";
|
|
@@ -103,7 +117,9 @@ const generateAppsScriptTypes = async ({
|
|
|
103
117
|
srcDir,
|
|
104
118
|
outDir,
|
|
105
119
|
outputFile,
|
|
106
|
-
projectInstance
|
|
120
|
+
projectInstance,
|
|
121
|
+
cache = true
|
|
122
|
+
// Default to true
|
|
107
123
|
}) => {
|
|
108
124
|
const absoluteSrcDir = path__namespace.resolve(projectPath, srcDir);
|
|
109
125
|
const absoluteOutDir = path__namespace.resolve(projectPath, outDir);
|
|
@@ -120,6 +136,16 @@ const generateAppsScriptTypes = async ({
|
|
|
120
136
|
project.addSourceFilesAtPaths([sourceFilesPattern, testFilesPattern]);
|
|
121
137
|
const sourceFiles = project.getSourceFiles();
|
|
122
138
|
consola.consola.info(`Found ${sourceFiles.length} source file(s).`);
|
|
139
|
+
if (cache) {
|
|
140
|
+
const currentHash = computeSourceHash(sourceFiles);
|
|
141
|
+
const cacheKey = absoluteOutputFile;
|
|
142
|
+
if (generationCache.get(cacheKey) === currentHash && fs__namespace.existsSync(absoluteOutputFile)) {
|
|
143
|
+
consola.consola.success(
|
|
144
|
+
`Skipping generation: Source files have not changed (Hash: ${currentHash.slice(0, 8)}).`
|
|
145
|
+
);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
123
149
|
const methodDefinitions = [];
|
|
124
150
|
const exportedDeclarations = [];
|
|
125
151
|
const exportedDeclarationNames = /* @__PURE__ */ new Set();
|
|
@@ -415,6 +441,10 @@ ${text}`;
|
|
|
415
441
|
}
|
|
416
442
|
outputContent += bodyContent;
|
|
417
443
|
fs__namespace.writeFileSync(absoluteOutputFile, outputContent);
|
|
444
|
+
if (cache) {
|
|
445
|
+
const currentHash = computeSourceHash(sourceFiles);
|
|
446
|
+
generationCache.set(absoluteOutputFile, currentHash);
|
|
447
|
+
}
|
|
418
448
|
};
|
|
419
449
|
|
|
420
450
|
function defineConfig(config) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
1
2
|
import * as fs from 'node:fs';
|
|
2
3
|
import * as path from 'node:path';
|
|
3
4
|
import { consola } from 'consola';
|
|
@@ -6,6 +7,18 @@ import { createJiti } from 'jiti';
|
|
|
6
7
|
|
|
7
8
|
const text = "export type RemoveReturnType<T> = {\n [P in keyof T]: T[P] extends (...args: infer A) => any\n ? (...args: A) => void\n : T[P];\n};\n\ntype _AppsScriptRun = RemoveReturnType<ServerScripts> & {\n [key: string]: (...args: any[]) => any;\n withSuccessHandler: <T = string | number | boolean | undefined, U = any>(\n callback: (returnValues: T, userObject?: U) => void,\n ) => _AppsScriptRun;\n withFailureHandler: <U = any>(\n callback: (error: Error, userObject?: U) => void,\n ) => _AppsScriptRun;\n withUserObject: <U = any>(userObject: U) => _AppsScriptRun;\n};\n\ntype _AppsScriptHistoryFunction = (\n stateObject: object,\n params: object,\n hash: string,\n) => void;\n\ninterface _WebAppLocationType {\n hash: string;\n parameter: Record<string, string>;\n parameters: Record<string, string[]>;\n}\n\nexport declare interface GoogleClientSideApi {\n script: {\n run: _AppsScriptRun;\n url: {\n getLocation: (callback: (location: _WebAppLocationType) => void) => void;\n };\n history: {\n push: _AppsScriptHistoryFunction;\n replace: _AppsScriptHistoryFunction;\n setChangeHandler: (\n callback: (e: { state: object; location: _WebAppLocationType }) => void,\n ) => void;\n };\n };\n}\n\ndeclare global {\n const google: GoogleClientSideApi;\n}\n";
|
|
8
9
|
|
|
10
|
+
const generationCache = /* @__PURE__ */ new Map();
|
|
11
|
+
const computeSourceHash = (sourceFiles) => {
|
|
12
|
+
const hash = crypto.createHash("md5");
|
|
13
|
+
const sortedFiles = [...sourceFiles].sort(
|
|
14
|
+
(a, b) => a.getFilePath().localeCompare(b.getFilePath())
|
|
15
|
+
);
|
|
16
|
+
for (const file of sortedFiles) {
|
|
17
|
+
hash.update(file.getFilePath());
|
|
18
|
+
hash.update(file.getFullText());
|
|
19
|
+
}
|
|
20
|
+
return hash.digest("hex");
|
|
21
|
+
};
|
|
9
22
|
const getInterfaceMethodDefinition_ = (name, node) => {
|
|
10
23
|
const typeParameters = node.getTypeParameters?.() ?? [];
|
|
11
24
|
const typeParamsString = typeParameters.length > 0 ? `<${typeParameters.map((tp) => tp.getText()).join(", ")}>` : "";
|
|
@@ -86,7 +99,9 @@ const generateAppsScriptTypes = async ({
|
|
|
86
99
|
srcDir,
|
|
87
100
|
outDir,
|
|
88
101
|
outputFile,
|
|
89
|
-
projectInstance
|
|
102
|
+
projectInstance,
|
|
103
|
+
cache = true
|
|
104
|
+
// Default to true
|
|
90
105
|
}) => {
|
|
91
106
|
const absoluteSrcDir = path.resolve(projectPath, srcDir);
|
|
92
107
|
const absoluteOutDir = path.resolve(projectPath, outDir);
|
|
@@ -103,6 +118,16 @@ const generateAppsScriptTypes = async ({
|
|
|
103
118
|
project.addSourceFilesAtPaths([sourceFilesPattern, testFilesPattern]);
|
|
104
119
|
const sourceFiles = project.getSourceFiles();
|
|
105
120
|
consola.info(`Found ${sourceFiles.length} source file(s).`);
|
|
121
|
+
if (cache) {
|
|
122
|
+
const currentHash = computeSourceHash(sourceFiles);
|
|
123
|
+
const cacheKey = absoluteOutputFile;
|
|
124
|
+
if (generationCache.get(cacheKey) === currentHash && fs.existsSync(absoluteOutputFile)) {
|
|
125
|
+
consola.success(
|
|
126
|
+
`Skipping generation: Source files have not changed (Hash: ${currentHash.slice(0, 8)}).`
|
|
127
|
+
);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
106
131
|
const methodDefinitions = [];
|
|
107
132
|
const exportedDeclarations = [];
|
|
108
133
|
const exportedDeclarationNames = /* @__PURE__ */ new Set();
|
|
@@ -398,6 +423,10 @@ ${text}`;
|
|
|
398
423
|
}
|
|
399
424
|
outputContent += bodyContent;
|
|
400
425
|
fs.writeFileSync(absoluteOutputFile, outputContent);
|
|
426
|
+
if (cache) {
|
|
427
|
+
const currentHash = computeSourceHash(sourceFiles);
|
|
428
|
+
generationCache.set(absoluteOutputFile, currentHash);
|
|
429
|
+
}
|
|
401
430
|
};
|
|
402
431
|
|
|
403
432
|
function defineConfig(config) {
|
package/dist/vite.cjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const consola = require('consola');
|
|
5
|
-
const config = require('./shared/gasnuki.
|
|
5
|
+
const config = require('./shared/gasnuki.DfLTmLhN.cjs');
|
|
6
|
+
require('node:crypto');
|
|
6
7
|
require('node:fs');
|
|
7
8
|
require('ts-morph');
|
|
8
9
|
require('jiti');
|
package/dist/vite.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { consola } from 'consola';
|
|
3
|
-
import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.
|
|
3
|
+
import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.SJQVcSIQ.mjs';
|
|
4
|
+
import 'node:crypto';
|
|
4
5
|
import 'node:fs';
|
|
5
6
|
import 'ts-morph';
|
|
6
7
|
import 'jiti';
|