Skip to content

Commit

Permalink
2.0.2: updates README.md for HTML-escape of mustache
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed May 22, 2017
1 parent c73235a commit 61a689f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Scaffold-generator is a scaffolding utility used to automate project creation from the specified template and data.

Scaffold-generator could be the core utility to create something like grunt-init and your yeoman generators.
Scaffold-generator could be the core utility to create something like grunt-init and yeoman generators.

`rename.json` of grunt-init is silly and scaffold-generator use template engine for both file content and file name.

Expand All @@ -23,7 +23,7 @@ Suppose the file structure is:

```
/path/from
|-- {{main}} // default to ejs template
|-- {{main}}
|-- package.json
```

Expand All @@ -40,11 +40,18 @@ And /path/from/package.json:
const Scaffold = require('scaffold-generator')
const mustache = require('mustache')

// All variables are HTML-escaped by mustache by default,
// and `lib/index.js` will be escaped to `lib/index.js`.
// To avoid this, override the `mustache.escape`
// or triple mustache `{{{name}}}` should be used.
mustache.escape = v => v

new Scaffold({
data: {
name: 'my-module',
main: 'lib/index.js'
},
// function `options.render` accepts `str` and `data`, then returns a `str`
render: mustache.render
})
.copy('/path/from', '/path/to')
Expand All @@ -53,7 +60,9 @@ new Scaffold({
})
```

Then,
Then:

File names will be substituted.

```
/path/to
Expand All @@ -62,7 +71,7 @@ Then,
|-- package.json
```

And /path/to/package.json
File contents will also be substitute. And the file `/path/to/package.json` will be

```json
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scaffold-generator",
"version": "2.0.1",
"version": "2.0.2",
"description": "Generates a repo from a specified template and data.",
"main": "scaffold.js",
"scripts": {
Expand Down
21 changes: 18 additions & 3 deletions test/scaffold-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const mustache = require('mustache')
const path = require('path')
const _tmp = require('tmp')

mustache.escape = v => v

const template = (filepath = '') =>
path.join(__dirname, 'fixtures', 'template', filepath)

Expand All @@ -13,8 +15,8 @@ const expected = (filepath = '') =>


// @param {path} dest dest dir
async function equal (t, dest, name, equal = true) {
const content = await fs.readFile(path.join(dest, name))
async function equal (t, dest, name, dest_name, equal = true) {
const content = await fs.readFile(path.join(dest, dest_name || name))
const expect_content = await fs.readFile(expected(name))

if (equal) {
Expand All @@ -30,7 +32,7 @@ async function equal (t, dest, name, equal = true) {


function notEqual (t, d, n) {
return equal(t, d, n, false)
return equal(t, d, n, undefined, false)
}


Expand Down Expand Up @@ -75,6 +77,19 @@ test('copy, override=false, not exists', async t => {
await equal(t, to, 'package.json')
})

test.only('copy, override=false, not exists, hierachical dirs', async t => {
const to = await tmp()
await s({
data: {
name: 'foo',
main: 'lib/index.js'
}
})
.copy(template(), to)

await equal(t, to, 'index.js', 'lib/index.js')
})


test('copy, override=false, exists', async t => {
const to = await tmp()
Expand Down

0 comments on commit 61a689f

Please sign in to comment.