gas-entry-generator
Google Apps Script用のtop level functionsを生成するnode package
fossamagna/gas-entry-generator
denoからはesm.shなどからimportすれば使える
globalというobjectにGASで使用したい函数を入れる
code: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
code: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()は公開用函数の名前を付けた空函数しか出力してくれない
中身は自分で別途作る必要がある
型定義ファイル
誰も作っていない模様
コードから推測して作る
https://github.com/fossamagna/gas-entry-generator/blob/v2.5.1/index.js
引数
sourceはstring
options
default optionsの一部はindex.jsからわかる
GlobalAssignmentsの引数にも使われている
どうやらdefaultOptionsにあるpropertiesで全てのようだ
戻り値
{ entryPointFunctions, globalAssignments }
entryPointFunctionsはescodegen.generate()の戻り値
globalAssignmentsはescodegen.generate()の戻り値かundefined
escodegenの型定義
https://doc.deno.land/https://esm.sh/escodegen@0.0.10
generateの戻り値はstring
code: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