Skip to content

Commit 7b55886

Browse files
committed
feat: adds client dir between src and app
Adds a directory layer in preparation for following the style guide in the blueprints Updates to templates, tests and build process Related to angular#316
1 parent a058996 commit 7b55886

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+147
-115
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="../../typings/browser.d.ts" />

addon/ng2/blueprints/ng2/files/src/typings.d.ts

-1
This file was deleted.

addon/ng2/blueprints/route-config/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
},
1212

1313
beforeInstall: function (options) {
14-
var routeConfigPath = path.join(options.project.root, 'src', 'app', 'route-config.ts');
14+
var routeConfigPath = path.join(options.project.root, 'src', 'client', 'app', 'route-config.ts');
1515
try {
1616
fs.unlinkSync(routeConfigPath);
1717
} catch (e) {

addon/ng2/utilities/dynamic-path-parser.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,30 @@ module.exports = function dynamicPathParser(project, entityName) {
55
var projectRoot = project.root;
66
var cwd = process.env.PWD;
77

8-
var rootPath = path.join(projectRoot, 'src', 'app');
8+
var rootPath = path.join(projectRoot, 'src', 'client', 'app');
99

1010
var outputPath = path.join(rootPath, entityName);
1111

1212
if (entityName.indexOf(path.sep) === 0) {
1313
outputPath = path.join(rootPath, entityName.substr(1));
1414
} else if (cwd.indexOf(rootPath) >= 0) {
1515
outputPath = path.join(cwd, entityName);
16-
} else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0 && entityName.indexOf('app') === 0) {
17-
outputPath = path.join(cwd, entityName);
16+
} else if (cwd.indexOf(path.join(projectRoot, 'src', 'client')) >= 0) {
17+
if (entityName.indexOf('app') === 0) {
18+
outputPath = path.join(cwd, entityName);
19+
} else {
20+
outputPath = path.join(cwd, 'app', entityName);
21+
}
1822
} else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0) {
19-
outputPath = path.join(cwd, 'app', entityName);
23+
if (entityName.indexOf(path.join('client', 'app')) === 0) {
24+
outputPath = path.join(cwd, entityName);
25+
} else if (entityName.indexOf('client') === 0) {
26+
outputPath = path.join(cwd, 'app', entityName);
27+
} else {
28+
outputPath = path.join(cwd, 'client', 'app', entityName);
29+
}
2030
}
21-
31+
2232
if (outputPath.indexOf(rootPath) < 0) {
2333
throw `Invalid path: "${entityName}" cannot be ` +
2434
`above the "${path.join('src', 'app')}" directory`;

lib/broccoli/angular2-app.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var Funnel = require('broccoli-funnel');
88
var mergeTrees = require('broccoli-merge-trees');
99
var uglify = require('broccoli-uglify-js');
1010
var Project = require('ember-cli/lib/models/project');
11-
var sourceDir = 'src';
11+
var sourceDir = 'src/client';
1212

1313
module.exports = Angular2App;
1414

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

21-
2221
/**
2322
* Create and return the app build system tree that:
2423
* - Get the `assets` tree
@@ -168,7 +167,7 @@ Angular2App.prototype._getIndexTree = function () {
168167
'index.html'
169168
];
170169

171-
var index = new Funnel('src', {
170+
var index = new Funnel('src/client', {
172171
files: files,
173172
description: 'Funnel: index.html'
174173
});
@@ -189,9 +188,9 @@ Angular2App.prototype._getIndexTree = function () {
189188
* @return {Tree} Tree for the src dir.
190189
*/
191190
Angular2App.prototype._getSourceTree = function () {
192-
return new Funnel('src', {
191+
return new Funnel('src/client', {
193192
include: ['*.ts', '**/*.ts', '**/*.d.ts'],
194-
destDir: 'src'
193+
destDir: 'src/client'
195194
});
196195
};
197196

@@ -222,7 +221,7 @@ Angular2App.prototype._getTsTree = function () {
222221
var typingsTree = this._getTypingsTree();
223222
var sourceTree = this._getSourceTree();
224223

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

255254
tsTree = new Funnel(tsTree, {
256-
srcDir: 'src',
257-
exclude: tsTreeExcludes
255+
srcDir: 'src/client',
256+
// exclude: tsTreeExcludes
258257
});
259258

260259
return tsTree;

tests/acceptance/dynamic-path-parser.spec.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,37 @@ describe('dynamic path parser', () => {
2525
expect(result.name).to.equal(entityName);
2626
});
2727

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

35-
it(`parse from proj src${path.sep}app${path.sep}child-dir`, () => {
36-
process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir');
35+
it(`parse from proj src${path.sep}client${path.sep}app dir`, () => {
36+
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app');
37+
var result = dynamicPathParser(project, entityName);
38+
expect(result.dir).to.equal('');
39+
expect(result.name).to.equal(entityName);
40+
});
41+
42+
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir`, () => {
43+
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app', 'child-dir');
3744
var result = dynamicPathParser(project, entityName);
3845
expect(result.dir).to.equal(`${path.sep}child-dir`);
3946
expect(result.name).to.equal(entityName);
4047
});
4148

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

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

tests/acceptance/generate-component.spec.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ describe('Acceptance: ng generate component', function () {
3232

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

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

4747
it('ng generate component test' + path.sep + '..' + path.sep + 'my-comp', function () {
4848
return ng(['generate', 'component', 'test' + path.sep + '..' + path.sep + 'my-comp'])
4949
.then(() => {
50-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
50+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.ts');
5151
expect(existsSync(testPath)).to.equal(true);
5252
});
5353
});
@@ -57,14 +57,15 @@ describe('Acceptance: ng generate component', function () {
5757
process.chdir('./src');
5858
resolve();
5959
})
60+
.then(() => process.chdir('./client'))
6061
.then(() => process.chdir('./app'))
6162
.then(() => fs.mkdirsSync('./1'))
6263
.then(() => process.chdir('./1'))
6364
.then(() => {
6465
return ng(['generate', 'component', 'my-comp'])
6566
})
6667
.then(() => {
67-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
68+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-comp', 'my-comp.ts');
6869
expect(existsSync(testPath)).to.equal(true);
6970
}, err => console.log('ERR: ', err));
7071
});
@@ -74,6 +75,7 @@ describe('Acceptance: ng generate component', function () {
7475
process.chdir('./src');
7576
resolve();
7677
})
78+
.then(() => process.chdir('./client'))
7779
.then(() => process.chdir('./app'))
7880
.then(() => fs.mkdirsSync('./1'))
7981
.then(() => process.chdir('./1'))
@@ -82,7 +84,7 @@ describe('Acceptance: ng generate component', function () {
8284
})
8385
.then(() => {
8486
var testPath = path.join(
85-
root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
87+
root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
8688
expect(existsSync(testPath)).to.equal(true);
8789
}, err => console.log('ERR: ', err));
8890
});
@@ -93,6 +95,7 @@ describe('Acceptance: ng generate component', function () {
9395
process.chdir('./src');
9496
resolve();
9597
})
98+
.then(() => process.chdir('./client'))
9699
.then(() => process.chdir('./app'))
97100
.then(() => fs.mkdirsSync('./1'))
98101
.then(() => process.chdir('./1'))
@@ -103,33 +106,34 @@ describe('Acceptance: ng generate component', function () {
103106
})
104107
.then(() => {
105108
var testPath =
106-
path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
109+
path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-comp', 'my-comp.ts');
107110
expect(existsSync(testPath)).to.equal(true);
108111
}, err => console.log('ERR: ', err));
109112
});
110113

111114
it('ng generate component ' + path.sep + 'my-comp from a child dir, gens under ' +
112-
path.join('src', 'app'),
115+
path.join('src', 'client', 'app'),
113116
() => {
114117
return new Promise(function (resolve) {
115118
process.chdir('./src');
116119
resolve();
117120
})
121+
.then(() => process.chdir('./client'))
118122
.then(() => process.chdir('./app'))
119123
.then(() => fs.mkdirsSync('./1'))
120124
.then(() => process.chdir('./1'))
121125
.then(() => {
122126
return ng(['generate', 'component', path.sep + 'my-comp'])
123127
})
124128
.then(() => {
125-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
129+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.ts');
126130
expect(existsSync(testPath)).to.equal(true);
127131
}, err => console.log('ERR: ', err));
128132
});
129133

130134
it('ng generate component ..' + path.sep + 'my-comp from root dir will fail', () => {
131135
return ng(['generate', 'component', '..' + path.sep + 'my-comp']).then(() => {
132-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts');
136+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '..', 'my-comp', 'my-comp.ts');
133137
expect(existsSync(testPath)).to.equal(false);
134138
});
135139
});

tests/acceptance/generate-directive.spec.js

+29-25
Original file line numberDiff line numberDiff line change
@@ -30,109 +30,113 @@ describe('Acceptance: ng generate directive', function () {
3030
return tmp.teardown('./tmp');
3131
});
3232

33-
it('ng generate directive my-comp', function () {
34-
return ng(['generate', 'directive', 'my-comp']).then(() => {
35-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
33+
it('ng generate directive my-dir', function () {
34+
return ng(['generate', 'directive', 'my-dir']).then(() => {
35+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-dir', 'my-dir.ts');
3636
expect(existsSync(testPath)).to.equal(true);
3737
});
3838
});
3939

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

47-
it('ng generate directive test' + path.sep + '..' + path.sep + 'my-comp', function () {
48-
return ng(['generate', 'directive', 'test' + path.sep + '..' + path.sep + 'my-comp'])
47+
it('ng generate directive test' + path.sep + '..' + path.sep + 'my-dir', function () {
48+
return ng(['generate', 'directive', 'test' + path.sep + '..' + path.sep + 'my-dir'])
4949
.then(() => {
50-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
50+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-dir', 'my-dir.ts');
5151
expect(existsSync(testPath)).to.equal(true);
5252
});
5353
});
5454

55-
it('ng generate directive my-comp from a child dir', () => {
55+
it('ng generate directive my-dir from a child dir', () => {
5656
return new Promise(function (resolve) {
5757
process.chdir('./src');
5858
resolve();
5959
})
60+
.then(() => process.chdir('./client'))
6061
.then(() => process.chdir('./app'))
6162
.then(() => fs.mkdirsSync('./1'))
6263
.then(() => process.chdir('./1'))
6364
.then(() => {
6465
process.env.CWD = process.cwd();
65-
return ng(['generate', 'directive', 'my-comp'])
66+
return ng(['generate', 'directive', 'my-dir'])
6667
})
6768
.then(() => {
68-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
69+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-dir', 'my-dir.ts');
6970
expect(existsSync(testPath)).to.equal(true);
7071
}, err => console.log('ERR: ', err));
7172
});
7273

73-
it('ng generate directive child-dir' + path.sep + 'my-comp from a child dir', () => {
74+
it('ng generate directive child-dir' + path.sep + 'my-dir from a child dir', () => {
7475
return new Promise(function (resolve) {
7576
process.chdir('./src');
7677
resolve();
7778
})
79+
.then(() => process.chdir('./client'))
7880
.then(() => process.chdir('./app'))
7981
.then(() => fs.mkdirsSync('./1'))
8082
.then(() => process.chdir('./1'))
8183
.then(() => {
8284
process.env.CWD = process.cwd();
83-
return ng(['generate', 'directive', 'child-dir' + path.sep + 'my-comp'])
85+
return ng(['generate', 'directive', 'child-dir' + path.sep + 'my-dir'])
8486
})
8587
.then(() => {
8688
var testPath = path.join(
87-
root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
89+
root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'child-dir', 'my-dir', 'my-dir.ts');
8890
expect(existsSync(testPath)).to.equal(true);
8991
}, err => console.log('ERR: ', err));
9092
});
9193

92-
it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir',
94+
it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-dir from a child dir',
9395
() => {
9496
return new Promise(function (resolve) {
9597
process.chdir('./src');
9698
resolve();
9799
})
100+
.then(() => process.chdir('./client'))
98101
.then(() => process.chdir('./app'))
99102
.then(() => fs.mkdirsSync('./1'))
100103
.then(() => process.chdir('./1'))
101104
.then(() => {
102105
process.env.CWD = process.cwd();
103106
return ng(
104-
['generate', 'directive', 'child-dir' + path.sep + '..' + path.sep + 'my-comp'])
107+
['generate', 'directive', 'child-dir' + path.sep + '..' + path.sep + 'my-dir'])
105108
})
106109
.then(() => {
107110
var testPath =
108-
path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
111+
path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-dir', 'my-dir.ts');
109112
expect(existsSync(testPath)).to.equal(true);
110113
}, err => console.log('ERR: ', err));
111114
});
112115

113-
it('ng generate directive ' + path.sep + 'my-comp from a child dir, gens under ' +
114-
path.join('src', 'app'),
116+
it('ng generate directive ' + path.sep + 'my-dir from a child dir, gens under ' +
117+
path.join('src', 'client', 'app'),
115118
() => {
116119
return new Promise(function (resolve) {
117120
process.chdir('./src');
118121
resolve();
119122
})
123+
.then(() => process.chdir('./client'))
120124
.then(() => process.chdir('./app'))
121125
.then(() => fs.mkdirsSync('./1'))
122126
.then(() => process.chdir('./1'))
123127
.then(() => {
124128
process.env.CWD = process.cwd();
125-
return ng(['generate', 'directive', path.sep + 'my-comp'])
129+
return ng(['generate', 'directive', path.sep + 'my-dir'])
126130
})
127131
.then(() => {
128-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
132+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-dir', 'my-dir.ts');
129133
expect(existsSync(testPath)).to.equal(true);
130134
}, err => console.log('ERR: ', err));
131135
});
132136

133-
it('ng generate directive ..' + path.sep + 'my-comp from root dir will fail', () => {
134-
return ng(['generate', 'directive', '..' + path.sep + 'my-comp']).then(() => {
135-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts');
137+
it('ng generate directive ..' + path.sep + 'my-dir from root dir will fail', () => {
138+
return ng(['generate', 'directive', '..' + path.sep + 'my-dir']).then(() => {
139+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '..', 'my-dir', 'my-dir.ts');
136140
expect(existsSync(testPath)).to.equal(false);
137141
});
138142
});

0 commit comments

Comments
 (0)