├── .eslintrc.yaml ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── cli.js ├── docs ├── config.md ├── jstransformer.md ├── tutorial.md └── underscore-reference.md ├── index.js ├── lib ├── getDefaults.js └── transformer.js ├── package.json └── test ├── .gitignore ├── README.md ├── fixtures ├── _defaults-subfolders │ ├── expected │ │ └── subfolder │ │ │ ├── nested │ │ │ └── two.html │ │ │ └── one.html │ ├── layouts │ │ └── author-editor.ejs │ └── src │ │ ├── _defaults.yaml │ │ └── subfolder │ │ ├── _defaults.yaml │ │ ├── nested │ │ ├── _defaults.yaml │ │ └── two.html │ │ └── one.html ├── _defaults │ ├── expected │ │ ├── author.html │ │ └── no-author.html │ ├── layouts │ │ └── author.ejs │ └── src │ │ ├── _defaults.yaml │ │ ├── author.html │ │ └── no-author.html ├── _ext │ ├── expected │ │ └── ext.html │ ├── layouts │ │ └── ext.ejs │ └── src │ │ └── ext.html ├── _path │ ├── expected │ │ └── path.html │ ├── layouts │ │ └── path.ejs │ └── src │ │ └── path.html ├── cli │ ├── README.md │ ├── expected │ │ ├── layout.html │ │ └── locals.html │ ├── layouts │ │ ├── html-title.ejs │ │ └── html.ejs │ └── src │ │ ├── layout.html │ │ └── locals.html ├── config-options │ ├── expected │ │ └── layout.html │ ├── layouts │ │ └── html.ejs │ ├── onessg.config.js │ └── src │ │ └── layout.html ├── default-layout │ ├── expected │ │ └── text.html │ ├── layouts │ │ └── html.ejs │ └── src │ │ ├── _defaults.yaml │ │ └── text.html ├── empty-dir │ └── .gitkeep ├── empty-files │ ├── expected │ │ ├── html.html │ │ └── md.html │ └── src │ │ ├── html.html │ │ └── md.md ├── json │ ├── expected │ │ └── front-matter.html │ ├── layouts │ │ └── author-editor.ejs │ └── src │ │ ├── _defaults.json │ │ └── front-matter.html ├── jstransformer-not-installed │ ├── layouts │ │ └── html.xyz │ └── src │ │ └── layout.html ├── layouts │ ├── expected │ │ ├── layout.html │ │ └── locals.html │ ├── layouts │ │ ├── html-title.ejs │ │ └── html.ejs │ └── src │ │ ├── layout.html │ │ └── locals.html ├── markdown │ ├── expected │ │ └── test.html │ └── src │ │ └── test.markdown ├── non-existent-layout │ └── src │ │ └── layout.html ├── subfolders │ ├── expected │ │ ├── folder │ │ │ └── inner.html │ │ └── outer.html │ └── src │ │ ├── folder │ │ └── inner.html │ │ └── outer.html ├── text │ ├── expected │ │ ├── text-html.html │ │ └── text-md.html │ └── src │ │ ├── text-html.html │ │ └── text-md.md └── yml │ ├── expected │ └── no-author.html │ ├── layouts │ └── author.ejs │ └── src │ ├── _defaults.yml │ └── no-author.html └── onessg.js /.eslintrc.yaml: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | mocha: true 4 | es6: true 5 | parserOptions: 6 | ecmaVersion: 6 7 | extends: "ryanzim" 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | *.pid.lock 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # nyc test coverage 19 | .nyc_output 20 | 21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 22 | .grunt 23 | 24 | # node-waf configuration 25 | .lock-wscript 26 | 27 | # Compiled binary addons (http://nodejs.org/api/addons.html) 28 | build/Release 29 | 30 | # Dependency directories 31 | node_modules 32 | jspm_packages 33 | 34 | # Optional npm cache directory 35 | .npm 36 | 37 | # Optional REPL history 38 | .node_repl_history 39 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "7" 4 | - "6" 5 | - "4" 6 | after_success: npm run coveralls 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Looking to contribute something to do? **Here's how you can help.** 2 | 3 | Please take a moment to review the guidelines below. 4 | 5 | ## General Conduct 6 | 7 | Please respect the following rules: 8 | 9 | - Please **do not** derail or troll issues or PR's. Keep the discussion on topic and respect the opinions of others. 10 | - Please **do not** post comments consisting solely of "+1" or ":thumbsup:". Use [GitHub's "reactions" feature](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments) instead. We will delete comments that violate this rule. 11 | - **Absolutely No** foul language, swearing, or name-calling. Comments that violate this rule will be edited to remove the offensive language or deleted by the moderators. 12 | 13 | ## Issues 14 | 15 | For bugs :beetle:, feature requests :bulb:, and questions :speech_balloon:, please file an issue! 16 | 17 | You may want to look at the [Roadmap](https://github.com/RyanZim/onessg/wiki/Roadmap) to see what features are already planned. If you have a need for one of these features, please file an issue so we can make it high-priority! 18 | 19 | ### Bug Reports 20 | 21 | Please search to make sure the issue hasn't already been reported by someone else. 22 | 23 | Make sure you can reproduce the issue using the current `master` branch. The issue may have been fixed since the last release. If that is the case and you need the bugfix urgently, you are welcome to file an issue asking for an ETA on the next release. I'll try to make one ASAP. 24 | 25 | Please try to be extremely detailed in your report. It may be best to create a reduced test case repository that we can clone and run `npm test` to see and debug the issue. 26 | 27 | ## Pull Requests 28 | 29 | Good pull requests are a great help. 30 | 31 | **Please ask first** before embarking on any significant pull request (e.g. adding a new feature, refactoring code, etc.). 32 | 33 | All new features must have tests, bugfixes should have tests to prevent regressions where practical. We have 100% code coverage and would like to keep it that way. 34 | 35 | [Test-Driven-Development](https://en.wikipedia.org/wiki/Test-driven_development) is a good practice (write tests first, then the actual code). 36 | 37 | - Run `npm test` to run the test suite. 38 | - Run `npm run coverage` to generate the line-by-line coverage report. The report will output to `coverage/lcov-report/index.html`. 39 | 40 | For more information on writing tests, please see [test/README.md](test/README.md). 41 | 42 | If you make changes to the headings in `README.md`, please run `npm run toc` to update the table of contents. 43 | 44 | **IMPORTANT**: By submitting a patch, you agree to allow the project owners to license your work under the terms of the [MIT License](LICENSE). 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Ryan Zimmerman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # onessg 2 | 3 | [![Travis](https://img.shields.io/travis/RyanZim/onessg.svg?maxAge=2592000)](https://travis-ci.org/RyanZim/onessg) 4 | [![Coveralls branch](https://img.shields.io/coveralls/RyanZim/onessg/master.svg)](https://coveralls.io/github/RyanZim/onessg) 5 | [![npm](https://img.shields.io/npm/v/onessg.svg?maxAge=2592000)](https://www.npmjs.com/package/onessg) 6 | [![npm](https://img.shields.io/npm/l/onessg.svg?maxAge=2592000)](https://github.com/RyanZim/onessg/blob/master/LICENSE) 7 | 8 | onessg (One Static Site Generator) is the Static Site Generator that does only one thing: compile your html and markdown. It won't minify your JS, concat your CSS, or optimize your images. Why? You most likely already have a favorite tool for doing that. 9 | 10 | > The Javascript pendulum has swung from restrictive, monolithic frameworks to modular, boilerplate-hindered libraries. 11 | > 12 | >-- [@ericclemmons](https://medium.com/@ericclemmons/javascript-fatigue-48d4011b6fc4#.7xcwmnave) 13 | 14 | onessg changes that. We believe in the unix philosophy: do one thing and do it well. 15 | 16 | We also believe in setting useful, but overridable defaults. Because of this, onessg requires no configuration files to get started. 17 | 18 | ## Contents 19 | 20 | 21 | 22 | 23 | - [Installation](#installation) 24 | - [Example](#example) 25 | - [CLI Usage & Options](#cli-usage--options) 26 | - [Contributing](#contributing) 27 | - [License](#license) 28 | 29 | 30 | 31 | ## Installation 32 | 33 | ```bash 34 | npm install -D onessg 35 | ``` 36 | 37 | You will also need to install the jstransformer for your favorite template engine. For example, if you use [EJS](https://github.com/mde/ejs), you would run: 38 | 39 | ```bash 40 | npm install -D jstransformer-ejs 41 | ``` 42 | 43 | You can read more about jstransformers [here](docs/jstransformer.md). 44 | 45 | **Note:** We recommend installing onessg as a devDependency (with the `-D` flag) and running it via an npm script. If you choose to install onessg globally, you will also need to install the jstransformer globally as well. 46 | 47 | ## Example 48 | 49 | Assuming the following file/directory structure: 50 | ``` 51 | . 52 | ├── src/ 53 | | ├── _defaults.yaml 54 | | └── page-one.md 55 | ├── layouts/ 56 | | └── page.ejs 57 | ├── dist/ 58 | └── package.json 59 | ``` 60 | 61 | **src/page-one.md**: 62 | ```html 63 | --- 64 | title: "My first Page" 65 | _layout: "page" 66 | --- 67 | Hello World! 68 | ``` 69 | 70 | The front-matter (the part between the `---` lines) is written in YAML ([other languages](https://github.com/jonschlinkert/gray-matter#optionslang) are supported as well). All keys in the front-matter will be passed as locals to your templates. 71 | 72 | Notice the underscore before `layout`. _Anything prefixed with an underscore is reserved word for onessg._ See the [full list of underscore keys](docs/underscore-reference.md). 73 | 74 | --- 75 | 76 | You can set defaults for your front-matter in `_defaults.yaml` (`_defaults.json` works too!). These defaults can be overridden in your front-matter. 77 | 78 | **src/_defaults.yaml**: 79 | ```yaml 80 | title: "Hello World!" # This title will be used if none is specified 81 | author: "John Smith" 82 | ``` 83 | 84 | If you place a `_defaults.yaml` file in a subdirectory in `src/`, settings there will only apply to files in that subdirectory and its child subdirectories. 85 | 86 | --- 87 | 88 | Layouts are written in the templating language of your choice. We are using EJS here, but you can use any template engine that has a [jstransformer](docs/jstransformer.md). You can also use multiple template engines in the same project! onessg will infer the correct template engine from the file extension. 89 | 90 | **layouts/page.ejs** looks like this: 91 | ```html 92 | 93 | 94 | 95 | 96 | <%= title %> 97 | 98 | 99 | 100 | <%- _body -%> 101 | 102 | 103 | ``` 104 | 105 | Notice the local `_body`. This is the local for outputing the contents of each file. For **page-one.md**, it is `Hello World!`. 106 | 107 | --- 108 | 109 | **Run:** 110 | 111 | ```bash 112 | onessg 113 | ``` 114 | 115 | onessg will compile all the html and markdown files in `src/` (and subdirectories), and output them to `dist/` (retaining the directory structure): 116 | 117 | ``` 118 | . 119 | ├── src/ 120 | | ├── _defaults.yaml 121 | | └── page-one.md 122 | ├── layouts/ 123 | | └── page.ejs 124 | ├── dist/ 125 | | └── page-one.html 126 | └── package.json 127 | ``` 128 | 129 | **dist/page-one.html** looks like this: 130 | 131 | ```html 132 | 133 | 134 | 135 | 136 | My first Page 137 | 138 | 139 | 140 |

Hello World!

141 | 142 | 143 | ``` 144 | 145 | **Success!!!** :tada: 146 | 147 | A few notes: 148 | 149 | - The title (`My first Page`) comes from the front-matter. 150 | - The author's name (`John Smith`) comes from the `_defaults.yaml` file. 151 | 152 | For further reading, see the [Tutorial](docs/tutorial.md). 153 | 154 | ## CLI Usage & Options 155 | 156 | ``` 157 | onessg 158 | onessg [-s ] [-d ] [-l ] 159 | 160 | Options: 161 | --help Show help [boolean] 162 | --version Show version number [boolean] 163 | -s, --src Set the src directory [string] [default: "src/"] 164 | -d, --dist Set the dist directory [string] [default: "dist/"] 165 | -l, --layouts Set the layouts directory [string] [default: "layouts/"] 166 | -c, --config Set the directory that contains onessg.config.js [string] 167 | 168 | Examples: 169 | onessg 170 | onessg -s posts/ -d output/ -l templates/ 171 | 172 | ``` 173 | 174 | ## `onessg.config.js` 175 | 176 | To pass options to your template engine, you will need to use a config file. Read more about it [here](docs/config.md). 177 | 178 | ## Contributing 179 | 180 | Contributions welcome; please read the [Contributing Guidelines](CONTRIBUTING.md) for more info. 181 | 182 | Check the [Roadmap](https://github.com/RyanZim/onessg/wiki/Roadmap) to see what's on the horizon. 183 | 184 | ## License 185 | 186 | [MIT](https://github.com/RyanZim/onessg/blob/master/LICENSE) 187 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* eslint no-console: "off" */ 3 | 'use strict'; 4 | const path = require('path'); 5 | const onessg = require('./index.js'); 6 | const argv = require('yargs') 7 | .usage(`$0 8 | $0 [-s ] [-d ] [-l ] [-c ]`) 9 | .alias({ 10 | s: 'src', 11 | d: 'dist', 12 | l: 'layouts', 13 | c: 'config', 14 | }) 15 | .string(['s', 'd', 'l', 'c']) 16 | .default({ 17 | s: 'src/', 18 | d: 'dist/', 19 | l: 'layouts/', 20 | }) 21 | .describe({ 22 | s: 'Set the src directory', 23 | d: 'Set the dist directory', 24 | l: 'Set the layouts directory', 25 | c: 'Set the directory that contains onessg.config.js', 26 | }) 27 | .example( 28 | `$0 29 | $0 -s posts/ -d output/ -l templates/` 30 | ) 31 | .argv; 32 | 33 | var conf = { 34 | src: argv.s, 35 | dist: argv.d, 36 | layouts: argv.l, 37 | }; 38 | 39 | // Try to load config file: 40 | try { 41 | let dir = argv.config ? path.resolve(argv.config) : process.cwd(); 42 | conf = Object.assign({}, require(path.join(dir, 'onessg.config.js')), conf); 43 | } catch (e) { /* Ignore */} 44 | 45 | onessg(conf) 46 | .catch(function (err) { 47 | console.error(err); 48 | process.exit(1); 49 | }); 50 | -------------------------------------------------------------------------------- /docs/config.md: -------------------------------------------------------------------------------- 1 | # `onessg.config.js` 2 | 3 | The config file must be named `onessg.config.js`. It is placed in the project root. (You can configure this via the CLI's `--config` option.) 4 | 5 | `onessg.config.js` is a JS config file. 6 | 7 | You can set options for your template engine with this file. 8 | 9 | **Example config for ejs:** 10 | 11 | ```js 12 | module.exports = { 13 | ejs: { 14 | rmWhitespace: true, 15 | strict: true, 16 | }, 17 | }; 18 | ``` 19 | 20 | **Example config for [nunjucks](https://github.com/mozilla/nunjucks):** 21 | 22 | ```js 23 | module.exports = { 24 | nunjucks: { 25 | throwOnUndefined: true, 26 | trimBlocks: true, 27 | }, 28 | }; 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/jstransformer.md: -------------------------------------------------------------------------------- 1 | # JSTransformer 2 | 3 | [JSTransformer](https://github.com/jstransformers/jstransformer) is the tool that enables onessg to work with almost any template engine. 4 | 5 | JSTransformer unifies template engines and other Node.js tools into a standardized API that onessg can use. From the JSTransformer README: 6 | 7 | > There are many good template engines and compilers written for Node.js. But there is a problem: all of them have slightly different APIs, requiring slightly different usage. JSTransformer unifies them into one standardized API. Code written for one transformer will work with any other transformer. There are over 100 transformers, ranging from Markdown parsers to template engines to code compilers. 8 | 9 | What does this mean for the end-user? 10 | 11 | - You can use almost any template engine with onessg, and you can also use multiple template engines in the same project. 12 | - You will need to install the correct JSTransformer for your template engine. 13 | 14 | ## Installing the correct JSTransformer 15 | 16 | Most of the time, jstransformers are named `jstransformer-`, where `` is the name of the template engine you wish to use. 17 | 18 | So for [pug](https://github.com/pugjs/pug) support, you would run: 19 | 20 | npm install -D jstransformer-pug 21 | 22 | onessg will automatically attempt to use `jstransformer-pug` for layouts with the `.pug` extension. 23 | -------------------------------------------------------------------------------- /docs/tutorial.md: -------------------------------------------------------------------------------- 1 | # onessg Tutorial 2 | 3 | Examples will use [EJS](https://github.com/mde/ejs/) as the template engine, but you can use any template engine that has a [jstransformer](docs/jstransformer.md). 4 | 5 | Part 1 mostly mirrors the information found in the README, if you've already read that, you may want to skip to [Part 2](#part-2). 6 | 7 | ## Part 1 8 | 9 | For this tutorial we will use the following file/directory structure: 10 | ``` 11 | . 12 | ├── src/ 13 | | ├── _defaults.yaml 14 | | └── page-one.md 15 | ├── layouts/ 16 | | └── page.ejs 17 | ├── dist/ 18 | └── package.json 19 | ``` 20 | onessg looks in the folders `src/` & `layouts/` and writes to `dist/` by default (you can change this if you wish via command line options). 21 | 22 | --- 23 | 24 | All files in `src/` can include front-matter. YAML is parsed by default, see the [gray-matter docs](https://github.com/jonschlinkert/gray-matter#optionslang) for a list of supported languages. 25 | 26 | **src/page-one.md**: 27 | ```html 28 | --- 29 | title: "My first Page" 30 | _layout: "page" 31 | --- 32 | Hello World! 33 | ``` 34 | 35 | Notice the underscore before `layout`. _Anything prefixed with an underscore is reserved word for onessg._ See the [full list of underscore keys](underscore-reference.md). All keys in the front-matter will be passed as a local to your templates. 36 | 37 | You can set defaults for your front-matter in `_defaults.yaml` (`_defaults.json` works too!). These defaults can be overridden in your front-matter. 38 | 39 | **src/_defaults.yaml**: 40 | ```yaml 41 | title: "Hello World!" # This title will be used if none is specified 42 | author: "John Smith" 43 | ``` 44 | 45 | Layouts are written in the templating language of your choice. We are using EJS here, but you can use any template engine that has a [jstransformer](docs/jstransformer.md). You can also use multiple template engines in the same project! onessg will infer the correct template engine from the file extension. 46 | 47 | **layouts/page.ejs** looks like this: 48 | ```html 49 | 50 | 51 | 52 | 53 | <%= title %> 54 | 55 | 56 | 57 | <%- _body -%> 58 | 59 | 60 | ``` 61 | 62 | Notice the local `_body`. This is the local for outputing the contents of each file. For **page-one.md**, it is `Hello World!`. 63 | 64 | **Run:** 65 | 66 | ```bash 67 | onessg 68 | ``` 69 | 70 | onessg will compile all the html and markdown files in `src/` (and subdirectories), and output them to `dist/` (retaining the directory structure): 71 | 72 | ``` 73 | . 74 | ├── src/ 75 | | ├── _defaults.yaml 76 | | └── page-one.md 77 | ├── layouts/ 78 | | └── page.ejs 79 | ├── dist/ 80 | | └── page-one.html 81 | └── package.json 82 | ``` 83 | 84 | **dist/page-one.html** looks like this: 85 | 86 | ```html 87 | 88 | 89 | 90 | 91 | My first Page 92 | 93 | 94 | 95 |

Hello World!

96 | 97 | 98 | ``` 99 | 100 | - The title (`My first Page`) comes from the front-matter. 101 | - The author's name (`John Smith`) comes from the `_defaults.yaml` file. 102 | 103 | **Success!!!** :tada: 104 | 105 | ## Part 2 106 | 107 | Now we are going to add a subdirectory to `src/`, named `subdirectory` (of course! :wink:). Inside the subdirectory, we will add a `_defaults.yaml` and an html page, named `subpage.html`. Now our directory tree looks like this: 108 | 109 | ``` 110 | . 111 | ├── src/ 112 | | ├── subdirectory 113 | | | ├── _defaults.yaml 114 | | | └── subpage.html 115 | | ├── _defaults.yaml 116 | | └── page-one.md 117 | ├── layouts/ 118 | | └── page.ejs 119 | ├── dist/ 120 | └── package.json 121 | ``` 122 | 123 | Here is the contents of the files: 124 | 125 | **src/subdirectory/_defaults.yaml**: 126 | ```yaml 127 | _layout: page 128 | author: Jane Smith 129 | ``` 130 | 131 | Note that settings here **only** affect files in `subdirectory/`! 132 | 133 | Let's discuss each line: 134 | - `_layout: page` Here we are setting a default layout. This means we will not have to set `_layout` in each pages' front-matter. 135 | - `author: Jane Smith` Here we are overriding the default author set in `src/_defaults.yaml`. 136 | 137 | **src/subdirectory/subpage.html**: 138 | ```html 139 |

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

140 | ``` 141 | 142 | Note that we have omitted the front-matter. The defaults from the `_defaults` file in this directory and parent directories (up to `src/`) will apply. 143 | 144 | We will run onessg again: 145 | ```bash 146 | onessg 147 | ``` 148 | 149 | Our directory structure is now: 150 | ``` 151 | . 152 | ├── src/ 153 | | ├── subdirectory 154 | | | ├── _defaults.yaml 155 | | | └── subpage.html 156 | | ├── _defaults.yaml 157 | | └── page-one.md 158 | ├── layouts/ 159 | | └── page.ejs 160 | ├── dist/ 161 | | ├── subdirectory 162 | | | └── subpage.html 163 | | └── page-one.html 164 | └── package.json 165 | ``` 166 | 167 | **dist/subdirectory/subpage.html** looks like this: 168 | ```html 169 | 170 | 171 | 172 | 173 | Hello World! 174 | 175 | 176 | 177 |

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

178 | 179 | 180 | ``` 181 | 182 | A few things to note: 183 | 184 | - The default title from `src/_defaults.yaml` has been applied. 185 | - The default author from `src/_defaults.yaml` has been overridden by the one in `src/subdirectory/_defaults.yaml`. 186 | 187 | **Hooray!** You are now a certified onessg user! :mortar_board: 188 | 189 | ## Further Reading 190 | 191 | - [Underscore Reference](underscore-reference.md) - A reference to all the underscore-prefixed values in onessg. 192 | -------------------------------------------------------------------------------- /docs/underscore-reference.md: -------------------------------------------------------------------------------- 1 | # Underscore Reference 2 | 3 | This is a reference to all the underscore-prefixed values in onessg. 4 | 5 | ## Keys You Set 6 | 7 | These are the keys you can set in your front-matter or `_defaults.yaml`. 8 | 9 | - `_layout` This is the layout (without the file extension) that will be used for the page. 10 | 11 | ## Keys onessg Sets 12 | 13 | These keys are set automatically by onessg and exposed to you templates as locals. Of course, you can access the keys you set in your templates as well. 14 | 15 | - `_body` This is the main contents of the file (the part outside the front-matter). 16 | - `_path` This is the path of the HTML or Markdown file, relative to `src/`. **Extensions are removed.** 17 | - `_ext` This is the extension of the HTML or Markdown file in `src/`. Possible values are `.html`, `.md`, & `.markdown`. 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const fs = require('fs-extra'); 3 | const path = require('path-extra'); 4 | const globby = require('globby'); 5 | const grayMatter = require('gray-matter'); 6 | const transformer = require('./lib/transformer'); 7 | const marked = require('universalify').fromCallback(require('marked')); 8 | const cloneDeep = require('lodash').cloneDeep; 9 | // Local Modules: 10 | const getDefaults = require('./lib/getDefaults.js'); 11 | 12 | // Config vars: 13 | var conf; 14 | 15 | module.exports = function (config) { 16 | return setConf(config) 17 | .then(() => globby('**/*.@(html|md|markdown)', {cwd: conf.src})) 18 | .then(arr => Promise.all(arr.map(processFile))); 19 | }; 20 | 21 | // Accepts filePath 22 | // Returns Promise when file has been written 23 | function processFile(filePath) { 24 | // Load file and convert to a data object: 25 | return loadFile(filePath) 26 | .then(middleware) 27 | .then(getDefaults) 28 | .then(data => { 29 | // If _layout, render it: 30 | if (data._layout) return render(data); 31 | // Else, return _body: 32 | else return data._body; 33 | }) 34 | .then(html => { 35 | // Get path to write to using path-extra: 36 | var writePath = path.replaceExt(path.join(conf.dist, filePath), '.html'); 37 | // Output using fs-extra: 38 | return fs.outputFile(writePath, html); 39 | }); 40 | } 41 | 42 | 43 | // HELPER FUNCTIONS: 44 | 45 | // Accepts filename 46 | // Returns Promise(data object) 47 | function loadFile(name) { 48 | return fs.readFile(path.join(conf.src, name), 'utf8') 49 | .then(grayMatter) 50 | .then(file => { 51 | // Need to perform a full clone of this object since gray-matter does some 52 | // agressive caching, and our mutation can mess up the cache 53 | var data = cloneDeep(file.data); 54 | data._body = file.content; 55 | data._path = path.removeExt(name); 56 | data._ext = path.extname(name); 57 | return data; 58 | }); 59 | } 60 | 61 | // Accepts data object, path extname 62 | // Returns Promise(data object) 63 | function middleware(data) { 64 | // Check path's ext: 65 | switch (data._ext) { 66 | case '.html': 67 | // noop: 68 | return Promise.resolve(data); 69 | case '.md': 70 | case '.markdown': 71 | // Render markdown: 72 | return marked(data._body) 73 | .then(res => { 74 | // Overwrite data._body: 75 | data._body = res; 76 | return data; 77 | }); 78 | } 79 | } 80 | 81 | // Accepts data object 82 | // Returns Promise(html string) 83 | function render(data) { 84 | return globby(path.join(conf.layouts, data._layout) + '.*') 85 | .then(arr => { 86 | var layout = arr[0]; 87 | // Globby doesn't throw an error if the layout path doesn't exist, so we do: 88 | if (!layout) throw new Error(`The layout: ${data._layout} cannot be found in ${conf.layouts}`); 89 | // Render with jstransformer: 90 | return transformer(layout, data); 91 | }) 92 | .then(obj => obj.body); 93 | } 94 | 95 | // Validates configuration, 96 | // Sets module-wide config vars, 97 | // Calls setConf on helper modules 98 | // Accepts config 99 | // Returns a promise 100 | function setConf(config) { 101 | // Check that src & layouts exists: 102 | return Promise.all([ 103 | fs.access(config.src), 104 | fs.access(config.layouts), 105 | ]) 106 | .then(() => { 107 | // Set vars: 108 | conf = config; 109 | // setConf in helper modules: 110 | getDefaults.setConf(conf); 111 | transformer.setConf(conf); 112 | }); 113 | } 114 | -------------------------------------------------------------------------------- /lib/getDefaults.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const readFile = require('fs-extra').readFile; 3 | const path = require('path-extra'); 4 | const globby = require('globby'); 5 | const yaml = require('js-yaml'); 6 | // Only load a subset of lodash: 7 | const _ = { 8 | spread: require('lodash/spread'), 9 | defaultsDeep: require('lodash/defaultsDeep'), 10 | }; 11 | 12 | const cache = {}; 13 | 14 | // Config vars: 15 | var src; 16 | 17 | module.exports = function (data) { 18 | // Must have src/ in the path so we know when to stop: 19 | return recurse(path.join(src, data._path)) 20 | .then(arr => { 21 | // Combine defaults: 22 | var defaults = _.spread(_.defaultsDeep)(arr); 23 | // Apply data and return the new data: 24 | return _.defaultsDeep(data, defaults); 25 | }); 26 | }; 27 | 28 | function recurse (p) { 29 | var arr = []; 30 | do { 31 | p = path.dirname(p); 32 | arr.push(load(p)); 33 | } while (path.normalizeTrim(p) !== path.normalizeTrim(src)); 34 | return Promise.all(arr); 35 | } 36 | 37 | function load(dirPath) { 38 | if (cache[dirPath]) return cache[dirPath]; 39 | return cache[dirPath] = globby(path.join(dirPath, '_defaults.@(yaml|yml|json)')) 40 | .then(res => { 41 | if (!res[0]) return {}; 42 | return readFile(res[0], 'utf8').then(yaml.safeLoad); 43 | }); 44 | } 45 | 46 | module.exports.setConf = function (conf) { 47 | src = conf.src; 48 | }; 49 | -------------------------------------------------------------------------------- /lib/transformer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const jstransformer = require('jstransformer'); 4 | const inputformat = require('inputformat-to-jstransformer'); 5 | 6 | var conf; 7 | 8 | module.exports = function (file, locals) { 9 | const format = path.extname(file).replace('.', ''); 10 | const transformer = inputformat(format); 11 | if (!transformer) return Promise.reject(new Error( 12 | `No jstransformer installed for the format "${format}"` 13 | )); 14 | return jstransformer(transformer).renderFileAsync(file, conf[transformer.name], locals); 15 | }; 16 | 17 | module.exports.setConf = function (config) { 18 | conf = config; 19 | }; 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "onessg", 3 | "version": "2.0.0", 4 | "description": "The Static Site Generator that does only one thing: compile your html and markdown.", 5 | "main": "index.js", 6 | "bin": { 7 | "onessg": "./cli.js" 8 | }, 9 | "scripts": { 10 | "test": "npm run lint && npm run mocha", 11 | "coverage": "npm run mocha && nyc report --reporter lcov", 12 | "toc": "doctoc README.md", 13 | "mocha": "nyc mocha --ui tdd", 14 | "lint": "eslint --ignore-path .gitignore .", 15 | "coveralls": "nyc report --reporter=text-lcov | coveralls" 16 | }, 17 | "keywords": [ 18 | "Static Site Generator", 19 | "jstransformers", 20 | "template engine", 21 | "simple", 22 | "layouts", 23 | "markdown" 24 | ], 25 | "author": "Ryan Zimmerman (http://ryanzim.com)", 26 | "license": "MIT", 27 | "repository": "RyanZim/onessg", 28 | "homepage": "https://github.com/RyanZim/onessg/", 29 | "bugs": "https://github.com/RyanZim/onessg/issues", 30 | "dependencies": { 31 | "fs-extra": "^5.0.0", 32 | "globby": "^7.0.0", 33 | "gray-matter": "^3.0.1", 34 | "inputformat-to-jstransformer": "^1.2.1", 35 | "js-yaml": "^3.6.1", 36 | "jstransformer": "^1.0.0", 37 | "lodash": "^4.14.0", 38 | "marked": "^0.3.6", 39 | "path-extra": "^4.0.0", 40 | "universalify": "^0.1.0", 41 | "yargs": "^11.0.0" 42 | }, 43 | "devDependencies": { 44 | "assert-dir-equal": "^1.0.1", 45 | "autoresolve": "0.0.3", 46 | "coveralls": "^3.0.0", 47 | "doctoc": "^1.2.0", 48 | "eslint": "~4.19.0", 49 | "eslint-config-ryanzim": "0.0.2", 50 | "jstransformer-ejs": "0.2.0", 51 | "mocha": "^5.0.0", 52 | "nyc": "^11.0.2", 53 | "suppose": "^0.6.1" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | 3 | Each folder in `fixtures/` contains `src/`, `expected/`, and `layouts/` (if applicable). The files in `src/` should compile to equal the files in `expected/`. 4 | 5 | ## `assert.fixture()` 6 | 7 | We have a custom `assert.fixture()` function for use in our tests. Here are the API docs: 8 | 9 | Usage is `assert.fixture(, done)`, where `` is the name of the folder in `fixtures/`, and `done` is the mocha `done()` callback. 10 | 11 | - This will compile the files in `/src/` to `/dist/`. 12 | - If `/layouts/` is present, that will be used as the layout directory. Otherwise, an empty directory (`fixtures/empty-dir/`) is used. 13 | - It will then compare the files in `dist/` to the ones in `expected/`, and call `done()` with an error if differences are found. Otherwise, it will call `done()`. 14 | 15 | ## Guidelines for writing tests: 16 | 17 | - All filenames should attempt to be self-explanatory of their contents. 18 | - Write basic tests in HTML, not markdown. 19 | - All front-matter and `_defaults` files should be written in yaml, except for the purpose of testing other configuration formats. 20 | - Markdown files should use the `.md` extension, except for the purpose of testing `.markdown` extension support. 21 | -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/expected/subfolder/nested/two.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 |
9 |

Author: Jane Doe

10 |

Editor: Betty Smith

11 |
12 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/expected/subfolder/one.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 |
9 |

Author: Jane Doe

10 |

Editor: Mark Smith

11 |
12 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/layouts/author-editor.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= title %> 6 | 7 | 8 |
9 |

Author: <%= author %>

10 |

Editor: <%= editor %>

11 |
12 | <%- _body -%> 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/src/_defaults.yaml: -------------------------------------------------------------------------------- 1 | title: "Hello World!" 2 | author: John Doe 3 | editor: Mark Smith -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/src/subfolder/_defaults.yaml: -------------------------------------------------------------------------------- 1 | author: Jane Doe 2 | -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/src/subfolder/nested/_defaults.yaml: -------------------------------------------------------------------------------- 1 | editor: Betty Smith 2 | -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/src/subfolder/nested/two.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "author-editor" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/_defaults-subfolders/src/subfolder/one.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "author-editor" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/_defaults/expected/author.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 |
9 |

Author: Mark Smith

10 |
11 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/_defaults/expected/no-author.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 |
9 |

Author: John Doe

10 |
11 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/_defaults/layouts/author.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= title %> 6 | 7 | 8 |
9 |

Author: <%= author %>

10 |
11 | <%- _body -%> 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/_defaults/src/_defaults.yaml: -------------------------------------------------------------------------------- 1 | author: John Doe 2 | -------------------------------------------------------------------------------- /test/fixtures/_defaults/src/author.html: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Hello World!" 3 | author: "Mark Smith" 4 | _layout: "author" 5 | --- 6 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 7 | -------------------------------------------------------------------------------- /test/fixtures/_defaults/src/no-author.html: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Hello World!" 3 | _layout: "author" 4 | --- 5 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 6 | -------------------------------------------------------------------------------- /test/fixtures/_ext/expected/ext.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | .html 8 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/_ext/layouts/ext.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- _ext %> 8 | <%- _body -%> 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/_ext/src/ext.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "ext" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/_path/expected/path.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | path 8 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/_path/layouts/path.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- _path %> 8 | <%- _body -%> 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/_path/src/path.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "path" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/cli/README.md: -------------------------------------------------------------------------------- 1 | **Warning:** This fixture is used by both the `cli` and `errors` suites. 2 | -------------------------------------------------------------------------------- /test/fixtures/cli/expected/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/cli/expected/locals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/cli/layouts/html-title.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= title %> 6 | 7 | 8 | <%- _body -%> 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/cli/layouts/html.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- _body -%> 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/cli/src/layout.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "html" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/cli/src/locals.html: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Hello World!" 3 | _layout: "html-title" 4 | --- 5 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 6 | -------------------------------------------------------------------------------- /test/fixtures/config-options/expected/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 8 | 9 | -------------------------------------------------------------------------------- /test/fixtures/config-options/layouts/html.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- _body -%> 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/config-options/onessg.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = { 3 | ejs: { 4 | rmWhitespace: true, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /test/fixtures/config-options/src/layout.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "html" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/default-layout/expected/text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/default-layout/layouts/html.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- _body -%> 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/default-layout/src/_defaults.yaml: -------------------------------------------------------------------------------- 1 | _layout: html 2 | -------------------------------------------------------------------------------- /test/fixtures/default-layout/src/text.html: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2 | -------------------------------------------------------------------------------- /test/fixtures/empty-dir/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanZim/onessg/e40a824a24424ffce717b33438320a93a7811574/test/fixtures/empty-dir/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/empty-files/expected/html.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanZim/onessg/e40a824a24424ffce717b33438320a93a7811574/test/fixtures/empty-files/expected/html.html -------------------------------------------------------------------------------- /test/fixtures/empty-files/expected/md.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanZim/onessg/e40a824a24424ffce717b33438320a93a7811574/test/fixtures/empty-files/expected/md.html -------------------------------------------------------------------------------- /test/fixtures/empty-files/src/html.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanZim/onessg/e40a824a24424ffce717b33438320a93a7811574/test/fixtures/empty-files/src/html.html -------------------------------------------------------------------------------- /test/fixtures/empty-files/src/md.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanZim/onessg/e40a824a24424ffce717b33438320a93a7811574/test/fixtures/empty-files/src/md.md -------------------------------------------------------------------------------- /test/fixtures/json/expected/front-matter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 |
9 |

Author: Jane Doe

10 |

Editor: Mark Smith

11 |
12 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/fixtures/json/layouts/author-editor.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= title %> 6 | 7 | 8 |
9 |

Author: <%= author %>

10 |

Editor: <%= editor %>

11 |
12 | <%- _body -%> 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/fixtures/json/src/_defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "John Doe", 3 | "editor": "Mark Smith" 4 | } -------------------------------------------------------------------------------- /test/fixtures/json/src/front-matter.html: -------------------------------------------------------------------------------- 1 | ---json 2 | { 3 | "title": "Hello World!", 4 | "_layout": "author-editor", 5 | "author": "Jane Doe" 6 | } 7 | --- 8 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 9 | -------------------------------------------------------------------------------- /test/fixtures/jstransformer-not-installed/layouts/html.xyz: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- _body -%> 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/jstransformer-not-installed/src/layout.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "html" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/layouts/expected/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/layouts/expected/locals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/layouts/layouts/html-title.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= title %> 6 | 7 | 8 | <%- _body -%> 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/layouts/layouts/html.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- _body -%> 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/layouts/src/layout.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "html" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/layouts/src/locals.html: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Hello World!" 3 | _layout: "html-title" 4 | --- 5 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 6 | -------------------------------------------------------------------------------- /test/fixtures/markdown/expected/test.html: -------------------------------------------------------------------------------- 1 |

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

2 | -------------------------------------------------------------------------------- /test/fixtures/markdown/src/test.markdown: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2 | -------------------------------------------------------------------------------- /test/fixtures/non-existent-layout/src/layout.html: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: "html" 3 | --- 4 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 5 | -------------------------------------------------------------------------------- /test/fixtures/subfolders/expected/folder/inner.html: -------------------------------------------------------------------------------- 1 | The quick, brown fox jumps over a lazy dog. 2 | -------------------------------------------------------------------------------- /test/fixtures/subfolders/expected/outer.html: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2 | -------------------------------------------------------------------------------- /test/fixtures/subfolders/src/folder/inner.html: -------------------------------------------------------------------------------- 1 | The quick, brown fox jumps over a lazy dog. 2 | -------------------------------------------------------------------------------- /test/fixtures/subfolders/src/outer.html: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2 | -------------------------------------------------------------------------------- /test/fixtures/text/expected/text-html.html: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2 | -------------------------------------------------------------------------------- /test/fixtures/text/expected/text-md.html: -------------------------------------------------------------------------------- 1 |

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

2 | -------------------------------------------------------------------------------- /test/fixtures/text/src/text-html.html: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2 | -------------------------------------------------------------------------------- /test/fixtures/text/src/text-md.md: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2 | -------------------------------------------------------------------------------- /test/fixtures/yml/expected/no-author.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 |
9 |

Author: John Doe

10 |
11 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/yml/layouts/author.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= title %> 6 | 7 | 8 |
9 |

Author: <%= author %>

10 |
11 | <%- _body -%> 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/yml/src/_defaults.yml: -------------------------------------------------------------------------------- 1 | author: John Doe 2 | -------------------------------------------------------------------------------- /test/fixtures/yml/src/no-author.html: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Hello World!" 3 | _layout: "author" 4 | --- 5 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 6 | -------------------------------------------------------------------------------- /test/onessg.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* eslint no-console: "off" */ 3 | const fs = require('fs-extra'); 4 | const path = require('path-extra'); 5 | const assert = require('assert'); 6 | const suppose = require('suppose'); 7 | const resolve = require('autoresolve'); 8 | const onessg = require(resolve('index.js')); 9 | 10 | // Expand the assert module: 11 | assert.dirsEqual = require('assert-dir-equal'); 12 | assert.fixture = function (fixture) { 13 | // Get layoutPath: 14 | var layoutPath = path.join('test/fixtures/', fixture, 'layouts'); 15 | try { 16 | fs.accessSync(layoutPath); 17 | } catch (e) { 18 | // Use a dummy directory if there isn't a local one: 19 | layoutPath = 'test/fixtures/empty-dir'; 20 | } 21 | 22 | // Clean dist: 23 | var distPath = path.join('test/fixtures/', fixture, 'dist'); 24 | fs.removeSync(distPath); 25 | 26 | // Run onessg: 27 | return onessg({ 28 | src: path.join('test/fixtures/', fixture, 'src'), 29 | dist: distPath, 30 | layouts: layoutPath, 31 | }) 32 | .then(() => { 33 | // Assert that dist/ & expected/ are equal: 34 | assert.dirsEqual(distPath, path.join('test/fixtures/', fixture, 'expected')); 35 | }); 36 | }; 37 | 38 | suite('cli', function () { 39 | this.timeout(5000); 40 | this.slow(3000); 41 | 42 | test('works', function (done) { 43 | fs.removeSync('test/fixtures/cli/dist'); 44 | suppose(resolve('cli.js'), [ 45 | 'ejs', 46 | '-s', 'test/fixtures/cli/src', 47 | '-d', 'test/fixtures/cli/dist', 48 | '-l', 'test/fixtures/cli/layouts', 49 | ]) 50 | .on('error', err => { 51 | console.error(err); 52 | done(err); 53 | }) 54 | .end(function (code) { 55 | assert.dirsEqual('test/fixtures/cli/dist', 'test/fixtures/cli/expected'); 56 | assert.equal(code, 0, 'CLI exited with non-zero exit code'); 57 | done(); 58 | }); 59 | }); 60 | 61 | test('returns errors', function (done) { 62 | var error; 63 | // Run cli.js ejs -s noop: 64 | suppose(resolve('cli.js'), ['ejs', '-s', 'noop']) 65 | .on('error', function (err) { 66 | error = err; 67 | }) 68 | .end(function (code) { 69 | assert.notEqual(code, 0, 'expected CLI to return non-zero exit code on error'); 70 | // Errors: 71 | assert(error, 'expected CLI to print error message'); 72 | done(); 73 | }); 74 | }); 75 | }); 76 | 77 | suite('html & markdown', function () { 78 | test('empty files', () => assert.fixture('empty-files')); 79 | test('text', () => assert.fixture('text')); 80 | test('subfolders', () => assert.fixture('subfolders')); 81 | }); 82 | 83 | suite('layouts & front-matter', function () { 84 | test('works', () => assert.fixture('layouts')); 85 | test('_path is set automatically', () => assert.fixture('_path')); 86 | test('_ext is set automatically', () => assert.fixture('_ext')); 87 | }); 88 | 89 | suite('_defaults file', function () { 90 | test('works', () => assert.fixture('_defaults')); 91 | test('can set default _layout', () => assert.fixture('default-layout')); 92 | test('works in subfolders', () => assert.fixture('_defaults-subfolders')); 93 | }); 94 | 95 | suite('onessg.config.js', function () { 96 | test('sets template engine options', function (done) { 97 | suppose(resolve('cli.js'), [ 98 | 'ejs', 99 | '-s', 'test/fixtures/config-options/src', 100 | '-d', 'test/fixtures/config-options/dist', 101 | '-l', 'test/fixtures/config-options/layouts', 102 | '-c', 'test/fixtures/config-options/', 103 | ]) 104 | .on('error', err => { 105 | console.error(err); 106 | done(err); 107 | }) 108 | .end(function (code) { 109 | assert.dirsEqual('test/fixtures/config-options/dist', 'test/fixtures/config-options/expected'); 110 | assert.equal(code, 0, 'CLI exited with non-zero exit code'); 111 | done(); 112 | }); 113 | }); 114 | }); 115 | 116 | suite('file types/extentions', function () { 117 | test('json', () => assert.fixture('json')); 118 | test('yml', () => assert.fixture('yml')); 119 | test('markdown', () => assert.fixture('markdown')); 120 | }); 121 | 122 | suite('errors', function () { 123 | var dirs = {}; 124 | 125 | // Run before each test: 126 | setup(() => { 127 | dirs.src = 'test/fixtures/cli/src'; 128 | dirs.dist = 'test/fixtures/cli/dist'; 129 | dirs.layouts = 'test/fixtures/cli/layouts'; 130 | }); 131 | 132 | test('invalid src/', function (done) { 133 | dirs.src = 'noop'; 134 | onessg(dirs) 135 | .catch(e => { 136 | done(assert(e)); 137 | }); 138 | }); 139 | 140 | test('invalid layouts/', function (done) { 141 | dirs.layouts = 'noop'; 142 | onessg(dirs) 143 | .catch(e => { 144 | done(assert(e)); 145 | }); 146 | }); 147 | 148 | test('non-existent layout', function (done) { 149 | onessg({ 150 | src: 'test/fixtures/non-existent-layout/src', 151 | dist: 'test/fixtures/non-existent-layout/dist', 152 | layouts: 'test/fixtures/non-existent-layout/layouts', 153 | }) 154 | .catch(e => { 155 | done(assert(e)); 156 | }); 157 | }); 158 | 159 | test('jstransformer not installed', function (done) { 160 | onessg({ 161 | src: 'test/fixtures/jstransformer-not-installed/src', 162 | dist: 'test/fixtures/jstransformer-not-installed/dist', 163 | layouts: 'test/fixtures/jstransformer-not-installed/layouts', 164 | }) 165 | .catch(e => { 166 | done(assert(e)); 167 | }); 168 | }); 169 | }); 170 | --------------------------------------------------------------------------------