mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +08:00
Windows does not populate this fix allows for determination of the directory from which an ng command was executed Fixes #297
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
var path = require('path');
|
|
var process = require('process');
|
|
|
|
module.exports = function dynamicPathParser(project, entityName) {
|
|
var projectRoot = project.root;
|
|
var cwd = process.env.PWD;
|
|
|
|
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;
|
|
}
|