https://github.com/blackglory/bundle
🌳 A directory structure for describing documents, inspired by TextBundle.
https://github.com/blackglory/bundle
esm library nodejs npm-package typescript
Last synced: 2 months ago
JSON representation
🌳 A directory structure for describing documents, inspired by TextBundle.
- Host: GitHub
- URL: https://github.com/blackglory/bundle
- Owner: BlackGlory
- License: mit
- Created: 2020-08-26T08:57:32.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-13T12:36:35.000Z (about 1 year ago)
- Last Synced: 2025-10-12T01:13:13.321Z (9 months ago)
- Topics: esm, library, nodejs, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@blackglory/bundle
- Size: 831 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# bundle
一种用于描述文档的目录结构, 受到[TextBundle]的启发.
与TextBundle的不同点:
- Bundle直接以目录结构在文件系统里表示, 不需要打包.
- Bundle的文本文件和元数据文件的格式是任意的, 不局限于Markdown和JSON.
[TextBundle]: http://textbundle.org/
## Install
```sh
npm install --save @blackglory/bundle
# or
yarn add @blackglory/bundle
```
## 定义
一个典型的bundle目录结构如下:
```
.
├── assets
│ ├── foo.png
│ └── bar.png
├── meta.json
└── text.md
```
bundle目录下的其他文件和目录会被忽略, 从而允许在此存放临时文件, 系统文件和版本控制系统.
### `/`
bundle的根目录, 目录名称是随意的, 只需要便于人类识别.
### `/meta.{extension}`
bundle的元数据, 它是一种能够被解析为键值对字典的文件, 格式不受限制, 取决于具体实现.
如果meta文件不存在, 或meta文件存在多个, 则不会将此目录视作一个bundle.
解析器使用`.`作为分隔符, 因此扩展名不可包含`.`.
### `/meta.{variant}.{extension}`
bundle元数据的变体, 可选.
相同变体名的meta文件只能存在一个, 否则将被视作无效变体.
解析器使用`.`作为分隔符, 因此变体名、扩展名不可包含`.`.
### `/text.{extension}`
bundle的文本, 格式不受限制, 取决于具体实现.
如果text文件不存在, 或text文件存在多个, 则不会将此目录视作一个bundle.
解析器使用`.`作为分隔符, 因此扩展名不可包含`.`.
### `/text.{variant}.{extension}`
bundle文本的变体, 可选.
相同变体名的text文件只能存在一个, 否则将被视作无效变体.
解析器使用`.`作为分隔符, 因此变体名、扩展名不可包含`.`.
### `/assets/**/*`
bundle的资源文件, 可选.
## API
```ts
interface IBundle {
/**
* The path of the root directory.
*/
root: string
/**
* The path of the meta file, relative to the root directory.
*/
meta: string
/**
* The path of the text file, relative to the root directory.
*/
text: string
/**
* The paths of assets, relative to the root directory.
*/
assets: string[]
/**
* The variants.
*/
variants: Record
}
interface IBundleVariant {
/**
* The path of the meta file variant, relative to the root directory.
*/
meta?: string
/**
* The path of the text file variant, relative to the root directory.
*/
text?: string
}
```
### buildBundle
```ts
/**
* @throws {NotDirectoryError}
* @throws {NoMetaFileError}
* @throws {NoTextFileError}
* @throws {TooManyMetaFilesError}
* @throws {TooManyTextFilesError}
*/
function buildBundle(pathname: string): Promise
```
### isBundle
```ts
function isBundle(pathname: string): Promise
```
### findAllBundles
```ts
function findAllBundles(pathname: string): AsyncIterable
```