Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edgejs-cli

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edgejs-cli

CLI utility to generate files based on edge templates

  • 1.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-88.89%
Maintainers
0
Weekly downloads
 
Created
Source

edgejs-cli

:warning: Maturity Level: Alpha

Minimal CLI utility to generate files using edge.js templates

Usage

pnpm i -g edgejs-cli
# ^ Will add an edget utility to PATH

# Render a single template
edget -i templates/home.edge -o site
# ^ Generates site/home.html by rendering home.edge

# Pass data to templates through a JSON/YAML file
edget -i templates/home.edge -o site -d data.json
# ^ Same as above but home.edge can use any values defined in data.json

# Render all templates within a directory (Files prefixed with . or _ are ignored)
edget -i templates -o site -d data.json

# Skip escaping if generating non-html content
edget -i sql-templates -o sql --skipEscaping

Advanced features

Multi-mode

It is not necessary that each input file generate exactly one input file, or that the output file name match input file name.

With multi-mode, we can render an output in the following format (inspired by Vue SFC):

<!-- post.multi.edge -->
<file path="post/summary.html">
Here is some summary content
</file>
<file path="post/details.html">
Here are some details
</file>

Note that the file extension needs to be .multi.edge.

This will generate two files <out-dir>/post/summary.html with content Here is some summary content and <out-dir>/post.details.html with content Here are some details.

XML parsing happens after the edge template has been rendered, so not only can the content inside <file> tags be dynamic, we can also dynamically add <file> tags too.

So the following is legal:

@each (post in posts)
<file path="post/{{post.slug}}/summary.html">
{{post.title}} - by {{post.author}}
</file>
<file path="post/{{post.slug}}/details.html">
{{post.body}}
</file>
@end

(final output must be valid XML)

It is possible to dedent and trim the content through attributes in the file tag:

<file path="post/summary.html" trim="true" dedent="true">
</file>

Use cases

This is intended to be a minimal utility that simplifies tasks like below for JS/TS developers comfortable with CLI:

  • Building static sites
  • Knowledge-graphs
  • Code generation
  • Using edge.js from other languages

Motivations

If you don't care about cross-language support, edgejs is easier than Handlebars/mustache/liquid etc. because the embedded expressions are plain JS - so there is less need to learn custom syntax specific to the templating language, and we also have first class support for async.

Also, unlike JSX based solutions, it is more versatile because it is not limited to HTML


:warning: This project has nothing to do with Microsoft edge browser.

Keywords

FAQs

Package last updated on 15 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc