CLI tool for compiling a directory into an EPUB ebook
Version: 3.1.0-BETA
- 🏗️ Build EPUB from a structured directory
- 📂 Create directory structure with all necessary files (including tool config & language files)
- 📖 Three book types –
textbook(reflowable),comic(fixed‑layout LTR),manga(fixed‑layout RTL) - 🖼️ Image → XHTML generation – auto‑generate page XHTML from comic/manga images
↔️ Auto double‑spread detection – detects wide landscape images and marks them aspage-spread-center- 🔄 Convert Markdown (.md) to XHTML (.xhtml) and vice versa
- 📄 Convert DOCX (.docx) to Markdown (.md) with smart heading detection
- ✂️ Split Markdown files by headings (
##) into multiple files - 🔗 Merge multiple Markdown files into one (reverse of split)
- 📥 Import existing EPUB – extract chapters, metadata, cover, and media into the project structure (auto‑detects comic/manga fixed‑layout)
- 🔍 Debug mode – watch
Markdowns/(textbook) orEPUB/images/pages/(comic/manga) and auto‑rebuild - 📦 Auto‑download dependencies – fetch and extract pre‑built
node_modulesfrom the repository - ⚙️ Tool settings – interactive configuration (language, watch delay, auto‑build, overwrite policy, default type)
- 🌍 Multilingual support (Indonesian & English) – language files stored separately for easy updates
- 📋 Chapter/page order control via optional
ord.txt(with extended format for comic/manga) - 🎨 Automatic cover, TOC, and metadata generation
- 📦 Zero-config build with sensible defaults
- ⚙️ Flexible input paths and force-overwrite options
git clone https://github.com/YogabyAllwaysever/epubcreator.js.git
cd epubcreator.jsor download as ZIP.
The tool itself is self‑contained – you only need Node.js. Dependencies and configuration files are downloaded automatically when you run createdir.
Main dependencies (auto‑downloaded via updatemodule):
- archiver@5.3.0
- marked@4.0.0
- turndown@7.2.4
Optional dependencies (for extra features):
- mammoth@1.6.0 – DOCX conversion
- adm-zip@0.5.10 & xml2js@0.5.0 – EPUB import
If you prefer to install manually:
npm install archiver@5.3.0 marked@4.0.0 turndown@7.2.4
# and optional:
npm install mammoth@1.6.0 adm-zip@0.5.10 xml2js@0.5.0Or run node epubcreator.js updatemodule to download everything automatically.
node epubcreator.js <command> [options]-
createdir [type]
Create full directory structure, config files, and download.epubcreator/.
typecan betextbook(default),comic, ormanga.
If omitted, you'll be prompted interactively.
For comic/manga you'll also be asked about chapter grouping and reading direction. -
convertch [path] [options]
Convert.mdfiles to.xhtml(default: scansMarkdowns/or given path). -
convertch img2xhtml [--regen-ord] [--force]
Generate.xhtmlpage files from images inEPUB/images/pages/(comic/manga mode).
Auto‑creates/updatesord.txt. -
convertch xhtml2md [path]
Convert.xhtmlfiles to.md(scansEPUB/or given path). -
convertch docx2md [path] [options]
Convert.docxfiles to.md(scansDocs/or given path; split by##). -
conv ...
Alias forconvertch(same subcommands and options). -
split [options]
Split a Markdown file (or all.mdfiles in a directory) by heading level 2 (##) into multiple files. -
merge [options]
Merge multiple Markdown files into one (reverse ofsplit). -
build
Build EPUB from current directory.
Auto‑detectstypefromconfig.txt(textbook→ reflowable,comic/manga→ fixed‑layout). -
debug
Watch for changes and auto‑rebuild.
Textbook mode watchesMarkdowns/; comic/manga mode watchesEPUB/images/pages/. -
import [options]
Import an existing.epubfile from the current directory into the project structure.
Auto‑detects fixed‑layout EPUBs and imports them as comic/manga. -
updatemodule [--force]
Download/updatenode_modulesfrom the repository (pre‑built bundle frommainbranch). -
updateconfig [--force]
Download/update.epubcreator/(tool settings & language files) from theconfigbranch. -
settings
Interactive tool settings editor (language, watch delay, auto‑build, overwrite policy, default type). -
validate
Validate the latest built EPUB usingepubcheck(requiresepubcheckinstalled). -
--version, -v
Show version. -
help, --help
Show help message.
Global options (apply to most commands):
--force, -f– Overwrite existing files without asking.
Options for convertch img2xhtml:
--regen-ord– Regenerateord.txtfrom scratch (asks for confirmation).--force, -f– Force regenerate all XHTML files.
Options for convertch docx2md:
--output <dir>– Output directory (default:Markdowns/fromdocx).--force, -f– Overwrite existing files.--no-images– Suppress warning about unsupported image extraction (images are ignored anyway).--nosplit, -n– Do not split by headings; output a single.mdper.docx.
Options for split:
--output <dir>– Output directory (default:Markdowns/split).--force, -f– Overwrite existing files.
Options for merge:
--output <file>– Output file path (default:merged.md).--force, -f– Overwrite existing file.
Options for import:
--force, -f– Overwrite existing files.--output <dir>– Target directory (default: current directory).
Options for updatemodule / updateconfig:
--force, -f– Skip confirmation and overwrite without asking.
./
├── config.txt ← Book metadata (required)
├── ord.txt ← Chapter order list (optional)
├── Docs/ ← Source .docx files (for docx2md)
├── Markdowns/ ← Source .md files (for convertch)
├── .epubcreator/ ← Tool configuration & language files (auto‑downloaded)
│ ├── settings.txt ← Tool settings (lang, watch_delay, auto_build, overwrite_policy, default_type)
│ └── lang/ ← Language files (en.txt, id.txt)
├── node_modules/ ← Dependencies (auto‑downloaded via updatemodule)
├── EPUB/
│ ├── images/
│ │ └── cover.png ← REQUIRED
│ ├── audiovideo/ ← Optional
│ ├── bab1.xhtml ← Chapters (any name, in EPUB/ root)
│ └── ...
└── builds/
└── [folder-name].epub ← Build result
./
├── config.txt ← type: comic | manga, reading_direction: ltr | rtl
├── ord.txt ← Optional: ordered list with * / ! / | alt
├── .epubcreator/ ← Tool configuration & language files
├── node_modules/ ← Dependencies
├── EPUB/
│ ├── images/
│ │ ├── cover.jpg ← REQUIRED
│ │ └── pages/
│ │ ├── ch1/ ← Optional chapter grouping
│ │ │ ├── 0001.jpg
│ │ │ └── 0002.jpg
│ │ └── ch2/
│ │ └── 0001.jpg
│ ├── xhtmls/ ← Auto-generated by "convertch img2xhtml"
│ │ ├── ch1/
│ │ │ ├── 0001.xhtml
│ │ │ └── 0002.xhtml
│ │ └── ch2/
│ │ └── 0001.xhtml
│ ├── about.xhtml ← Back-matter (reflowable) optional
│ └── audiovideo/ ← Optional
└── builds/
└── [folder-name].epub ← Build result
Textbook mode:
# Tipe buku: textbook | comic | manga
type: textbook
# Judul utama (wajib)
title: Judul Buku
# Subjudul (opsional)
subtitle: Subjudul
# Volume / jilid (opsional)
volume: Vol. 1
# Penulis / creator (wajib)
author: Nama Penulis
# Bahasa (default: en)
language: en
# Identifier unik (URN atau ISBN), kosongkan untuk otomatis
identifier:
# Tanggal terbit (YYYY-MM-DD), kosongkan pakai hari ini
date:
# Penerbit (opsional)
publisher:
# Deskripsi / sinopsis (opsional)
description: Deskripsi singkat buku ini.
# Subjek / kategori, pisahkan dengan koma
subjects: Fiksi, Petualangan
# Nama seri (opsional)
series_name:
# Nomor seri (opsional)
series_number:
# Kontributor tambahan: nama|peran, nama|peran, ...
contributors:
# Judul tambahan (opsional), pisahkan dengan koma
extra_titles: Comic / Manga mode:
# Tipe buku: textbook | comic | manga
type: comic
# Arah baca: ltr | rtl
reading_direction: ltr
# Sifat spread: auto | none | landscape | both
spread: auto
# Fit mode gambar halaman: contain | cover | width | height | none
fit_mode: contain
title: Judul Komik
subtitle:
volume:
author: Nama Penulis
language: en
identifier:
date:
publisher:
description:
subjects:
series_name:
series_number:
contributors:
extra_titles: DOCX heading mapping (optional, textbook):
[docx-mapping]
heading1 = 24
heading2 = 18
heading3 = 14This file is automatically created when you run createdir or settings.
lang = en
watch_delay = 500
auto_build = false
overwrite_policy = ask
default_type = textbook- lang – Interface language (
idoren). - watch_delay – Debounce delay (ms) for
debugmode. - auto_build – If
true, automatically runbuildafter a successfulconvertch. - overwrite_policy – How to handle existing files:
ask,force, orskip. - default_type – Default type for
createdirwhen run interactively (textbook,comic, ormanga).
Textbook format:
# Daftar urutan bab (satu baris satu .xhtml)
bab1.xhtml
bab2.xhtml
bab3.xhtmlComic / Manga format (extended):
# Daftar urutan halaman (satu baris satu .xhtml, path relatif dari EPUB/xhtmls/)
# Format: [*|!]path [| alt-text]
# * = force page-spread-center (double spread)
# ! = force single spread
# (tanpa prefix) = auto-detect
ch1/0001.xhtml | Haruko masuk ke kafe
ch1/0002.xhtml | "Kamu ke mana?"
*ch2/0001.xhtml | Double spread opening*forcespage-spread-center!forces a single spread (alternating based on reading direction)- No prefix → auto-detects double-spread by image aspect ratio (> 1.4 = double)
| alt-textprovides a custom page title (used in TOC)
If ord.txt doesn't exist, chapters/pages are sorted naturally (numeric‑aware).
- Scans the
Markdowns/directory (or a given path) for.mdfiles. - Extracts
## Headingas chapter title. - Converts Markdown to valid XHTML.
- Handles images, lists, tables, etc.
- Supports
--forceto overwrite existing files without prompts.
- Scans
EPUB/images/pages/recursively for image files (.png,.jpg,.jpeg,.gif,.webp,.svg). - Generates matching
.xhtmlfiles inEPUB/xhtmls/, preserving subdirectory structure. - Reads image dimensions (PNG, JPEG, GIF, WebP) to set viewport and fit mode.
- Only regenerates if the image is newer than the existing XHTML (or with
--force). - Auto-creates or updates
ord.txt:- If missing → generates a fresh list.
- If exists → appends new entries (asks for confirmation).
- With
--regen-ord→ asks to regenerate from scratch.
fit_modefromconfig.txtcontrols how images scale (contain,cover,width,height,none).
- Scans the
EPUB/directory (or a given path) for.xhtmlfiles. - Extracts
<title>as chapter title. - Converts XHTML back to Markdown.
- Excludes
cover.xhtml,toc.xhtml,nav.xhtml.
- Scans the
Docs/directory (or a given path) for.docxfiles. - Converts DOCX to HTML using
mammoth. - Detects headings by Word styles (
Heading 1,Heading 2,Heading 3) or by font size if[docx-mapping]is configured inconfig.txt. - Splits output into multiple
.mdfiles by##headings by default. - Supports
--output,--force,--no-images, and--nosplit.
- Splits a
.mdfile (or all.mdfiles in a directory) into separate files at each level‑2 heading (##). - Each part is saved as
[basename]-pN.md. - Supports
--outputand--force.
- Merges all
.mdfiles found in a directory (or a single file) into one output file. - Files are combined in natural (numeric‑aware) order.
- Supports
--outputand--force.
-
Create the project:
node epubcreator.js createdir comic # or node epubcreator.js createdir manga -
Place your page images in
EPUB/images/pages/(optionally grouped inch1/,ch2/, …).
Place the cover atEPUB/images/cover.jpg. -
Generate XHTML pages:
node epubcreator.js convertch img2xhtml
This creates
EPUB/xhtmls/and populatesord.txt. -
Edit
config.txt– set title, author, reading direction, spread mode, etc. -
Edit
ord.txtif needed – add*for double spreads,!for singles,| alt-textfor page titles. -
Build:
node epubcreator.js build
The builder will:
- Auto‑sync XHTML from images (silent).
- Detect double‑spreads by aspect ratio (or respect
*/!inord.txt). - Generate a fixed‑layout OPF (
rendition:layout: prepaginated,rendition:spread). - Produce nested TOC if chapter folders are used.
- Include any back‑matter XHTML (reflowable) from
EPUB/root.
Textbook mode – watches Markdowns/:
- Converts all
.mdfiles to.xhtml(force overwrite) - Builds the EPUB
Comic / Manga mode – watches EPUB/images/pages/:
- Syncs XHTML from images
- Builds the EPUB
Usage:
node epubcreator.js debug- Runs until you press
Ctrl+C. - Uses a debounce delay from
.epubcreator/settings.txt(default: 500ms).
The import command extracts an existing .epub file into the project structure:
- Scans the current directory for
.epubfiles. - If multiple are found, prompts you to choose one.
- Detects the book type from OPF metadata:
rendition:layout: prepaginated→ comic/manga import- otherwise → textbook import
- Extracts:
- Metadata – title, author, language, identifier, date, publisher, description, subjects, series info, contributors.
- Chapters/Pages – all XHTML files in the spine.
- Cover image – saved to
EPUB/images/. - Other images – saved to
EPUB/images/. - Audio/Video – saved to
EPUB/audiovideo/.
- Generates
config.txtandord.txtautomatically. - For comic/manga: page images are extracted to
EPUB/images/pages/, XHTML is regenerated, andord.txtreflects the original spine order.
Example:
node epubcreator.js import
node epubcreator.js import --force --output ./my_bookDownloads a pre‑built tarball from the main branch and extracts node_modules.
node epubcreator.js updatemodule
node epubcreator.js updatemodule --forceDownloads the latest .epubcreator/ folder (settings & language files) from the config branch.
node epubcreator.js updateconfig
node epubcreator.js updateconfig --forcenode epubcreator.js settingsEdit lang, watch_delay, auto_build, overwrite_policy, default_type.
Press Enter to keep, type a new value to change, save to save, cancel to abort.
The build command:
- Reads
config.txtfor metadata andtype. - Branches based on type:
- Textbook → collects chapters from
EPUB/(respectsord.txt). - Comic/Manga → syncs XHTML from images, collects pages via
ord.txt, detects spreads.
- Textbook → collects chapters from
- Detects cover image (
cover.*inEPUB/images/). - Generates:
volume.opf– EPUB package file (withrendition:*metadata for comic/manga)toc.xhtml– Table of Contents (nested for comic chapters)cover.xhtml– Cover pageMETA-INF/container.xml
- Packages everything into
builds/[folder-name].epub.
- Default language is English (
en). - Change via
settingsor by editing.epubcreator/settings.txt. - Language files live in
.epubcreator/lang/. - Falls back to built‑in English strings if a file is missing.
node epubcreator.js createdir
# or force mode
node epubcreator.js createdir textbooknode epubcreator.js createdir comicnode epubcreator.js createdir manganode epubcreator.js convertch
node epubcreator.js convertch ./my_markdown
node epubcreator.js convertch --forcenode epubcreator.js convertch img2xhtml
node epubcreator.js convertch img2xhtml --regen-ord
node epubcreator.js convertch img2xhtml --forcenode epubcreator.js convertch docx2md
node epubcreator.js convertch docx2md ./MyDocs --output ./MyMarkdowns
node epubcreator.js conv docx2md -f
node epubcreator.js convertch docx2md --nosplitnode epubcreator.js split Markdowns/
node epubcreator.js split chapter.md --output ./split_parts --forcenode epubcreator.js merge Markdowns/
node epubcreator.js merge ./split_parts --output full.md --forcenode epubcreator.js import
node epubcreator.js import --force --output ./imported_booknode epubcreator.js build
# Output: builds/[folder-name].epubnode epubcreator.js convertch xhtml2md
node epubcreator.js conv xhtml2md ./EPUB/customnode epubcreator.js updatemodulenode epubcreator.js updateconfignode epubcreator.js settingsnode epubcreator.js debugarchiver(5.3.0) – ZIP packagingmarked(4.0.0) – Markdown parsingturndown(7.2.4) – XHTML to Markdown conversionmammoth(1.6.0) – DOCX to HTML conversion (optional)adm-zip(0.5.10) – EPUB import (optional)xml2js(0.5.0) – OPF parsing for import (optional)
All dependencies can be installed manually via npm install or automatically via updatemodule.
MIT Copyright (C) 2026 YogabyAllwaysever
If you find this tool useful, please give it a ⭐ on GitHub!
Happy EPUB-creating! 📚✨