Required:
- Node.js version 20
Optional (but recommended):
You can either follow the manual instructions below, or use the swig-cli-init npm package by simply running the following command:
npx swig-cli-init@latest
Note that this requires you either have Node.js 20 or Volta installed.
Many project types and javascript flavors will work, but typescript with tsx is the recommended approach. Below are some simple steps to get a new project setup quickly.
These instructions assume you use Volta to manage NodeJS versions and would like to use NodeJS version 20 - adjust as necessary.
- Install swig-cli globally:
npm i -g swig-cli
- Create a new directory and navigate to it
npm init -y
- (optional)
volta pin node@20
- Update package.json so it has
"type": "module"
(can be accomplished with a CLI by runningnpm pkg set type="module"
) - Create a tsconfig.json with something like this (the important settings are
target
,module
andmoduleResolution
):{ "compilerOptions": { "target": "ESNext", "module": "NodeNext", "moduleResolution": "NodeNext", "allowSyntheticDefaultImports": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, "types": [ "node" ], "noEmit": true, "baseUrl": ".", "rootDir": "." }, "include": [ "swigfile.ts" ], "exclude": [ "node_modules" ] }
npm i -D typescript tsx @types/node@20 swig-cli
- Create a file
swigfile.ts
with this content:import { series } from 'swig-cli' export const helloWorld = series(hello, world) async function hello() { console.log('hello') } async function world() { console.log('world') }
- Verify it's working with:
- List available tasks:
swig
- Run your hello world task:
swig helloWorld
- List available tasks: