Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from proshunsuke/v2
Browse files Browse the repository at this point in the history
v2
  • Loading branch information
proshunsuke authored Mar 10, 2021
2 parents fd3f28e + e36284b commit 353c4ba
Show file tree
Hide file tree
Showing 31 changed files with 5,003 additions and 4,474 deletions.
20 changes: 0 additions & 20 deletions .babelrc

This file was deleted.

5 changes: 4 additions & 1 deletion .clasp.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"scriptId":"1nm2BIhYyOpqUmj-vKRr4p69bhMEGBf-Cq9opE4u3xvfyd67C38majtmI","rootDir":"./dist","projectId":"augc-260709"}
{
"scriptId":"1rzoffgXqdRqq98pRPxJSCMJnLmJ3cUTyhpjZsfm54WbHByH7swQv7n8V",
"rootDir":"./dist"
}
28 changes: 28 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
project: ['./tsconfig.eslint.json'],
},
plugins: ['@typescript-eslint', 'jest'],
extends: [
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
rules: {
quotes: ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }],
semi: ['error', 'always'],
'import/no-extraneous-dependencies': 'off',
'no-void': ['error', { allowAsStatement: true }],
'no-console': ['error', { allow: ['info', 'error'] }],
'@typescript-eslint/unbound-method': 'off'
},
};
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package.json
yarn.lock
tsconfig.*
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist: trusty
sudo: false
cache: yarn
script:
- make test/ci && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
- make lint
- make test/ci && cat ./coverage/lcov.info | yarn coveralls
56 changes: 38 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
NODE_MODULUES_BIN_DIR := ./node_modules/.bin

setup:
$(MAKE) yarn/install

yarn/install:
install:
yarn install

webpack/build:
$(NODE_MODULUES_BIN_DIR)/webpack
build: install
ENV=production yarn webpack

watch:
ENV=local yarn webpack watch

server:
yarn run functions-framework --target=getKeyakiSchedule --source=./gcpFunctions/getKeyakiSchedule

run/setSchedule:
node -e 'require("./dist/index.js");global.setSchedule();'

clasp/login:
$(NODE_MODULUES_BIN_DIR)/clasp login
login:
yarn clasp login

clasp/push: yarn/install webpack/build
$(NODE_MODULUES_BIN_DIR)/clasp push -f
push: build
yarn clasp push -f

clasp/run:
$(NODE_MODULUES_BIN_DIR)/clasp run execute
run:
yarn clasp run execute

clasp/open:
$(NODE_MODULUES_BIN_DIR)/clasp open
open:
yarn clasp open

clasp/logs:
$(NODE_MODULUES_BIN_DIR)/clasp logs
logs:
yarn clasp logs

test:
$(NODE_MODULUES_BIN_DIR)/jest
ENV=production yarn jest

test/ci:
$(MAKE) webpack/build
$(NODE_MODULUES_BIN_DIR)/jest --coverage
$(MAKE) build
ENV=production yarn jest --coverage

lint:
yarn eslint "src/**/*.ts" "tests/**/*.ts"

fix:
$(MAKE) fix/prettier
$(MAKE) fix/eslint

fix/eslint:
yarn eslint "src/**/*.ts" "tests/**/*.ts" --fix

fix/prettier:
yarn prettier --check --write "src/**/*.ts" "tests/**/*.ts"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ make test
### リリース

```shell script
make clasp/push
make push
```

## 連絡先
Expand Down
3 changes: 2 additions & 1 deletion dist/appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/script.scriptapp"
],
"exceptionLogging": "STACKDRIVER"
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
File renamed without changes.
30 changes: 23 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,48 @@
"license": "MIT",
"devDependencies": {
"@babel/core": "*",
"@babel/plugin-proposal-class-properties": "*",
"@babel/preset-env": "*",
"@babel/preset-typescript": "*",
"@google-cloud/functions-framework": "*",
"@google/clasp": "*",
"@types/google-apps-script": "*",
"@types/jest": "*",
"@types/node": "*",
"@types/node-fetch": "*",
"@typescript-eslint/eslint-plugin": "*",
"@typescript-eslint/parser": "*",
"babel-loader": "*",
"core-js": "*",
"coveralls": "*",
"dayjs": "*",
"es3ify-webpack-plugin": "*",
"eslint": "*",
"eslint-config-airbnb-typescript": "*",
"eslint-config-prettier": "*",
"eslint-plugin-import": "*",
"eslint-plugin-jest": "*",
"gas-webpack-plugin": "*",
"jest": "*",
"jest-fetch-mock": "*",
"mockdate": "*",
"node-fetch": "*",
"prettier": "*",
"puppeteer": "*",
"regenerator-runtime": "*",
"ts-jest": "*",
"tslint": "*",
"ts-loader": "*",
"webpack": "*",
"webpack-cli": "*"
},
"jest": {
"moduleFileExtensions": [
"ts",
"js"
"js",
"ts"
],
"transform": {
"^.+\\.ts$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.json"
"tsconfig": "tsconfig.json"
},
"CalendarApp": {},
"UrlFetchApp": {},
Expand All @@ -46,6 +58,10 @@
},
"testMatch": [
"**/tests/**/*.test.ts"
],
"automock": false,
"setupFiles": [
"./setupJest.js"
]
}
}
1 change: 1 addition & 0 deletions setupJest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('jest-fetch-mock').enableMocks()
81 changes: 50 additions & 31 deletions src/calendar.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
import { ScheduleObj, KeyakiCalendarObj, keyakiCalendarIds} from "./keyakizaka/keyakiObjects"
import Retry from "./lib/retry";
import {
ScheduleObj,
KeyakiCalendarObj,
keyakiCalendarIds,
} from './keyakizaka/keyakiObjects';
import Retry from './lib/retry';

export default class Calendar {
/**
*
* @param {GoogleAppsScript.Calendar.CalendarEvent} event
*/
deleteEvent(event: GoogleAppsScript.Calendar.CalendarEvent): void {
Retry.retryable(3, () => {
event.deleteEvent();
});
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする
/**
*
* @param {GoogleAppsScript.Calendar.CalendarEvent} event
*/
static deleteEvent(event: GoogleAppsScript.Calendar.CalendarEvent): void {
Retry.retryable(3, () => {
event.deleteEvent();
});
if (process.env.ENV === 'production') {
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする
}
}

/**
*
* @param {ScheduleObj} schedule
*/
createEvent(schedule: ScheduleObj): void {
const keyakiCalendarId: KeyakiCalendarObj | undefined = keyakiCalendarIds.find((keyakiCalendarId: KeyakiCalendarObj) => {
return (keyakiCalendarId.kind === schedule.className);
});
if (typeof keyakiCalendarId === 'undefined') {
console.info("スケジュールの内容: ");
console.info(schedule);
throw new Error("存在しない種類のスケジュールです。className: " + schedule.className);
}
const calendarId: string = keyakiCalendarId.calendarId;
Retry.retryable(3, () => {
CalendarApp.getCalendarById(calendarId).createAllDayEvent(schedule.title, new Date(schedule.start));
});
console.info("予定を作成しました。日付: " + schedule.start + ", タイトル: " + schedule.title);
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする
};
/**
*
* @param {ScheduleObj} schedule
*/
static createEvent(schedule: ScheduleObj): void {
const keyakiCalendarId:
| KeyakiCalendarObj
| undefined = keyakiCalendarIds.find(
(id) => id.kind === schedule.className
);
if (typeof keyakiCalendarId === 'undefined') {
console.info('スケジュールの内容: ');
console.info(schedule);
throw new Error(
`存在しない種類のスケジュールです。className: ${schedule.className}`
);
}
const { calendarId } = keyakiCalendarId;
Retry.retryable(3, () => {
if (process.env.ENV === 'production') {
CalendarApp.getCalendarById(calendarId).createAllDayEvent(
schedule.title,
new Date(schedule.start)
);
}
});
console.info(
`予定を作成しました。日付: ${schedule.start}, タイトル: ${schedule.title}`
);
if (process.env.ENV === 'production') {
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする
}
}
}
39 changes: 15 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import Schedule from "./schedule";
import Trigger from "./lib/trigger";
import dayjs from "dayjs";
import dayjs from 'dayjs';
import Schedule from './schedule';
import Trigger from './lib/trigger';
import 'regenerator-runtime';

// @ts-ignore
declare const global: {
[x: string]: any;
[x: string]: () => void | Promise<void>;
};

/**
*
* @param e
*/
global.createSetScheduleTrigger = function (e: any) {
console.info("スケジュール更新のトリガーを作成します");
Trigger.setTrigger(dayjs());
console.info("スケジュール更新のトリガーを作成しました");
global.createSetScheduleTrigger = (): void => {
console.info('スケジュール更新のトリガーを作成します');
Trigger.setTrigger(dayjs());
console.info('スケジュール更新のトリガーを作成しました');
};

/**
*
* @param e
*/
global.setSchedule = function (e: any) {
const schedule = new Schedule();
console.info("スケジュール更新を開始します");
schedule.setSchedule();
console.info("スケジュール更新が完了しました");
global.setSchedule = async (): Promise<void> => {
console.info('スケジュール更新を開始します');
await Schedule.setSchedule();
console.info('スケジュール更新が完了しました');
};

export const createSetScheduleTrigger = global.createSetScheduleTrigger;
export const setSchedule = global.setSchedule;
export const { createSetScheduleTrigger } = global;
export const { setSchedule } = global;
7 changes: 7 additions & 0 deletions src/keyakizaka/fetchUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fetch from 'node-fetch';

// eslint-disable-next-line import/prefer-default-export
export async function fetchUrl(customUrl: string): Promise<string> {
const response = await fetch(customUrl);
return response.text();
}
Loading

0 comments on commit 353c4ba

Please sign in to comment.