generated at
gas-entry-generator
Google Apps Script用のtop level functionsを生成するnode package
denoからはesm.shなどからimportすれば使える

global というobjectにGASで使用したい函数を入れる
sample.js
// comments for add function add(a, b) { return a + b; } // comments for main function main() { console.log(add(1, 2)); } global.main = main;

sample code
$ deno run --allow-net -r=https://scrapbox.io https://scrapbox.io/api/code/takker/gas-entry-generator/index.js
index.js
import {generate} from 'https://esm.sh/gas-entry-generator@2.1.0'; const res = await fetch('https://scrapbox.io/api/code/takker/gas-entry-generator/sample.js'); const code = await res.text(); const output = generate(code, { comment: true, }); console.log(output.entryPointFunctions); console.log(`let global=this;\n${output.entryPointFunctions}\n(() => {\n${code}\n})();`);
ここ地味に罠なのだが、 generate() は公開用函数の名前を付けた空函数しか出力してくれない
中身は自分で別途作る必要がある

型定義ファイル
誰も作っていない模様
コードから推測して作る
引数
source string
options
default optionsの一部はindex.jsからわかる
GlobalAssignments の引数にも使われている
どうやらdefaultOptionsにあるpropertiesで全てのようだ
戻り値
{ entryPointFunctions, globalAssignments }
entryPointFunctions escodegen.generate() の戻り値
globalAssignments escodegen.generate() の戻り値か undefined
escodegenの型定義
generate の戻り値は string
index.d.ts
export function generate(source: string, options?: GenerateOptions): GenerateResult; export interface GenerateOptions { comment?: boolean, autoGlobalExports?: boolean, exportsIdentifierName?: string, globalIdentifierName?: string, } export interface GenerateResult { entryPointFunctions: string; globalAssignments: string | undefined; }

#2024-03-26 14:57:20
#2021-07-11 13:08:26