Skip to content
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
13 changes: 7 additions & 6 deletions schematics/scully/src/create-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}`);
Expand All @@ -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,
});

Expand Down
6 changes: 3 additions & 3 deletions schematics/scully/src/create-markdown/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `, () => {
Expand Down Expand Up @@ -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}`, () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion schematics/scully/src/scully/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
}
};`);
Expand Down
5 changes: 3 additions & 2 deletions schematics/scully/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface Data {
name: string;
type: string;
slug: string;
route: string;
sourceDir?: string;
route?: string;
}

export interface PackageJson {
Expand All @@ -42,7 +42,7 @@ export interface PackageJsonConfigPart<T> {
}

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}': {
Expand Down Expand Up @@ -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,
Expand Down