52
#SitecoreSYM #SitecoreSYM © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners. 1 Take Your Sitecore Project To The Next Level With Node.js Presented by Anastasiya Flynn, Sitecore Architect at @AnastasiyaFlynn

Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM#SitecoreSYM© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

1

Take Your Sitecore Project

To The Next Level

With Node.js

Presented by Anastasiya Flynn,

Sitecore Architect at

@AnastasiyaFlynn

Page 2: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

Agenda

This presentation will cover common tasks that Sitecore architects and

developers encounter in projects, and I will show you how to leverage

server-side JavaScript to solve these tasks.

2

Setup Development Testing

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 3: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 3

Demo – Creating a Node Module

@AnastasiyaFlynn© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 4: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

Setup

Automate the setup of a complex

Sitecore project with Yeoman

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners. 4@AnastasiyaFlynn

Setup Development Testing

Page 5: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 5

New Solution Checklist

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

C# Projects

Helix structure

Sitecore NuGet

references

Build profiles

Unit tests

TDS Projects

Helix structure

Validation rules

Package generation

Glass models generation

Assembly inclusion

Code Style

Resharperinspection

rules

Stylecopconfiguration

EditorConfigfile

@AnastasiyaFlynn

TypeScript Library

Headless build

Bundling/ minification

Transpilationto ES5

Unit Tests/ Runner

Linting

Front-End Assets

Sass Compilation

Bundling/ minification

Linting

DevOps

Gulpfile

Node dependencies

Page 6: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 6

New Solution Checklist

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Create C#

projects

Find correct

Sitecore NuGets

Add TDS projects

Set up build

profiles

Set up package

generation

How do we build Sass

and JS again?

Let’s just

build it

YSOD

Coffee

Is my target

framework right?

Repeat for other Helix

layers

@AnastasiyaFlynn

Page 7: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 7

http://yeoman.io/

“Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any

decisions. Every decision is made by generators.”

Automate Project Setup With Yeoman

App

Sub Module

Sub Module

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 8: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 8

Yeoman Generator – Setting Up

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 9: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 9

Yeoman – Setting Up

app

add-bootstrap

add-typescript

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

/package.json

Page 10: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 10

Yeoman – Template Variables

Solution name

Solution namespace

MVC area name

Local Sitecore URL

Sitecore version

.NET framework

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 11: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 11

Initializing

Prompting

Configuring

Default

Writing

Conflicts

Install

End

Yeoman – Generator Lifecycle

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/generators/app/index.js

Page 12: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 12© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/generators/app/index.js Initializing

• Log Message

• Initialize settings object

Prompting

• Prompt user for project-specific settings

Configuring

• Save all the settings that have been provided to config file

Writing

• Write settings to config file on disk

• Copy templates to destination, transforming content using project-specific settings

Install

• Install node modules in destination

End

• Log Message

Page 13: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

/generators/app/index.js

13© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/generators/lib/prompter.js

Page 14: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

/generators/app/index.js

14© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/generators/lib/prompter.js

Page 15: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 15© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/generators/app/index.js Initializing

• Log Message

• Initialize settings object

Prompting

• Prompt user for project-specific settings

Configuring

• Save all the settings that have been provided to config file

Writing

• Write settings to config file on disk

• Copy templates to destination, transforming content using project-specific settings

Install

• Install node modules in destination

End

• Log Message

Page 16: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

/generators/app/index.js

16© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/generators/lib/writer.js

Page 17: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

/generators/app/index.js

17© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/generators/lib/writer.js

Page 18: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 18© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Initializing

• Log Message

• Initialize settings object

Prompting

• Prompt user for project-specific settings

Configuring

• Save all the settings that have been provided to config file

Writing

• Write settings to config file on disk

• Copy templates to destination, transforming content using project-specific settings

Install

• Install node modules in destination

End

• Log Message

/generators/app/index.js

Page 19: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 19

Yeoman – Exposing Generator For Testing

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 20: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 20

Yeoman – Running Main Generator

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 21: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 21© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Initializing

• Log Message

• Read previously defined settings

Writing

• Update Node module dependency declarations

• Copy templates to destination, transforming content using project-specific settings

Install

• Install new Node module dependencies

/generators/add-bootstrap/index.js

Page 22: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 22

Yeoman – Running Sub-Generator

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 23: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 23

New Solution Checklist – Conquered!

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

C# Projects

Helix structure

Sitecore NuGet

references

Build profiles

Unit tests

TDS Projects

Helix structure

Validation rules

Package generation

Glass models generation

Assembly inclusion

Code Style

Resharperinspection

rules

Stylecopconfiguration

EditorConfigfile

@AnastasiyaFlynn

TypeScript Library

Headless build

Bundling/ minification

Transpilationto ES5

Unit Tests/ Runner

Linting

Front-End Assets

Sass Compilation

Bundling/ minification

Linting

DevOps

Gulpfile

Node dependencies

Page 24: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

DevelopmentUse Webpack to

• Helix-ify the JavaScript layer

• Build against a headless CMS

• Perform on-the-fly compilation

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

24@AnastasiyaFlynn

Setup Development Testing

Page 25: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 25

Project (C#)

Feature (C#)

Foundation (C#)

TypeScript Helix

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Project Feature Foundation

JavaScript/TypeScript Library

Page 26: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 26

What is Webpack?

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

https://webpack.js.org/

Page 27: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 27

Webpack - Configuration

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

> yarn add webpack --dev

> yarn add webpack-cli --dev

/package.json/webpack.config.json

Page 28: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 28

Project

Feature

Foundation

TypeScript Helix

Component Factory

Event Manager

Global Context

Shared Utilities

Gallery CarouselAdd To

CartCustomer Reviews

Related Products

Group - Common Group - Product

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 29: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 29

Webpack – Demo ‘npm run build’

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 30: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 30

Project

Feature

Foundation

TypeScript Helix

Component Factory

Event Manager

Global Context

Shared Utilities

/html /json /css /images

Gallery CarouselAdd To

CartCustomer Reviews

Related Products

Group - Common Group - Product

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 31: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 31

Webpack Dev Server - Configuration

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

https://webpack.js.org/configuration/dev-server/

> yarn add webpack-dev-server --dev

/package.json/webpack.config.json

Page 32: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 32

Webpack – Demo ‘npm run dev’

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 33: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 33

Dev Server – Ajax?

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 34: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 34

• Encapsulate all Ajax functionality in an injectable helper

• Never hardcode server endpoints

Server interaction

• Accept server interaction helpers as parameters in constructors

• Don’t talk to the server directly

UI component classes

TypeScript Helix – Best practice patterns

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 35: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 35© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/src/project/pages/index.html

Page 36: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 36© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 37: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 37

Headless CMS – Sample Component

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 38: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

Testing

Unit test JavaScript with

Jasmine and Karma

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

38@AnastasiyaFlynn

Setup Development Testing

Page 39: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 39

Unit tests are valuable because they:

• Document the code

• Shows how code is expected to work

• Shows how code is expected to be used

• Enforce good class design

• Classes have to be broken up into granular functions (units)

• Classes have to use dependency injection

• Enforce good Sitecore component design

• UI component classes must be autonomous and self-contained

Why Unit Test JavaScript?

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 40: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 40

https://jasmine.github.io

> yarn add jasmine --dev

> yarn add jasmine-core --dev

> yarn add @types/jasmine --dev

Jasmine - Setup

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 41: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 41

Jasmine - Implementation

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 42: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 42

• Encapsulate all Ajax functionality in an injectable helper

• Never hardcode server endpoints

Server interaction

• Accept server interaction helpers as parameters in constructors

• Don’t talk to the server directly

• Accept interface injection, not concrete classes

UI component classes

TypeScript Helix – Best practice patterns (continued)

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 43: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 43

Unit Testing UI Components – Sample Component

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 44: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 44

• Encapsulate all Ajax functionality in an injectable helper

• Never hardcode server endpoints

Server interaction

• Accept server interaction helpers as parameters in constructors

• Don’t talk to the server directly

• Accept interface injection, not concrete classes

• Accept a DOM element in the constructor

• Scope all actions to it’s DOM element

UI component classes

TypeScript Helix – Best practice patterns (continued)

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 45: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 45

Unit Testing UI Components – Sample Component

@AnastasiyaFlynn © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

Page 46: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 46© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 47: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 47

Karma - Setup

http://karma-runner.github.io

> yarn add karma --dev

> yarn add karma-jasmine -- dev

> yarn add karma-chrome-launcher --dev

> yarn add karma-coverage-istanbul-reporter --dev

> yarn add karma-spec-reporter --dev

> yarn add karma-webpack --dev

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/package.json

Page 48: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 48© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/karma.conf.js

Page 49: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 49© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

/webpack.config.karma.js

Page 50: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM 50

Jasmine/Karma – Demo

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

@AnastasiyaFlynn

Page 51: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM#SitecoreSYM © 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

51@AnastasiyaFlynn

Get the code

https://bitbucket.org/anastasiya29

/yeoman-sitecore-generator

Page 52: Take Your Sitecore Project To The Next Level With Node · #SitecoreSYM 7 “Yeoman is a generic scaffolding system... Yeoman by itself doesn’t make any decisions. Every decision

#SitecoreSYM

FOR DISCUSSION PURPOSES ONLY. Sitecore Confidential and Proprietary. © 2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners.

© 2001-2018 Sitecore Corporation A/S. All rights reserved. Sitecore® and Own the Experience® are registered trademarks of Sitecore Corporation A/S. All other brand and product names are the property of their respective owners. 52

Let’s continue the conversation on

Twitter @AnastasiyaFlynn