Skip to content

feat: adds client dir between src and app #379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/ng2/blueprints/ng2/files/src/client/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../../typings/browser.d.ts" />
1 change: 0 additions & 1 deletion addon/ng2/blueprints/ng2/files/src/typings.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion addon/ng2/blueprints/route-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
},

beforeInstall: function (options) {
var routeConfigPath = path.join(options.project.root, 'src', 'app', 'route-config.ts');
var routeConfigPath = path.join(options.project.root, 'src', 'client', 'app', 'route-config.ts');
try {
fs.unlinkSync(routeConfigPath);
} catch (e) {
Expand Down
20 changes: 15 additions & 5 deletions addon/ng2/utilities/dynamic-path-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ module.exports = function dynamicPathParser(project, entityName) {
var projectRoot = project.root;
var cwd = process.env.PWD;

var rootPath = path.join(projectRoot, 'src', 'app');
var rootPath = path.join(projectRoot, 'src', 'client', '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', 'client')) >= 0) {
if (entityName.indexOf('app') === 0) {
outputPath = path.join(cwd, entityName);
} else {
outputPath = path.join(cwd, 'app', entityName);
}
} else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0) {
outputPath = path.join(cwd, 'app', entityName);
if (entityName.indexOf(path.join('client', 'app')) === 0) {
outputPath = path.join(cwd, entityName);
} else if (entityName.indexOf('client') === 0) {
outputPath = path.join(cwd, 'app', entityName);
} else {
outputPath = path.join(cwd, 'client', 'app', entityName);
}
}

if (outputPath.indexOf(rootPath) < 0) {
throw `Invalid path: "${entityName}" cannot be ` +
`above the "${path.join('src', 'app')}" directory`;
Expand Down
13 changes: 6 additions & 7 deletions lib/broccoli/angular2-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var uglify = require('broccoli-uglify-js');
var Project = require('ember-cli/lib/models/project');
var sourceDir = 'src';
var sourceDir = 'src/client';

module.exports = Angular2App;

Expand All @@ -18,7 +18,6 @@ function Angular2App(defaults, options) {
this.options = options || {};
}


/**
* Create and return the app build system tree that:
* - Get the `assets` tree
Expand Down Expand Up @@ -168,7 +167,7 @@ Angular2App.prototype._getIndexTree = function () {
'index.html'
];

var index = new Funnel('src', {
var index = new Funnel('src/client', {
files: files,
description: 'Funnel: index.html'
});
Expand All @@ -189,9 +188,9 @@ Angular2App.prototype._getIndexTree = function () {
* @return {Tree} Tree for the src dir.
*/
Angular2App.prototype._getSourceTree = function () {
return new Funnel('src', {
return new Funnel('src/client', {
include: ['*.ts', '**/*.ts', '**/*.d.ts'],
destDir: 'src'
destDir: 'src/client'
});
};

Expand Down Expand Up @@ -222,7 +221,7 @@ Angular2App.prototype._getTsTree = function () {
var typingsTree = this._getTypingsTree();
var sourceTree = this._getSourceTree();

var tsconfig = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8'));
var tsconfig = JSON.parse(fs.readFileSync('src/client/tsconfig.json', 'utf-8'));
// Add all spec files to files. We need this because spec files are their own entry
// point.
fs.readdirSync(sourceDir).forEach(function addPathRecursive(name) {
Expand Down Expand Up @@ -253,7 +252,7 @@ Angular2App.prototype._getTsTree = function () {
}

tsTree = new Funnel(tsTree, {
srcDir: 'src',
srcDir: 'src/client',
exclude: tsTreeExcludes
});

Expand Down
23 changes: 15 additions & 8 deletions tests/acceptance/dynamic-path-parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,37 @@ describe('dynamic path parser', () => {
expect(result.name).to.equal(entityName);
});

it(`parse from proj src${path.sep}app dir`, () => {
process.env.PWD = path.join(process.cwd(), 'src', 'app');
it(`parse from proj src${path.sep}client dir`, () => {
process.env.PWD = path.join(process.cwd(), 'src', 'client');
var result = dynamicPathParser(project, entityName);
expect(result.dir).to.equal('');
expect(result.name).to.equal(entityName);
});

it(`parse from proj src${path.sep}app${path.sep}child-dir`, () => {
process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir');
it(`parse from proj src${path.sep}client${path.sep}app dir`, () => {
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app');
var result = dynamicPathParser(project, entityName);
expect(result.dir).to.equal('');
expect(result.name).to.equal(entityName);
});

it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir`, () => {
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app', 'child-dir');
var result = dynamicPathParser(project, entityName);
expect(result.dir).to.equal(`${path.sep}child-dir`);
expect(result.name).to.equal(entityName);
});

it(`parse from proj src${path.sep}app${path.sep}child-dir w/ ..${path.sep}`, () => {
process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir');
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir w/ ..${path.sep}`, () => {
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app', 'child-dir');
var result = dynamicPathParser(project, '..' + path.sep + entityName);
expect(result.dir).to.equal('');
expect(result.name).to.equal(entityName);
});

it(`parse from proj src${path.sep}app${path.sep}child-dir${path.sep}grand-child-dir w/ ..${path.sep}`,
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir${path.sep}grand-child-dir w/ ..${path.sep}`,
() => {
process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir', 'grand-child-dir');
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app', 'child-dir', 'grand-child-dir');
var result = dynamicPathParser(project, '..' + path.sep + entityName);
expect(result.dir).to.equal(`${path.sep}child-dir`);
expect(result.name).to.equal(entityName);
Expand Down
22 changes: 13 additions & 9 deletions tests/acceptance/generate-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ describe('Acceptance: ng generate component', function () {

it('ng generate component my-comp', function () {
return ng(['generate', 'component', 'my-comp']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(true);
});
});

it('ng generate component test' + path.sep + 'my-comp', function () {
return ng(['generate', 'component', 'test' + path.sep + 'my-comp']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'test', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(true);
});
});

it('ng generate component test' + path.sep + '..' + path.sep + 'my-comp', function () {
return ng(['generate', 'component', 'test' + path.sep + '..' + path.sep + 'my-comp'])
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(true);
});
});
Expand All @@ -57,14 +57,15 @@ describe('Acceptance: ng generate component', function () {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.then(() => process.chdir('./app'))
.then(() => fs.mkdirsSync('./1'))
.then(() => process.chdir('./1'))
.then(() => {
return ng(['generate', 'component', 'my-comp'])
})
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});
Expand All @@ -74,6 +75,7 @@ describe('Acceptance: ng generate component', function () {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.then(() => process.chdir('./app'))
.then(() => fs.mkdirsSync('./1'))
.then(() => process.chdir('./1'))
Expand All @@ -82,7 +84,7 @@ describe('Acceptance: ng generate component', function () {
})
.then(() => {
var testPath = path.join(
root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});
Expand All @@ -93,6 +95,7 @@ describe('Acceptance: ng generate component', function () {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.then(() => process.chdir('./app'))
.then(() => fs.mkdirsSync('./1'))
.then(() => process.chdir('./1'))
Expand All @@ -103,33 +106,34 @@ describe('Acceptance: ng generate component', function () {
})
.then(() => {
var testPath =
path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});

it('ng generate component ' + path.sep + 'my-comp from a child dir, gens under ' +
path.join('src', 'app'),
path.join('src', 'client', 'app'),
() => {
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.then(() => process.chdir('./app'))
.then(() => fs.mkdirsSync('./1'))
.then(() => process.chdir('./1'))
.then(() => {
return ng(['generate', 'component', path.sep + 'my-comp'])
})
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});

it('ng generate component ..' + path.sep + 'my-comp from root dir will fail', () => {
return ng(['generate', 'component', '..' + path.sep + 'my-comp']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '..', 'my-comp', 'my-comp.ts');
expect(existsSync(testPath)).to.equal(false);
});
});
Expand Down
54 changes: 29 additions & 25 deletions tests/acceptance/generate-directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,109 +30,113 @@ describe('Acceptance: ng generate directive', function () {
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');
it('ng generate directive my-dir', function () {
return ng(['generate', 'directive', 'my-dir']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-dir', 'my-dir.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');
it('ng generate directive test' + path.sep + 'my-dir', function () {
return ng(['generate', 'directive', 'test' + path.sep + 'my-dir']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'test', 'my-dir', 'my-dir.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'])
it('ng generate directive test' + path.sep + '..' + path.sep + 'my-dir', function () {
return ng(['generate', 'directive', 'test' + path.sep + '..' + path.sep + 'my-dir'])
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-dir', 'my-dir.ts');
expect(existsSync(testPath)).to.equal(true);
});
});

it('ng generate directive my-comp from a child dir', () => {
it('ng generate directive my-dir from a child dir', () => {
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.then(() => process.chdir('./app'))
.then(() => fs.mkdirsSync('./1'))
.then(() => process.chdir('./1'))
.then(() => {
process.env.CWD = process.cwd();
return ng(['generate', 'directive', 'my-comp'])
return ng(['generate', 'directive', 'my-dir'])
})
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-dir', 'my-dir.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', () => {
it('ng generate directive child-dir' + path.sep + 'my-dir from a child dir', () => {
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.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'])
return ng(['generate', 'directive', 'child-dir' + path.sep + 'my-dir'])
})
.then(() => {
var testPath = path.join(
root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'child-dir', 'my-dir', 'my-dir.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',
it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-dir from a child dir',
() => {
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.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'])
['generate', 'directive', 'child-dir' + path.sep + '..' + path.sep + 'my-dir'])
})
.then(() => {
var testPath =
path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-dir', 'my-dir.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'),
it('ng generate directive ' + path.sep + 'my-dir from a child dir, gens under ' +
path.join('src', 'client', 'app'),
() => {
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./client'))
.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'])
return ng(['generate', 'directive', path.sep + 'my-dir'])
})
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-dir', 'my-dir.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');
it('ng generate directive ..' + path.sep + 'my-dir from root dir will fail', () => {
return ng(['generate', 'directive', '..' + path.sep + 'my-dir']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '..', 'my-dir', 'my-dir.ts');
expect(existsSync(testPath)).to.equal(false);
});
});
Expand Down
Loading