Skip to content

Commit ddfea57

Browse files
authored
Schematics/scully config js (#11)
* schematics(feature): support scully.conf.js * schematics(js): add config for projectRoot
1 parent 0bf2a11 commit ddfea57

File tree

11 files changed

+103
-28
lines changed

11 files changed

+103
-28
lines changed
-32 KB
Binary file not shown.

schematics/scully/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schematics/scully/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scullyio/init",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Add scully to your angular app",
55
"repository": {
66
"type": "GIT",

schematics/scully/src/add-markdown/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"name": {
1414
"type": "string",
1515
"description": "add the name for the folder and module"
16+
},
17+
"slug": {
18+
"type": "string",
19+
"description": "add the name for the :${slug}"
1620
}
1721
},
1822
"required": []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export interface Schema {
22
name: string;
3+
slug?: string;
34
}

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics';
2+
import {addRouteToScullyConfig} from '../utils/utils';
3+
import {strings} from '@angular-devkit/core';
24
// @ts-ignore
35
export default function(options: any): Rule {
46
return (host: Tree, context: SchematicContext) => {
@@ -18,14 +20,13 @@ publish: false
1820
`);
1921
context.logger.info(`✅️Blog ${fullDay}-${name} file created`);
2022
}
21-
22-
context.logger.info(`start json scully`);
23+
/*
2324
// add into scully config
2425
try {
2526
const content: Buffer | null = host.read(`/scully.json`);
2627
let jsonContent;
2728
if (content) { jsonContent = JSON.parse(content.toString()); }
28-
/* tslint:disable:no-string-literal */
29+
/* tslint:disable:no-string-literal
2930
jsonContent.routes['/blog/:slug'] = {
3031
type: 'contentFolder',
3132
slug: {
@@ -37,6 +38,26 @@ publish: false
3738
} catch (e) {
3839
context.logger.error('Cant update scully.json');
3940
}
41+
*/
42+
let scullyJson;
43+
try {
44+
scullyJson = (host.read('/scully.config.js')).toString();
45+
} catch (e) {
46+
// for test in schematics
47+
scullyJson = `exports.config = {
48+
routes: {
49+
'/demo/:id': {
50+
type: 'fake',
51+
numberOfPages: 100
52+
},
53+
},
54+
};`;
55+
}
56+
const newScullyJson = addRouteToScullyConfig(scullyJson, {name: 'blog', slug: 'slug', type: 'contentFolder'});
57+
host.overwrite(`/scully.config.js`, newScullyJson);
58+
context.logger.info('✅️ Update scully.config.js');
59+
60+
options.path = options.path ? options.path : strings.dasherize(`./src/app/${name}`);
4061

4162
// test schematics
4263
let path = './src/files/blog-module/';

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66

77
import { strings, normalize } from '@angular-devkit/core';
88
import {Schema as MyServiceSchema} from './schema';
9+
import {addRouteToScullyConfig} from '../utils/utils';
910

1011
export default function(options: MyServiceSchema): Rule {
1112
return (host: Tree, context: SchematicContext) => {
@@ -26,24 +27,26 @@ publish: false
2627
`);
2728
context.logger.info(`✅ ${fullDay}-${name} file created`);
2829
}
29-
context.logger.info(`start json scully`);
30-
// add into scully config
30+
31+
let scullyJson;
3132
try {
32-
const content: Buffer | null = host.read(`/scully.json`);
33-
let jsonContent;
34-
if (content) { jsonContent = JSON.parse(content.toString()); }
35-
/* tslint:disable:no-string-literal */
36-
jsonContent.routes[`${name}/:id`] = {
37-
type: 'contentFolder',
38-
id: {
39-
folder: './${name}'
40-
}
41-
};
42-
host.overwrite(`/scully.json`, JSON.stringify(jsonContent, undefined, 2));
43-
context.logger.info('✅️ Update scully.json');
33+
scullyJson = (host.read('/scully.config.js')).toString();
4434
} catch (e) {
45-
context.logger.error('Cant update scully.json');
35+
// for test in schematics
36+
scullyJson = `exports.config = {
37+
projectRoot: "./src/app",
38+
routes: {
39+
'/demo/:id': {
40+
type: 'fake',
41+
numberOfPages: 100
42+
},
43+
},
44+
};`;
4645
}
46+
const slug = options.slug ? options.slug : 'id';
47+
const newScullyJson = addRouteToScullyConfig(scullyJson, {name, slug, type: 'contentFolder'});
48+
host.overwrite(`/scully.config.js`, newScullyJson);
49+
context.logger.info('✅️ Update scully.config.js');
4750

4851
options.path = options.path ? options.path : strings.dasherize(`./src/app/${name}`);
4952

schematics/scully/src/create-markdown/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"name": {
1414
"type": "string",
1515
"description": "add the name for the folder and module"
16+
},
17+
"slug": {
18+
"type": "string",
19+
"description": "add the name for the :${slug}"
1620
}
1721
},
1822
"required": []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface Schema {
22
name: string;
33
path?: string;
4+
slug?: string;
45
}

schematics/scully/src/scully/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ export function scully(options: any): Rule {
2222
context.logger.info('✅️ Update package.json');
2323

2424
// add config file
25-
if (!tree.exists('./scully.json')) {
26-
tree.create('./scully.json',
27-
`{
28-
"projectRoot": "./src/app",
29-
"routes": {
25+
if (!tree.exists('./scully.config.js')) {
26+
tree.create('./scully.config.js',
27+
`exports.config = {
28+
projectRoot: "./src/app",
29+
routes: {
3030
}
31-
}
32-
`);
31+
};`);
3332
}
3433

3534
// end return

0 commit comments

Comments
 (0)