gas-entry-generator
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.jsimport {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
GlobalAssignments
の引数にも使われている
戻り値
{ entryPointFunctions, globalAssignments }
entryPointFunctions
は escodegen.generate()
の戻り値
globalAssignments
は escodegen.generate()
の戻り値か undefined
generate
の戻り値は string
index.d.tsexport 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;
}