0.0.7 • Published 1 year ago
@macropygia/pug-graph
English | 日本語
Pugの include
と extends
を解析して依存関係を取得する
インストール
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
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 |
getImporters(filepath, ignorePartial)
Parameter | Type | Default | Required |
---|
filepath | string | | Yes |
ignorePartial | boolean | false | No |
unlink(filepath)
Parameter | Type | Default | Required |
---|
filepath | string | | Yes |
getRawData()
- Returns:
object[]
- データベースの全レコードのオブジェクト配列を返す
exit()