json-api-builder-create-folders
v1.0.0
Published
Create folders stage for JSON API Builder.
Readme
json-api-builder-create-folders
Stage 1 of 8: Stage 1: Structural Directory Scaffolding from JSON Specification Trees
Part of the modular JSON API Builder ecosystem by KeshavSoft.
The Story
Traverses tree.json specifications using json-traversal-core to create the physical directory structure under the client's output directory. It guarantees that all necessary parent paths and nested route directories exist before any files or code are generated.
The Problem It Solves
Monolithic generators mix directory creation with file templating. When intermediate folder generation fails, partial files are left behind, leading to corrupted, half-written project states.
The Solution
Decouples directory structure creation into a deterministic, idempotent, and standalone stage. It safely ensures every target directory exists before any files or code are touched.
Architecture & Pipeline Position
[1. Folders] ──▶ [2. Files] ──▶ [3. Content] ──▶ [4. Hook Routes]
│
[8. Orchestrator] ◀── [7. Validate] ◀── [6. Endpoints] ◀── [5. App]This repository implements Stage 1 in isolation. It can be used independently in custom build workflows or composed automatically via json-api-builder.
Installation
npm install json-api-builder-create-foldersQuick Start
import { createFolders } from "json-api-builder-create-folders";
const result = createFolders({
clientRoot: "./my-project",
outputRoot: "./my-project/output",
treePath: "./my-project/input/source-of-truth/tree.json"
});
console.log("Created directories under:", result.outputRoot);Input Specification
Nested tree.json where objects represent directories and string leaves point to route definitions.
{
"api": {
"routes.js": "routes.estree.json",
"v1": {
"routes.js": "routes.estree.json",
"clinics": {
"routes.js": "routes.estree.json"
}
}
}
}Output Transformation
Pure directory nodes created on the file system, perfectly matching the tree structure.
output/
└── api/
└── v1/
└── clinics/API Reference
createFolders
Accepts an options object with the following configuration:
| Option | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| clientRoot | string | process.cwd() | Root path of the client project containing input and output. |
| outputRoot | string | path.join(clientRoot, 'output') | Destination directory where folders will be created. |
| treePath | string | input/source-of-truth/tree.json | Absolute or relative path to the tree.json definition file. |
Sibling Pipeline Packages
| Stage | Package | Description | | :---: | :--- | :--- | | 01 | json-api-builder-create-folders | Directory hierarchy scaffolding | | 02 | json-api-builder-create-files | Non-destructive placeholder file creation | | 03 | json-api-builder-insert-content | ESTree template to JavaScript insertion | | 04 | json-api-builder-alter-content | Hierarchical route hooking & AST imports | | 05 | json-api-builder-create-app | Root app.js assembly & server runtime | | 06 | json-api-builder-create-endpoints | CRUD endpoints & local JSON file sync | | 07 | json-api-builder-validation | Specification linting & artifact checks | | 08 | json-api-builder | Master orchestrator coordinating all stages |
Development & Testing
# Install dependencies
npm install
# Run automated tests
npm test
# Run syntax check
npm run check
# Prepublish verification
npm run prepublishOnlyLicense
MIT © 2026 KeshavSoft
