import { chain , noop , Rule , Tree } from '@angular-devkit/schematics' ; import { ANGULAR_JSON , NG_ESSENTIALS } from '../constants' ; import { findDefaultProjectNameInAngularJson , installPackage , runNpmPackageInstall , runNpmScript } from '../utils' ; import { addCypress } from './cypress' ; import { addEsLint } from './eslint' ; import { addEssentials } from './essentials' ; import { addHusky } from './husky' ; import { addJest } from './jest' ; import { addKarma } from './karma' ; import { NgEssentialsOptions } from './schema' ; export function essentials ( options ) { return ( tree ) => { options = readNgEssentialsOptionsFromAngularJson ( tree , options ) ; const defaultProjectName = findDefaultProjectNameInAngularJson ( tree ) ; const hasDefaultApplication = defaultProjectName !== '' ; return chain ( [ addKarma ( options ) , addJest ( options ) , addCypress ( options ) , addEsLint ( options ) , addEssentials ( options ) , addHusky ( options ) , hasDefaultApplication ? runNpmScript ( 'lint' , '--' , '--fix' ) : noop ( ) , runNpmScript ( 'format' ) , installPackage ( '@froko/ng-essentials' ) , runNpmPackageInstall ( ) ] ) ; } ; } function readNgEssentialsOptionsFromAngularJson ( host , options ) { options . firstRun = true ; const sourceText = host . read ( ANGULAR_JSON ) . toString ( 'utf-8' ) ; const angularJson = JSON . parse ( sourceText ) ; if ( ! angularJson [ 'schematics' ] ) { return options ; } const optionsFromAngularJson = angularJson [ 'schematics' ] [ NG_ESSENTIALS ] ; if ( optionsFromAngularJson ) { options . firstRun = false ; options . jest = optionsFromAngularJson . jest ; options . cypress = optionsFromAngularJson . cypress ; } return options ; }