{"id":15662357,"url":"https://github.com/kt3k/berber","last_synced_at":"2025-05-05T23:45:39.529Z","repository":{"id":21229521,"uuid":"91935606","full_name":"kt3k/berber","owner":"kt3k","description":"Static site generator generator on top of gulp ecosystem","archived":false,"fork":false,"pushed_at":"2023-10-24T12:11:03.000Z","size":545,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T12:13:57.150Z","etag":null,"topics":["cli","frontend","gulp","node","static-site-generator","static-site-generator-generator"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kt3k.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-21T05:36:16.000Z","updated_at":"2023-08-22T11:24:50.000Z","dependencies_parsed_at":"2023-01-14T09:00:17.733Z","dependency_job_id":"fd076fcf-57b6-48c0-8ed4-d5c2c42aa6bb","html_url":"https://github.com/kt3k/berber","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fberber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fberber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fberber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fberber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kt3k","download_url":"https://codeload.github.com/kt3k/berber/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596326,"owners_count":21773842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","frontend","gulp","node","static-site-generator","static-site-generator-generator"],"created_at":"2024-10-03T13:32:04.243Z","updated_at":"2025-05-05T23:45:39.511Z","avatar_url":"https://github.com/kt3k.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# berber v1.4.1\n\n[![CircleCI](https://circleci.com/gh/kt3k/berber.svg?style=svg)](https://circleci.com/gh/kt3k/berber)\n[![codecov](https://codecov.io/gh/kt3k/berber/branch/master/graph/badge.svg)](https://codecov.io/gh/kt3k/berber)\n\n\n\u003e Static site generator generator on top of gulp ecosystem\n\nBerber is a tool for creating your own **static site generator cli** with the combination of gulp plugins and/or gulp compatible transforms. There are lots of nice gulp plugins and utilities on npm, so most of transformations / transpilations / bundlings of static resources which are necessary for various kind of demands can be done by the existing plugins and modules. You can build your own static site generator for your specific demands with these abundant ecosystem and can automate lots of your build configuration tasks for static site building.\n\nWith berber, you can build static site generator with 2 main commands `build` and `serve`.Suppose your tool's name is `foobar`, then your command works as development server when called like `foobar serve`. It outputs static resources when called like `foobar build`. What you need to set up with berber is only your build pipelines using `berber.asset(paths)` method.\n\n```js\nconst berber = require('berber')\n\nberber.name('my-site-generator')\n\nberber.asset('source/**/*.md').pipe(marked())\n```\n\nThe above script works as cli. When called with `build` command like `script.js build`, then it outputs static resources to `build/` directory. When you want configure the output directory, then call `berber.dest(dest)` method:\n\n```js\nberber.dest('output')\n```\n\nWhen you want to this output path configurable by the user of your command, then bind to `config` event on `berber` object:\n\n```js\nconst berber = require('berber')\nconst { asset, dest } = berber\n\nberber.name('my-site-generator')\n\nberber.on('config', config =\u003e {\n  const dest = config.dest || 'build'\n\n  dest(dest)\n\n  asset(...).pipe(...)\n})\n```\n\nHere `asset()` chains to `.pipe` method. This `.pipe` call defines your pipeline for the assets. You can chain arbitrary number of pipes.\n\n```js\nconst frontMatter = require('gulp-front-matter')\nconst marked = require('gulp-marked')\nconst layout1 = require('layout1')\n\nberber.asset('source/**/*.md')\n  .pipe(frontMatter({ property: 'data' })\n  .pipe(marked())\n  .pipe(layout1.nunjucks(path.join(__dirname, 'src/layout.njk'))\n```\n\nThe above transforms the markdown files at `source/**/*.md` by 3 transforms; extracting frontmatters, transforming them to htmls and wrapping them with the nunjucks template `src/layout.njk`. This is similar to what `middleman` does to markdown files.\n\nYou can even define different kinds of starting points:\n\n```js\nberber.asset(paths.markdowns).pipe(...)\nberber.asset(paths.css).pipe(...)\nberber.asset(paths.js).pipe(...)\n```\n\nThe above example transforms markdowns, stylesheets and javascripts with different pipelines for each resource.\n\n# :cd: Install\n\nInstall via npm:\n\n    npm i berber\n\nFirst create your script like below:\n\n```js\nconst path = require('path')\nconst berber = require('berber')\n\nberber.on('config', config =\u003e {\n  const source = config.source || 'source'\n  const dest = config.dest || 'source'\n\n  berber.asset(path.join(source, '**/*.md'))\n    .pipe(marked())\n    .pipe(yourAwesomeTransform())\n\n  berber.dest(dest)\n})\n\nberber.name('foobar')\n```\n\nWith the above settings, your tool's name is `foobar` and when the user of this script invokes it, it looks up the config file of the name `foobar.yml` `foobar.json` or `foobar.js`. (If you want to change the name of the config file from your tool's name, then use `berber.configName(name)` method.)\n\nThen set the above script to `bin` property in your `package.json`.\n\n```json\n{\n  ...\n  \"bin\": {\n    \"foobar\": \"index.js\"\n  },\n  ...\n}\n```\n\nThen publish it to npm and your command works like the below:\n\n```console\n./node_modules/.bin/foobar build # =\u003e builds your site\n./node_modules/.bin/foobar serve # =\u003e serves your site with builtin dev server\n```\n\nThat's the basics of berber.\n\n# Custom action\n\nYou can add the custom action by calling `berber.action`.\n\n```js\nberber.action('post', 'Post the new article', argv =\u003e {\n  doSomething(argv)\n})\n```\n\nThe above adds the command `foobar post` (given that your module name is `foobar`) and when the user of your module hit the command `foobar post`, then the above doSomething(argv) is called, where argv is the cli options parsed by minimist.\n\n# APIs\n\n```js\nconst {\n  name,\n  configName,\n  asset,\n  on,\n  dest,\n  base,\n  port,\n  debugPageTitle,\n  debugPagePath,\n  loggerTitle,\n  addMiddleware,\n  action\n} = require('berber')\n```\n\n## name(name)\n\n- @param {string} name The name of your command\n\nSets the name of your command.\n\n## configName(name)\n\n- @param {string} name\n\nSets the name of your command's config file. Default is the same as the name.\n\n## asset(...paths)\n\n- @param {string[]} paths\n- @return {AssetFacade}\n\nSets the asset from the given paths. You can build your pipeline by chaining `.pipe()` call to each asset. The returned value has the same interface as [bulbo][bulbo]'s asset interface. See [bulbo][bulbo]'s document for details.\n\n## on(event, cb)\n\n- @param {string} event\n- @param {Function} cb\n\nBinds cb to the given event.\n\nCurrently available events: `config`, `serve`\n\n### `config` event\n\nAt `config` event, `cb` is called with given user config object. You can set assets, paths etc according to the user's configuration.\n\n```js\nberber.on('config', config =\u003e {\n  berber.asset(`${config.source}/**/*.md`).pipe(marked())\n})\n```\n\nIn the above example, your command look for `${config.source}/**/*.md` as markdown sources, which means your command's user can configure the location where markdown files exist.\n\n### `serve` event\n\nThis event happens when the berber start serving files. The features which only work on serve actions, like livereload, should be set up on this event.\n\n## dest(path)\n\n- @param {string} path\n\nSets the build destination path.\n\n## base(path)\n\n- @param {string} path\n\nSets the default basepath of your assets.\n\nIf the basepath is `src` and one of your assets is `src/js/foo/bar.js`, then it builds into `build/js/foo/bar/js`. If you change base to `src/js`, then it builds into `build/foo/bar.js`.\n\n## port(port)\n\n- @param {number} port\n\nSets the port number of the dev server.\n\nThis works for `serve` command.\n\n## debugPageTitle(title)\n\n- @param {string} title\n\nSets the title of the debug page.\n\nThis works for `serve` command.\n\n## debugPagePath(path)\n\n- @param {string} path\n\nSets the path of the debug page.\n\nThis works for `serve` command.\n\nExample:\n```js\ndebugPagePath('__mytool__')\n// =\u003e This makes the debug page path to be `http://localhost:[port]/__mytool__`\n```\n\nThe default of the debug page path is `__berber__`.\n\n## loggerTitle(title)\n\n- @param {string} title\n\nSets the title of the logger. Default is the same as `name` of your command.\n\n## addMiddleware(middleware)\n\n- @param {Function} middleware\n\nAdds the connect compliant middleware to the server.\n\n```js\nconst livereload = require('connect-livereload')\n\naddMiddleware(() =\u003e livereload())\n```\n\n## action(name, description, cb)\n\n- @param {string} name The name of the action\n- @param {string} description The description of the command. This appears in the help message of your command.\n- @param {Function} cb The implementation of your command\n\nSets the custom action to your command. `cb` takes the command line options as an object which is parsed by `minimist`.\n\n# Examples\n\n- [hello example](https://github.com/kt3k/berber/blob/master/examples/hello/index.js)\n- [domaindoc][domaindoc]\n  - [domaindoc][domaindoc] is a static site generator for building documentation site of domain models of your software.\n- [langsheet][langsheet]\n  - [langsheet][langsheet] is a static site generator for building i18n phrase table.\n- [remarker][remarker]\n  - [remarker][remarker] is a static site generator for slideshow, which generates remark-based slideshow html from input markdown files.\n\n# History\n\n- 2018-06-10   v1.4.1   Added `serve` event.\n\n# License\n\nMIT\n\n[domaindoc]: https://github.com/kt3k/domaindoc\n[bulbo]: https://github.com/kt3k/bulbo\n[langsheet]: https://github.com/kt3k/langsheet\n[remarker]: https://github.com/kt3k/remarker\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkt3k%2Fberber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkt3k%2Fberber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkt3k%2Fberber/lists"}