@scaffdog/core
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

@scaffdog/core

@scaffdog/core is a low layer of scaffdog.

Install

Install via npm:

$ npm install @scaffdog/core

Usage

template.md:

# Variables

- key: `{{ input | upper }}`

# `{{ input }}.txt`

```
{{ output.path }}
```

index.ts:

import fs from 'fs';
import path from 'path';
import { createContext, compile } from '@scaffdog/engine';
import { extract } from '@scaffdog/core';

const source = fs.readFileSync('template.md', 'utf8');
const context = createContext({});

const { variables, templates } = extract(source, context);

for (const [key, ast] of variables) {
  context.variables.set(key, compile(ast, context));
}

for (const template of templates) {
  const filename = compile(template.filename, context);

  const data = compile(
    template.content,
    extendContext({
      variables: new Map([
        [
          'output',
          {
            path: filename,
          },
        ],
      ]),
    }),
  );

  fs.writeFileSync(filename, data);
}

// --> Generated "path/to/scaffdog.txt"

Package Sidebar

Install

npm i @scaffdog/core

Weekly Downloads

28,625

Version

4.0.0

License

MIT

Unpacked Size

5.85 kB

Total Files

5

Last publish

Collaborators

  • wadackel