Skip to content

Commit c696383

Browse files
committed
feat: add components/directives/pipes/services to barrel when generated into a shared dir
1 parent aac9abf commit c696383

File tree

8 files changed

+132
-8
lines changed

8 files changed

+132
-8
lines changed

addon/ng2/blueprints/component/index.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var path = require('path');
22
var Blueprint = require('ember-cli/lib/models/blueprint');
33
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
4-
4+
var addBarrelRegistration = require('../../utilities/barrel-management');
55
var getFiles = Blueprint.prototype.files;
66

77
module.exports = {
@@ -35,10 +35,10 @@ module.exports = {
3535
files: function() {
3636
var fileList = getFiles.call(this);
3737

38-
if (this.options.flat) {
38+
if (this.options && this.options.flat) {
3939
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
4040
}
41-
if (!this.options.route) {
41+
if (this.options && !this.options.route) {
4242
fileList = fileList.filter(p => p.indexOf(path.join('shared', 'index.ts')) <= 0);
4343
}
4444

@@ -60,6 +60,7 @@ module.exports = {
6060
}
6161
}
6262
this.appDir = dir.replace(`src${path.sep}client${path.sep}`, '');
63+
this.generatePath = dir;
6364
return dir;
6465
},
6566
__styleext__: () => {
@@ -72,11 +73,20 @@ module.exports = {
7273
if (!options.flat) {
7374
var filePath = path.join('src', 'client', 'system-config.ts');
7475
var barrelUrl = this.appDir.replace(path.sep, '/');
75-
return this.insertIntoFile(
76-
filePath,
77-
` '${barrelUrl}',`,
78-
{ before: ' /** @cli-barrel */' }
79-
);
76+
77+
return addBarrelRegistration(this, this.generatePath)
78+
.then(() => {
79+
return this.insertIntoFile(
80+
filePath,
81+
` '${barrelUrl}',`,
82+
{ before: ' /** @cli-barrel */' }
83+
);
84+
})
85+
} else {
86+
return addBarrelRegistration(
87+
this,
88+
this.generatePath,
89+
options.entity.name + '.component');
8090
}
8191
}
8292
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive';

addon/ng2/blueprints/directive/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
var path = require('path');
2+
var Blueprint = require('ember-cli/lib/models/blueprint');
23
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
4+
var addBarrelRegistration = require('../../utilities/barrel-management');
5+
var getFiles = Blueprint.prototype.files;
36

47
module.exports = {
58
description: '',
@@ -23,6 +26,16 @@ module.exports = {
2326
rawEntityName: this.rawEntityName
2427
};
2528
},
29+
30+
files: function() {
31+
var fileList = getFiles.call(this);
32+
33+
if (this.options && this.options.flat) {
34+
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
35+
}
36+
37+
return fileList;
38+
},
2639

2740
fileMapTokens: function (options) {
2841
// Return custom template variables here.
@@ -32,8 +45,22 @@ module.exports = {
3245
if (!options.locals.flat) {
3346
dir += path.sep + options.dasherizedModuleName;
3447
}
48+
this.generatePath = dir;
3549
return dir;
3650
}
3751
};
52+
},
53+
54+
afterInstall: function(options) {
55+
if (!options.flat) {
56+
return addBarrelRegistration(
57+
this,
58+
this.generatePath);
59+
} else {
60+
return addBarrelRegistration(
61+
this,
62+
this.generatePath,
63+
options.entity.name + '.directive');
64+
}
3865
}
3966
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.pipe';

addon/ng2/blueprints/pipe/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
var path = require('path');
2+
var Blueprint = require('ember-cli/lib/models/blueprint');
23
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
4+
var addBarrelRegistration = require('../../utilities/barrel-management');
5+
var getFiles = Blueprint.prototype.files;
36

47
module.exports = {
58
description: '',
@@ -21,6 +24,16 @@ module.exports = {
2124
flat: options.flat
2225
};
2326
},
27+
28+
files: function() {
29+
var fileList = getFiles.call(this);
30+
31+
if (this.options && this.options.flat) {
32+
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
33+
}
34+
35+
return fileList;
36+
},
2437

2538
fileMapTokens: function (options) {
2639
// Return custom template variables here.
@@ -30,8 +43,22 @@ module.exports = {
3043
if (!options.locals.flat) {
3144
dir += path.sep + options.dasherizedModuleName;
3245
}
46+
this.generatePath = dir;
3347
return dir;
3448
}
3549
};
50+
},
51+
52+
afterInstall: function(options) {
53+
if (!options.flat) {
54+
return addBarrelRegistration(
55+
this,
56+
this.generatePath);
57+
} else {
58+
return addBarrelRegistration(
59+
this,
60+
this.generatePath,
61+
options.entity.name + '.pipe');
62+
}
3663
}
3764
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.service';

addon/ng2/blueprints/service/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
var path = require('path');
2+
var Blueprint = require('ember-cli/lib/models/blueprint');
23
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
4+
var addBarrelRegistration = require('../../utilities/barrel-management');
5+
var getFiles = Blueprint.prototype.files;
36

47
module.exports = {
58
description: '',
@@ -21,6 +24,16 @@ module.exports = {
2124
flat: options.flat
2225
};
2326
},
27+
28+
files: function() {
29+
var fileList = getFiles.call(this);
30+
31+
if (this.options && this.options.flat) {
32+
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
33+
}
34+
35+
return fileList;
36+
},
2437

2538
fileMapTokens: function (options) {
2639
// Return custom template variables here.
@@ -30,8 +43,22 @@ module.exports = {
3043
if (!options.locals.flat) {
3144
dir += path.sep + options.dasherizedModuleName;
3245
}
46+
this.generatePath = dir;
3347
return dir;
3448
}
3549
};
50+
},
51+
52+
afterInstall: function(options) {
53+
if (!options.flat) {
54+
return addBarrelRegistration(
55+
this,
56+
this.generatePath);
57+
} else {
58+
return addBarrelRegistration(
59+
this,
60+
this.generatePath,
61+
options.entity.name + '.service');
62+
}
3663
}
3764
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var path = require('path');
2+
var EOL = require('os').EOL;
3+
4+
module.exports = addBarrelRegistration;
5+
6+
function addBarrelRegistration(blueprint, installationDir, fileName) {
7+
var parts = installationDir.split(path.sep);
8+
var idx = -1;
9+
if (parts[parts.length - 1] === 'shared') {
10+
idx = parts.length - 1;
11+
} else if (parts[parts.length - 2] === 'shared') {
12+
idx = parts.length - 2;
13+
}
14+
15+
if (idx === -1) {
16+
return Promise.resolve();
17+
}
18+
19+
var sharedDir = parts.slice(0, idx + 1).join(path.sep);
20+
var relativeParts = parts.splice(idx + 1);
21+
if (fileName) {
22+
relativeParts.push(fileName);
23+
}
24+
var importFrom = './' + relativeParts.join('/');
25+
26+
return blueprint.insertIntoFile(
27+
sharedDir + path.sep + 'index.ts',
28+
`export * from '${importFrom}';${EOL}`
29+
);
30+
}

0 commit comments

Comments
 (0)