Skip to content

Commit df0190d

Browse files
authored
feat(schematics): add support for nx monorepos (#162)
fix #108
1 parent 9980f5f commit df0190d

6 files changed

Lines changed: 27 additions & 14 deletions

File tree

575 KB
Binary file not shown.

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Rule, Tree, url, applyTemplates, move, chain, SchematicContext } from '@angular-devkit/schematics';
22
import { strings, normalize } from '@angular-devkit/core';
33
import {Schema as MyServiceSchema} from './schema';
4-
import {addRouteToModule, addRouteToScullyConfig, applyWithOverwrite, getPrefix} from '../utils/utils';
4+
import {addRouteToModule, addRouteToScullyConfig, applyWithOverwrite, getPrefix, getSrc} from '../utils/utils';
55

66
export default function(options: MyServiceSchema): Rule {
77
return (host: Tree, context: SchematicContext) => {
@@ -29,8 +29,10 @@ publish: false
2929
scullyJson = (host.read('/scully.config.js')).toString();
3030
} catch (e) {
3131
// for test in schematics
32+
// tslint:disable-next-line:no-shadowed-variable
33+
const srcFolder = getSrc(host);
3234
scullyJson = `exports.config = {
33-
projectRoot: "./src/app",
35+
projectRoot: "${srcFolder}/app",
3436
routes: {
3537
'/demo/:id': {
3638
type: 'fake',
@@ -43,8 +45,8 @@ publish: false
4345
const newScullyJson = addRouteToScullyConfig(scullyJson, {name, slug: options.slug, type: 'contentFolder'});
4446
host.overwrite(`/scully.config.js`, newScullyJson);
4547
context.logger.info('✅️ Update scully.config.js');
46-
47-
options.path = options.path ? options.path : strings.dasherize(`./src/app/${name}`);
48+
const srcFolder = getSrc(host);
49+
options.path = options.path ? options.path : strings.dasherize(`${srcFolder}/app/${name}`);
4850
let prefix = 'app';
4951
if (host.exists('./angular.json')) {
5052
prefix = getPrefix(host.read('./angular.json').toString());

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Schema} from './schema';
66
import {scullyVersion, scullyComponentVersion} from './version-names';
77
import {addModuleImportToRootModule, getProjectFromWorkspace, getWorkspace} from 'schematics-utilities';
88
import {NodePackageInstallTask, RunSchematicTask} from '@angular-devkit/schematics/tasks';
9+
import {getSrc} from '../utils/utils';
910

1011
export default function(options: Schema): Rule {
1112
return (host: Tree, context: SchematicContext) => {
@@ -24,25 +25,26 @@ export default function(options: Schema): Rule {
2425
} catch (e) { }
2526

2627
// add new polyfills
28+
const srcFolder = getSrc(host);
2729
// @ts-ignore
28-
let polyfills = host.read('./src/polyfills.ts').toString();
30+
let polyfills = host.read(`${srcFolder}/polyfills.ts`).toString();
2931
if (polyfills.includes('SCULLY IMPORTS')) {
3032
context.logger.info('⚠️️ Skipping polyfills.ts');
3133
} else {
3234
polyfills = `${polyfills}\n/***************************************************************************************************
3335
\n* SCULLY IMPORTS
3436
\n*/
3537
\n// tslint:disable-next-line: align \nimport 'zone.js/dist/task-tracking';`;
36-
host.overwrite('./src/polyfills.ts', polyfills);
38+
host.overwrite(`${srcFolder}/polyfills.ts`, polyfills);
3739
}
3840

3941
try {
4042
// inject idleService
41-
const appComponent = host.read('./src/app/app.component.ts').toString();
43+
const appComponent = host.read(`${srcFolder}/app/app.component.ts`).toString();
4244
if (appComponent.includes('IdleMonitorService')) {
43-
context.logger.info('⚠️️ Skipping ./src/app/app.component.ts');
45+
context.logger.info(`⚠️️ Skipping ${srcFolder}/app/app.component.ts`);
4446
} else {
45-
const idleImport = "import {IdleMonitorService, TransferStateService} from '@scullyio/ng-lib';";
47+
const idleImport = 'import {IdleMonitorService, TransferStateService} from \'@scullyio/ng-lib\';';
4648
// add
4749
const idImport = `${idleImport} \n ${appComponent}`;
4850
const idle = 'private idle: IdleMonitorService, private transferState: TransferStateService';
@@ -65,7 +67,7 @@ export default function(options: Schema): Rule {
6567
output = [idImport.slice(0, position), add, idImport.slice(position)].join('');
6668
}
6769
}
68-
host.overwrite('./src/app/app.component.ts', output);
70+
host.overwrite(`${srcFolder}/app/app.component.ts`, output);
6971
}
7072

7173
function haveMoreInjects(fullComponent: string) {

schematics/scully/src/scully/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Rule, SchematicContext, Tree, SchematicsException} from '@angular-devkit/schematics';
2+
import {getSrc} from '../utils/utils';
23
// for now we dont have any option for use
34
// @ts-ignore
45
export function scully(options: any): Rule {
@@ -23,9 +24,10 @@ export function scully(options: any): Rule {
2324

2425
// add config file
2526
if (!tree.exists('./scully.config.js')) {
27+
const srcFolder = getSrc(tree);
2628
tree.create('./scully.config.js',
2729
`exports.config = {
28-
projectRoot: "./src/app",
30+
projectRoot: "${srcFolder}/app",
2931
routes: {
3032
}
3133
};`);

schematics/scully/src/utils/utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ export function getPrefix(angularjson: string) {
9090
}
9191

9292
export function addRouteToModule(host: Tree, options: any) {
93-
94-
let path = './src/app/app-routing.module.ts';
93+
const srcFolder = getSrc(host);
94+
let path = `${srcFolder}/app/app-routing.module.ts`;
9595
if (!host.exists(path)) {
96-
path = './src/app/app.module.ts';
96+
path = `${srcFolder}/app/app.module.ts`;
9797
}
9898
const text = host.read(path);
9999
if (!text) {
@@ -129,3 +129,10 @@ function buildRelativeModulePath(options: ModuleOptions, modulePath: string): st
129129

130130
return buildRelativePath(modulePath, importModulePath);
131131
}
132+
133+
export function getSrc(host: Tree) {
134+
const angularConfig = JSON.parse(host.read('./angular.json').toString());
135+
// TODO: make scully handle other projects as just the default one.
136+
const defaultProject = angularConfig.defaultProject;
137+
return angularConfig.projects[defaultProject].sourceRoot;
138+
}

scully/scullyio-scully-0.0.45.tgz

149 KB
Binary file not shown.

0 commit comments

Comments
 (0)