Skip to content

Commit 784c694

Browse files
authored
Sander/chores (#261)
* small fixes * fix(fix killserver on install bug): some small touchups
1 parent 1bd3fac commit 784c694

3 files changed

Lines changed: 19 additions & 115 deletions

File tree

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

Lines changed: 12 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import {chain, Rule, SchematicContext, SchematicsException, Tree} from '@angular-devkit/schematics';
2-
import {addPackageToPackageJson, getPackageVersionFromPackageJson} from './package-config';
3-
import {Schema} from './schema';
4-
import {scullyVersion, scullyComponentVersion} from './version-names';
52
import {NodePackageInstallTask, RunSchematicTask} from '@angular-devkit/schematics/tasks';
6-
import {getSourceFile, getSrc} from '../utils/utils';
3+
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
74
import {addImportToModule, insertImport} from '@schematics/angular/utility/ast-utils';
85
import {InsertChange} from '@schematics/angular/utility/change';
9-
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
10-
6+
import {getSourceFile, getSrc} from '../utils/utils';
7+
import {addPackageToPackageJson, getPackageVersionFromPackageJson} from './package-config';
8+
import {Schema} from './schema';
9+
import {scullyComponentVersion, scullyVersion} from './version-names';
1110
export default (options: Schema): Rule => {
1211
return chain([
13-
addDependencies(),
14-
// importHttpClientModule(options.project),
15-
// addHttpClientModule(options.project),
12+
checkAngularVersion(),
1613
importScullyModule(options.project),
1714
addScullyModule(options.project),
1815
addPolyfill(options.project),
19-
// injectIdleService(options.project),
2016
runBlogSchematic(options),
2117
runScullySchematic(options),
18+
addDependencies(),
2219
]);
2320
};
24-
const addDependencies = () => (tree: Tree, context: SchematicContext) => {
25-
addPackageToPackageJson(tree, '@scullyio/scully', `${scullyVersion}`);
21+
const checkAngularVersion = () => (tree: Tree, context: SchematicContext) => {
2622
const ngCoreVersionTag = getPackageVersionFromPackageJson(tree, '@angular/core');
2723
if (+ngCoreVersionTag.search(/(\^7|~7|\^6|~6|\^5|~5|\^4|~4)/g) === 0) {
2824
console.log('==============================================================');
@@ -33,6 +29,10 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {
3329
console.log('==============================================================');
3430
process.exit(0);
3531
}
32+
};
33+
const addDependencies = () => (tree: Tree, context: SchematicContext) => {
34+
addPackageToPackageJson(tree, '@scullyio/scully', `${scullyVersion}`);
35+
const ngCoreVersionTag = getPackageVersionFromPackageJson(tree, '@angular/core');
3636
if (+ngCoreVersionTag.search(/(\^8|~8)/g) === 0) {
3737
context.logger.info('Install ng-lib for Angular v8');
3838
addPackageToPackageJson(tree, '@scullyio/ng-lib-v8', `${scullyComponentVersion}`);
@@ -42,53 +42,10 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {
4242
}
4343
context.logger.info('✅️ Added dependency');
4444
};
45-
/*
46-
const importHttpClientModule = (project: string) => (tree: Tree, context: SchematicContext) => {
47-
try {
48-
const mainFilePath = `./${getSrc(tree, project)}/app/app.module.ts`;
49-
const recorder = tree.beginUpdate(mainFilePath);
50-
51-
const mainFileSource = getSourceFile(tree, mainFilePath);
52-
const importChange = insertImport(
53-
mainFileSource,
54-
mainFilePath,
55-
'HttpClientModule',
56-
'@angular/common/http'
57-
) as InsertChange;
58-
if (importChange.toAdd) {
59-
recorder.insertLeft(importChange.pos, importChange.toAdd);
60-
}
61-
tree.commitUpdate(recorder);
62-
return tree;
63-
} catch (e) {
64-
context.logger.error('error into import httpclient', e);
65-
}
66-
};
67-
68-
const addHttpClientModule = (project: string) => (tree: Tree, context: SchematicContext) => {
69-
const mainFilePath = `./${getSrc(tree, project)}/app/app.module.ts`;
70-
const text = tree.read(mainFilePath);
71-
if (text === null) {
72-
throw new SchematicsException(`File ${mainFilePath} does not exist.`);
73-
}
74-
const sourceText = text.toString();
75-
const source = ts.createSourceFile(mainFilePath, sourceText, ts.ScriptTarget.Latest, true);
76-
const changes = addImportToModule(source, mainFilePath, 'HttpClientModule', '@angular/common/http');
77-
const recorder = tree.beginUpdate(mainFilePath);
78-
for (const change of changes) {
79-
if (change instanceof InsertChange) {
80-
recorder.insertLeft(change.pos, change.toAdd);
81-
}
82-
}
83-
tree.commitUpdate(recorder);
84-
return tree;
85-
};
86-
*/
8745
const importScullyModule = (project: string) => (tree: Tree, context: SchematicContext) => {
8846
try {
8947
const mainFilePath = `./${getSrc(tree, project)}/app/app.module.ts`;
9048
const recorder = tree.beginUpdate(mainFilePath);
91-
9249
const mainFileSource = getSourceFile(tree, mainFilePath);
9350
const importChange = insertImport(
9451
mainFileSource,
@@ -105,7 +62,6 @@ const importScullyModule = (project: string) => (tree: Tree, context: SchematicC
10562
context.logger.error('error into import SculyLib', e);
10663
}
10764
};
108-
10965
const addScullyModule = (project: string) => (tree: Tree, context: SchematicContext) => {
11066
const mainFilePath = `./${getSrc(tree, project)}/app/app.module.ts`;
11167
const text = tree.read(mainFilePath);
@@ -124,7 +80,6 @@ const addScullyModule = (project: string) => (tree: Tree, context: SchematicCont
12480
tree.commitUpdate(recorder);
12581
return tree;
12682
};
127-
12883
const addPolyfill = (project: string) => (tree: Tree, context: SchematicContext) => {
12984
let polyfills = tree.read(`${getSrc(tree, project)}/polyfills.ts`).toString();
13085
if (polyfills.includes('SCULLY IMPORTS')) {
@@ -140,57 +95,6 @@ import 'zone.js/dist/task-tracking';`;
14095
tree.overwrite(`${getSrc(tree, project)}/polyfills.ts`, polyfills);
14196
}
14297
};
143-
144-
// const injectIdleService = (project: string) => (tree: Tree, context: SchematicContext) => {
145-
// try {
146-
// const appComponentPath = `${getSrc(tree, project)}/app/app.component.ts`;
147-
// const appComponent = tree.read(appComponentPath).toString();
148-
// if (appComponent.includes('IdleMonitorService')) {
149-
// context.logger.info(`⚠️️ Skipping ${appComponentPath}`);
150-
// } else {
151-
// const ngCoreVersionTag = getPackageVersionFromPackageJson(tree, '@angular/core');
152-
// let v8 = '';
153-
// if (+ngCoreVersionTag.search(/(\^8|~8)/g) === 0) {
154-
// v8 = '-v8';
155-
// }
156-
// const idleImport = `import {IdleMonitorService} from '@scullyio/ng-lib${v8}';`;
157-
// // add
158-
// const idImport = `${idleImport}\n${appComponent}`;
159-
// const idle = 'private idle: IdleMonitorService';
160-
// let output = '';
161-
// // check if exist
162-
// if (idImport.search(/constructor/) === -1) {
163-
// // add if no exist the constructor
164-
// const add = ` \n constructor (${idle}) { } \n`;
165-
// const position =
166-
// idImport.search(/export class AppComponent {/g) + 'export class AppComponent {'.length;
167-
// output = [idImport.slice(0, position), add, idImport.slice(position)].join('');
168-
// } else {
169-
// const coma = haveMoreInjects(idImport);
170-
// const add = `${idle}${coma}`;
171-
// if (idImport.search(/constructor \(/) === -1) {
172-
// const position = idImport.search(/constructor\(/g) + 'constructor('.length;
173-
// output = [idImport.slice(0, position), add, idImport.slice(position)].join('');
174-
// } else {
175-
// const position = idImport.search(/constructor \(/g) + 'constructor ('.length;
176-
// output = [idImport.slice(0, position), add, idImport.slice(position)].join('');
177-
// }
178-
// }
179-
// tree.overwrite(appComponentPath, output);
180-
// }
181-
182-
// function haveMoreInjects(fullComponent: string) {
183-
// const match = '(([^()]*(private|public)[^()]*))';
184-
// if (fullComponent.search(match) !== -1) {
185-
// return ',';
186-
// }
187-
// return '';
188-
// }
189-
// } catch (e) {
190-
// context.logger.error('error in idle service');
191-
// }
192-
// };
193-
19498
const runBlogSchematic = (options: Schema) => (tree: Tree, context: SchematicContext) => {
19599
const nextRules: Rule[] = [];
196100
if (options.blog === true) {
@@ -200,7 +104,6 @@ const runBlogSchematic = (options: Schema) => (tree: Tree, context: SchematicCon
200104
}
201105
return chain(nextRules);
202106
};
203-
204107
const runScullySchematic = (options: Schema) => (tree: Tree, context: SchematicContext) => {
205108
const nextRules: Rule[] = [];
206109
nextRules.push((host: Tree, ctx: SchematicContext) => {

scully/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
"scully": "./scully.js"
1111
},
1212
"main": "/index.js",
13-
"scripts": {
14-
"postinstall": "npx scully killServer"
15-
},
1613
"dependencies": {
1714
"asciidoctor.js": "^1.5.9",
1815
"chalk": "2.4.2",

scully/utils/startup.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ export const startScully = (url?: string) => {
3434
const duration = durations.Duration;
3535
// tslint:disable-next-line:variable-name
3636
const seconds = duration / 1000;
37-
const routesProSecond = Math.ceil((numberOfRoutes / seconds) * 100) / 100;
3837
const singleTime = duration / numberOfRoutes;
38+
const routesProSecond = Math.ceil((1000 / singleTime) * 100) / 100;
3939
log(`
4040
Generating took ${yellow(Math.floor(seconds * 100) / 100)} seconds for ${yellow(numberOfRoutes)} pages:
4141
That is ${yellow(routesProSecond)} pages per second,
4242
or ${yellow(Math.ceil(singleTime))} milliseconds for each page.
43-
44-
Finding routes in the angular app took ${logSeconds(durations.Traverse)}
43+
${
44+
durations.Traverse
45+
? `
46+
Finding routes in the angular app took ${logSeconds(durations.Traverse)}`
47+
: ''
48+
}
4549
Pulling in route-data took ${logSeconds(durations.Discovery)}
4650
Rendering the pages took ${logSeconds(durations.Render)}
4751

0 commit comments

Comments
 (0)