From b5824708e80a3d78af083873c6aff935393a06b9 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Thu, 7 Dec 2023 16:58:23 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=93=E3=83=AB=E3=83=89=E6=99=82=E9=96=93?= =?UTF-8?q?=E3=82=92=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apps/入金予定結果/index.tsx | 2 ++ src/apps/定期予約選考/index.ts | 2 ++ src/mypage/lib.ts | 10 ++++++---- tsconfig.json | 1 + types/env.d.ts | 15 +++++++++++++++ webpack.config.js | 17 ++++++++++------- 6 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 types/env.d.ts diff --git a/src/apps/入金予定結果/index.tsx b/src/apps/入金予定結果/index.tsx index 55bc93e..f45e478 100644 --- a/src/apps/入金予定結果/index.tsx +++ b/src/apps/入金予定結果/index.tsx @@ -69,6 +69,8 @@ const getCallbackFillAmount = (record: 入金予定結果) => { }; (() => { + console.info("script build at " + process.env.BUILD_TIME); + kintone.events.on("app.record.detail.show", (event) => { const currentRecord = event.record as 入金予定結果; diff --git a/src/apps/定期予約選考/index.ts b/src/apps/定期予約選考/index.ts index 05e9de5..821e277 100644 --- a/src/apps/定期予約選考/index.ts +++ b/src/apps/定期予約選考/index.ts @@ -110,6 +110,8 @@ const getCallBackHandleFinish = (currentRecord: 定期予約選考) => { }; (() => { + console.info("script build at " + process.env.BUILD_TIME); + const events = ["app.record.create.show", "app.record.edit.show"]; kintone.events.on(events, (event) => { const record = event.record as 定期予約選考; diff --git a/src/mypage/lib.ts b/src/mypage/lib.ts index 2280c33..a83a7a2 100644 --- a/src/mypage/lib.ts +++ b/src/mypage/lib.ts @@ -5,16 +5,18 @@ type MyPageApiResponse = { }; export const getUrl = (apiId: MyPageApiID) => { - return [process.env.MYPAGE_BASE_URL ?? "", "api-from-kintone", apiId].join( - "/" - ); + return [ + process.env.VAR.MYPAGE_BASE_URL ?? "", + "api-from-kintone", + apiId, + ].join("/"); }; export const send = async (apiId: MyPageApiID, data: object) => { const url = getUrl(apiId); const sendData = { ...data, - token: process.env.MYPAGE_TOKEN ?? "", + token: process.env.VAR.MYPAGE_TOKEN ?? "", }; console.info("MyPageAPICall", url, data); diff --git a/tsconfig.json b/tsconfig.json index f9bfb78..8252bce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,6 +19,7 @@ }, "files": [ "./node_modules/@kintone/dts-gen/kintone.d.ts", + "./types/env.d.ts", ], "include": [ "src/**/*" diff --git a/types/env.d.ts b/types/env.d.ts new file mode 100644 index 0000000..7fdbde1 --- /dev/null +++ b/types/env.d.ts @@ -0,0 +1,15 @@ +declare global { + namespace NodeJS { + interface ProcessEnv { + NODE_ENV: "development" | "production" | "test"; + // 他の環境変数も追加できます + VAR: { + MYPAGE_BASE_URL: string; + MYPAGE_TOKEN: string; + }; + BUILD_TIME: string; + } + } +} + +export {}; diff --git a/webpack.config.js b/webpack.config.js index 8a76a6c..f9588df 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,9 +6,13 @@ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const Dotenv = require('dotenv-webpack'); +const dotenv = require('dotenv'); +const { format } = require('date-fns'); const basePath = path.resolve('src', 'apps'); +const env = dotenv.config().parsed + // basePath配下の各ディレクトリを複数のentryとする const entries = glob.sync('**/index.+(js|ts|tsx)', { cwd: basePath }).reduce( (prev, file) => ({ @@ -63,7 +67,7 @@ module.exports = { filename: '[name].js', }, plugins: [ - new Dotenv({ systemvars: true }), + // new Dotenv({ systemvars: true }), new ForkTsCheckerWebpackPlugin(), // new BundleAnalyzerPlugin(), { @@ -100,11 +104,10 @@ module.exports = { ); }, }, - // new webpack.DefinePlugin({ - // 'process.env': { - // "MYPAGE_BASE_URL": JSON.stringify(process.env.MYPAGE_BASE_URL), - // "MYPAGE_TOKEN": JSON.stringify(process.env.MYPAGE_TOKEN), - // } - // }), + new webpack.DefinePlugin({ + 'process.env.VAR': JSON.stringify(env), + 'process.env.BUILD_TIME': JSON.stringify(format(new Date(), 'yyyy-MM-dd HH:mm:ss')), + + }), ], };