First, create a new directory for your project and initialize it with npm.
mkdir my-tool
cd my-tool
npm init -y
npm install --save-dev typescript tsx
# More deps here
# `ofetch` for http calls, for example
npm install --save ofetch
Create a tsconfig.json
file in the root of your project.
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
Create a .gitignore
file in the root of your project.
node_modules
dist
Project structure:
my-tool/
├── src/
│ └── index.ts
├── package.json
├── tsconfig.json
└── .gitignore
src/index.ts
import { ofetch } from 'ofetch';
async function main() {
console.info(await ofetch('http://dummyjson.com/test'));
}
main();
"scripts": {
"start": "tsx src/index.ts",
"build": "tsc",
"dev": "tsx watch src/index.ts"
}
npm run dev
npm run build
Output located in folder dist
.