UNPKG

ohayolibs

Version:

Ohayo is a set of essential modules for ohayojp.

76 lines (68 loc) 2.11 kB
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; import { join } from 'path'; import { Schema as NgAddSchema } from '../ng-add/schema'; export const APPNAME = 'foo'; export interface AppResult { runner: SchematicTestRunner; tree: UnitTestTree; } export function createNgRunner(): SchematicTestRunner { return new SchematicTestRunner('schematics', join('./node_modules/@schematics/angular/collection.json')); } export function createOhayoRunner(): SchematicTestRunner { return new SchematicTestRunner('schematics', join(__dirname, '../collection.json')); } export async function createOhayoApp(ngAddOptions?: NgAddSchema): Promise<AppResult> { const baseRunner = createNgRunner(); const workspaceTree = await baseRunner .runSchematicAsync('workspace', { name: 'workspace', newProjectRoot: 'projects', version: '8.0.0', }) .toPromise(); const appTree = await baseRunner .runSchematicAsync( 'application', { name: APPNAME, inlineStyle: false, inlineTemplate: false, routing: false, style: 'css', skipTests: false, skipPackageJson: false, }, workspaceTree, ) .toPromise(); const ohayoRunner = createOhayoRunner(); const tree = await ohayoRunner .runSchematicAsync( 'ng-add', { skipPackageJson: false, ...ngAddOptions, }, appTree, ) .toPromise(); return { runner: ohayoRunner, tree }; } export async function createOhayoAndModuleApp(name: string = 'trade', ngAddOptions?: object): Promise<AppResult> { const res = await createOhayoApp(ngAddOptions); res.tree = await res.runner.runSchematicAsync('module', { name, project: APPNAME, routing: true }, res.tree).toPromise(); return res; } export async function createTestApp(): Promise<UnitTestTree> { const res = await createNgRunner() .runSchematicAsync('ng-new', { name: APPNAME, directory: '', version: '6.0.0', routing: true, style: 'less', }) .toPromise(); return res; }