Skip to content

Commit 72edd9d

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 5110e7d commit 72edd9d

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

+135
-113
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ function Angular2App(defaults, options) {
1616
}
1717

1818
Angular2App.prototype.toTree = function () {
19-
var sourceDir = 'src';
19+
var sourceDir = 'src/client';
2020

21-
var sourceTree = new Funnel('src', {
21+
var sourceTree = new Funnel('src/client', {
2222
include: ['*.ts', '**/*.ts', '**/*.d.ts'],
23-
destDir: 'src'
23+
destDir: 'src/client'
2424
});
2525

2626
var typingsTree = new Funnel('typings', {
@@ -44,7 +44,7 @@ Angular2App.prototype.toTree = function () {
4444
vendorNpmFiles = vendorNpmFiles.concat(this.options.vendorNpmFiles);
4545
}
4646

47-
var tsconfig = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8'));
47+
var tsconfig = JSON.parse(fs.readFileSync('src/client/tsconfig.json', 'utf-8'));
4848
// Add all spec files to files. We need this because spec files are their own entry
4949
// point.
5050
fs.readdirSync(sourceDir).forEach(function addPathRecursive(name) {
@@ -67,7 +67,7 @@ Angular2App.prototype.toTree = function () {
6767
var tsTree = new compileWithTypescript(srcAndTypingsTree, tsconfig);
6868

6969
tsTree = new Funnel(tsTree, {
70-
srcDir: 'src',
70+
srcDir: 'src/client',
7171
exclude: ['*.d.ts', 'tsconfig.json']
7272
});
7373

@@ -215,7 +215,7 @@ Angular2App.prototype.index = function () {
215215
'index.html'
216216
];
217217

218-
var index = new Funnel('src', {
218+
var index = new Funnel('src/client', {
219219
files: files,
220220
description: 'Funnel: index.html'
221221
});

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

+20-8
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,47 @@ describe('dynamic path parser', () => {
2020

2121
it('parse from proj src dir', () => {
2222
process.env.PWD = path.join(process.cwd(), 'src');
23+
try{
2324
var result = dynamicPathParser(project, entityName);
25+
}catch(e){
26+
console.log('EXCEPTION ', e);
27+
}
28+
console.log('result ', JSON.stringify(result));
2429
expect(result.dir).to.equal('');
2530
expect(result.name).to.equal(entityName);
2631
});
2732

28-
it(`parse from proj src${path.sep}app dir`, () => {
29-
process.env.PWD = path.join(process.cwd(), 'src', 'app');
33+
it(`parse from proj src${path.sep}client dir`, () => {
34+
process.env.PWD = path.join(process.cwd(), 'src', 'client');
3035
var result = dynamicPathParser(project, entityName);
3136
expect(result.dir).to.equal('');
3237
expect(result.name).to.equal(entityName);
3338
});
3439

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');
40+
it(`parse from proj src${path.sep}client${path.sep}app dir`, () => {
41+
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app');
42+
var result = dynamicPathParser(project, entityName);
43+
expect(result.dir).to.equal('');
44+
expect(result.name).to.equal(entityName);
45+
});
46+
47+
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir`, () => {
48+
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app', 'child-dir');
3749
var result = dynamicPathParser(project, entityName);
3850
expect(result.dir).to.equal(`${path.sep}child-dir`);
3951
expect(result.name).to.equal(entityName);
4052
});
4153

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');
54+
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir w/ ..${path.sep}`, () => {
55+
process.env.PWD = path.join(process.cwd(), 'src', 'client', 'app', 'child-dir');
4456
var result = dynamicPathParser(project, '..' + path.sep + entityName);
4557
expect(result.dir).to.equal('');
4658
expect(result.name).to.equal(entityName);
4759
});
4860

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

tests/acceptance/generate-component.spec.js

+9-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
});
@@ -64,7 +64,7 @@ describe('Acceptance: ng generate component', function () {
6464
return ng(['generate', 'component', 'my-comp'])
6565
})
6666
.then(() => {
67-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
67+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-comp', 'my-comp.ts');
6868
expect(existsSync(testPath)).to.equal(true);
6969
}, err => console.log('ERR: ', err));
7070
});
@@ -82,7 +82,7 @@ describe('Acceptance: ng generate component', function () {
8282
})
8383
.then(() => {
8484
var testPath = path.join(
85-
root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
85+
root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
8686
expect(existsSync(testPath)).to.equal(true);
8787
}, err => console.log('ERR: ', err));
8888
});
@@ -103,13 +103,13 @@ describe('Acceptance: ng generate component', function () {
103103
})
104104
.then(() => {
105105
var testPath =
106-
path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
106+
path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-comp', 'my-comp.ts');
107107
expect(existsSync(testPath)).to.equal(true);
108108
}, err => console.log('ERR: ', err));
109109
});
110110

111111
it('ng generate component ' + path.sep + 'my-comp from a child dir, gens under ' +
112-
path.join('src', 'app'),
112+
path.join('src', 'client', 'app'),
113113
() => {
114114
return new Promise(function (resolve) {
115115
process.chdir('./src');
@@ -122,14 +122,14 @@ describe('Acceptance: ng generate component', function () {
122122
return ng(['generate', 'component', path.sep + 'my-comp'])
123123
})
124124
.then(() => {
125-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
125+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.ts');
126126
expect(existsSync(testPath)).to.equal(true);
127127
}, err => console.log('ERR: ', err));
128128
});
129129

130130
it('ng generate component ..' + path.sep + 'my-comp from root dir will fail', () => {
131131
return ng(['generate', 'component', '..' + path.sep + 'my-comp']).then(() => {
132-
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-comp', 'my-comp.ts');
133133
expect(existsSync(testPath)).to.equal(false);
134134
});
135135
});

tests/acceptance/generate-directive.spec.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@ 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();
@@ -62,15 +62,15 @@ describe('Acceptance: ng generate directive', function () {
6262
.then(() => process.chdir('./1'))
6363
.then(() => {
6464
process.env.CWD = process.cwd();
65-
return ng(['generate', 'directive', 'my-comp'])
65+
return ng(['generate', 'directive', 'my-dir'])
6666
})
6767
.then(() => {
68-
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-dir', 'my-dir.ts');
6969
expect(existsSync(testPath)).to.equal(true);
7070
}, err => console.log('ERR: ', err));
7171
});
7272

73-
it('ng generate directive child-dir' + path.sep + 'my-comp from a child dir', () => {
73+
it('ng generate directive child-dir' + path.sep + 'my-dir from a child dir', () => {
7474
return new Promise(function (resolve) {
7575
process.chdir('./src');
7676
resolve();
@@ -80,16 +80,16 @@ describe('Acceptance: ng generate directive', function () {
8080
.then(() => process.chdir('./1'))
8181
.then(() => {
8282
process.env.CWD = process.cwd();
83-
return ng(['generate', 'directive', 'child-dir' + path.sep + 'my-comp'])
83+
return ng(['generate', 'directive', 'child-dir' + path.sep + 'my-dir'])
8484
})
8585
.then(() => {
8686
var testPath = path.join(
87-
root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts');
87+
root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'child-dir', 'my-dir', 'my-dir.ts');
8888
expect(existsSync(testPath)).to.equal(true);
8989
}, err => console.log('ERR: ', err));
9090
});
9191

92-
it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir',
92+
it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-dir from a child dir',
9393
() => {
9494
return new Promise(function (resolve) {
9595
process.chdir('./src');
@@ -101,17 +101,17 @@ describe('Acceptance: ng generate directive', function () {
101101
.then(() => {
102102
process.env.CWD = process.cwd();
103103
return ng(
104-
['generate', 'directive', 'child-dir' + path.sep + '..' + path.sep + 'my-comp'])
104+
['generate', 'directive', 'child-dir' + path.sep + '..' + path.sep + 'my-dir'])
105105
})
106106
.then(() => {
107107
var testPath =
108-
path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts');
108+
path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '1', 'my-dir', 'my-dir.ts');
109109
expect(existsSync(testPath)).to.equal(true);
110110
}, err => console.log('ERR: ', err));
111111
});
112112

113-
it('ng generate directive ' + path.sep + 'my-comp from a child dir, gens under ' +
114-
path.join('src', 'app'),
113+
it('ng generate directive ' + path.sep + 'my-dir from a child dir, gens under ' +
114+
path.join('src', 'client', 'app'),
115115
() => {
116116
return new Promise(function (resolve) {
117117
process.chdir('./src');
@@ -122,17 +122,17 @@ describe('Acceptance: ng generate directive', function () {
122122
.then(() => process.chdir('./1'))
123123
.then(() => {
124124
process.env.CWD = process.cwd();
125-
return ng(['generate', 'directive', path.sep + 'my-comp'])
125+
return ng(['generate', 'directive', path.sep + 'my-dir'])
126126
})
127127
.then(() => {
128-
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts');
128+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-dir', 'my-dir.ts');
129129
expect(existsSync(testPath)).to.equal(true);
130130
}, err => console.log('ERR: ', err));
131131
});
132132

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');
133+
it('ng generate directive ..' + path.sep + 'my-dir from root dir will fail', () => {
134+
return ng(['generate', 'directive', '..' + path.sep + 'my-dir']).then(() => {
135+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', '..', 'my-dir', 'my-dir.ts');
136136
expect(existsSync(testPath)).to.equal(false);
137137
});
138138
});

0 commit comments

Comments
 (0)