Skip to content

chore(paths): dynamic paths for directives, pipes and services #286

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
Mar 10, 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
45 changes: 10 additions & 35 deletions addon/ng2/blueprints/component/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,24 @@
var stringUtils = require('ember-cli/lib/utilities/string');
var path = require('path');
var process = require('process');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');

module.exports = {
description: '',
normalizeEntityName: function(entityName){

normalizeEntityName: function(entityName) {
var cwd = this.project.cli.testing
? process.cwd()
: process.env.PWD;

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

if (outputPath.indexOf(rootPath) < 0) {
throw `Invalid component path: "${entityName}" cannot be ` +
`above the "${path.join('src', 'app')}" directory`;
}

var adjustedPath = outputPath.replace(rootPath, '');
var parsedPath = dynamicPathParser(cwd, this.project.root, entityName);

var parsedPath = path.parse(adjustedPath);
this.dynamicPath = {
name: parsedPath.name,
path: parsedPath.dir
};
this.dynamicPath = parsedPath;
return parsedPath.name;
},
locals: function(options){

locals: function(options) {
return {
dynamicPath: this.dynamicPath.path
}
dynamicPath: this.dynamicPath.dir
};
},

fileMapTokens: function(options) {
Expand All @@ -53,7 +28,7 @@ module.exports = {
return this.dynamicPath.name;
},
__path__: (options) => {
return this.dynamicPath.path;
return this.dynamicPath.dir;
}
};
}
Expand Down
35 changes: 35 additions & 0 deletions addon/ng2/blueprints/directive/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var stringUtils = require('ember-cli/lib/utilities/string');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');

module.exports = {
description: '',

normalizeEntityName: function(entityName) {
var cwd = this.project.cli.testing
? process.cwd()
: process.env.PWD;

var parsedPath = dynamicPathParser(cwd, this.project.root, entityName);

this.dynamicPath = parsedPath;
return parsedPath.name;
},

locals: function(options) {
return {
dynamicPath: this.dynamicPath.dir
};
},

fileMapTokens: function(options) {
// Return custom template variables here.
return {
__name__: (options) => {
return this.dynamicPath.name;
},
__path__: (options) => {
return this.dynamicPath.dir;
}
};
}
};
35 changes: 35 additions & 0 deletions addon/ng2/blueprints/pipe/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var stringUtils = require('ember-cli/lib/utilities/string');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');

module.exports = {
description: '',

normalizeEntityName: function(entityName) {
var cwd = this.project.cli.testing
? process.cwd()
: process.env.PWD;

var parsedPath = dynamicPathParser(cwd, this.project.root, entityName);

this.dynamicPath = parsedPath;
return parsedPath.name;
},

locals: function(options) {
return {
dynamicPath: this.dynamicPath.dir
};
},

fileMapTokens: function(options) {
// Return custom template variables here.
return {
__name__: (options) => {
return this.dynamicPath.name;
},
__path__: (options) => {
return this.dynamicPath.dir;
}
};
}
};

This file was deleted.

This file was deleted.

39 changes: 29 additions & 10 deletions addon/ng2/blueprints/service/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
var stringUtils = require('ember-cli/lib/utilities/string');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');

module.exports = {
description: ''
description: '',

//locals: function(options) {
// // Return custom template variables here.
// return {
//
// };
//}
normalizeEntityName: function(entityName) {
var cwd = this.project.cli.testing
? process.cwd()
: process.env.PWD;

var parsedPath = dynamicPathParser(cwd, this.project.root, entityName);

this.dynamicPath = parsedPath;
return parsedPath.name;
},

// afterInstall: function(options) {
// // Perform extra work here.
// }
locals: function(options) {
return {
dynamicPath: this.dynamicPath.dir
};
},

fileMapTokens: function(options) {
// Return custom template variables here.
return {
__name__: (options) => {
return this.dynamicPath.name;
},
__path__: (options) => {
return this.dynamicPath.dir;
}
};
}
};
30 changes: 30 additions & 0 deletions addon/ng2/utilities/dynamic-path-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var path = require('path');
var process = require('process');

module.exports = function dynamicPathParser(cwd, projectRoot, entityName) {
var rootPath = path.join(projectRoot, 'src', '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')) >= 0) {
outputPath = path.join(cwd, 'app', entityName);
}

if (outputPath.indexOf(rootPath) < 0) {
throw `Invalid path: "${entityName}" cannot be ` +
`above the "${path.join('src', 'app')}" directory`;
}

var adjustedPath = outputPath.replace(rootPath, '');

var parsedPath = path.parse(adjustedPath);

return parsedPath;
}
Loading