Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active November 10, 2025 05:13
Show Gist options
  • Select an option

  • Save 3lvis/4d91cb5c06247814b2ae162a6c950858 to your computer and use it in GitHub Desktop.

Select an option

Save 3lvis/4d91cb5c06247814b2ae162a6c950858 to your computer and use it in GitHub Desktop.
Bootstrap ES module
#!/usr/bin/env bash
set -euo pipefail
PROJECT_NAME=${1:-}
if [ -z "$PROJECT_NAME" ]; then
echo "Usage: ./bootstrap.sh <project-name>"
exit 1
fi
mkdir "$PROJECT_NAME"
cd "$PROJECT_NAME"
echo "πŸ“¦ Initializing project: $PROJECT_NAME"
# 1) Init package.json
pnpm init
# 2) Dev deps
pnpm add -D typescript vitest tsx @types/node
# 3) Scripts + ESM
npm pkg set \
type=module \
scripts.dev="tsx src/index.ts" \
scripts.build="tsc -p tsconfig.json" \
scripts.test="vitest run" \
scripts.test:watch="vitest"
# 4) tsconfig β€” exact config we want
cat > tsconfig.json <<'EOF'
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"types": ["node", "vitest"],
"resolveJsonModule": true,
"esModuleInterop": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"sourceMap": true
},
"include": ["src"],
"exclude": ["tests", "dist", "node_modules"]
}
EOF
# 5) Folders + starter files
mkdir -p src tests
cat > src/index.ts <<'EOF'
console.log("hello from TypeScript πŸš€");
EOF
cat > tests/sanity.test.ts <<'EOF'
import { expect, it } from "vitest";
it("works", () => {
expect(2 + 2).toBe(4);
});
EOF
# 6) .gitignore
cat > .gitignore <<'EOF'
node_modules/
.pnpm-store/
.pnp.*
pnpm-debug.log*
npm-debug.log*
yarn-debug.log*
yarn-error.log*
dist/
build/
out/
tsconfig.tsbuildinfo
coverage/
.vitest/
.env
.env.*
!.env.example
logs/
*.log
.DS_Store
Thumbs.db
.idea/
.vscode/
EOF
# 7) Git init + first commit
git init -q
git branch -M main || true
git add -A
git commit -m "chore: bootstrap TypeScript + Vitest project" -q
echo ""
echo "βœ… Project $PROJECT_NAME created and committed."
echo "Next:"
echo " cd $PROJECT_NAME"
echo " pnpm build # build the app"
echo " pnpm dev # run the app"
echo " pnpm test # run tests once"
echo " pnpm run test:watch # watch mode"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment