Skip to content

Instantly share code, notes, and snippets.

@Sharlottes
Created March 31, 2024 12:34
Show Gist options
  • Save Sharlottes/c575f925c8a394722a3e069182eb7823 to your computer and use it in GitHub Desktop.
Save Sharlottes/c575f925c8a394722a3e069182eb7823 to your computer and use it in GitHub Desktop.
/*
Env generator
This script is located at "scripts/envGenerator.js" and reads the env file ".env.local" in the top-level path to create the file "src/@types/env.ts".
You will need to modify the paths to the files you want to read or create yourself.
이 스크립트는 "scripts/envGenerator.js"에 위치하여 최상위 경로의 ".env.local" 환경변수 파일을 읽어 "src/@types/env.ts" 파일을 생성합니다.
읽거나 만들 파일의 경로는 직접 수정해야 합니다.
*/
/*
MIT License
Copyright (c) 2024 Sharlottes#0018
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// @ts-check
const fs = require("fs");
const path = require("path");
const envDir = path.resolve(__dirname, "..", ".env.local");
const tsDir = path.resolve(__dirname, "..", "src", "@types", "env.ts");
const result = fs.readFileSync(envDir, "utf8");
const content = `interface Env {
${result
.split("\r\n")
.filter((line) => !line.startsWith("#") && line.length > 0)
.map((line) => ` ${line.split("=")[0]}: string;`)
.join("\n")}
}
`;
fs.writeFileSync(tsDir, content, "utf8");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment