Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jan 27, 2017
1 parent 3ea5dc3 commit 42d3c67
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
3 changes: 3 additions & 0 deletions generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = function(app, base, env) {
*/

app.helper('date', require('helper-date'));
app.helper('escapeQuotes', function(str) {
return str.replace(/\\?"/g, '\\"');
});

/**
* Middleware
Expand Down
2 changes: 1 addition & 1 deletion templates/$package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rename:
---
{
"name": "<%= ask('name') %>",
"description": "<%= ask('description') %>",
"description": "<%= escapeQuotes(ask('description')) %>",
"version": "<%= ask('version') %>",
"homepage": "<%= ask('homepage') %>",
"author": "<%= ask('author.name') %> (<%= ask('author.url') %>)",
Expand Down
2 changes: 1 addition & 1 deletion templates/min.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rename:
---
{
"name": "<%= ask('name') %>",
"description": "<%= ask('description') %>",
"description": "<%= escapeQuotes(ask('description')) %>",
"version": "<%= ask('version') %>",
"homepage": "<%= ask('homepage') %>",
"author": "<%= ask('author.name') %> (<%= ask('author.url') %>)",
Expand Down
2 changes: 1 addition & 1 deletion templates/sub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ rename:
---
{
"name": "<%= ask('subname') %>",
"description": "<%= ask('description') %>",
"description": "<%= escapeQuotes(ask('description')) %>",
"private": true
}
2 changes: 1 addition & 1 deletion test/fixtures/$package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rename:
---
{
"name": "<%= ask('name') %>",
"description": "<%= ask('description') %>",
"description": "<%= escapeQuotes(ask('description')) %>",
"version": "<%= ask('version') %>",
"homepage": "https://github.com/<%= ask('author.username') %>/<%= ask('name') %>",
"author": "<%= ask('author.name') %> (<%= ask('author.url') %>)",
Expand Down
37 changes: 31 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ function exists(name, cb) {
describe('generate-package', function() {
beforeEach(function() {
app = generate({silent: true});
app.cwd = actual();
app.option('dest', actual());
app.option('askWhen', 'not-answered');

// provide template data to avoid prompts
app.data(require('../package'));
app.data('project', require('../package'));
app.use(function fn() {
if (!this.isApp) return;
this.cwd = actual();
this.option('dest', actual());
this.option('askWhen', 'not-answered');

// provide template data to avoid prompts
this.data(require('../package'));
this.data('project', require('../package'));
return fn;
});
});

describe('plugin', function() {
Expand Down Expand Up @@ -127,6 +132,26 @@ describe('generate-package', function() {
app.generate('package:default', exists('package.json', cb));
});

it('should run the `default` task when defined explicitly', function(cb) {
app.register('package', generator);
app.generate('package:default', exists('package.json', cb));
});

it('should escape quotes in the description field', function(cb) {
app.use(function fn() {
if (!this.isApp) return;
this.data({description: 'foo "bar" baz'});
this.postRender(/package/, function(file, next) {
assert(/"description": "foo \\"bar\\" baz"/.test(file.content));
next();
});
return fn;
});

app.register('package', generator);
app.generate('package:default', exists('package.json', cb));
});

it('should run the `new` task', function(cb) {
app.register('package', generator);
app.generate('package:new', exists('package.json', cb));
Expand Down

0 comments on commit 42d3c67

Please sign in to comment.