@macropygia/pug-graph
v0.0.7
Published
Parses include and extends in a Pug file and gets dependencies.
Downloads
2
Readme
@macropygia/pug-graph
English | 日本語
Pugの include
と extends
を解析して依存関係を取得する
- このパッケージは不安定版です
- パッチリリースを含め予告なく破壊的変更が行われる可能性があります
- 変更点は CHANGELOG をご覧ください
- 実行前にPrettierの @prettier/plugin-pug を使用してフォーマットすることを推奨
- 半角スペースのみインデントとして認識する
インストール
npm install @macropygia/pug-graph
使用方法
import fg from 'fast-glob'
import PugGraph from '@macropygia/pug-graph'
// 初期化
const graph = new PugGraph({ baseDir: 'src' })
// 追加
await graph.parse('src/foo.pug')
// 再帰的に追加
await graph.parse('src/foo.pug', { recursive: true })
// 更新
await graph.parse('src/foo.pug')
// 削除
graph.unlink('src/foo.pug')
// 複数ファイルの処理
const files = fg.sync('src/**/[^_]*.pug')
await Promise.all(
files.map((file) =>
graph.parse(file, { recursive: true })
)
)
// 依存関係を取得
const fooDependsOn = graph.getImportedFiles('src/foo.pug')
const barIsImportedBy = graph.getImporters('src/templates/mixins/_bar.pug', {
ignorePartial: true,
})
// 終了
graph.exit()
API
constructor(options)
| Parameter | Type | Default | Required |
| -------------------- | --------- | ------- | -------- |
| options.baseDir
| string
| ""
| No |
| options.useAbsPath
| boolean
| false
| No |
options.baseDir
- Pugの同名オプションと同一
options.useAbsPath
- 絶対パスを使用する
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 |
- 非同期
options.insertOnly
- データベース上に存在する場合はスキップする
options.recursive
- 再帰的に実行する
- データベース上に存在する子孫はスキップする
options.updateDescendants
- データベース上に存在する子孫も更新する
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[]
- データベースの全レコードのオブジェクト配列を返す
exit()
- データベースを閉じて終了する