Comparing version 2.0.4 to 2.1.0
@@ -10,3 +10,3 @@ var Metalsmith = require('metalsmith') | ||
// register hendlebars helper | ||
// register handlebars helper | ||
Handlebars.registerHelper('if_eq', function (a, b, opts) { | ||
@@ -40,2 +40,5 @@ return a === b | ||
}) | ||
opts.helpers && Object.keys(opts.helpers).map(function (key) { | ||
Handlebars.registerHelper(key, opts.helpers[key]) | ||
}) | ||
metalsmith | ||
@@ -42,0 +45,0 @@ .use(askQuestions(opts.prompts)) |
@@ -15,6 +15,3 @@ var path = require('path') | ||
module.exports = function options (name, dir) { | ||
var file = path.join(dir, 'meta.json') | ||
var opts = exists(file) | ||
? metadata.sync(file) | ||
: {} | ||
var opts = getMetadata(dir) | ||
@@ -33,2 +30,27 @@ setDefault(opts, 'name', name) | ||
/** | ||
* Gets the metadata from either a meta.json or meta.js file. | ||
* | ||
* @param {String} dir | ||
* @return {Object} | ||
*/ | ||
function getMetadata (dir) { | ||
var json = path.join(dir, 'meta.json') | ||
var js = path.join(dir, 'meta.js') | ||
var opts = {} | ||
if (exists(json)) { | ||
opts = metadata.sync(json) | ||
} else if (exists(js)) { | ||
var req = require(js) | ||
if (req !== Object(req)) { | ||
throw new Error('meta.js needs to expose an object') | ||
} | ||
opts = req | ||
} | ||
return opts | ||
} | ||
/** | ||
* Set the default value for a prompt question | ||
@@ -35,0 +57,0 @@ * |
{ | ||
"name": "vue-cli", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "A simple CLI for scaffolding Vue.js projects.", | ||
@@ -28,3 +28,3 @@ "preferGlobal": true, | ||
"lint": "eslint test/test.js lib bin/* --env mocha", | ||
"e2e": "rimraf test/e2e/mock-template-build/*.* && BABEL_ENV=development mocha test/e2e/test.js --slow 1000 --compilers js:babel-core/register" | ||
"e2e": "rimraf test/e2e/mock-template-build/*.* && cross-env BABEL_ENV=development mocha test/e2e/test.js --slow 1000 --compilers js:babel-core/register" | ||
}, | ||
@@ -54,2 +54,3 @@ "dependencies": { | ||
"chai": "^3.5.0", | ||
"cross-env": "^1.0.7", | ||
"eslint": "^2.7.0", | ||
@@ -56,0 +57,0 @@ "eslint-config-standard": "^5.1.0", |
@@ -71,3 +71,3 @@ # vue-cli [![Build Status](https://img.shields.io/circleci/project/vuejs/vue-cli/master.svg)](https://circleci.com/gh/vuejs/vue-cli) [![npm package](https://img.shields.io/npm/v/vue-cli.svg)](https://www.npmjs.com/package/vue-cli) | ||
- A template repo **may** have a `meta.json` file that provides metadata for the template. The `meta.json` can contain the following fields: | ||
- A template repo **may** have a metadata file for the template which can be either a `meta.js` or `meta.json` file. It can contain the following fields: | ||
@@ -82,3 +82,3 @@ - `prompts`: used to collect user options data; | ||
The `prompts` field in `meta.json` should be an object hash containing prompts for the user. For each entry, the key is the variable name and the value is an [Inquirer.js question object](https://github.com/SBoudrias/Inquirer.js/#question). Example: | ||
The `prompts` field in the metadata file should be an object hash containing prompts for the user. For each entry, the key is the variable name and the value is an [Inquirer.js question object](https://github.com/SBoudrias/Inquirer.js/#question). Example: | ||
@@ -134,5 +134,23 @@ ``` json | ||
##### Custom Handlebars Helpers | ||
You may want to register additional Handlebars helpers using the `helpers` property in the metadata file. The object key is the helper name: | ||
``` js | ||
module.exports = { | ||
helpers: { | ||
lowercase: str => str.toLowerCase() | ||
} | ||
} | ||
``` | ||
Upon registration, they can be used as follows: | ||
``` handlebars | ||
{{ lowercase name }} | ||
``` | ||
#### File filters | ||
The `filters` field in `meta.json` should be an object hash containing file filtering rules. For each entry, the key is a [minimatch glob pattern](https://github.com/isaacs/minimatch) and the value is a JavaScript expression evaluated in the context of prompt answers data. Example: | ||
The `filters` field in the metadata file should be an object hash containing file filtering rules. For each entry, the key is a [minimatch glob pattern](https://github.com/isaacs/minimatch) and the value is a JavaScript expression evaluated in the context of prompt answers data. Example: | ||
@@ -139,0 +157,0 @@ ``` json |
@@ -12,2 +12,3 @@ const { expect } = require('chai') | ||
const generate = require('../../lib/generate') | ||
const metadata = require('../../lib/options') | ||
@@ -45,2 +46,27 @@ const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo' | ||
it('read metadata from json', done => { | ||
const meta = metadata('test-pkg', MOCK_TEMPLATE_REPO_PATH) | ||
expect(meta).to.be.an('object') | ||
expect(meta.prompts).to.have.property('description') | ||
done() | ||
}) | ||
it('read metadata from js', done => { | ||
const meta = metadata('test-pkg', __dirname + '/mock-metadata-repo-js') | ||
expect(meta).to.be.an('object') | ||
expect(meta.prompts).to.have.property('description') | ||
done() | ||
}) | ||
it('helpers', done => { | ||
monkeyPatchInquirer(answers) | ||
const buildPath = __dirname + '/mock-metadata-repo-js' | ||
generate('test', buildPath, MOCK_TEMPLATE_BUILD_PATH, err => { | ||
if (err) done(err) | ||
const contents = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/readme.md`, 'utf-8') | ||
expect(contents).to.equal(answers.name.toUpperCase()) | ||
done() | ||
}) | ||
}) | ||
it('template generation', done => { | ||
@@ -47,0 +73,0 @@ monkeyPatchInquirer(answers) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28644
26
523
165
10
4