From 6efc8ee9323e51159d1392a7d986652c808d65de Mon Sep 17 00:00:00 2001 From: Stephen Cavaliere Date: Fri, 13 May 2016 13:37:33 -0400 Subject: [PATCH] fix(generator): --dry-run no longer modifies files --- addon/ng2/blueprints/component/index.js | 4 ++++ addon/ng2/blueprints/route/index.js | 14 ++++++++------ tests/acceptance/generate-component.spec.js | 10 ++++++++++ tests/acceptance/generate-route.spec.js | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/addon/ng2/blueprints/component/index.js b/addon/ng2/blueprints/component/index.js index 3c1f171ecabe..58950e13d396 100644 --- a/addon/ng2/blueprints/component/index.js +++ b/addon/ng2/blueprints/component/index.js @@ -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, '/'); diff --git a/addon/ng2/blueprints/route/index.js b/addon/ng2/blueprints/route/index.js index 4df205b95375..780de6a19d32 100644 --- a/addon/ng2/blueprints/route/index.js +++ b/addon/ng2/blueprints/route/index.js @@ -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) { @@ -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; diff --git a/tests/acceptance/generate-component.spec.js b/tests/acceptance/generate-component.spec.js index 34357bbbb028..a0b126e9cba7 100644 --- a/tests/acceptance/generate-component.spec.js +++ b/tests/acceptance/generate-component.spec.js @@ -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); + }); + }); }); diff --git a/tests/acceptance/generate-route.spec.js b/tests/acceptance/generate-route.spec.js index fdeb5d5adc78..ce665427a56d 100644 --- a/tests/acceptance/generate-route.spec.js +++ b/tests/acceptance/generate-route.spec.js @@ -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); + }); + }); });