Skip to content

Commit 641ca23

Browse files
jorgeucanoSanderElias
authored andcommitted
Schematics/multiproject (#227)
* schematics(project): add option project for support multi-projects apps * schematics(projects): move to configure the project by default * schematics(projects): change creation of scully.config.js * schematics(projects): fix name of projectName * schematics(projects): change options for support project into npm run scully * Schematics(test): update test for support project * schematics(project): fix missing project function * feat(schematics): add project option for support multiple project * improvement(scully): rewrite the scully.config.js everytime with the project name * feat(scully): check project option exist in angular.json
1 parent 965ef93 commit 641ca23

File tree

19 files changed

+109
-81
lines changed

19 files changed

+109
-81
lines changed
61.8 KB
Binary file not shown.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function(options: Schema): Rule {
1010
slug: 'slug',
1111
sourceDir: 'blog',
1212
route: 'blog',
13+
project: options.project,
1314
};
1415

1516
if (options.routingScope) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
"type": "string",
1010
"description": "The scope for the new routing module.",
1111
"default": "Child"
12+
},
13+
"project": {
14+
"type": "string",
15+
"description": "add the project",
16+
"default": "defaultProject"
1217
}
1318
},
1419
"required": []

schematics/scully/src/add-blog/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export interface Schema {
33
* The scope for the new routing module.
44
*/
55
routingScope?: 'Child' | 'Root';
6+
project?: string;
67
}

schematics/scully/src/add-plugin/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {Rule, Tree, url, applyTemplates, move, chain, SchematicContext} from '@angular-devkit/schematics';
22
import {strings, normalize} from '@angular-devkit/core';
33
import {Schema} from './schema';
4-
import {applyWithOverwrite, getRoot} from '../utils/utils';
4+
import {applyWithOverwrite, getRoot, getScullyConfig} from '../utils/utils';
55

66
export default (options: Schema): Rule => {
77
return chain([addPlugin(options), registerPlugin(options)]);
88
};
99

1010
const addPlugin = (options: Schema) => (tree: Tree, context: SchematicContext) => {
11-
const sourceRoot = getRoot(tree);
11+
const sourceRoot = getRoot(tree, options.project);
1212
const pathName = strings.dasherize(`${sourceRoot}/scullyPlugins/${options.name}.js`);
1313
return applyWithOverwrite(url('../files/add-plugin'), [
1414
applyTemplates({
@@ -22,7 +22,8 @@ const addPlugin = (options: Schema) => (tree: Tree, context: SchematicContext) =
2222
};
2323

2424
const registerPlugin = (options: Schema) => (tree: Tree, context: SchematicContext) => {
25-
let scullyConfig = tree.read(`${getRoot(tree)}/scully.config.js`).toString();
25+
const scullyConfigFile = getScullyConfig(tree, options.project);
26+
let scullyConfig = tree.read(`${getRoot(tree, options.project)}/${scullyConfigFile}`).toString();
2627
scullyConfig = `require('./scullyPlugins/extra-plugin.js');\n${scullyConfig}`;
27-
tree.overwrite(`${getRoot(tree)}/scully.config.js`, scullyConfig);
28+
tree.overwrite(`${getRoot(tree, options.project)}/${scullyConfigFile}`, scullyConfig);
2829
};

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"type": "string",
99
"description": "add the name for the plugin",
1010
"x-prompt": "What name do you want to use for the plugin?"
11+
},
12+
"project": {
13+
"type": "string",
14+
"description": "add the project",
15+
"default": "defaultProject"
1116
}
1217
},
1318
"required": ["name"]

schematics/scully/src/add-plugin/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export interface Schema {
33
* add the name for the plugin
44
*/
55
name: string;
6+
project: string;
67
}

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,18 @@ import {
1010
getSrc,
1111
getFileContents,
1212
toAscii,
13+
getScullyConfig,
1314
} from '../utils/utils';
1415
import {RunSchematicTask} from '@angular-devkit/schematics/tasks';
1516

16-
const SCULLY_CONF_FILE = '/scully.config.js';
1717
const ANGULAR_CONF_FILE = './angular.json';
1818

1919
export default (options: Schema): Rule => {
2020
options.name = toAscii(options.name) || 'blog';
2121
options.slug = toAscii(options.slug) || 'id';
2222
options.route = toAscii(options.route) || options.name;
2323
options.sourceDir = options.sourceDir || options.name;
24-
return chain([
25-
addPost(options),
26-
updateScullyConfig(options),
27-
addModule(options),
28-
]);
24+
return chain([addPost(options), updateScullyConfig(options), addModule(options)]);
2925
};
3026

3127
const addPost = (options: Schema) => (tree: Tree, context: SchematicContext) => {
@@ -45,9 +41,10 @@ const addPost = (options: Schema) => (tree: Tree, context: SchematicContext) =>
4541
};
4642

4743
const updateScullyConfig = (options: Schema) => (tree: Tree, context: SchematicContext) => {
48-
const scullyJs = getFileContents(tree, SCULLY_CONF_FILE);
44+
const scullyConfigFile = getScullyConfig(tree, options.project);
45+
const scullyJs = getFileContents(tree, scullyConfigFile);
4946
if (!scullyJs) {
50-
context.logger.error(`No scully configuration file found ${SCULLY_CONF_FILE}`);
47+
context.logger.error(`No scully configuration file found ${scullyConfigFile}`);
5148
}
5249
const newScullyJs = addRouteToScullyConfig(scullyJs, {
5350
name: options.name,
@@ -57,16 +54,16 @@ const updateScullyConfig = (options: Schema) => (tree: Tree, context: SchematicC
5754
route: options.route,
5855
});
5956

60-
tree.overwrite(SCULLY_CONF_FILE, newScullyJs);
61-
context.logger.info(`✅️ Update ${SCULLY_CONF_FILE}`);
57+
tree.overwrite(scullyConfigFile, newScullyJs);
58+
context.logger.info(`✅️ Update ${scullyConfigFile}`);
6259
};
6360

6461
const addModule = (options: Schema) => (tree: Tree, context: SchematicContext) => {
65-
const sourceDir = getSrc(tree);
62+
const sourceDir = getSrc(tree, options.project);
6663
const pathName = strings.dasherize(`${sourceDir}/app/${options.name}`);
6764
let prefix = 'app';
6865
if (tree.exists(ANGULAR_CONF_FILE)) {
69-
prefix = getPrefix(getFileContents(tree, ANGULAR_CONF_FILE));
66+
prefix = getPrefix(tree, getFileContents(tree, ANGULAR_CONF_FILE), options.project);
7067
addRouteToModule(tree, options);
7168
}
7269

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('create-markdown', () => {
1515
const defaultOptions: Schema = {
1616
name: '',
1717
slug: '',
18+
project: 'defaultProject',
1819
};
1920
let appTree: UnitTestTree;
2021

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"type": "string",
3232
"description": "define the route where your post will be available",
3333
"x-prompt": "Under which route do you want your files to be requested?"
34+
},
35+
"project": {
36+
"type": "string",
37+
"description": "add the project",
38+
"default": "defaultProject"
3439
}
3540
},
3641
"required": ["name", "slug"]

0 commit comments

Comments
 (0)