Comparing version 1.2.0 to 2.0.0
39
cli.js
#!/usr/bin/env node | ||
/* eslint no-console: "off" */ | ||
'use strict'; | ||
var argv = require('yargs') | ||
.usage(`$0 <template_engine> [--dev] | ||
$0 <template_engine> [-s <source_dir>] [-d <output_dir>] [-l <layout_dir>] [--dev]`) | ||
.demand(1, 1, 'Error: You must specify an template engine') | ||
const path = require('path'); | ||
const onessg = require('./index.js'); | ||
const argv = require('yargs') | ||
.usage(`$0 | ||
$0 [-s <source_dir>] [-d <output_dir>] [-l <layout_dir>] [-c <config_dir>]`) | ||
.alias({ | ||
@@ -12,5 +13,5 @@ s: 'src', | ||
l: 'layouts', | ||
c: 'config', | ||
}) | ||
.string(['s', 'd', 'l']) | ||
.boolean('dev') | ||
.string(['s', 'd', 'l', 'c']) | ||
.default({ | ||
@@ -25,11 +26,10 @@ s: 'src/', | ||
l: 'Set the layouts directory', | ||
dev: 'Dev Mode, compiles drafts along with normal files', | ||
c: 'Set the directory that contains onessg.config.js', | ||
}) | ||
.help() | ||
.version() | ||
.example(`$0 ejs | ||
$0 ejs -s posts/ -d output/ -l templates/`) | ||
.epilog('A list of supported template engines may be found at: https://github.com/tj/consolidate.js/#supported-template-engines.') | ||
.example(`$0 | ||
$0 -s posts/ -d output/ -l templates/`) | ||
.argv; | ||
var onessg = require('./index.js'); | ||
var conf = { | ||
@@ -39,9 +39,14 @@ src: argv.s, | ||
layouts: argv.l, | ||
devMode: argv.dev, | ||
}; | ||
onessg(argv._[0], conf, function (err) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
// Try to load config file: | ||
try { | ||
let dir = argv.config ? path.resolve(argv.config) : process.cwd(); | ||
conf = Object.assign({}, require(path.join(dir, 'onessg.config.js')), conf); | ||
} catch (e) { /* Ignore */} | ||
onessg(conf) | ||
.catch(function (err) { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
# onessg Tutorial | ||
Examples will use [EJS](https://github.com/mde/ejs/) as the template engine, you can use any template engine supported by [consolidate.js](https://github.com/tj/consolidate.js/). | ||
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). | ||
@@ -37,3 +37,3 @@ 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). | ||
You can set defaults for your front-matter in `_defaults.yaml` (`_defaults.json` works too!). These defaults can be overridden in your front-matter. `_defaults.yaml` is also the place to set options for your template engine. | ||
You can set defaults for your front-matter in `_defaults.yaml` (`_defaults.json` works too!). These defaults can be overridden in your front-matter. | ||
@@ -44,6 +44,5 @@ **src/_defaults.yaml**: | ||
author: "John Smith" | ||
rmWhitespace: true # Here we are setting an option for ejs | ||
``` | ||
Layouts are written in the templating language of your choice. We are using EJS here, but you can use any template engine on [this list](https://github.com/tj/consolidate.js/#supported-template-engines). | ||
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. | ||
@@ -54,10 +53,10 @@ **layouts/page.ejs** looks like this: | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title><%= title %></title> | ||
<meta name="author" content="<%= author %>"> | ||
</head> | ||
<body> | ||
<%- _body -%> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title><%= title %></title> | ||
<meta name="author" content="<%= author %>"> | ||
</head> | ||
<body> | ||
<%- _body -%> | ||
</body> | ||
</html> | ||
@@ -71,7 +70,5 @@ ``` | ||
```bash | ||
onessg ejs | ||
onessg | ||
``` | ||
(Substitute `ejs` with the name of your template engine) | ||
onessg will compile all the html and markdown files in `src/` (and subdirectories), and output them to `dist/` (retaining the directory structure): | ||
@@ -96,10 +93,10 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>My first Page</title> | ||
<meta name="author" content="John Smith"> | ||
</head> | ||
<body> | ||
<p>Hello World!</p> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>My first Page</title> | ||
<meta name="author" content="John Smith"> | ||
</head> | ||
<body> | ||
<p>Hello World!</p> | ||
</body> | ||
</html> | ||
@@ -110,3 +107,2 @@ ``` | ||
- The author's name (`John Smith`) comes from the `_defaults.yaml` file. | ||
- Leading whitespace is removed by ejs due to the `rmWhitespace` option that we set in `_defaults.yaml`. | ||
@@ -156,3 +152,3 @@ **Success!!!** :tada: | ||
```bash | ||
onessg ejs | ||
onessg | ||
``` | ||
@@ -182,10 +178,10 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Hello World!</title> | ||
<meta name="author" content="Jane Smith"> | ||
</head> | ||
<body> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Hello World!</title> | ||
<meta name="author" content="Jane Smith"> | ||
</head> | ||
<body> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> | ||
</body> | ||
</html> | ||
@@ -198,3 +194,2 @@ ``` | ||
- The default author from `src/_defaults.yaml` has been overridden by the one in `src/subdirectory/_defaults.yaml`. | ||
- The `rmWhitespace` option from `src/_defaults.yaml` is also in effect. | ||
@@ -201,0 +196,0 @@ **Hooray!** You are now a certified onessg user! :mortar_board: |
@@ -10,3 +10,2 @@ # Underscore Reference | ||
- `_layout` This is the layout (without the file extension) that will be used for the page. | ||
- `_draft` Sets this page as a draft. Drafts will not be compiled unless you pass the `--dev` option. | ||
@@ -18,2 +17,3 @@ ## Keys onessg Sets | ||
- `_body` This is the main contents of the file (the part outside the front-matter). | ||
- `_path` This is the path of the HTML or Markdown file, relative to `src/`. Note that extensions are preserved, i.e. `index.md` is a possible value. | ||
- `_path` This is the path of the HTML or Markdown file, relative to `src/`. **Extensions are removed.** | ||
- `_ext` This is the extension of the HTML or Markdown file in `src/`. Possible values are `.html`, `.md`, & `.markdown`. |
136
index.js
'use strict'; | ||
var p = require('thenify'); | ||
var fs = require('fs-extra'); | ||
var pfs = { | ||
const p = require('thenify'); | ||
const fs = require('fs-extra'); | ||
const pfs = { | ||
access: p(fs.access), | ||
@@ -9,34 +9,17 @@ outputFile: p(fs.outputFile), | ||
}; | ||
var path = require('path-extra'); | ||
var globby = require('globby'); | ||
var matter = require('gray-matter'); | ||
var cons = require('consolidate'); | ||
var marked = p(require('marked')); | ||
const path = require('path-extra'); | ||
const globby = require('globby'); | ||
const grayMatter = require('gray-matter'); | ||
const transformer = require('./lib/transformer'); | ||
const marked = p(require('marked')); | ||
// Local Modules: | ||
var getDefaults = require('./lib/getDefaults.js'); | ||
const getDefaults = require('./lib/getDefaults.js'); | ||
// Config vars: | ||
var engine; | ||
var src; | ||
var layouts; | ||
var dist; | ||
var devMode; | ||
module.exports = function (engine, conf, cb) { | ||
// Make engine and dirs available globally: | ||
setConf(engine, conf) | ||
.then(function () { | ||
// Get files: | ||
return globby('**/*.@(html|md|markdown)', {nodir: true, cwd: src}); | ||
}) | ||
.then(function (arr) { | ||
// Process each file | ||
// return a promise when all files have been processed: | ||
return Promise.all(arr.map(function (item) { | ||
return processFile(item); | ||
})); | ||
}) | ||
.then(function () { | ||
// Call cb: | ||
cb(); | ||
}) | ||
.catch(cb); | ||
var conf; | ||
module.exports = function (config) { | ||
return setConf(config) | ||
.then(() => globby('**/*.@(html|md|markdown)', {nodir: true, cwd: conf.src})) | ||
.then(arr => Promise.all(arr.map(processFile))); | ||
}; | ||
@@ -49,35 +32,31 @@ | ||
return loadFile(filePath) | ||
.then(function (data) { | ||
// If it's a draft and devMode is off, return undefined: | ||
if (data._draft && !devMode) return undefined; | ||
// Else, run through middleware: | ||
return middleware(data) | ||
.then(getDefaults) | ||
.then(function (data) { | ||
// If _layout, render it: | ||
if (data._layout) return render(data); | ||
// Else, return _body: | ||
else return data._body; | ||
}) | ||
.then(function (html) { | ||
// Get path to write to using path-extra: | ||
var writePath = path.replaceExt(path.join(dist, filePath), '.html'); | ||
// Output using fs-extra: | ||
return pfs.outputFile(writePath, html); | ||
}); | ||
.then(middleware) | ||
.then(getDefaults) | ||
.then(data => { | ||
// If _layout, render it: | ||
if (data._layout) return render(data); | ||
// Else, return _body: | ||
else return data._body; | ||
}) | ||
.then(html => { | ||
// Get path to write to using path-extra: | ||
var writePath = path.replaceExt(path.join(conf.dist, filePath), '.html'); | ||
// Output using fs-extra: | ||
return pfs.outputFile(writePath, html); | ||
}); | ||
} | ||
// HELPER FUNCTIONS | ||
// HELPER FUNCTIONS: | ||
// Accepts filename | ||
// Returns Promise(data object) | ||
function loadFile(name) { | ||
return pfs.readFile(path.join(src, name), 'utf8') | ||
.then(function (text) { | ||
return matter(text); | ||
}) | ||
.then(function (file) { | ||
return pfs.readFile(path.join(conf.src, name), 'utf8') | ||
.then(grayMatter) | ||
.then(file => { | ||
var data = file.data; | ||
data._body = file.content; | ||
data._path = name; | ||
data._path = path.removeExt(name); | ||
data._ext = path.extname(name); | ||
return data; | ||
@@ -91,3 +70,3 @@ }); | ||
// Check path's ext: | ||
switch (path.extname(data._path)) { | ||
switch (data._ext) { | ||
case '.html': | ||
@@ -100,3 +79,3 @@ // noop: | ||
return marked(data._body) | ||
.then(function (res) { | ||
.then(res => { | ||
// Overwrite data._body: | ||
@@ -112,10 +91,11 @@ data._body = res; | ||
function render(data) { | ||
return globby(path.join(layouts, data._layout) + '.*') | ||
.then(function (arr) { | ||
return globby(path.join(conf.layouts, data._layout) + '.*') | ||
.then(arr => { | ||
var layout = arr[0]; | ||
// Globby doesn't throw an error if the layout path doesn't exist, so we do: | ||
if (!layout) throw new Error(`The layout: ${data._layout} cannot be found in ${layouts}`); | ||
// Render with consolidate.js: | ||
return engine(layout, data); | ||
}); | ||
if (!layout) throw new Error(`The layout: ${data._layout} cannot be found in ${conf.layouts}`); | ||
// Render with jstransformer: | ||
return transformer(layout, data); | ||
}) | ||
.then(obj => obj.body); | ||
} | ||
@@ -126,27 +106,17 @@ | ||
// Calls setConf on helper modules | ||
// Accepts engine, dirs | ||
// Accepts config | ||
// Returns a promise | ||
function setConf(eng, conf) { | ||
function setConf(config) { | ||
// Check that src & layouts exists: | ||
return Promise.all([ | ||
pfs.access(conf.src), | ||
pfs.access(conf.layouts), | ||
new Promise(function (resolve) { | ||
// Check that engine is a string: | ||
if (typeof eng !== 'string' || eng === '') throw new Error('Please pass a valid engine parameter'); | ||
// Check that engine is supported by consolidate.js: | ||
if (typeof cons[eng] !== 'function') throw new Error(`${eng} is not a valid consolidate.js template engine`); | ||
resolve(); | ||
}), | ||
pfs.access(config.src), | ||
pfs.access(config.layouts), | ||
]) | ||
.then(function () { | ||
.then(() => { | ||
// Set vars: | ||
src = conf.src; | ||
dist = conf.dist; | ||
layouts = conf.layouts; | ||
engine = p(cons[eng]); | ||
devMode = conf.devMode; | ||
conf = config; | ||
// setConf in helper modules: | ||
getDefaults.setConf(conf); | ||
transformer.setConf(conf); | ||
}); | ||
} |
'use strict'; | ||
var readFile = require('thenify')(require('fs-extra').readFile); | ||
var path = require('path-extra'); | ||
var globby = require('globby'); | ||
var yaml = require('js-yaml'); | ||
const readFile = require('thenify')(require('fs-extra').readFile); | ||
const path = require('path-extra'); | ||
const globby = require('globby'); | ||
const yaml = require('js-yaml'); | ||
// Only load a subset of lodash: | ||
var _ = { | ||
const _ = { | ||
spread: require('lodash/spread'), | ||
defaultsDeep: require('lodash/defaultsDeep'), | ||
}; | ||
var cache = {}; | ||
const cache = {}; | ||
// Config vars: | ||
@@ -19,7 +20,7 @@ var src; | ||
return recurse(path.join(src, data._path)) | ||
.then(function (arr) { | ||
.then(arr => { | ||
// Combine defaults: | ||
var defaults = _.spread(_.defaultsDeep)(arr); | ||
// Apply data, set cache: true, and return the new data: | ||
return _.defaultsDeep(data, defaults, {cache: true}); | ||
// Apply data and return the new data: | ||
return _.defaultsDeep(data, defaults); | ||
}); | ||
@@ -40,7 +41,5 @@ }; | ||
return cache[dirPath] = globby(path.join(dirPath, '_defaults.@(yaml|yml|json)')) | ||
.then(function (res) { | ||
var defaults = {}; | ||
if (!res[0]) return defaults; | ||
defaults = readFile(res[0], 'utf8').then(d => yaml.safeLoad(d)); | ||
return defaults; | ||
.then(res => { | ||
if (!res[0]) return {}; | ||
return readFile(res[0], 'utf8').then(yaml.safeLoad); | ||
}); | ||
@@ -47,0 +46,0 @@ } |
{ | ||
"name": "onessg", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "The Static Site Generator that does only one thing: compile your html and markdown.", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"mocha": "nyc mocha --ui tdd", | ||
"lint": "eslint --ignore-path .gitignore '**/*.js'", | ||
"lint": "eslint --ignore-path .gitignore .", | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls" | ||
@@ -20,3 +20,3 @@ }, | ||
"Static Site Generator", | ||
"consolidate.js", | ||
"jstransformers", | ||
"template engine", | ||
@@ -33,7 +33,8 @@ "simple", | ||
"dependencies": { | ||
"consolidate": "^0.14.1", | ||
"fs-extra": "^1.0.0", | ||
"fs-extra": "^2.1.0", | ||
"globby": "^6.0.0", | ||
"gray-matter": "^2.0.2", | ||
"inputformat-to-jstransformer": "^1.2.1", | ||
"js-yaml": "^3.6.1", | ||
"jstransformer": "^1.0.0", | ||
"lodash": "^4.14.0", | ||
@@ -43,3 +44,3 @@ "marked": "^0.3.6", | ||
"thenify": "^3.2.0", | ||
"yargs": "^6.0.0" | ||
"yargs": "^7.0.1" | ||
}, | ||
@@ -51,4 +52,5 @@ "devDependencies": { | ||
"doctoc": "^1.2.0", | ||
"ejs": "^2.5.1", | ||
"eslint": "~3.13.0", | ||
"eslint": "~3.18.0", | ||
"eslint-config-ryanzim": "0.0.2", | ||
"jstransformer-ejs": "0.0.3", | ||
"mocha": "^3.0.2", | ||
@@ -55,0 +57,0 @@ "nyc": "^10.0.0", |
@@ -34,9 +34,15 @@ # onessg | ||
```bash | ||
npm i onessg | ||
npm install -D onessg | ||
``` | ||
You will also need to install your favorite [consolidate.js-supported template engine](https://github.com/tj/consolidate.js/#supported-template-engines). | ||
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: | ||
**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 your template engine globally as well. | ||
```bash | ||
npm install -D jstransformer-ejs | ||
``` | ||
You can read more about jstransformers [here](docs/jstransformer.md). | ||
**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. | ||
## Example | ||
@@ -71,3 +77,3 @@ | ||
You can set defaults for your front-matter in `_defaults.yaml` (`_defaults.json` works too!). These defaults can be overridden in your front-matter. `_defaults.yaml` is also the place to set options for your template engine. | ||
You can set defaults for your front-matter in `_defaults.yaml` (`_defaults.json` works too!). These defaults can be overridden in your front-matter. | ||
@@ -78,3 +84,2 @@ **src/_defaults.yaml**: | ||
author: "John Smith" | ||
rmWhitespace: true # Here we are setting an option for ejs | ||
``` | ||
@@ -86,3 +91,3 @@ | ||
Layouts are written in the templating language of your choice. We are using EJS here, but you can use any template engine on [this list](https://github.com/tj/consolidate.js/#supported-template-engines). | ||
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. | ||
@@ -93,10 +98,10 @@ **layouts/page.ejs** looks like this: | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title><%= title %></title> | ||
<meta name="author" content="<%= author %>"> | ||
</head> | ||
<body> | ||
<%- _body -%> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title><%= title %></title> | ||
<meta name="author" content="<%= author %>"> | ||
</head> | ||
<body> | ||
<%- _body -%> | ||
</body> | ||
</html> | ||
@@ -112,7 +117,5 @@ ``` | ||
```bash | ||
onessg ejs | ||
onessg | ||
``` | ||
(Substitute `ejs` with the name of your template engine) | ||
onessg will compile all the html and markdown files in `src/` (and subdirectories), and output them to `dist/` (retaining the directory structure): | ||
@@ -137,10 +140,10 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>My first Page</title> | ||
<meta name="author" content="John Smith"> | ||
</head> | ||
<body> | ||
<p>Hello World!</p> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>My first Page</title> | ||
<meta name="author" content="John Smith"> | ||
</head> | ||
<body> | ||
<p>Hello World!</p> | ||
</body> | ||
</html> | ||
@@ -155,3 +158,2 @@ ``` | ||
- The author's name (`John Smith`) comes from the `_defaults.yaml` file. | ||
- Leading whitespace is removed by EJS due to the `rmWhitespace` option that we set in `_defaults.yaml`. | ||
@@ -163,4 +165,4 @@ For further reading, see the [Tutorial](docs/tutorial.md). | ||
``` | ||
onessg <template_engine> [--dev] | ||
onessg <template_engine> [-s <source_dir>] [-d <output_dir>] [-l <layout_dir>] [--dev] | ||
onessg | ||
onessg [-s <source_dir>] [-d <output_dir>] [-l <layout_dir>] | ||
@@ -171,3 +173,3 @@ Options: | ||
-l, --layouts Set the layouts directory [string] [default: "layouts/"] | ||
--dev Dev Mode, compiles drafts along with normal files [boolean] | ||
-c, --config Set the directory that contains onessg.config.js [string] | ||
--help Show help [boolean] | ||
@@ -177,9 +179,11 @@ --version Show version number [boolean] | ||
Examples: | ||
onessg ejs | ||
onessg ejs -s posts/ -d output/ -l templates/ | ||
onessg | ||
onessg -s posts/ -d output/ -l templates/ | ||
A list of supported template engines may be found at: | ||
https://github.com/tj/consolidate.js/#supported-template-engines. | ||
``` | ||
## `onessg.config.js` | ||
To pass options to your template engine, you will need to use a config file. Read more about it [here](docs/config.md). | ||
## Contributing | ||
@@ -186,0 +190,0 @@ |
@@ -0,11 +1,13 @@ | ||
'use strict'; | ||
/* eslint no-console: "off" */ | ||
'use strict'; | ||
var fs = require('fs-extra'); | ||
var path = require('path-extra'); | ||
var assert = require('assert'); | ||
var suppose = require('suppose'); | ||
var resolve = require('autoresolve'); | ||
var onessg = require(resolve('index.js')); | ||
const fs = require('fs-extra'); | ||
const path = require('path-extra'); | ||
const assert = require('assert'); | ||
const suppose = require('suppose'); | ||
const resolve = require('autoresolve'); | ||
const onessg = require(resolve('index.js')); | ||
// Expand the assert module: | ||
assert.dirsEqual = require('assert-dir-equal'); | ||
assert.fixture = function (fixture, done, devMode) { | ||
assert.fixture = function (fixture) { | ||
// Get layoutPath: | ||
@@ -19,20 +21,16 @@ var layoutPath = path.join('test/fixtures/', fixture, 'layouts'); | ||
} | ||
// Clean dist: | ||
var distPath = path.join('test/fixtures/', fixture, 'dist'); | ||
// Clean dist: | ||
fs.removeSync(distPath); | ||
// Run onessg: | ||
onessg('ejs', { | ||
return onessg({ | ||
src: path.join('test/fixtures/', fixture, 'src'), | ||
dist: distPath, | ||
layouts: layoutPath, | ||
devMode: devMode, | ||
}, function (err) { | ||
if (err) return done(err); | ||
}) | ||
.then(() => { | ||
// Assert that dist/ & expected/ are equal: | ||
try { | ||
assert.dirsEqual(path.join('test/fixtures/', fixture, 'dist'), path.join('test/fixtures/', fixture, 'expected')); | ||
} catch (e) { | ||
return done(e); | ||
} | ||
done(); | ||
assert.dirsEqual(distPath, path.join('test/fixtures/', fixture, 'expected')); | ||
}); | ||
@@ -44,2 +42,3 @@ }; | ||
this.slow(3000); | ||
test('works', function (done) { | ||
@@ -53,3 +52,3 @@ fs.removeSync('test/fixtures/cli/dist'); | ||
]) | ||
.on('error', function (err) { | ||
.on('error', err => { | ||
console.error(err); | ||
@@ -64,2 +63,3 @@ done(err); | ||
}); | ||
test('returns errors', function (done) { | ||
@@ -79,105 +79,54 @@ var error; | ||
}); | ||
test('--dev works', function (done) { | ||
// Clean dist: | ||
fs.removeSync('test/fixtures/dev-mode/dist'); | ||
}); | ||
suite('html & markdown', function () { | ||
test('empty files', () => assert.fixture('empty-files')); | ||
test('text', () => assert.fixture('text')); | ||
test('subfolders', () => assert.fixture('subfolders')); | ||
}); | ||
suite('layouts & front-matter', function () { | ||
test('works', () => assert.fixture('layouts')); | ||
test('_path is set automatically', () => assert.fixture('_path')); | ||
test('_ext is set automatically', () => assert.fixture('_ext')); | ||
}); | ||
suite('_defaults file', function () { | ||
test('works', () => assert.fixture('_defaults')); | ||
test('can set default _layout', () => assert.fixture('default-layout')); | ||
test('works in subfolders', () => assert.fixture('_defaults-subfolders')); | ||
}); | ||
suite('onessg.config.js', function () { | ||
test('sets template engine options', function (done) { | ||
suppose(resolve('cli.js'), [ | ||
'ejs', | ||
'--dev', | ||
'-s', 'test/fixtures/dev-mode/src', | ||
'-d', 'test/fixtures/dev-mode/dist', | ||
'-l', 'test/fixtures/empty-dir', | ||
'-s', 'test/fixtures/config-options/src', | ||
'-d', 'test/fixtures/config-options/dist', | ||
'-l', 'test/fixtures/config-options/layouts', | ||
'-c', 'test/fixtures/config-options/', | ||
]) | ||
.on('error', function (err) { | ||
.on('error', err => { | ||
console.error(err); | ||
done(err); | ||
}) | ||
.end(function () { | ||
// Assert Normal file was compiled: | ||
assert.equal( | ||
fs.readFileSync('test/fixtures/dev-mode/expected/text.html', 'utf8'), | ||
fs.readFileSync('test/fixtures/dev-mode/dist/text.html', 'utf8') | ||
); | ||
// Assert Draft was compiled: | ||
assert.equal( | ||
fs.readFileSync('test/fixtures/dev-mode/expected/draft.html', 'utf8'), | ||
fs.readFileSync('test/fixtures/dev-mode/dist/draft.html', 'utf8') | ||
); | ||
.end(function (code) { | ||
assert.dirsEqual('test/fixtures/config-options/dist', 'test/fixtures/config-options/expected'); | ||
assert.equal(code, 0, 'CLI exited with non-zero exit code'); | ||
done(); | ||
}); | ||
}); | ||
test('--dev is not on by default', function (done) { | ||
// Clean dist: | ||
fs.removeSync('test/fixtures/drafts/dist'); | ||
suppose(resolve('cli.js'), [ | ||
'ejs', | ||
'-s', 'test/fixtures/drafts/src', | ||
'-d', 'test/fixtures/drafts/dist', | ||
'-l', 'test/fixtures/empty-dir', | ||
]) | ||
.on('error', function (err) { | ||
console.error(err); | ||
done(err); | ||
}) | ||
.end(function () { | ||
// Assert draft.html does not exist: | ||
assert.throws(function () { | ||
fs.accessSync('test/fixtures/drafts/dist/draft.html'); | ||
}, 'draft.html exists'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
// Tests: | ||
suite('html & markdown', function () { | ||
test('empty files', function (done) { | ||
assert.fixture('empty-files', done); | ||
}); | ||
test('text', function (done) { | ||
assert.fixture('text', done); | ||
}); | ||
test('subfolders', function (done) { | ||
assert.fixture('subfolders', done); | ||
}); | ||
}); | ||
suite('layouts & front-matter', function () { | ||
test('works', function (done) { | ||
assert.fixture('layouts', done); | ||
}); | ||
test('_path is set automatically', function (done) { | ||
assert.fixture('_path', done); | ||
}); | ||
}); | ||
suite('_defaults file', function () { | ||
test('works', function (done) { | ||
assert.fixture('_defaults', done); | ||
}); | ||
test('can set default _layout', function (done) { | ||
assert.fixture('default-layout', done); | ||
}); | ||
test('works in subfolders', function (done) { | ||
assert.fixture('_defaults-subfolders', done); | ||
}); | ||
}); | ||
suite('drafts', function () { | ||
test('are not compiled by default', function (done) { | ||
assert.fixture('drafts', done); | ||
}); | ||
test('are compiled in dev mode', function (done) { | ||
assert.fixture('dev-mode', done, true); | ||
}); | ||
}); | ||
suite('file types/extentions', function () { | ||
test('json', function (done) { | ||
assert.fixture('json', done); | ||
}); | ||
test('yml', function (done) { | ||
assert.fixture('yml', done); | ||
}); | ||
test('markdown', function (done) { | ||
assert.fixture('markdown', done); | ||
}); | ||
test('json', () => assert.fixture('json')); | ||
test('yml', () => assert.fixture('yml')); | ||
test('markdown', () => assert.fixture('markdown')); | ||
}); | ||
suite('errors', function () { | ||
var dirs = {}; | ||
setup(function () { | ||
// Run before each test: | ||
setup(() => { | ||
dirs.src = 'test/fixtures/cli/src'; | ||
@@ -187,33 +136,40 @@ dirs.dist = 'test/fixtures/cli/dist'; | ||
}); | ||
test('invalid src/', function (done) { | ||
dirs.src = 'noop'; | ||
onessg('ejs', dirs, function (e) { | ||
onessg(dirs) | ||
.catch(e => { | ||
done(assert(e)); | ||
}); | ||
}); | ||
test('invalid layouts/', function (done) { | ||
dirs.layouts = 'noop'; | ||
onessg('ejs', dirs, function (e) { | ||
onessg(dirs) | ||
.catch(e => { | ||
done(assert(e)); | ||
}); | ||
}); | ||
test('non-existent layout', function (done) { | ||
onessg('ejs', { | ||
onessg({ | ||
src: 'test/fixtures/non-existent-layout/src', | ||
dist: 'test/fixtures/non-existent-layout/dist', | ||
layouts: 'test/fixtures/non-existent-layout/layouts', | ||
}, function (e) { | ||
}) | ||
.catch(e => { | ||
done(assert(e)); | ||
}); | ||
}); | ||
test('invalid type for engine', function (done) { | ||
onessg(0, dirs, function (e) { | ||
test('jstransformer not installed', function (done) { | ||
onessg({ | ||
src: 'test/fixtures/jstransformer-not-installed/src', | ||
dist: 'test/fixtures/jstransformer-not-installed/dist', | ||
layouts: 'test/fixtures/jstransformer-not-installed/layouts', | ||
}) | ||
.catch(e => { | ||
done(assert(e)); | ||
}); | ||
}); | ||
test('unsupported engine', function (done) { | ||
onessg('noop', dirs, function (e) { | ||
done(assert(e)); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
107
187
64955
11
10
372
6
+ Addedjstransformer@^1.0.0
+ Addedasap@2.0.6(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedfs-extra@2.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedinputformat-to-jstransformer@1.4.0(transitive)
+ Addedis-promise@2.2.2(transitive)
+ Addedjstransformer@1.0.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.7(transitive)
+ Addedpromise@7.3.1(transitive)
+ Addedrequire-one@1.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedyargs@7.1.2(transitive)
+ Addedyargs-parser@5.0.1(transitive)
- Removedconsolidate@^0.14.1
- Removedbluebird@3.7.2(transitive)
- Removedconsolidate@0.14.5(transitive)
- Removedfs-extra@1.0.0(transitive)
- Removedklaw@1.3.1(transitive)
- Removedyargs@6.6.0(transitive)
- Removedyargs-parser@4.2.1(transitive)
Updatedfs-extra@^2.1.0
Updatedyargs@^7.0.1