Skip to content

Commit 34ef8c6

Browse files
authored
Merge pull request #8 from true-runes/update_development_environments
Update development environments
2 parents 5a50ebf + e8cf4c1 commit 34ef8c6

File tree

8 files changed

+63
-6
lines changed

8 files changed

+63
-6
lines changed

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# suikoden-election-2020-spreadsheet
2+
23
Spreadsheet (Suikoden election 2020)
34

45
# GAS Template
6+
57
A GAS template is powered by [howdy39/gas-clasp-starter: A starter template for Google Apps Script by clasp](https://github.com/howdy39/gas-clasp-starter)
68

7-
# 手順
9+
# 環境構築手順
10+
811
- あらかじめ `$ clasp login` を行って `~/.clasprc.json` を作っておく必要がある
912
- `.clasp.sample.json` をもとにして `.clasp.json` を作成する
1013
- `"scriptId"` の値には、スクリプトページの URL の以下の部分の値を設定する
@@ -14,7 +17,21 @@ A GAS template is powered by [howdy39/gas-clasp-starter: A starter template for
1417
- つまりスプレッドシートごとにリポジトリを作る必要がある
1518
- 開発用と本番用の場合はこの限りではない
1619

20+
# 開発手順
21+
22+
- `webpack.config.js` のエンドポイントに合わせて、コードを書く
23+
- これを書いている時点では `src/index.ts` にごりごり書く
24+
- ビルドしてできるファイルは `bundle.js` の一つになる
25+
- `$ yarn build``dist/` 配下にビルド成果が生成される
26+
- `$ clasp push` で push されるのはこの `dist/` 配下のファイルになる
27+
- 現在の `$ yarn build` を実行すると、ビルド前に `dist/` は削除される
28+
- 現在の `webpack.config.js` では `src/*.ts` がトランスパイル対象になる
29+
- `package.json``scripts``webpack.config.js` は自分用に修正していった方がいい
30+
- デフォルトの `scripts` は自分にあっていないためリネームしてある
31+
- `sample/` 配下には `gas-clasp-starter` に含まれているサンプルコードを配置してある
32+
1733
# 参考
34+
1835
- [howdy39/gas-clasp-starter: A starter template for Google Apps Script by clasp](https://github.com/howdy39/gas-clasp-starter)
1936
- [Google Apps Script をローカル環境で快適に開発するためのテンプレートを作りました - Qiita](https://qiita.com/howdy39/items/0e799a9bfc1d3bccf6e5)
20-
- [5分で作るclaspを使ったGoogle Apps Scriptの開発環境 - Qiita](https://qiita.com/suin/items/b264092eab3ce553f16a)
37+
- [5 分で作る clasp を使った Google Apps Script の開発環境 - Qiita](https://qiita.com/suin/items/b264092eab3ce553f16a)

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"lint": "eslint --fix src/**/*.ts",
7+
"default:lint": "eslint --fix src/**/*.ts",
8+
"default:build": "npm run lint && npm run test && rimraf dist && webpack && cpx src/appsscript.json dist && cpx \"src/**/*.html\" dist",
9+
"default:push": "npm run build && clasp push",
810
"test": "jest",
9-
"build": "npm run lint && npm run test && rimraf dist && webpack && cpx src/appsscript.json dist && cpx \"src/**/*.html\" dist",
10-
"push": "npm run build && clasp push"
11+
"build": "rimraf dist && webpack && cpx src/appsscript.json dist"
1112
},
1213
"repository": {
1314
"type": "git",

sample/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { SheetService } from './sheet.service';
2+
3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4+
declare let global: any;
5+
6+
global.createNewFile = (): void => {
7+
const ss = SheetService.createInitialFile('New file');
8+
ss.getRange('A2').setValue('Happy gas!');
9+
};

sample/sampel.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function debugFunction(): void {
2+
console.log('Hello, debugFunction!')
3+
}
4+
5+
debugFunction()

sample/sheet.service.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Spreadsheet = GoogleAppsScript.Spreadsheet.Spreadsheet;
2+
import { getDayFormat } from './util';
3+
4+
export class SheetService {
5+
static createInitialFile(prefix: string): Spreadsheet {
6+
const fileName = `${prefix} ${getDayFormat()}`;
7+
const ss = SpreadsheetApp.create(fileName);
8+
const range = ss.getRange('A1');
9+
range.setValue('Hello, clasp!');
10+
return ss;
11+
}
12+
}

sample/util.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const getDayFormat = (date = new Date()): string => {
2+
const year = date.getFullYear();
3+
const month = date.getMonth() + 1;
4+
const day = date.getDate();
5+
return `${year}-${month}-${day}`;
6+
};

src/appsscript.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"timeZone": "Asia/Tokyo",
3+
"dependencies": {
4+
},
5+
"exceptionLogging": "STACKDRIVER",
6+
"runtimeVersion": "V8"
7+
}

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
module: {
1313
rules: [
1414
{
15-
test: /\.ts$/,
15+
test: /\src\/.ts$/,
1616
use: 'ts-loader',
1717
},
1818
],

0 commit comments

Comments
 (0)