From f020f8a2596c3c5bde3a453bff5341d9f4b260ad Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Wed, 9 Mar 2016 21:24:30 -0500 Subject: [PATCH] chore(paths): dynamic paths for directives, pipes and services --- addon/ng2/blueprints/component/index.js | 45 +---- .../__name__/__name__.spec.ts | 0 .../__name__/__name__.ts | 0 addon/ng2/blueprints/directive/index.js | 35 ++++ .../__name__/__name__.spec.ts | 0 .../{pipes => __path__}/__name__/__name__.ts | 0 addon/ng2/blueprints/pipe/index.js | 35 ++++ .../app/services/__name__/__name__.spec.ts | 25 --- .../src/app/services/__name__/__name__.ts | 9 - addon/ng2/blueprints/service/index.js | 39 +++- addon/ng2/utilities/dynamic-path-parser.js | 30 +++ tests/acceptance/generate-directive.spec.js | 180 ++++++++++++++++++ tests/acceptance/generate-pipe.spec.js | 180 ++++++++++++++++++ tests/acceptance/generate-service.spec.js | 180 ++++++++++++++++++ 14 files changed, 679 insertions(+), 79 deletions(-) rename addon/ng2/blueprints/directive/files/src/app/{directives => __path__}/__name__/__name__.spec.ts (100%) rename addon/ng2/blueprints/directive/files/src/app/{directives => __path__}/__name__/__name__.ts (100%) create mode 100644 addon/ng2/blueprints/directive/index.js rename addon/ng2/blueprints/pipe/files/src/app/{pipes => __path__}/__name__/__name__.spec.ts (100%) rename addon/ng2/blueprints/pipe/files/src/app/{pipes => __path__}/__name__/__name__.ts (100%) create mode 100644 addon/ng2/blueprints/pipe/index.js delete mode 100644 addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.spec.ts delete mode 100644 addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.ts create mode 100644 addon/ng2/utilities/dynamic-path-parser.js create mode 100644 tests/acceptance/generate-directive.spec.js create mode 100644 tests/acceptance/generate-pipe.spec.js create mode 100644 tests/acceptance/generate-service.spec.js diff --git a/addon/ng2/blueprints/component/index.js b/addon/ng2/blueprints/component/index.js index 69d536712eda..b0fa1925397e 100644 --- a/addon/ng2/blueprints/component/index.js +++ b/addon/ng2/blueprints/component/index.js @@ -1,49 +1,24 @@ var stringUtils = require('ember-cli/lib/utilities/string'); -var path = require('path'); -var process = require('process'); +var dynamicPathParser = require('../../utilities/dynamic-path-parser'); module.exports = { description: '', - - normalizeEntityName: function(entityName){ + + normalizeEntityName: function(entityName) { var cwd = this.project.cli.testing ? process.cwd() : process.env.PWD; - - var rootPath = path.join(this.project.root, 'src', 'app'); - - var outputPath = path.join(rootPath, entityName); - - if (entityName.indexOf(path.sep) === 0) { - outputPath = path.join(rootPath, entityName.substr(1)); - } else if (cwd.indexOf(rootPath) >= 0) { - outputPath = path.join(cwd, entityName); - } else if (cwd.indexOf(path.join(this.project.root, 'src')) >= 0 - && entityName.indexOf('app') === 0) { - outputPath = path.join(cwd, entityName); - } else if (cwd.indexOf(path.join(this.project.root, 'src')) >= 0) { - outputPath = path.join(cwd, 'app', entityName); - } - - if (outputPath.indexOf(rootPath) < 0) { - throw `Invalid component path: "${entityName}" cannot be ` + - `above the "${path.join('src', 'app')}" directory`; - } - var adjustedPath = outputPath.replace(rootPath, ''); + var parsedPath = dynamicPathParser(cwd, this.project.root, entityName); - var parsedPath = path.parse(adjustedPath); - this.dynamicPath = { - name: parsedPath.name, - path: parsedPath.dir - }; + this.dynamicPath = parsedPath; return parsedPath.name; }, - - locals: function(options){ + + locals: function(options) { return { - dynamicPath: this.dynamicPath.path - } + dynamicPath: this.dynamicPath.dir + }; }, fileMapTokens: function(options) { @@ -53,7 +28,7 @@ module.exports = { return this.dynamicPath.name; }, __path__: (options) => { - return this.dynamicPath.path; + return this.dynamicPath.dir; } }; } diff --git a/addon/ng2/blueprints/directive/files/src/app/directives/__name__/__name__.spec.ts b/addon/ng2/blueprints/directive/files/src/app/__path__/__name__/__name__.spec.ts similarity index 100% rename from addon/ng2/blueprints/directive/files/src/app/directives/__name__/__name__.spec.ts rename to addon/ng2/blueprints/directive/files/src/app/__path__/__name__/__name__.spec.ts diff --git a/addon/ng2/blueprints/directive/files/src/app/directives/__name__/__name__.ts b/addon/ng2/blueprints/directive/files/src/app/__path__/__name__/__name__.ts similarity index 100% rename from addon/ng2/blueprints/directive/files/src/app/directives/__name__/__name__.ts rename to addon/ng2/blueprints/directive/files/src/app/__path__/__name__/__name__.ts diff --git a/addon/ng2/blueprints/directive/index.js b/addon/ng2/blueprints/directive/index.js new file mode 100644 index 000000000000..b0fa1925397e --- /dev/null +++ b/addon/ng2/blueprints/directive/index.js @@ -0,0 +1,35 @@ +var stringUtils = require('ember-cli/lib/utilities/string'); +var dynamicPathParser = require('../../utilities/dynamic-path-parser'); + +module.exports = { + description: '', + + normalizeEntityName: function(entityName) { + var cwd = this.project.cli.testing + ? process.cwd() + : process.env.PWD; + + var parsedPath = dynamicPathParser(cwd, this.project.root, entityName); + + this.dynamicPath = parsedPath; + return parsedPath.name; + }, + + locals: function(options) { + return { + dynamicPath: this.dynamicPath.dir + }; + }, + + fileMapTokens: function(options) { + // Return custom template variables here. + return { + __name__: (options) => { + return this.dynamicPath.name; + }, + __path__: (options) => { + return this.dynamicPath.dir; + } + }; + } +}; diff --git a/addon/ng2/blueprints/pipe/files/src/app/pipes/__name__/__name__.spec.ts b/addon/ng2/blueprints/pipe/files/src/app/__path__/__name__/__name__.spec.ts similarity index 100% rename from addon/ng2/blueprints/pipe/files/src/app/pipes/__name__/__name__.spec.ts rename to addon/ng2/blueprints/pipe/files/src/app/__path__/__name__/__name__.spec.ts diff --git a/addon/ng2/blueprints/pipe/files/src/app/pipes/__name__/__name__.ts b/addon/ng2/blueprints/pipe/files/src/app/__path__/__name__/__name__.ts similarity index 100% rename from addon/ng2/blueprints/pipe/files/src/app/pipes/__name__/__name__.ts rename to addon/ng2/blueprints/pipe/files/src/app/__path__/__name__/__name__.ts diff --git a/addon/ng2/blueprints/pipe/index.js b/addon/ng2/blueprints/pipe/index.js new file mode 100644 index 000000000000..b0fa1925397e --- /dev/null +++ b/addon/ng2/blueprints/pipe/index.js @@ -0,0 +1,35 @@ +var stringUtils = require('ember-cli/lib/utilities/string'); +var dynamicPathParser = require('../../utilities/dynamic-path-parser'); + +module.exports = { + description: '', + + normalizeEntityName: function(entityName) { + var cwd = this.project.cli.testing + ? process.cwd() + : process.env.PWD; + + var parsedPath = dynamicPathParser(cwd, this.project.root, entityName); + + this.dynamicPath = parsedPath; + return parsedPath.name; + }, + + locals: function(options) { + return { + dynamicPath: this.dynamicPath.dir + }; + }, + + fileMapTokens: function(options) { + // Return custom template variables here. + return { + __name__: (options) => { + return this.dynamicPath.name; + }, + __path__: (options) => { + return this.dynamicPath.dir; + } + }; + } +}; diff --git a/addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.spec.ts b/addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.spec.ts deleted file mode 100644 index 5650fee31b81..000000000000 --- a/addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { - it, - iit, - describe, - ddescribe, - expect, - inject, - injectAsync, - TestComponentBuilder, - beforeEachProviders -} from 'angular2/testing'; -import {provide} from 'angular2/core'; -import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>'; - - -describe('<%= classifiedModuleName %> Service', () => { - - beforeEachProviders(() => [<%= classifiedModuleName %>]); - - - it('should ...', inject([<%= classifiedModuleName %>], (service:<%= classifiedModuleName %>) => { - - })); - -}); diff --git a/addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.ts b/addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.ts deleted file mode 100644 index b6affa0cde77..000000000000 --- a/addon/ng2/blueprints/service/files/src/app/services/__name__/__name__.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {Injectable} from 'angular2/core'; - - -@Injectable() -export class <%= classifiedModuleName %> { - - constructor() {} - -} diff --git a/addon/ng2/blueprints/service/index.js b/addon/ng2/blueprints/service/index.js index 8540d5f2f309..b0fa1925397e 100644 --- a/addon/ng2/blueprints/service/index.js +++ b/addon/ng2/blueprints/service/index.js @@ -1,16 +1,35 @@ var stringUtils = require('ember-cli/lib/utilities/string'); +var dynamicPathParser = require('../../utilities/dynamic-path-parser'); module.exports = { - description: '' + description: '', - //locals: function(options) { - // // Return custom template variables here. - // return { - // - // }; - //} + normalizeEntityName: function(entityName) { + var cwd = this.project.cli.testing + ? process.cwd() + : process.env.PWD; + + var parsedPath = dynamicPathParser(cwd, this.project.root, entityName); + + this.dynamicPath = parsedPath; + return parsedPath.name; + }, - // afterInstall: function(options) { - // // Perform extra work here. - // } + locals: function(options) { + return { + dynamicPath: this.dynamicPath.dir + }; + }, + + fileMapTokens: function(options) { + // Return custom template variables here. + return { + __name__: (options) => { + return this.dynamicPath.name; + }, + __path__: (options) => { + return this.dynamicPath.dir; + } + }; + } }; diff --git a/addon/ng2/utilities/dynamic-path-parser.js b/addon/ng2/utilities/dynamic-path-parser.js new file mode 100644 index 000000000000..e63ce15b3390 --- /dev/null +++ b/addon/ng2/utilities/dynamic-path-parser.js @@ -0,0 +1,30 @@ +var path = require('path'); +var process = require('process'); + +module.exports = function dynamicPathParser(cwd, projectRoot, entityName) { + var rootPath = path.join(projectRoot, 'src', 'app'); + + var outputPath = path.join(rootPath, entityName); + + if (entityName.indexOf(path.sep) === 0) { + outputPath = path.join(rootPath, entityName.substr(1)); + } else if (cwd.indexOf(rootPath) >= 0) { + outputPath = path.join(cwd, entityName); + } else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0 + && entityName.indexOf('app') === 0) { + outputPath = path.join(cwd, entityName); + } else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0) { + outputPath = path.join(cwd, 'app', entityName); + } + + if (outputPath.indexOf(rootPath) < 0) { + throw `Invalid path: "${entityName}" cannot be ` + + `above the "${path.join('src', 'app')}" directory`; + } + + var adjustedPath = outputPath.replace(rootPath, ''); + + var parsedPath = path.parse(adjustedPath); + + return parsedPath; +} \ No newline at end of file diff --git a/tests/acceptance/generate-directive.spec.js b/tests/acceptance/generate-directive.spec.js new file mode 100644 index 000000000000..b851acf79f96 --- /dev/null +++ b/tests/acceptance/generate-directive.spec.js @@ -0,0 +1,180 @@ +'use strict'; + +var fs = require('fs-extra'); +var ng = require('../helpers/ng'); +var existsSync = require('exists-sync'); +var expect = require('chai').expect; +var forEach = require('lodash/collection/forEach'); +var walkSync = require('walk-sync'); +var Blueprint = require('ember-cli/lib/models/blueprint'); +var path = require('path'); +var tmp = require('../helpers/tmp'); +var root = process.cwd(); +var util = require('util'); +var conf = require('ember-cli/tests/helpers/conf'); +var EOL = require('os').EOL; +var path = require('path'); +var Promise = require('ember-cli/lib/ext/promise'); + +describe('Acceptance: ng generate directive', function() { + before(conf.setup); + + after(conf.restore); + + beforeEach(function() { + return tmp.setup('./tmp') + .then(function() { + process.chdir('./tmp'); + }) + .then(function(){ + return ng([ + 'new', + 'foo', + '--skip-npm', + '--skip-bower' + ]); + }); + }); + + afterEach(function() { + this.timeout(10000); + + // return tmp.teardown('./tmp'); + }); + + it('ng generate directive my-comp', function() { + return ng([ + 'generate', + 'directive', + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate directive test' + path.sep + 'my-comp', function() { + return ng([ + 'generate', + 'directive', + 'test' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate directive test' + path.sep + '..' + path.sep + 'my-comp', function() { + return ng([ + 'generate', + 'directive', + 'test' + path.sep + '..' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate directive my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'directive', + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate directive child-dir' + path.sep + 'my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'directive', + 'child-dir' + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'directive', + 'child-dir' + path.sep + '..' + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate directive ' + path.sep + 'my-comp from a child dir, gens under ' + path.join('src', 'app'), () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'directive', + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate directive ..' + path.sep + 'my-comp from root dir will fail', () => { + return ng([ + 'generate', + 'directive', + '..' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(false); + }); + }); +}); \ No newline at end of file diff --git a/tests/acceptance/generate-pipe.spec.js b/tests/acceptance/generate-pipe.spec.js new file mode 100644 index 000000000000..4b17555ecf64 --- /dev/null +++ b/tests/acceptance/generate-pipe.spec.js @@ -0,0 +1,180 @@ +'use strict'; + +var fs = require('fs-extra'); +var ng = require('../helpers/ng'); +var existsSync = require('exists-sync'); +var expect = require('chai').expect; +var forEach = require('lodash/collection/forEach'); +var walkSync = require('walk-sync'); +var Blueprint = require('ember-cli/lib/models/blueprint'); +var path = require('path'); +var tmp = require('../helpers/tmp'); +var root = process.cwd(); +var util = require('util'); +var conf = require('ember-cli/tests/helpers/conf'); +var EOL = require('os').EOL; +var path = require('path'); +var Promise = require('ember-cli/lib/ext/promise'); + +describe('Acceptance: ng generate pipe', function() { + before(conf.setup); + + after(conf.restore); + + beforeEach(function() { + return tmp.setup('./tmp') + .then(function() { + process.chdir('./tmp'); + }) + .then(function(){ + return ng([ + 'new', + 'foo', + '--skip-npm', + '--skip-bower' + ]); + }); + }); + + afterEach(function() { + this.timeout(10000); + + // return tmp.teardown('./tmp'); + }); + + it('ng generate pipe my-comp', function() { + return ng([ + 'generate', + 'pipe', + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate pipe test' + path.sep + 'my-comp', function() { + return ng([ + 'generate', + 'pipe', + 'test' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate pipe test' + path.sep + '..' + path.sep + 'my-comp', function() { + return ng([ + 'generate', + 'pipe', + 'test' + path.sep + '..' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate pipe my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'pipe', + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate pipe child-dir' + path.sep + 'my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'pipe', + 'child-dir' + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate pipe child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'pipe', + 'child-dir' + path.sep + '..' + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate pipe ' + path.sep + 'my-comp from a child dir, gens under ' + path.join('src', 'app'), () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'pipe', + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate pipe ..' + path.sep + 'my-comp from root dir will fail', () => { + return ng([ + 'generate', + 'pipe', + '..' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(false); + }); + }); +}); \ No newline at end of file diff --git a/tests/acceptance/generate-service.spec.js b/tests/acceptance/generate-service.spec.js new file mode 100644 index 000000000000..c6764800357a --- /dev/null +++ b/tests/acceptance/generate-service.spec.js @@ -0,0 +1,180 @@ +'use strict'; + +var fs = require('fs-extra'); +var ng = require('../helpers/ng'); +var existsSync = require('exists-sync'); +var expect = require('chai').expect; +var forEach = require('lodash/collection/forEach'); +var walkSync = require('walk-sync'); +var Blueprint = require('ember-cli/lib/models/blueprint'); +var path = require('path'); +var tmp = require('../helpers/tmp'); +var root = process.cwd(); +var util = require('util'); +var conf = require('ember-cli/tests/helpers/conf'); +var EOL = require('os').EOL; +var path = require('path'); +var Promise = require('ember-cli/lib/ext/promise'); + +describe('Acceptance: ng generate service', function() { + before(conf.setup); + + after(conf.restore); + + beforeEach(function() { + return tmp.setup('./tmp') + .then(function() { + process.chdir('./tmp'); + }) + .then(function(){ + return ng([ + 'new', + 'foo', + '--skip-npm', + '--skip-bower' + ]); + }); + }); + + afterEach(function() { + this.timeout(10000); + + // return tmp.teardown('./tmp'); + }); + + it('ng generate service my-comp', function() { + return ng([ + 'generate', + 'service', + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate service test' + path.sep + 'my-comp', function() { + return ng([ + 'generate', + 'service', + 'test' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate service test' + path.sep + '..' + path.sep + 'my-comp', function() { + return ng([ + 'generate', + 'service', + 'test' + path.sep + '..' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); + }); + + it('ng generate service my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'service', + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate service child-dir' + path.sep + 'my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'service', + 'child-dir' + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate service child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'service', + 'child-dir' + path.sep + '..' + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate service ' + path.sep + 'my-comp from a child dir, gens under ' + path.join('src', 'app'), () => { + return new Promise(function (resolve, reject) { + process.chdir('./src'); + resolve(); + }) + .then(_ => process.chdir('./app')) + .then(_ => fs.mkdirsSync('./1')) + .then(_ => process.chdir('./1')) + .then(_ => { + process.env.CWD = process.cwd(); + return ng([ + 'generate', + 'service', + path.sep + 'my-comp' + ]) + }) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate service ..' + path.sep + 'my-comp from root dir will fail', () => { + return ng([ + 'generate', + 'service', + '..' + path.sep + 'my-comp' + ]) + .then(_ => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(false); + }); + }); +}); \ No newline at end of file