npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@isocialpractice/html-dwt-cmd-template

v1.0.0

Published

Command-line tool and library for HTML templates that follow the Adobe Dreamweaver templating system.

Readme

HTML DWT Template CLI

Command-line tool and library for HTML templates that follow the Adobe Dreamweaver templating system: update every page based on a template while keeping each page's own content, from a terminal, a script, or another tool.

Follows the Adobe Dreamweaver templating system; not affiliated with Adobe. Adobe and Dreamweaver are trademarks of Adobe.

Features

  • Update Files Based on Template: rebuild every page and child template based on a template, keeping the content of their editable regions.
  • Template parameters and editable attributes: TemplateParam values, @@(param)@@ placeholders (also inside attribute values), and optional regions (TemplateBeginIf).
  • Repeating regions with their entries kept.
  • Nested templates: a child template is refreshed from its parent before the files based on it are updated.
  • Prompts or automation: confirm each file with a diff, or apply every update with --auto-apply.
  • Backups: the three most recent backups per template, restorable with one command. Turn them off with --no-backup.
  • Safe by default: files are written only inside the site root (symbolic links included), each page keeps its own line endings, and safety checks stop an update that would lose content.
  • Library API: the same engine as a Node.js package, with pure string functions and a small host interface.

Install

# As a command
npm install -g @isocialpractice/html-dwt-cmd-template
html-dwt-cmd --help

# Without installing
npx --package @isocialpractice/html-dwt-cmd-template html-dwt-cmd --help

# As a library in a project
npm install @isocialpractice/html-dwt-cmd-template

When the registry is unavailable, install a release from GitHub instead; npm builds it on install:

npm install github:isocialPractice/html-dwt-cmd-template#v1.0.0

Quick Start

Run the commands from the site root, the folder that holds Templates/, or point to it with --cwd.

my-site/
├── Templates/
│   ├── main.dwt
│   └── article.dwt        (child template of main.dwt)
├── index.html             (based on main.dwt)
└── pages/
    ├── about.html         (based on main.dwt)
    └── news.html          (based on article.dwt)
# Update the files based on main.dwt, confirming each file
html-dwt-cmd update-all Templates/main.dwt

# Update them all without prompts
html-dwt-cmd update-all Templates/main.dwt --auto-apply

# Update only the pages in one folder, without backups
html-dwt-cmd update-folder pages Templates/main.dwt --auto-apply --no-backup

# Run from anywhere
html-dwt-cmd update-all Templates/main.dwt --cwd /path/to/my-site

Commands

| Command | What it does | | --- | --- | | update-all <template> | Updates the child templates and pages based directly on the template. | | sync <template> | Same as update-all. | | update-folder <folder> <template> | Updates only the pages inside the folder (relative to the site root). Child templates are not touched. | | find-instances <template> | Lists the pages based directly on the template. | | create-page <template> --output <path> | Creates a new page from the template. The page is exactly what an update of it would produce. Refuses an existing file and a path outside the site root. | | show-regions <file> | Lists the editable regions of a template or page. | | restore-backup | Restores the files of the most recent backup, after asking. | | help, --help, -h | Shows usage. | | version, --version, -v | Shows the version. |

| Option | Meaning | | --- | --- | | --auto-apply, -a | Apply every update without asking. Files that fail the safety checks are skipped. restore-backup restores without asking. | | --no-backup | Do not back up files before updating them. | | --cwd <path> | The site root. Defaults to the current folder. | | --output, -o <path> | The new page for create-page. | | --template, -t <path> | The template, instead of the positional argument. |

Prompts

Without --auto-apply, each file that would change is offered:

Update 'pages/about.html' with template changes?
  1. Apply
  2. Apply to All
  3. Show Diff
  4. Skip
  5. Cancel
Select an option (number):

Show Diff prints a colored line diff and asks again. Apply to All applies this file and every later one without asking. Cancel, Ctrl+C, or the end of input stops the run; files already written stay written.

A file whose update fails the safety checks (a region's content would be lost, markers are unbalanced, or the page would shrink too much) is shown with the reasons and offered Next File, Show Diff, or Cancel. It is never written.

What an Update Does

  1. Backs up the files about to change (unless --no-backup).
  2. When the template is a child template whose parameters feed @@(param)@@ placeholders in its parent, refreshes it from the parent first, without asking, so the placeholders take the child's values.
  3. Updates each child template based on the template. A child template keeps its own TemplateBeginEditable regions and parameters for its pages.
  4. Updates each page: the template's structure is rebuilt with the page's own editable-region content, repeat entries, and parameter values. Optional regions are shown or left out by their conditions, @@(param)@@ placeholders are resolved, and TemplateParam becomes InstanceParam.

Updates go one level down. To update a whole tree, run the command for the master template, then for each child template.

Exit Codes

| Code | Meaning | | --- | --- | | 0 | Success. Files skipped by a prompt or a safety check do not count as errors. | | 1 | Error: a missing or invalid template, a folder outside the site, or a file that could not be updated. | | 2 | Cancelled. |

Backups

Before an update writes anything, the files it will change are copied to .html-dwt-cmd-template-backups/<template>/1/ in the site root, keeping their folders. Older backups move to 2 and 3; the fourth is removed. restore-backup restores the newest backup of any template.

File Discovery

  • Pages are .html, .htm, and .php files whose InstanceBegin marker names the template.
  • Templates are .dwt, .html, .htm, and .php files directly in the site's Templates/ folder. Subfolders such as _notes are skipped.
  • Skipped while looking for pages: any folder named Templates, the backup and temp folders (.html-dwt-*), node_modules, and .git.
  • Symbolic links and junctions are followed once, and only when they resolve inside the site root. Nothing outside the site root is ever written.

Library API

npm install @isocialpractice/html-dwt-cmd-template

Importing the package runs nothing. It has type declarations.

Pure Functions

These work on strings and never touch the file system.

import { mergeInstance, createPageFromTemplate, listEditableRegions } from '@isocialpractice/html-dwt-cmd-template';

const templateText = '<html><head></head><body><!-- TemplateBeginEditable name="main" --><p>Welcome</p><!-- TemplateEndEditable --></body></html>';

// A new page based on Templates/main.dwt
const pageText = createPageFromTemplate(templateText, { templateRef: '/Templates/main.dwt' });

// Merge a page with a changed template
const result = mergeInstance(templateText, pageText, { templateRef: '/Templates/main.dwt' });
console.log(result.status);        // 'updated' or 'unchanged'
console.log(result.safetyIssues);  // [] when the result is safe to write
console.log(listEditableRegions(result.rebuilt).map(region => region.name)); // ['main']

| Function | Purpose | | --- | --- | | mergeInstance(template, page, options) | Merge one page or child template (options.childTemplate) with its template. | | createPageFromTemplate(template, options) | Text of a new page based on the template. | | listEditableRegions(text) | Editable regions with their offsets, nested ones included. | | parseTemplateParameters(text), parseInstanceParameters(text) | Parameters of a template or a page. | | setInstanceParameters(page, values, templateParams) | Set a page's parameter values. | | findRepeatEntryAt(text, offset), insertRepeatEntry(text, offset, 'before' \| 'after', template?) | Locate or copy a repeat entry. | | hasTemplateMarkers(text), isTemplateInstanceText(text), isTemplateFilePath(path) | Recognize templates and pages. |

Updating a Site

The update functions take an EngineHost: the program that reads and writes files, shows prompts, and reports progress. This host updates my-site without prompts:

import * as fs from 'fs';
import * as path from 'path';
import { EngineHost, updateFilesBasedOnTemplate } from '@isocialpractice/html-dwt-cmd-template';

const siteRoot = path.resolve('my-site');

const host: EngineHost = {
  siteRoot,
  readText: file => fs.promises.readFile(file, 'utf8'),
  writeText: async (file, text) => {
    await fs.promises.mkdir(path.dirname(file), { recursive: true });
    await fs.promises.writeFile(file, text, 'utf8');
  },
  log: line => console.log(line),
  notify: (level, message) => console.log(`${level}: ${message}`),
  confirmApply: async () => 'applyAll',
  confirmSafety: async () => 'next',
  withProgress: (_title, task) => task(() => false)
};

const summary = await updateFilesBasedOnTemplate(host, path.join(siteRoot, 'Templates', 'main.dwt'));
console.log(`Updated ${summary.updated.length}, skipped ${summary.skipped.length}, failed ${summary.failed.length}`);

| Function | Purpose | | --- | --- | | updateFilesBasedOnTemplate(host, template, options) | Update Files Based on Template. Returns a RunSummary. | | updateInstance(host, file, options) | Update one page or child template from the template its InstanceBegin names. | | findTemplateInstances(siteRoot, template, options) | Pages based directly on a template. | | findChildTemplates(siteRoot, template), findDescendantTemplates(siteRoot, template) | Child templates, one level or all levels down. | | findLastBackup(siteRoot), restoreLastBackup(host) | The newest backup, and restoring it. |

UpdateOptions: autoApply, skipBackup, folder (site-relative scope), backupDirName, tempDirName, suppressCompletionNotice.

The host decides how confirmApply ('apply' | 'applyAll' | 'skip' | 'cancel') and confirmSafety ('next' | 'showDiff' | 'cancel') are answered. Every write goes through host.writeText, after the engine has checked that the path stays inside host.siteRoot. A host that edits open documents (an editor) can return their unsaved text from readText. It can also use onRunStart and onRunEnd to suspend its own edit protection while the engine writes.

Architecture

src/
  index.ts      Public API: re-exports only
  cli.ts        The html-dwt-cmd command: arguments, host, exit code
  cli/          Commands, the console host (prompts, Ctrl+C), the colored diff
  core/         Pure string transforms: merge, params, attributes, repeat,
                regions, safety, page, detect, text
  engine/       Update runs over a host: update, run, attributesProcess, backups
  fs/           Discovery and path rules: templatePaths, fileSystemSafety,
                findTemplateInstances, findChildTemplates
  host/         The EngineHost contract and option and summary types

core/ never touches the file system or the process. engine/ uses a host for everything a person sees or a file that changes. cli/ is one host.

Template Syntax

<!-- TemplateBeginEditable name="main" -->
  <p>Default content</p>
<!-- TemplateEndEditable -->

<!-- TemplateParam name="showSidebar" type="boolean" value="true" -->
<!-- TemplateBeginIf cond="showSidebar" -->
  <aside>Sidebar</aside>
<!-- TemplateEndIf -->

<!-- TemplateParam name="logo" type="URL" value="/img/logo.png" -->
<img src="@@(logo)@@" alt="logo">

<!-- TemplateBeginRepeat name="rows" -->
  <tr><td><!-- TemplateBeginEditable name="cell" -->Cell<!-- TemplateEndEditable --></td></tr>
<!-- TemplateEndRepeat -->

A page based on the template declares it after <html> and ends before </html>:

<html><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
...
<!-- InstanceEnd --></html>

Requirements

  • Node.js 14.14 or later to run the tool.
  • Node.js 21 or later to run the tests.

Development

git clone https://github.com/isocialPractice/html-dwt-cmd-template.git
cd html-dwt-cmd-template
npm install          # also builds out/
npm test             # end-to-end harness and unit tests
npm run test:golden -- --check
  • npm run compile builds out/; npm run clean removes it.
  • scripts/test-harness.js changes the demo site in site/, runs the CLI, checks the results, and restores site/.
  • scripts/golden-test.js checks that a refactor changes no output: it updates a copy of a site with every template and compares the result with a recording (--import <site>, --record, --check).

Troubleshooting

| Problem | Check | | --- | --- | | Templates directory not found | Run from the site root, or pass --cwd. | | Not a template in the site's Templates folder | The template must be in Templates/ directly under the site root. | | No instances found | The page's InstanceBegin marker must name the template, for example template="/Templates/main.dwt". Pages inside Templates/ and backup folders are not pages. | | A file is reported as flagged by safety checks | Use Show Diff to see the update; fix the page or template so no editable content is lost. | | A long run must stop | Press Ctrl+C once to stop after the current file, twice to exit at once. |

License

MIT. See LICENSE.