diff --git a/schematics/scully/scullyio-init-0.0.7.tgz b/schematics/scully/scullyio-init-0.0.7.tgz index 71b69a74f..f542e91d3 100644 Binary files a/schematics/scully/scullyio-init-0.0.7.tgz and b/schematics/scully/scullyio-init-0.0.7.tgz differ diff --git a/schematics/scully/src/create-markdown/index.ts b/schematics/scully/src/create-markdown/index.ts index afbb500d0..cd99f6858 100644 --- a/schematics/scully/src/create-markdown/index.ts +++ b/schematics/scully/src/create-markdown/index.ts @@ -1,7 +1,7 @@ import { Rule, Tree, url, applyTemplates, move, chain, SchematicContext } from '@angular-devkit/schematics'; import { strings, normalize } from '@angular-devkit/core'; import {Schema as MyServiceSchema} from './schema'; -import {addRouteToModule, addRouteToScullyConfig, applyWithOverwrite, getPrefix} from '../utils/utils'; +import {addRouteToModule, addRouteToScullyConfig, applyWithOverwrite, getPrefix, getSrc} from '../utils/utils'; export default function(options: MyServiceSchema): Rule { return (host: Tree, context: SchematicContext) => { @@ -29,8 +29,10 @@ publish: false scullyJson = (host.read('/scully.config.js')).toString(); } catch (e) { // for test in schematics + // tslint:disable-next-line:no-shadowed-variable + const srcFolder = getSrc(host); scullyJson = `exports.config = { - projectRoot: "./src/app", + projectRoot: "${srcFolder}/app", routes: { '/demo/:id': { type: 'fake', @@ -43,8 +45,8 @@ publish: false const newScullyJson = addRouteToScullyConfig(scullyJson, {name, slug: options.slug, type: 'contentFolder'}); host.overwrite(`/scully.config.js`, newScullyJson); context.logger.info('✅️ Update scully.config.js'); - - options.path = options.path ? options.path : strings.dasherize(`./src/app/${name}`); + const srcFolder = getSrc(host); + options.path = options.path ? options.path : strings.dasherize(`${srcFolder}/app/${name}`); let prefix = 'app'; if (host.exists('./angular.json')) { prefix = getPrefix(host.read('./angular.json').toString()); diff --git a/schematics/scully/src/ng-add/index.ts b/schematics/scully/src/ng-add/index.ts index 8054787c7..f9405f7d1 100644 --- a/schematics/scully/src/ng-add/index.ts +++ b/schematics/scully/src/ng-add/index.ts @@ -6,6 +6,7 @@ import {Schema} from './schema'; import {scullyVersion, scullyComponentVersion} from './version-names'; import {addModuleImportToRootModule, getProjectFromWorkspace, getWorkspace} from 'schematics-utilities'; import {NodePackageInstallTask, RunSchematicTask} from '@angular-devkit/schematics/tasks'; +import {getSrc} from '../utils/utils'; export default function(options: Schema): Rule { return (host: Tree, context: SchematicContext) => { @@ -24,8 +25,9 @@ export default function(options: Schema): Rule { } catch (e) { } // add new polyfills + const srcFolder = getSrc(host); // @ts-ignore - let polyfills = host.read('./src/polyfills.ts').toString(); + let polyfills = host.read(`${srcFolder}/polyfills.ts`).toString(); if (polyfills.includes('SCULLY IMPORTS')) { context.logger.info('⚠️️ Skipping polyfills.ts'); } else { @@ -33,16 +35,16 @@ export default function(options: Schema): Rule { \n* SCULLY IMPORTS \n*/ \n// tslint:disable-next-line: align \nimport 'zone.js/dist/task-tracking';`; - host.overwrite('./src/polyfills.ts', polyfills); + host.overwrite(`${srcFolder}/polyfills.ts`, polyfills); } try { // inject idleService - const appComponent = host.read('./src/app/app.component.ts').toString(); + const appComponent = host.read(`${srcFolder}/app/app.component.ts`).toString(); if (appComponent.includes('IdleMonitorService')) { - context.logger.info('⚠️️ Skipping ./src/app/app.component.ts'); + context.logger.info(`⚠️️ Skipping ${srcFolder}/app/app.component.ts`); } else { - const idleImport = "import {IdleMonitorService, TransferStateService} from '@scullyio/ng-lib';"; + const idleImport = 'import {IdleMonitorService, TransferStateService} from \'@scullyio/ng-lib\';'; // add const idImport = `${idleImport} \n ${appComponent}`; const idle = 'private idle: IdleMonitorService, private transferState: TransferStateService'; @@ -65,7 +67,7 @@ export default function(options: Schema): Rule { output = [idImport.slice(0, position), add, idImport.slice(position)].join(''); } } - host.overwrite('./src/app/app.component.ts', output); + host.overwrite(`${srcFolder}/app/app.component.ts`, output); } function haveMoreInjects(fullComponent: string) { diff --git a/schematics/scully/src/scully/index.ts b/schematics/scully/src/scully/index.ts index a5e74d62f..442d1efcf 100644 --- a/schematics/scully/src/scully/index.ts +++ b/schematics/scully/src/scully/index.ts @@ -1,4 +1,5 @@ import {Rule, SchematicContext, Tree, SchematicsException} from '@angular-devkit/schematics'; +import {getSrc} from '../utils/utils'; // for now we dont have any option for use // @ts-ignore export function scully(options: any): Rule { @@ -23,9 +24,10 @@ export function scully(options: any): Rule { // add config file if (!tree.exists('./scully.config.js')) { + const srcFolder = getSrc(tree); tree.create('./scully.config.js', `exports.config = { - projectRoot: "./src/app", + projectRoot: "${srcFolder}/app", routes: { } };`); diff --git a/schematics/scully/src/utils/utils.ts b/schematics/scully/src/utils/utils.ts index bd5648c46..1e2bbcb36 100644 --- a/schematics/scully/src/utils/utils.ts +++ b/schematics/scully/src/utils/utils.ts @@ -90,10 +90,10 @@ export function getPrefix(angularjson: string) { } export function addRouteToModule(host: Tree, options: any) { - - let path = './src/app/app-routing.module.ts'; + const srcFolder = getSrc(host); + let path = `${srcFolder}/app/app-routing.module.ts`; if (!host.exists(path)) { - path = './src/app/app.module.ts'; + path = `${srcFolder}/app/app.module.ts`; } const text = host.read(path); if (!text) { @@ -129,3 +129,10 @@ function buildRelativeModulePath(options: ModuleOptions, modulePath: string): st return buildRelativePath(modulePath, importModulePath); } + +export function getSrc(host: Tree) { + const angularConfig = JSON.parse(host.read('./angular.json').toString()); + // TODO: make scully handle other projects as just the default one. + const defaultProject = angularConfig.defaultProject; + return angularConfig.projects[defaultProject].sourceRoot; +} diff --git a/scully/scullyio-scully-0.0.45.tgz b/scully/scullyio-scully-0.0.45.tgz new file mode 100644 index 000000000..7330d6fef Binary files /dev/null and b/scully/scullyio-scully-0.0.45.tgz differ