Skip to content

Commit 78da93b

Browse files
d-koppenhagenjorgeucano
authored andcommitted
feat: use only ascii chars within route option (#210)
* test(schematics): use `outDir` instead of `outFolder` * feat(schematics): do only use ascii chars for route option
1 parent f86196f commit 78da93b

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

schematics/scully/src/create-markdown/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ const ANGULAR_CONF_FILE = './angular.json';
1919
export default (options: Schema): Rule => {
2020
options.name = toAscii(options.name) || 'blog';
2121
options.slug = toAscii(options.slug) || 'id';
22+
options.route = toAscii(options.route) || options.name;
2223
options.sourceDir = options.sourceDir || options.name;
2324
return chain([
24-
addPost(options, options.sourceDir),
25-
updateScullyConfig(options.sourceDir, options),
25+
addPost(options),
26+
updateScullyConfig(options),
2627
addModule(options),
2728
]);
2829
};
2930

30-
const addPost = (options: Schema, target: string) => (tree: Tree, context: SchematicContext) => {
31+
const addPost = (options: Schema) => (tree: Tree, context: SchematicContext) => {
3132
const nameDasherized = strings.dasherize(options.name);
32-
const targetDirName = strings.dasherize(target);
33+
const targetDirName = strings.dasherize(options.sourceDir);
3334
const date = new Date();
3435
// format yyyy-mm-dd
3536
const fullDay = date.toISOString().substring(0, 10);
@@ -43,7 +44,7 @@ const addPost = (options: Schema, target: string) => (tree: Tree, context: Schem
4344
}
4445
};
4546

46-
const updateScullyConfig = (target: string, options: Schema) => (tree: Tree, context: SchematicContext) => {
47+
const updateScullyConfig = (options: Schema) => (tree: Tree, context: SchematicContext) => {
4748
const scullyJs = getFileContents(tree, SCULLY_CONF_FILE);
4849
if (!scullyJs) {
4950
context.logger.error(`No scully configuration file found ${SCULLY_CONF_FILE}`);
@@ -52,7 +53,7 @@ const updateScullyConfig = (target: string, options: Schema) => (tree: Tree, con
5253
name: options.name,
5354
slug: options.slug,
5455
type: 'contentFolder',
55-
sourceDir: target,
56+
sourceDir: options.sourceDir,
5657
route: options.route,
5758
});
5859

schematics/scully/src/create-markdown/index_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('create-markdown', () => {
8181
describe('when using a specific `slug`', () => {
8282
beforeEach(async () => {
8383
appTree = await schematicRunner
84-
.runSchematicAsync('md', {...defaultOptions, slug: 'FooBar Baz'}, appTree)
84+
.runSchematicAsync('md', {...defaultOptions, slug: 'Foo&Bar !Baz'}, appTree)
8585
.toPromise();
8686
});
8787
it(`should update the file ${SCULLY_CONF_FILE} and `, () => {
@@ -145,7 +145,7 @@ describe('create-markdown', () => {
145145
describe('when using a default specific `sourceDir`', () => {
146146
beforeEach(async () => {
147147
appTree = await schematicRunner
148-
.runSchematicAsync('md', {...defaultOptions, route: 'bar'}, appTree)
148+
.runSchematicAsync('md', {...defaultOptions, route: 'ba%r!'}, appTree)
149149
.toPromise();
150150
});
151151
it(`should update the file ${SCULLY_CONF_FILE}`, () => {
@@ -174,7 +174,7 @@ describe('create-markdown', () => {
174174
describe('when using a specific module name', () => {
175175
beforeEach(async () => {
176176
appTree = await schematicRunner
177-
.runSchematicAsync('md', {...defaultOptions, name: 'fooBar Baz'}, appTree)
177+
.runSchematicAsync('md', {...defaultOptions, name: 'foo§Bar =Baz'}, appTree)
178178
.toPromise();
179179
});
180180
it('should create the markdown file by calling the post schematic', () => {

schematics/scully/src/scully/index_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('scully schematic', () => {
4343
const scullyConfFile = getFileContent(appTree, SCULLY_PATH);
4444
expect(scullyConfFile).toEqual(`exports.config = {
4545
projectRoot: "./src/app",
46-
outFolder: './dist/static',
46+
outDir: './dist/static',
4747
routes: {
4848
}
4949
};`);

schematics/scully/src/utils/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ interface Data {
2727
name: string;
2828
type: string;
2929
slug: string;
30+
route: string;
3031
sourceDir?: string;
31-
route?: string;
3232
}
3333

3434
export interface PackageJson {
@@ -42,7 +42,7 @@ export interface PackageJsonConfigPart<T> {
4242
}
4343

4444
export function addRouteToScullyConfig(scullyConfigJs: string, data: Data) {
45-
const baseRoute = data.route ? strings.dasherize(data.route) : strings.dasherize(data.name);
45+
const baseRoute = strings.dasherize(data.route);
4646
const completeRoute = normalize(`/${baseRoute}/:${strings.camelize(data.slug)}`);
4747
const contentDirectoy = data.sourceDir ? strings.dasherize(data.sourceDir) : strings.dasherize(data.name);
4848
const addRoute = `\n '${completeRoute}': {
@@ -241,6 +241,7 @@ export const yamlToJson = (filePath: string) => {
241241
export const jsonToJaml = (metaData: {}) => yaml.safeDump(metaData);
242242

243243
export const toAscii = (src: string) => {
244+
if (!src) { return null; }
244245
// tslint:disable-next-line:one-variable-per-declaration
245246
let ch,
246247
str,

0 commit comments

Comments
 (0)