Skip to content

Commit

Permalink
feat: allow lazy route prefix to be configurable
Browse files Browse the repository at this point in the history
Fixes #842
  • Loading branch information
Brocco committed May 24, 2016
1 parent c92f330 commit c3fd9c7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion addon/ng2/blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ module.exports = {
dir += path.sep + options.dasherizedModuleName;

if (options.locals.isLazyRoute) {
var lazyRoutePrefix = '+';
if (this.project.ngConfig &&
this.project.ngConfig.defaults &&
this.project.ngConfig.defaults.lazyRoutePrefix !== undefined) {
lazyRoutePrefix = this.project.ngConfig.defaults.lazyRoutePrefix;
}
var dirParts = dir.split(path.sep);
dirParts[dirParts.length - 1] = `+${dirParts[dirParts.length - 1]}`;
dirParts[dirParts.length - 1] = `${lazyRoutePrefix}${dirParts[dirParts.length - 1]}`;
dir = dirParts.join(path.sep);
}
}
Expand Down
3 changes: 2 additions & 1 deletion addon/ng2/blueprints/ng2/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prefix": "<%= prefix %>",
"sourceDir": "<%= sourceDir %>",
"styleExt": "<%= styleExt %>",
"prefixInterfaces": false
"prefixInterfaces": false,
"lazyRoutePrefix": "+"
}
}
8 changes: 7 additions & 1 deletion addon/ng2/blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,14 @@ module.exports = {

// Insert the import statement.
let content = fs.readFileSync(parentFile, 'utf-8');
let lazyRoutePrefix = '+';
if (this.project.ngConfig &&
this.project.ngConfig.defaults &&
this.project.ngConfig.defaults.lazyRoutePrefix !== undefined) {
lazyRoutePrefix = this.project.ngConfig.defaults.lazyRoutePrefix;
}
content = _insertImport(content, `${jsComponentName}Component`,
`./${options.isLazyRoute ? '+' : ''}${stringUtils.dasherize(base)}`);
`./${options.isLazyRoute ? lazyRoutePrefix : ''}${stringUtils.dasherize(base)}`);

let defaultReg = options.default ? ', useAsDefault: true' : '';
let routePath = options.path || `/${base}`;
Expand Down
3 changes: 3 additions & 0 deletions lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
},
"prefixInterfaces": {
"type": "boolean"
},
"lazyRoutePrefix": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
10 changes: 10 additions & 0 deletions tests/acceptance/generate-route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,14 @@ describe('Acceptance: ng generate route', function () {
expect(afterGenerateParentHtml).to.equal(unmodifiedParentComponentHtml);
});
});

it('lazy route prefix', () => {
return ng(['set', 'defaults.lazyRoutePrefix', 'myprefix'])
.then(() => ng(['generate', 'route', 'prefix-test']))
.then(() => {
var folderPath = path.join(testPath, 'myprefixprefix-test', 'prefix-test.component.ts');
expect(existsSync(folderPath))
.to.equal(true);
});
});
});

0 comments on commit c3fd9c7

Please sign in to comment.