From cd59c4c5e3b5df793b48a992717470e16e1ebb1b Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Thu, 11 Aug 2016 23:52:50 -0400 Subject: [PATCH] chore(barrels): remove barrels from blueprints --- addon/ng2/blueprints/class/index.js | 8 - .../component/files/__path__/index.ts | 1 - .../component/files/__path__/shared/index.ts | 0 addon/ng2/blueprints/component/index.js | 13 -- .../directive/files/__path__/index.ts | 1 - addon/ng2/blueprints/directive/index.js | 19 -- addon/ng2/blueprints/enum/index.js | 8 - addon/ng2/blueprints/interface/index.js | 8 - .../blueprints/pipe/files/__path__/index.ts | 1 - addon/ng2/blueprints/pipe/index.js | 19 -- .../service/files/__path__/index.ts | 1 - addon/ng2/blueprints/service/index.js | 27 --- addon/ng2/utilities/barrel-management.js | 43 ----- tests/acceptance/barrel-management.spec.js | 169 ------------------ 14 files changed, 318 deletions(-) delete mode 100644 addon/ng2/blueprints/component/files/__path__/index.ts delete mode 100644 addon/ng2/blueprints/component/files/__path__/shared/index.ts delete mode 100644 addon/ng2/blueprints/directive/files/__path__/index.ts delete mode 100644 addon/ng2/blueprints/pipe/files/__path__/index.ts delete mode 100644 addon/ng2/blueprints/service/files/__path__/index.ts delete mode 100644 addon/ng2/utilities/barrel-management.js delete mode 100644 tests/acceptance/barrel-management.spec.js diff --git a/addon/ng2/blueprints/class/index.js b/addon/ng2/blueprints/class/index.js index a3c09e6d6010..6e92316d493f 100644 --- a/addon/ng2/blueprints/class/index.js +++ b/addon/ng2/blueprints/class/index.js @@ -1,6 +1,5 @@ const stringUtils = require('ember-cli-string-utils'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); -var addBarrelRegistration = require('../../utilities/barrel-management'); module.exports = { description: '', @@ -40,12 +39,5 @@ module.exports = { return this.fileName; } }; - }, - - afterInstall: function() { - return addBarrelRegistration( - this, - this.generatePath, - this.fileName); } }; diff --git a/addon/ng2/blueprints/component/files/__path__/index.ts b/addon/ng2/blueprints/component/files/__path__/index.ts deleted file mode 100644 index 031eb01977aa..000000000000 --- a/addon/ng2/blueprints/component/files/__path__/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './<%= dasherizedModuleName %>.component'; diff --git a/addon/ng2/blueprints/component/files/__path__/shared/index.ts b/addon/ng2/blueprints/component/files/__path__/shared/index.ts deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/addon/ng2/blueprints/component/index.js b/addon/ng2/blueprints/component/index.js index 7f992c6ebea8..77e77c63e95c 100644 --- a/addon/ng2/blueprints/component/index.js +++ b/addon/ng2/blueprints/component/index.js @@ -2,7 +2,6 @@ var path = require('path'); var chalk = require('chalk'); var Blueprint = require('ember-cli/lib/models/blueprint'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); -var addBarrelRegistration = require('../../utilities/barrel-management'); var getFiles = Blueprint.prototype.files; const stringUtils = require('ember-cli-string-utils'); const astUtils = require('../../utilities/ast-utils'); @@ -65,12 +64,6 @@ module.exports = { files: function() { var fileList = getFiles.call(this); - if (this.options && this.options.flat) { - fileList = fileList.filter(p => p.indexOf('index.ts') <= 0); - } - if (this.options && !this.options.route) { - fileList = fileList.filter(p => p.indexOf(path.join('shared', 'index.ts')) <= 0); - } if (this.options && this.options.inlineTemplate) { fileList = fileList.filter(p => p.indexOf('.html') < 0); } @@ -127,12 +120,6 @@ module.exports = { const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath); const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; - if (!options.flat) { - returns.push(addBarrelRegistration(this, componentDir)); - } else { - returns.push(addBarrelRegistration(this, componentDir, fileName)); - } - if (!options['skip-import']) { returns.push( astUtils.addComponentToModule(modulePath, className, importPath) diff --git a/addon/ng2/blueprints/directive/files/__path__/index.ts b/addon/ng2/blueprints/directive/files/__path__/index.ts deleted file mode 100644 index 75625b4c093b..000000000000 --- a/addon/ng2/blueprints/directive/files/__path__/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './<%= dasherizedModuleName %>.directive'; diff --git a/addon/ng2/blueprints/directive/index.js b/addon/ng2/blueprints/directive/index.js index fbba059a453d..00511a141039 100644 --- a/addon/ng2/blueprints/directive/index.js +++ b/addon/ng2/blueprints/directive/index.js @@ -1,8 +1,5 @@ var path = require('path'); -var Blueprint = require('ember-cli/lib/models/blueprint'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); -var addBarrelRegistration = require('../../utilities/barrel-management'); -var getFiles = Blueprint.prototype.files; const stringUtils = require('ember-cli-string-utils'); const astUtils = require('../../utilities/ast-utils'); @@ -29,16 +26,6 @@ module.exports = { }; }, - files: function() { - var fileList = getFiles.call(this); - - if (this.options && this.options.flat) { - fileList = fileList.filter(p => p.indexOf('index.ts') <= 0); - } - - return fileList; - }, - fileMapTokens: function (options) { // Return custom template variables here. return { @@ -65,12 +52,6 @@ module.exports = { const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath); const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; - if (!options.flat) { - returns.push(addBarrelRegistration(this, componentDir)); - } else { - returns.push(addBarrelRegistration(this, componentDir, fileName)); - } - if (!options['skip-import']) { returns.push( astUtils.addComponentToModule(modulePath, className, importPath) diff --git a/addon/ng2/blueprints/enum/index.js b/addon/ng2/blueprints/enum/index.js index 7de86df0de62..d4e5b8bce2d8 100644 --- a/addon/ng2/blueprints/enum/index.js +++ b/addon/ng2/blueprints/enum/index.js @@ -1,6 +1,5 @@ const stringUtils = require('ember-cli-string-utils'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); -var addBarrelRegistration = require('../../utilities/barrel-management'); module.exports = { description: '', @@ -33,12 +32,5 @@ module.exports = { return this.fileName; } }; - }, - - afterInstall: function() { - return addBarrelRegistration( - this, - this.generatePath, - this.fileName); } }; diff --git a/addon/ng2/blueprints/interface/index.js b/addon/ng2/blueprints/interface/index.js index 0ed4979ed602..f14afb9525d0 100644 --- a/addon/ng2/blueprints/interface/index.js +++ b/addon/ng2/blueprints/interface/index.js @@ -1,6 +1,5 @@ const stringUtils = require('ember-cli-string-utils'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); -var addBarrelRegistration = require('../../utilities/barrel-management'); module.exports = { description: '', @@ -47,12 +46,5 @@ module.exports = { return this.fileName; } }; - }, - - afterInstall: function() { - return addBarrelRegistration( - this, - this.generatePath, - this.fileName); } }; diff --git a/addon/ng2/blueprints/pipe/files/__path__/index.ts b/addon/ng2/blueprints/pipe/files/__path__/index.ts deleted file mode 100644 index 2ed8c4199414..000000000000 --- a/addon/ng2/blueprints/pipe/files/__path__/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './<%= dasherizedModuleName %>.pipe'; diff --git a/addon/ng2/blueprints/pipe/index.js b/addon/ng2/blueprints/pipe/index.js index b747844910d0..d6fe6ce7f2b7 100644 --- a/addon/ng2/blueprints/pipe/index.js +++ b/addon/ng2/blueprints/pipe/index.js @@ -1,8 +1,5 @@ var path = require('path'); -var Blueprint = require('ember-cli/lib/models/blueprint'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); -var addBarrelRegistration = require('../../utilities/barrel-management'); -var getFiles = Blueprint.prototype.files; const stringUtils = require('ember-cli-string-utils'); const astUtils = require('../../utilities/ast-utils'); @@ -26,16 +23,6 @@ module.exports = { flat: options.flat }; }, - - files: function() { - var fileList = getFiles.call(this); - - if (this.options && this.options.flat) { - fileList = fileList.filter(p => p.indexOf('index.ts') <= 0); - } - - return fileList; - }, fileMapTokens: function (options) { // Return custom template variables here. @@ -63,12 +50,6 @@ module.exports = { const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath); const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; - if (!options.flat) { - returns.push(addBarrelRegistration(this, componentDir)); - } else { - returns.push(addBarrelRegistration(this, componentDir, fileName)); - } - if (!options['skip-import']) { returns.push( astUtils.addComponentToModule(modulePath, className, importPath) diff --git a/addon/ng2/blueprints/service/files/__path__/index.ts b/addon/ng2/blueprints/service/files/__path__/index.ts deleted file mode 100644 index 02137771b26d..000000000000 --- a/addon/ng2/blueprints/service/files/__path__/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './<%= dasherizedModuleName %>.service'; diff --git a/addon/ng2/blueprints/service/index.js b/addon/ng2/blueprints/service/index.js index 6fbe84ad5e5f..d29dae56eb33 100644 --- a/addon/ng2/blueprints/service/index.js +++ b/addon/ng2/blueprints/service/index.js @@ -1,9 +1,5 @@ var path = require('path'); -var Blueprint = require('ember-cli/lib/models/blueprint'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); -var addBarrelRegistration = require('../../utilities/barrel-management'); -var getFiles = Blueprint.prototype.files; -const stringUtils = require('ember-cli-string-utils'); module.exports = { description: '', @@ -26,16 +22,6 @@ module.exports = { }; }, - files: function() { - var fileList = getFiles.call(this); - - if (this.options && this.options.flat) { - fileList = fileList.filter(p => p.indexOf('index.ts') <= 0); - } - - return fileList; - }, - fileMapTokens: function (options) { // Return custom template variables here. return { @@ -48,18 +34,5 @@ module.exports = { return dir; } }; - }, - - afterInstall: function(options) { - const returns = []; - const fileName = stringUtils.dasherize(`${options.entity.name}.service`); - - if (!options.flat) { - returns.push(addBarrelRegistration(this, this.generatePath)); - } else { - returns.push(addBarrelRegistration(this, this.generatePath, fileName)); - } - - return Promise.all(returns); } }; diff --git a/addon/ng2/utilities/barrel-management.js b/addon/ng2/utilities/barrel-management.js deleted file mode 100644 index 41c9031b4d67..000000000000 --- a/addon/ng2/utilities/barrel-management.js +++ /dev/null @@ -1,43 +0,0 @@ -var path = require('path'); -var fs = require('fs'); -var EOL = require('os').EOL; - -module.exports = addBarrelRegistration; - -function sortBarrel(contents) { - var parts = contents.split(EOL).filter(function(l){ - return l.trim().length > 0; - }); - parts.sort(); - return parts.join(EOL) + EOL; -} - -function addBarrelRegistration(blueprint, installationDir, fileName) { - var parts = installationDir.split(path.sep); - - var idx = parts.lastIndexOf('shared'); - if (idx < parts.length -2) { - return Promise.resolve(); - } - - var sharedDir = parts.slice(0, idx + 1).join(path.sep); - var relativeParts = parts.splice(idx + 1); - if (fileName) { - relativeParts.push(fileName); - } - var importFrom = './' + relativeParts.join('/'); - - return blueprint.insertIntoFile( - sharedDir + path.sep + 'index.ts', - `export * from '${importFrom}';${EOL}` - ).then(function(r){ - var contents = fs.readFileSync(r.path, 'utf8'); - - contents = sortBarrel(contents); - - fs.writeFileSync(r.path, contents, 'utf8'); - - r.contents = contents; - return r; - }); -} diff --git a/tests/acceptance/barrel-management.spec.js b/tests/acceptance/barrel-management.spec.js deleted file mode 100644 index 4613c1466a67..000000000000 --- a/tests/acceptance/barrel-management.spec.js +++ /dev/null @@ -1,169 +0,0 @@ -'use strict'; - -var expect = require('chai').expect; -var path = require('path'); -var addBarrelRegistration = require('../../addon/ng2/utilities/barrel-management'); -var mockFs = require('mock-fs'); -var existsSync = require('exists-sync'); -var EOL = require('os').EOL; - -var Blueprint = require('ember-cli/lib/models/blueprint'); - -describe('barrel-management', () => { - var blueprint; - var installationDirectory; - - beforeEach(() => { - blueprint = new Blueprint('/'); - blueprint.project = { - root: '/' - } - }); - - describe('when not shared', () => { - - - beforeEach(() => { - var mockDrive = { - '/src/app/my-component': {} - }; - mockFs(mockDrive); - - installationDirectory = path.join('src', 'app', 'my-component'); - }); - - afterEach(() => { - mockFs.restore(); - }); - - it('should do nothing', () => { - return addBarrelRegistration(blueprint, installationDirectory).then(() => { - var barrelPath = path.join(installationDirectory, 'index.ts'); - expect(existsSync(barrelPath)).to.equal(false); - }); - }); - }); - - describe('no pre-existing barrel', () => { - - beforeEach(() => { - var mockDrive = { - '/src/app/shared/my-component': {} - }; - mockFs(mockDrive); - - installationDirectory = path.join('/src/app/shared/my-component'); - }); - - afterEach(() => { - mockFs.restore(); - }); - - it('create barrel from installation dir', () => { - return addBarrelRegistration(blueprint, installationDirectory).then(() => { - var fs = require('fs'); - var barrelPath = path.join(installationDirectory, '..', 'index.ts'); - expect(existsSync(barrelPath)).to.equal(true); - var contents = fs.readFileSync(barrelPath, 'utf8'); - var expectedContents = `export * from './my-component';${EOL}`; - expect(contents).to.equal(expectedContents); - }); - }); - - it('create barrel from installation dir with file name', () => { - return addBarrelRegistration(blueprint, installationDirectory, 'my-smaller-component').then(() => { - var fs = require('fs'); - var barrelPath = path.join(installationDirectory, '..', 'index.ts'); - expect(existsSync(barrelPath)).to.equal(true); - var contents = fs.readFileSync(barrelPath, 'utf8'); - var expectedContents = `export * from './my-component/my-smaller-component';${EOL}`; - expect(contents).to.equal(expectedContents); - }); - }); - - }); - - describe('pre-existing barrel', () => { - - beforeEach(() => { - var mockDrive = { - '/src/app/shared': { - 'my-component': {}, - 'index.ts': `export * from './another-component${EOL}export * from './other-component${EOL}` - } - }; - mockFs(mockDrive); - - installationDirectory = path.join('/src/app/shared/my-component'); - }); - - afterEach(() => { - mockFs.restore(); - }); - - it('update barrel from installation dir', () => { - return addBarrelRegistration(blueprint, installationDirectory).then(() => { - var fs = require('fs'); - var barrelPath = path.join(installationDirectory, '..', 'index.ts'); - expect(existsSync(barrelPath)).to.equal(true); - var contents = fs.readFileSync(barrelPath, 'utf8'); - var expectedContents = `export * from './another-component${EOL}export * from './my-component';${EOL}export * from './other-component${EOL}`; - expect(contents).to.equal(expectedContents); - }); - }); - - it('updateA barrel from installation dir with file name', () => { - return addBarrelRegistration(blueprint, installationDirectory, 'my-smaller-component').then(() => { - var fs = require('fs'); - var barrelPath = path.join(installationDirectory, '..', 'index.ts'); - expect(existsSync(barrelPath)).to.equal(true); - var contents = fs.readFileSync(barrelPath, 'utf8'); - var expectedContents = `export * from './another-component${EOL}export * from './my-component/my-smaller-component';${EOL}export * from './other-component${EOL}`; - expect(contents).to.equal(expectedContents); - }); - }); - - }); - - describe('pre-existing barrel with export already defined', () => { - - beforeEach(() => { - var mockDrive = { - '/src/app/shared': { - 'my-component': {}, - 'index.ts': `export * from './other-component${EOL}export * from './my-component';${EOL}export * from './another-component${EOL}export * from './my-component/my-smaller-component';${EOL}` - } - }; - mockFs(mockDrive); - - installationDirectory = path.join('/src/app/shared/my-component'); - }); - - afterEach(() => { - mockFs.restore(); - }); - - it('update barrel from installation dir should add nothing', () => { - return addBarrelRegistration(blueprint, installationDirectory).then(() => { - var fs = require('fs'); - var barrelPath = path.join(installationDirectory, '..', 'index.ts'); - expect(existsSync(barrelPath)).to.equal(true); - var contents = fs.readFileSync(barrelPath, 'utf8'); - var expectedContents = `export * from './another-component${EOL}export * from './my-component';${EOL}export * from './my-component/my-smaller-component';${EOL}export * from './other-component${EOL}`; - expect(contents).to.equal(expectedContents); - }); - }); - - it('update barrel from installation dir with file name should add nothing', () => { - return addBarrelRegistration(blueprint, installationDirectory, 'my-smaller-component').then(() => { - var fs = require('fs'); - var barrelPath = path.join(installationDirectory, '..', 'index.ts'); - expect(existsSync(barrelPath)).to.equal(true); - var contents = fs.readFileSync(barrelPath, 'utf8'); - var expectedContents = `export * from './another-component${EOL}export * from './my-component';${EOL}export * from './my-component/my-smaller-component';${EOL}export * from './other-component${EOL}`; - expect(contents).to.equal(expectedContents); - }); - }); - - }); -});