Skip to content

Commit

Permalink
fix(generator): --dry-run no longer modifies files
Browse files Browse the repository at this point in the history
  • Loading branch information
delasteve authored and Brocco committed May 19, 2016
1 parent 8e2ee29 commit 6efc8ee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
4 changes: 4 additions & 0 deletions addon/ng2/blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ module.exports = {
},

afterInstall: function(options) {
if (options.dryRun) {
return;
}

if (!options.flat) {
var filePath = path.join(this.project.ngConfig.defaults.sourceDir, 'system-config.ts');
var barrelUrl = this.appDir.replace(/\\/g, '/');
Expand Down
14 changes: 8 additions & 6 deletions addon/ng2/blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ module.exports = {
},

afterInstall: function (options) {
if (!options.skipRouterGeneration) {
this._addRouteToParent(options);
this._verifyParentRoute(options);
if (options.dryRun || options.skipRouterGeneration) {
return;
}

this._addRouteToParent(options);
this._verifyParentRoute(options);
},

afterUninstall: function (options) {
Expand Down Expand Up @@ -214,9 +216,9 @@ module.exports = {
}

let isAppComponent = false;
let appComponentFile =
path.join(this.project.root,
this.dynamicPath.dir,
let appComponentFile =
path.join(this.project.root,
this.dynamicPath.dir,
this.project.name() + '.component.ts');
if (parentFile == appComponentFile) {
isAppComponent = true;
Expand Down
10 changes: 10 additions & 0 deletions tests/acceptance/generate-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,14 @@ describe('Acceptance: ng generate component', function () {
});
});

it('ng generate component my-comp --dry-run does not register a barrel in system-config.ts', () => {
var configPath = path.join(root, 'tmp', 'foo', 'src', 'system-config.ts');
var unmodifiedFile = fs.readFileSync(configPath, 'utf8');

return ng(['generate', 'component', 'my-comp', '--dry-run']).then(() => {
var afterGenerateFile = fs.readFileSync(configPath, 'utf8');

expect(afterGenerateFile).to.equal(unmodifiedFile);
});
});
});
16 changes: 16 additions & 0 deletions tests/acceptance/generate-route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,20 @@ describe('Acceptance: ng generate route', function () {
expect(appContent).to.match(/path: '\/details\/:id'/m);
});
});

it('ng generate route my-route --dry-run does not modify files', () => {
var parentComponentPath = path.join(testPath, 'foo.component.ts');
var parentComponentHtmlPath = path.join(testPath, 'foo.component.html')

var unmodifiedParentComponent = fs.readFileSync(parentComponentPath, 'utf8');
var unmodifiedParentComponentHtml = fs.readFileSync(parentComponentHtmlPath, 'utf8');

return ng(['generate', 'route', 'my-route', '--dry-run']).then(() => {
var afterGenerateParentComponent = fs.readFileSync(parentComponentPath, 'utf8');
var afterGenerateParentHtml = fs.readFileSync(parentComponentHtmlPath, 'utf8');

expect(afterGenerateParentComponent).to.equal(unmodifiedParentComponent);
expect(afterGenerateParentHtml).to.equal(unmodifiedParentComponentHtml);
});
});
});

0 comments on commit 6efc8ee

Please sign in to comment.