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
Binary file modified schematics/scully/scullyio-init-0.0.7.tgz
Binary file not shown.
10 changes: 6 additions & 4 deletions schematics/scully/src/create-markdown/index.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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',
Expand All @@ -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());
Expand Down
14 changes: 8 additions & 6 deletions schematics/scully/src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -24,25 +25,26 @@ 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 {
polyfills = `${polyfills}\n/***************************************************************************************************
\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';
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion schematics/scully/src/scully/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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: {
}
};`);
Expand Down
13 changes: 10 additions & 3 deletions schematics/scully/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Binary file added scully/scullyio-scully-0.0.45.tgz
Binary file not shown.