Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Check if config.js exists before attempting to modify in angular sub-…
Browse files Browse the repository at this point in the history
…generators
  • Loading branch information
Wtower committed Jan 4, 2017
1 parent beb68aa commit de423ff
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

v0.5.3
------

Date: Upcoming

- Check if config.js exists before attempting to modify in angular sub-generators

v0.5.2
------

Expand Down
19 changes: 11 additions & 8 deletions generators/angular-component-detail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var prompts = require('../../services/prompts');
var buildContext = require('../../services/build-context');
var pathNames = require('../../services/path-names');
var append = require('../../services/append');
var fs = require('fs');

module.exports = yeoman.Base.extend({
prompting: function () {
Expand Down Expand Up @@ -78,13 +79,15 @@ module.exports = yeoman.Base.extend({
this.props.angularAppName,
this.props.angularAppName + '.config.js'
);
this.fs.copy(templatePath, templatePath, {
process: function (content) {
return append.angularRoute(
content,
$this.props.objectUrl + 's/:' + $this.props.objectName + 'Id',
$this.props.objectUrl + '-detail');
}
});
if (fs.existsSync(templatePath)) {
this.fs.copy(templatePath, templatePath, {
process: function (content) {
return append.angularRoute(
content,
$this.props.objectUrl + 's/:' + $this.props.objectName + 'Id',
$this.props.objectUrl + '-detail');
}
});
}
}
});
13 changes: 8 additions & 5 deletions generators/angular-component-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var prompts = require('../../services/prompts');
var buildContext = require('../../services/build-context');
var pathNames = require('../../services/path-names');
var append = require('../../services/append');
var fs = require('fs');

module.exports = yeoman.Base.extend({
prompting: function () {
Expand Down Expand Up @@ -88,10 +89,12 @@ module.exports = yeoman.Base.extend({
this.props.angularAppName,
this.props.angularAppName + '.config.js'
);
this.fs.copy(templatePath, templatePath, {
process: function (content) {
return append.angularRoute(content, $this.props.objectUrl + 's', $this.props.objectUrl + '-list');
}
});
if (fs.existsSync(templatePath)) {
this.fs.copy(templatePath, templatePath, {
process: function (content) {
return append.angularRoute(content, $this.props.objectUrl + 's', $this.props.objectUrl + '-list');
}
});
}
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-makrina",
"version": "0.5.2",
"version": "0.5.3",
"description": "Generate MEAN boilerplate. Featuring model and route CRUD endpoint sub-gens and an admin interface.",
"homepage": "https://github.com/Wtower/generator-makrina",
"author": {
Expand Down
19 changes: 12 additions & 7 deletions test/angular-component-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ describe('generator-makrina:angular-component-detail', function () {
var destinationPrefix = 'public/javascripts/admin';
// run with and without options to increase branch coverage
var runs = [
{it: 'no options', options: {}},
{it: 'no options', options: {}, configFile: true},
{it: 'no options, no config file', options: {}, configFile: false},
{it: 'options', options: {
angularAppName: 'admin',
angularAppFullName: 'yeotestsAdminApp',
angularAppPath: 'public/javascripts',
objectName: 'node',
objectTitle: 'Node',
objectUrl: 'node'
}}];
}, configFile: true}
];
var stub = stubRuns(runs, 2);

beforeEach(function () {
Expand All @@ -31,10 +33,12 @@ describe('generator-makrina:angular-component-detail', function () {
path.join(__dirname, '../generators/angular-app/templates/_angular-app-name_.module.js'),
path.join(dir, destinationPrefix, 'admin.module.js')
);
fs.copySync(
path.join(__dirname, '../generators/angular-app/templates/_angular-app-name_.config.js'),
path.join(dir, destinationPrefix, 'admin.config.js')
);
if (run.configFile) {
fs.copySync(
path.join(__dirname, '../generators/angular-app/templates/_angular-app-name_.config.js'),
path.join(dir, destinationPrefix, 'admin.config.js')
);
}
})
.withOptions(run.options)
.toPromise();
Expand All @@ -55,7 +59,8 @@ describe('generator-makrina:angular-component-detail', function () {

it('updates files with ' + run.it, function () {
assert.fileContent(path.join(destinationPrefix, 'admin.module.js'), 'nodeDetail');
assert.fileContent(path.join(destinationPrefix, 'admin.config.js'), 'node-detail');
if (run.configFile) assert.fileContent(path.join(destinationPrefix, 'admin.config.js'), 'node-detail');
else assert.noFile(path.join(destinationPrefix, 'admin.config.js'));
});
});
});
19 changes: 12 additions & 7 deletions test/angular-component-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ describe('generator-makrina:angular-component-list', function () {
var destinationPrefix = 'public/javascripts/admin';
// run with and without options to increase branch coverage
var runs = [
{it: 'no options', options: {}},
{it: 'no options', options: {}, configFile: true},
{it: 'no options, no config file', options: {}, configFile: false},
{it: 'options', options: {
angularAppName: 'admin',
angularAppFullName: 'yeotestsAdminApp',
angularAppPath: 'public/javascripts',
objectName: 'node',
objectTitle: 'Node',
objectUrl: 'node'
}}];
}, configFile: true}
];
var stub = stubRuns(runs, 2);

beforeEach(function () {
Expand All @@ -31,10 +33,12 @@ describe('generator-makrina:angular-component-list', function () {
path.join(__dirname, '../generators/angular-app/templates/_angular-app-name_.module.js'),
path.join(dir, destinationPrefix, 'admin.module.js')
);
fs.copySync(
path.join(__dirname, '../generators/angular-app/templates/_angular-app-name_.config.js'),
path.join(dir, destinationPrefix, 'admin.config.js')
);
if (run.configFile) {
fs.copySync(
path.join(__dirname, '../generators/angular-app/templates/_angular-app-name_.config.js'),
path.join(dir, destinationPrefix, 'admin.config.js')
);
}
})
.withOptions(run.options)
.toPromise();
Expand All @@ -56,7 +60,8 @@ describe('generator-makrina:angular-component-list', function () {

it('updates files with ' + run.it, function () {
assert.fileContent(path.join(destinationPrefix, 'admin.module.js'), 'nodeList');
assert.fileContent(path.join(destinationPrefix, 'admin.config.js'), 'node-list');
if (run.configFile) assert.fileContent(path.join(destinationPrefix, 'admin.config.js'), 'node-list');
else assert.noFile(path.join(destinationPrefix, 'admin.config.js'));
});
});
});

0 comments on commit de423ff

Please sign in to comment.