Skip to content

Instantly share code, notes, and snippets.

@ferdiebergado
Last active January 22, 2024 08:06
Show Gist options
  • Save ferdiebergado/2945310d379fcae34d3121244f152f69 to your computer and use it in GitHub Desktop.
Save ferdiebergado/2945310d379fcae34d3121244f152f69 to your computer and use it in GitHub Desktop.
Shell script to scaffold a typescript project with bun and vite
#!/usr/bin/env sh
PROJ_DIR="$HOME/Projects/typescript/BUN"
PROJ=${1:-bun-vite-proj$(date +'%s')}
test -z $(command -v unzip) && sudo dnf install unzip
test -z $(command -v bun) && curl -fsSL https://bun.sh/install | bash
source ~/.bashrc
cd "$PROJ_DIR"
bunx create-vite --template vanilla-ts $PROJ
cd "$PROJ"
bun i
bun a -d postcss-preset-env autoprefixer cssnano jest @types/jest eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-config-standard-with-typescript eslint-plugin-import eslint-plugin-jest eslint-plugin-n eslint-plugin-promise eslint-plugin-security
bun a -d prettier --save-exact
cat <<EOF >postcss.config.js
module.exports = {
plugins: {
autoprefixer: {},
cssnano: {}
}
}
EOF
cat <<EOF >tsconfig.eslint.json
{
"extends": ["./tsconfig.json"],
}
EOF
cat <<EOF >.eslintrc.js
module.exports = {
env: {
es2021: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:jest/recommended',
'prettier',
],
plugins: ['@typescript-eslint', 'import', 'security', 'n', 'promise', 'jest'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.eslint.json'],
tsconfigRootDir: __dirname,
ecmaVersion: 'latest',
sourceType: 'module',
warnOnUnsupportedTypeScriptVersion: true,
EXPERIMENTAL_useProjectService: true,
},
ignorePatterns: ['**/*.js', 'node_modules', 'dist', '.netlify', 'netlify'],
overrides: [
{
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
{
files: ['**/*.test.ts', '**/*.test.tsx'],
env: {
node: true,
jest: true,
},
},
],
root: true,
};
EOF
### ###
### EDITORCONFIG ###
cat <<EOF >.editorconfig
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
[*.json]
indent_size = 2
# TypeScript files
[*.ts]
indent_size = 2
EOF
### PRETTIER ###
cat <<EOF >.prettierrc.json
{
"arrowParens": "avoid",
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "all",
"printWidth": 80
}
EOF
### ###
### NETLIFY ###
cat <<EOF >netlify.toml
[build]
publish = "dist"
command = "npm run build"
[[headers]]
for = "/*"
[headers.values]
Referrer-Policy = "same-origin"
X-Content-Type-Options = "nosniff"
X-Frame-Options = "DENY"
X-XSS-Protection = "1; mode=block"
Content-Security-Policy = "default-src 'self'; script-src 'self'; font-src 'self' https://fonts.gstatic.com; style-src 'self' https://fonts.googleapis.com; img-src 'self'; connect-src 'self';"
EOF
echo "## $PROJ ##" >README.md
git init
# vim: ft=sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment