ClaspをBunとTypeScriptでproject作成
from Clasp
背景
Claspはv3からTypeScriptをサポートしなくなった
自前でbundleやtranspileしないといけない
面倒なので全部Bunでやる
project作成など
$ bun init
$ bun add bun-types
$ bun add @google/clasp
$ bun add -D @types/google-apps-script
claspの設定
$ bun clasp login
$ bun clasp create
.clasp.jsonのrootdirをdistにする
code:.clasp.json
{
...
"rootDir": "dist",
...
}
appscscript.jsonのtimeZoneを変更する
"timeZone": "Asia/Tokyo",
code:appsscript.json
{
"timeZone":"Asia/Tokyo",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
サンプル
code:src/index.ts
const greeter = (person: string) => {
return Hello, ${person}!;
}
function testGreeter() {
const user = 'Grant';
console.log(greeter(user));
}
Bun Bundlerの設定
code:build.ts
await Bun.build({
entrypoints: "./src/index.ts", // 必須:エントリーファイル
outdir: "./dist", // 出力先フォルダ
});
code:package.json
"scripts": {
"build": "bun run build.ts && cp appsscript.json dist/appsscript.json",
},
$ bun run build
これで、dist/内に2つのファイルができるはず
appscript.json
index.js
実行
$ bun run build
$ bun clasp push
todos
Bunの型