@anygridtech/frappe-ts-tools
v0.2.0
Published
Build tools for Frappe DocTypes with TypeScript
Maintainers
Readme
@anygridtech/frappe-ts-tools
Build tools for Frappe DocTypes with TypeScript support.
Features
- 🚀 Fast bundling with esbuild
- 👀 Watch mode for development
- 🔍 TypeScript type-checking
- 📦 Auto-discovers DocTypes with TypeScript
- 📁 Compiles public TypeScript files (one-to-one, no bundling)
- ⚡ Zero configuration needed
Installation
npm install --save-dev @anygridtech/frappe-ts-tools typescriptConfiguration
You need a tsconfig.json file in your module's root directory (or in the directory with the public/ folder). Here's a recommended configuration:
{
"compilerOptions": {
"rootDir": ".",
"outDir": "./js",
"module": "preserve",
"target": "ESNext",
"esModuleInterop": false,
"importHelpers": false,
"noEmitHelpers": true,
"verbatimModuleSyntax": false,
"types": [
"jquery",
"@anygridtech/frappe-agt-types",
"@anygridtech/frappe-types"
],
"sourceMap": false,
"allowSyntheticDefaultImports": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"noImplicitOverride": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"removeComments": true,
"strict": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force"
},
"include": ["ts/**/*.ts", "**/ts/**/*.ts"],
"exclude": ["node_modules", "**/__bundle_entry__.ts"],
"watchOptions": {
"watchFile": "fixedPollingInterval",
"watchDirectory": "fixedPollingInterval",
"fallbackPolling": "dynamicPriority"
}
}Note: Adjust the types array according to your installed type packages.
Usage
Build all DocTypes
npx frappe-buildWatch mode (auto-rebuild on changes)
npx frappe-watchWatch mode with type-checking
npx frappe-watch --typecheckType-check only
npx frappe-typecheckType-check in watch mode
npx frappe-typecheck --watchProject Structure
Your Frappe app should have this structure:
your_app/
├── your_module/
│ └── doctype/
│ └── your_doctype/
│ ├── your_doctype.json
│ ├── your_doctype.py
│ ├── your_doctype.js (output)
│ └── ts/ (source)
│ ├── onload.ts
│ ├── refresh.ts
│ └── ...
├── public/ (optional)
│ ├── ts/ (source)
│ │ ├── utils.ts
│ │ ├── api.ts
│ │ └── ...
│ └── js/ (output)
│ ├── utils.js
│ ├── api.js
│ └── ...
├── tsconfig.json
└── package.jsonDocType TypeScript (Bundled)
Place TypeScript files in ts/ folder next to your DocType. All .ts files will be bundled into a single <doctype_name>.js file.
Public TypeScript (Individual Files)
Place TypeScript files in public/ts/ folder. Each .ts file will be compiled to a corresponding .js file in public/js/ folder without bundling. This is perfect for:
- Utility libraries
- Shared modules
- API clients
- Independent scripts
Example: public/ts/utils.ts → public/js/utils.js
Optional: Add to package.json
For convenience, you can add scripts to your package.json:
{
"scripts": {
"build": "frappe-build",
"watch": "frappe-watch",
"typecheck": "frappe-typecheck"
}
}Then run: npm run watch
How it works
DocType Compilation (Bundled)
- Scans your app for DocTypes with
ts/folders - Creates a temporary bundle entry that imports all
.tsfiles - Bundles with esbuild into
<doctype_name>.js - Cleans up temporary files
Public Folder Compilation (Individual)
- Scans your app for
public/ts/folders - Compiles each
.tsfile individually (no bundling) - Outputs to
public/js/folder maintaining the same filename - Each TypeScript file becomes its own JavaScript file
Both modes run in parallel and support watch mode with optional TypeScript type-checking.
Requirements
- Node.js >= 18
- TypeScript >= 5.0
- Frappe app structure
License
MIT
