Skip to content

Commit 8fe07c6

Browse files
committed
fix(): fixed paths internal in files
The paths/url references inside files were not changed to allow for dynamic paths Added the ability to utlize dynamic paths from within the project structure
1 parent e802a8f commit 8fe07c6

File tree

7 files changed

+82
-14
lines changed

7 files changed

+82
-14
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ You can use the `ng generate` (or just `ng g`) command to generate Angular compo
7070
```bash
7171
ng generate component my-new-component
7272
ng g component my-new-component # using the alias
73+
74+
# components support relative path generation
75+
# if in the directory src/app/feature/ and you run
76+
ng g component new-cmp
77+
# your component will be generated in src/app/feature/new-cmp
78+
# but if you were to run
79+
ng g component ../newer-cmp
80+
# your component will be generated in src/app/newer-cmp
7381
```
7482
You can find all possible blueprints in the table below:
7583

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
var component = require('../component');
2-
3-
module.exports = component;
1+
module.exports = {
2+
description: '',
3+
4+
// ******************************************************
5+
// ******************************************************
6+
// LEAVE THIS HERE
7+
// Must override install to prevent ember's component tests
8+
// ******************************************************
9+
// ******************************************************
10+
11+
install: function(options){}
12+
};

addon/ng2/blueprints/component/files/src/app/__path__/__name__/__name__.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {Component} from 'angular2/core';
33

44
@Component({
55
selector: '<%= dasherizedModuleName %>',
6-
templateUrl: 'app/components/<%= dasherizedModuleName %>/<%= dasherizedModuleName %>.html',
7-
styleUrls: ['app/components/<%= dasherizedModuleName %>/<%= dasherizedModuleName %>.css'],
6+
templateUrl: 'app/<%= dynamicPath %>/<%= dasherizedModuleName %>/<%= dasherizedModuleName %>.html',
7+
styleUrls: ['app/<%= dynamicPath %>/<%= dasherizedModuleName %>/<%= dasherizedModuleName %>.css'],
88
providers: [],
99
directives: [],
1010
pipes: []

addon/ng2/blueprints/component/index.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
var stringUtils = require('ember-cli/lib/utilities/string');
22
var path = require('path');
3+
var process = require('process');
34

45
module.exports = {
56
description: '',
6-
7-
locals: function(options) {
8-
var parsedPath = path.parse(options.entity.name);
9-
// build the locals for generating the name & path
10-
return {
7+
8+
normalizeEntityName: function(entityName){
9+
var rootPath = path.join(this.project.root, 'src', 'app');
10+
11+
var outputPath = path.join(process.env.PWD, entityName);
12+
13+
if (outputPath.indexOf(rootPath) < 0) {
14+
throw `Invalid component path: "${entityName}" cannot be above the "${path.join('src', 'app')}" directory`;
15+
}
16+
17+
var adjustedPath = outputPath.replace(rootPath, '');
18+
19+
var parsedPath = path.parse(adjustedPath);
20+
this.dynamicPath = {
1121
name: parsedPath.name,
1222
path: parsedPath.dir
1323
};
24+
return parsedPath.name;
25+
},
26+
27+
locals: function(options){
28+
return {
29+
dynamicPath: this.dynamicPath.path
30+
}
1431
},
1532

1633
fileMapTokens: function(options) {
1734
// Return custom template variables here.
1835
return {
19-
__name__: function(options) {
20-
return options.locals.name;
36+
__name__: (options) => {
37+
return this.dynamicPath.name;
2138
},
22-
__path__: function(options) {
23-
return options.locals.path || 'components';
39+
__path__: (options) => {
40+
return this.dynamicPath.path || 'components';
2441
}
2542
};
2643
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
it,
3+
iit,
4+
describe,
5+
ddescribe,
6+
expect,
7+
inject,
8+
injectAsync,
9+
TestComponentBuilder,
10+
beforeEachProviders
11+
} from 'angular2/testing';
12+
import {provide} from 'angular2/core';
13+
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>';
14+
15+
16+
describe('<%= classifiedModuleName %> Service', () => {
17+
18+
beforeEachProviders(() => [<%= classifiedModuleName %>]);
19+
20+
21+
it('should ...', inject([<%= classifiedModuleName %>], (service:<%= classifiedModuleName %>) => {
22+
23+
}));
24+
25+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Injectable} from 'angular2/core';
2+
3+
4+
@Injectable()
5+
export class <%= classifiedModuleName %> {
6+
7+
constructor() {}
8+
9+
}

0 commit comments

Comments
 (0)