# @macropygia/pug-graph

> Parses include and extends in a Pug file and gets dependencies.

Latest version **0.0.7** (published 2022-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @macropygia/pug-graph
pnpm add @macropygia/pug-graph
yarn add @macropygia/pug-graph
bun add @macropygia/pug-graph
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2022-12-23 |
| First published | 2022-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 26.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | macropygia |
| Maintainers | macropygia |
| Keywords | pug, graph |

## Links

- npm: https://www.npmjs.com/package/@macropygia/pug-graph
- Repository: https://github.com/macropygia/static-site-stack
- Homepage: https://github.com/macropygia/static-site-stack/tree/main/packages/pug-graph#readme
- Issues: https://github.com/macropygia/static-site-stack/issues
- npm.io page: https://npm.io/package/@macropygia/pug-graph

## Dependencies (1)

- [lokijs](https://npm.io/package/lokijs.md) ^1.5.12

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2022-12-23
- 0.0.6 — 2022-12-23
- 0.0.5 — 2022-07-13
- 0.0.4 — 2022-06-11
- 0.0.3 — 2022-06-08
- 0.0.2 — 2022-06-01
- 0.0.1 — 2022-05-29

## README

# @macropygia/pug-graph

[![npm version](https://img.shields.io/npm/v/@macropygia/pug-graph.svg?style=flat-square)](https://www.npmjs.com/package/@macropygia/pug-graph)
[![MIT](https://img.shields.io/npm/l/@macropygia/pug-graph?style=flat-square)](./LICENSE)
[![TypeScript](https://img.shields.io/badge/TypeScript-3178c6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
[![Pug](https://img.shields.io/badge/Pug-a86454?style=flat-square&logo=pug&logoColor=white)](https://pugjs.org/)

**English** | [日本語](README.ja_JP.md)

Parses `include` and `extends` in a Pug file and gets dependencies.

- **This package is currently unstable.**
    - Breaking changes may occur without any notice, even if in patch releases.
    - See [CHANGELOG](CHANGELOG.md) for changes.
- Recommended running Prettier with [@prettier/plugin-pug](https://www.npmjs.com/package/@prettier/plugin-pug) before execution.
- Use only spaces for indentation.

## Installation

```shell
npm install @macropygia/pug-graph
```

## Usage

```js
import fg from 'fast-glob'
import PugGraph from '@macropygia/pug-graph'

// Init
const graph = new PugGraph({ baseDir: 'src' })

// Insert
await graph.parse('src/foo.pug')

// Insert recursively
await graph.parse('src/foo.pug', { recursive: true })

// Update
await graph.parse('src/foo.pug')

// Delete
graph.unlink('src/foo.pug')

// Multiple files
const files = fg.sync('src/**/[^_]*.pug')
await Promise.all(
  files.map((file) =>
    graph.parse(file, { recursive: true })
  )
)

// Get dependencies
const fooDependsOn = graph.getImportedFiles('src/foo.pug')
const barIsImportedBy = graph.getImporters('src/templates/mixins/_bar.pug', {
  ignorePartial: true,
})

// Exit
graph.exit()
```

## API

### constructor(options)

| Parameter            | Type      | Default | Required |
| -------------------- | --------- | ------- | -------- |
| `options.baseDir`    | `string`  | `""`    | No       |
| `options.useAbsPath` | `boolean` | `false` | No       |

- `options.baseDir`
    - Same as Pug option.
- `options.useAbsPath`
    - Use absolute path.

### parse(filepath, options)

| Parameter                   | Type      | Default | Required |
| --------------------------- | --------- | ------- | -------- |
| `filepath`                  | `string`  |         | Yes      |
| `options.insertOnly`        | `boolean` | `false` | No       |
| `options.recursive`         | `boolean` | `false` | No       |
| `options.updateDescendants` | `boolean` | `false` | No       |

- Asynchronous
- `options.insertOnly`
    - Skip if the file already exists in the database.
- `options.recursive`
    - Parse recursively.
    - Skip if the file of the descendants already exists in the database.
- `options.updateDescendants`
    - Use with recursive option.
    - Force update the descendants.

### getImportedFiles(filepath)

| Parameter  | Type     | Default | Required |
| ---------- | -------- | ------- | -------- |
| `filepath` | `string` |         | Yes      |

- Returns: `Set<string>`

### getImporters(filepath, ignorePartial)

| Parameter       | Type      | Default | Required |
| --------------- | --------- | ------- | -------- |
| `filepath`      | `string`  |         | Yes      |
| `ignorePartial` | `boolean` | `false` | No       |

- Returns: `Set<string>`

### unlink(filepath)

| Parameter  | Type     | Default | Required |
| ---------- | -------- | ------- | -------- |
| `filepath` | `string` |         | Yes      |

### getRawData()

- Returns: `object[]`
- Returns all records as object array.

### exit()

- Close the database and exit.

---
_Source: https://npm.io/package/@macropygia/pug-graph · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
