Skip to content

Instantly share code, notes, and snippets.

@sitek94
Last active July 23, 2023 06:52
Show Gist options
  • Save sitek94/b206d93209dbca994c26761e179ef6f5 to your computer and use it in GitHub Desktop.
Save sitek94/b206d93209dbca994c26761e179ef6f5 to your computer and use it in GitHub Desktop.
Project Init
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
{
"arrowParens": "avoid",
"bracketSpacing": true,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false,
"proseWrap": "always",
"printWidth": 80,
"overrides": [
{
"files": "*.md",
"options": {
"printWidth": 120
}
}
]
}
const getEnv = (name: string): string => {
const value = process.env[name];
if (!value) {
throw new Error(`Missing: process.env['${name}'].`);
}
return value;
};
const isNumber = (envVar: string) => {
const value = Number(envVar);
if (isNaN(value)) {
throw new Error(`Provided ENV var "${envVar}" is not a number.`);
}
return value;
};
const isBool = (envVar: string) => {
if (envVar !== "true" && envVar !== "false") {
throw new Error(`Provided ENV var "${envVar}" is not "true" or "false"`);
}
return Boolean(envVar);
};
const config = {
string: getEnv("REACT_APP_STRING"),
number: isNumber(getEnv("REACT_APP_NUMBER")),
boolean: isBool(getEnv("REACT_APP_BOOLEAN"))
};
export default config;

Installation

  1. Install NPM dependencies.
yarn install
  1. Start development server.
yarn start

(Optional): Before 1. and 2.

  1. Register at to get your API key.

  2. Create .env file at the root directory.

REACT_APP_API_KEY=your-api-key
REACT_APP_API_HOST=<api-provider>.com
const fs = require("fs");
const https = require("https");
const url =
"https://gist.githubusercontent.com/sitek94/b206d93209dbca994c26761e179ef6f5/raw/.prettierrc.json";
https
.get(url, (res) => {
console.log("Fetching Prettier config...");
let chunks = [];
res.on("data", (chunk) => {
chunks.push(chunk);
});
res.on("end", () => {
console.log("Prettier config fetched!");
const json = Buffer.concat(chunks).toString();
console.log("Writing Prettier config...");
fs.writeFileSync(".prettierrc", json);
console.log("Prettier config created!");
});
})
.on("error", (err) => {
console.log("Error: ", err.message);
});
{
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment