diff --git a/schematics/scully/src/create-markdown/index.ts b/schematics/scully/src/create-markdown/index.ts index b11245770..86fc53013 100644 --- a/schematics/scully/src/create-markdown/index.ts +++ b/schematics/scully/src/create-markdown/index.ts @@ -19,17 +19,18 @@ const ANGULAR_CONF_FILE = './angular.json'; export default (options: Schema): Rule => { options.name = toAscii(options.name) || 'blog'; options.slug = toAscii(options.slug) || 'id'; + options.route = toAscii(options.route) || options.name; options.sourceDir = options.sourceDir || options.name; return chain([ - addPost(options, options.sourceDir), - updateScullyConfig(options.sourceDir, options), + addPost(options), + updateScullyConfig(options), addModule(options), ]); }; -const addPost = (options: Schema, target: string) => (tree: Tree, context: SchematicContext) => { +const addPost = (options: Schema) => (tree: Tree, context: SchematicContext) => { const nameDasherized = strings.dasherize(options.name); - const targetDirName = strings.dasherize(target); + const targetDirName = strings.dasherize(options.sourceDir); const date = new Date(); // format yyyy-mm-dd const fullDay = date.toISOString().substring(0, 10); @@ -43,7 +44,7 @@ const addPost = (options: Schema, target: string) => (tree: Tree, context: Schem } }; -const updateScullyConfig = (target: string, options: Schema) => (tree: Tree, context: SchematicContext) => { +const updateScullyConfig = (options: Schema) => (tree: Tree, context: SchematicContext) => { const scullyJs = getFileContents(tree, SCULLY_CONF_FILE); if (!scullyJs) { context.logger.error(`No scully configuration file found ${SCULLY_CONF_FILE}`); @@ -52,7 +53,7 @@ const updateScullyConfig = (target: string, options: Schema) => (tree: Tree, con name: options.name, slug: options.slug, type: 'contentFolder', - sourceDir: target, + sourceDir: options.sourceDir, route: options.route, }); diff --git a/schematics/scully/src/create-markdown/index_spec.ts b/schematics/scully/src/create-markdown/index_spec.ts index fe4d14e4e..5966c5b8b 100644 --- a/schematics/scully/src/create-markdown/index_spec.ts +++ b/schematics/scully/src/create-markdown/index_spec.ts @@ -81,7 +81,7 @@ describe('create-markdown', () => { describe('when using a specific `slug`', () => { beforeEach(async () => { appTree = await schematicRunner - .runSchematicAsync('md', {...defaultOptions, slug: 'FooBar Baz'}, appTree) + .runSchematicAsync('md', {...defaultOptions, slug: 'Foo&Bar !Baz'}, appTree) .toPromise(); }); it(`should update the file ${SCULLY_CONF_FILE} and `, () => { @@ -145,7 +145,7 @@ describe('create-markdown', () => { describe('when using a default specific `sourceDir`', () => { beforeEach(async () => { appTree = await schematicRunner - .runSchematicAsync('md', {...defaultOptions, route: 'bar'}, appTree) + .runSchematicAsync('md', {...defaultOptions, route: 'ba%r!'}, appTree) .toPromise(); }); it(`should update the file ${SCULLY_CONF_FILE}`, () => { @@ -174,7 +174,7 @@ describe('create-markdown', () => { describe('when using a specific module name', () => { beforeEach(async () => { appTree = await schematicRunner - .runSchematicAsync('md', {...defaultOptions, name: 'fooBar Baz'}, appTree) + .runSchematicAsync('md', {...defaultOptions, name: 'foo§Bar =Baz'}, appTree) .toPromise(); }); it('should create the markdown file by calling the post schematic', () => { diff --git a/schematics/scully/src/scully/index_spec.ts b/schematics/scully/src/scully/index_spec.ts index 87470827e..be4a7d628 100644 --- a/schematics/scully/src/scully/index_spec.ts +++ b/schematics/scully/src/scully/index_spec.ts @@ -43,7 +43,7 @@ describe('scully schematic', () => { const scullyConfFile = getFileContent(appTree, SCULLY_PATH); expect(scullyConfFile).toEqual(`exports.config = { projectRoot: "./src/app", - outFolder: './dist/static', + outDir: './dist/static', routes: { } };`); diff --git a/schematics/scully/src/utils/utils.ts b/schematics/scully/src/utils/utils.ts index 89f932f93..086db5e5a 100644 --- a/schematics/scully/src/utils/utils.ts +++ b/schematics/scully/src/utils/utils.ts @@ -27,8 +27,8 @@ interface Data { name: string; type: string; slug: string; + route: string; sourceDir?: string; - route?: string; } export interface PackageJson { @@ -42,7 +42,7 @@ export interface PackageJsonConfigPart { } export function addRouteToScullyConfig(scullyConfigJs: string, data: Data) { - const baseRoute = data.route ? strings.dasherize(data.route) : strings.dasherize(data.name); + const baseRoute = strings.dasherize(data.route); const completeRoute = normalize(`/${baseRoute}/:${strings.camelize(data.slug)}`); const contentDirectoy = data.sourceDir ? strings.dasherize(data.sourceDir) : strings.dasherize(data.name); const addRoute = `\n '${completeRoute}': { @@ -241,6 +241,7 @@ export const yamlToJson = (filePath: string) => { export const jsonToJaml = (metaData: {}) => yaml.safeDump(metaData); export const toAscii = (src: string) => { + if (!src) { return null; } // tslint:disable-next-line:one-variable-per-declaration let ch, str,