Code Monkey home page Code Monkey logo

angular-seed-advanced's Introduction

Angular Seed AdvancedAngular Seed Advanced Integrations

Angular Style Guide Build Status MIT license Dependency Status devDependency Status

This is an advanced seed project for Angular apps based on Minko Gechev's angular-seed that expands on all of its great features to include core support for:

Integration with:

Multiple Platforms
The zen of multiple platforms. Chrome, Android and iPhone all running the same code.
Desktop
Programming Nirvana. Mac and Windows desktop both running the same code.

Table of Contents

Advice: If your project is intended to target a single platform (i.e, web only), then angular-seed is likely more than suitable for your needs. However if your project goals are to target multiple platforms (web, native mobile and native desktop), with powerful out of the box library support and highly configurable/flexible testing options, then you might want to keep reading.

Prerequisites

Note you should have node v6.5.0 or higher and npm 3.10.3 or higher.

  • To run the NativeScript app:
npm install -g nativescript
npm install -g typescript

How to start

# install the project's dependencies
$ npm install
# fast install (via Yarn, https://yarnpkg.com)
$ yarn install  # or yarn

# watches your files and uses livereload by default
$ npm start
# api document for the app
# npm run build.docs

# generate api documentation
$ npm run compodoc
$ npm run serve.compodoc

# to start deving with livereload site and coverage as well as continuous testing
$ npm run start.deving

# dev build
$ npm run build.dev
# prod build
$ npm run build.prod

How to start with AoT

Note that AoT compilation requires node v6.5.0 or higher and npm 3.10.3 or higher.

In order to start the seed with AoT use:

# prod build with AoT compilation, will output the production application in `dist/prod`
# the produced code can be deployed (rsynced) to a remote server
$ npm run build.prod.aot

Mobile app

The mobile app is provided via NativeScript, an open source framework for building truly native mobile apps.

Setup

npm install -g nativescript 

Dev Workflow

You can make changes to files in src/client/app or nativescript/src/app folders. A symbolic link exists between the web src/client/app and the nativescript/src/app folder so changes in either location are mirrored because they are the same directory inside.

Create .tns.html and .tns.scss NativeScript view files for every web component view file you have. You will see an example of the app.component.html as a NativeScript view file here.

The root module for the mobile app is nativescript/src/native.module.ts: NativeModule.

Run

iOS:                      npm run start.ios   
iOS (device):             npm run start.ios.device

// or...

Android:                      npm run start.android
Android (device):             npm run start.android.device

OR...

Building with Webpack for release builds

Create AoT builds for deployment to App Store and Google Play.

Android:   npm run build.android
iOS:       npm run build.ios

Desktop app

The desktop app is provided via Electron, cross platform desktop apps with JavaScript, HTML, and CSS.

Develop

Mac:      npm run start.desktop
Windows:  npm run start.desktop.windows

Develop with livesync

Mac:      npm run start.livesync.desktop
Windows:  npm run start.livesync.desktop.windows

Release: Package Electron App for Mac, Windows or Linux

Mac:      npm run build.desktop.mac
Windows:  npm run build.desktop.windows
Linux:    npm run build.desktop.linux

Running tests

$ npm test

# Development. Your app will be watched by karma
# on each change all your specs will be executed.
$ npm run test.watch
# NB: The command above might fail with a "EMFILE: too many open files" error.
# Some OS have a small limit of opened file descriptors (256) by default
# and will result in the EMFILE error.
# You can raise the maximum of file descriptors by running the command below:
$ ulimit -n 10480


# code coverage (istanbul)
# auto-generated at the end of `npm test`
# view coverage report:
$ npm run serve.coverage

# e2e (aka. end-to-end, integration) - In three different shell windows
# Make sure you don't have a global instance of Protractor

# npm install webdriver-manager <- Install this first for e2e testing
# npm run webdriver-update <- You will need to run this the first time
$ npm run webdriver-start
$ npm run serve.e2e
$ npm run e2e

# e2e live mode - Protractor interactive mode
# Instead of last command above, you can use:
$ npm run e2e.live

You can learn more about Protractor Interactive Mode here

Web configuration options

Default application server configuration

var PORT             = 5555;
var LIVE_RELOAD_PORT = 4002;
var DOCS_PORT        = 4003;
var APP_BASE         = '/';

Configure at runtime

npm start -- --port 8080 --reload-port 4000 --base /my-app/

Environment configuration

If you have different environments and you need to configure them to use different end points, settings, etc. you can use the files dev.ts or prod.ts in./tools/env/. The name of the file is environment you want to use.

The environment can be specified by using:

$ npm start -- --env-config ENV_NAME

Currently the ENV_NAMEs are dev, prod, staging, but you can simply add a different file "ENV_NAME.ts". file in order to alter extra such environments.

Tools documentation

A documentation of the provided tools can be found in tools/README.md.

Code organization overview

  • nativescript: Root of this directory is reserved for mobile app.
    • src: mobile app src.
      • app: Symbolic link of shared code from web app.
      • App_Resources: iOS and Android platform specific config files and images.
      • mobile: Mobile specific services, etc. Build out mobile specific services here as well as overrides for web services that need to be provided for in the mobile app. Safe to import {N} modules here.
      • native.module.ts: Root module for the mobile app provided by NativeScript. Override/provide native mobile implementations of services here.
  • src/client: Root of this directory is reserved for web and desktop.
    • app: All the code in this directory is shared with the mobile app via a symbolic link.
      • components: Reserved for primary routing components. Since each app usually has it's own set of unique routes, you can provide the app's primary routing components here.
      • shared: Shared code across all platforms. Reusable sub components, services, utilities, etc.
        • analytics: Provides services for analytics. Out of the box, Segment is configured.
        • core: Low level services. Foundational layer.
        • electron: Services specific to electron integration. Could be refactored out in the future since this is not needed to be shared with the mobile app.
        • i18n: Various localization features.
        • ngrx: Central ngrx coordination. Brings together state from any other feature modules etc. to setup the initial app state.
        • sample: Just a sample module pre-configured with a scalable ngrx setup.
        • test: Testing utilities. This could be refactored into a different location in the future.
    • assets: Various locale files, images and other assets the app needs to load.
    • css: List of the main style files to be created via the SASS compilation (enabled by default).
    • scss: Partial SASS files - reserved for things like _variables.scss and other imported partials for styling.
    • index.html: The index file for the web and desktop app (which share the same setup).
    • main.desktop.ts: The file used by Electron to start the desktop app.
    • main.web.prod.ts: Bootstraps the AoT web build. Generally won't modify anything here
    • main.web.ts: Bootstraps the development web build. Generally won't modify anything here
    • package.json: Used by Electron to start the desktop app.
    • system-config.ts: This loads the SystemJS configuration defined here and extended in your own app's customized project.config.ts.
    • tsconfig.json: Used by compodoc - The missing documentation tool for your Angular application - to generate api docs for your code.
    • web.module.ts: The root module for the web and desktop app.
  • src/e2e: Integration/end-to-end tests for the web app.

How-tos

i18n

  • how to add a language?
    • src/client/assets/i18n/
      • add [language code].json (copy existing one and adapt the translation strings)
    • Create a file similar to the sample app-config
      • Define your app's SUPPORTED_LANGUAGES.
    • src/client/app/shared/i18n/components/lang-switcher.component.spec.ts
      • fix test

General best practice guide to sharing code

There’s actually only a few things to keep in mind when sharing code between web/mobile. The seed does take care of quite a few of those things but here’s a brief list:

  • Don’t import {N} modules into your components/services. {N} modules can only be used inside the {N} app therefore cannot be shared. To get around this, use OpaqueTokens which is a fancy name for something quite simple. Learn more here. A great example of how to integrate 2 different plugins (1 for web, 1 for {N}) and share all the code exists in this wiki article: How to integrate Firebase across all platforms written by the awesome Scott Lowe.
  • Use the conditional hooks provided by the seed in shared methods where you may need to handle something differently in {N} than you do on the web. For example, see here.
  • Don’t use window global. Inject the WindowService provided by the seed instead. This includes usage of alert, confirm, etc. For example:

If you were thinking about doing: alert('Something happened!');, Don't. Instead inject WindowService:

constructor(private win: WindowService) {}

public userAction() {
  if (success) {
    // do stuff
  } else {
    this.win.alert('Something happened!');
  }
}

This ensures that when the same code is run in the {N} app, the native dialogs module will be used.

The advice I like to give is:

Code with web mentality first. Then provide the native capability using Angular’s {provide: SomeWebService, useClass: SomeNativeService } during bootstrap.

There are some cases where you may want to use useValue vs. useClass, and other times may need to use useFactory. Read the Angular docs here to learn more about which you may need for your use case.

How best to use for your project

Setup

NOTE: This should be done first before you start making any changes and building out your project.

  1. git clone https://github.com/NathanWalker/angular-seed-advanced.git [your-project-name]
  2. cd [your-project-name]
  3. git remote set-url origin [your-project-git-repo] - This will setup origin properly.
  4. git remote add upstream https://github.com/NathanWalker/angular-seed-advanced.git - This will setup upstream properly to merge in upstream changes later.
  5. git push - Go ahead and push up the initial project.
  6. Now you have git setup and ready to develop your app as well as merge in upstream changes in the future.
  7. npm install (and all other usage docs in this README apply) - continue following instructions here.
  8. Create a new folder (or several sub-folders) for your app in src/client/app/shared to build your codebase out. Say your app is called AwesomeApp, then create awesomeapp and start building out all your components and services in there. Create other frameworks as you see fit to organize.

Merging latest upstream changes

  1. git fetch upstream - This will fetch latest upstream.
  2. git merge upstream/master - This will merge in upstream changes.
  3. Handle any conflicts to get latest upstream into your app.
  4. Continue building your app.

You can read more about syncing a fork here.

If you have any suggestions to this workflow, please post here.

Dockerization

The application provides full Docker support. You can use it for both development as well as production builds and deployments.

How to build and start the dockerized version of the application

The Dockerization infrastructure is described in the docker-compose.yml (respectively docker-compose.production.yml. The application consists of two containers:

  • angular-seed - In development mode, this container serves the angular app. In production mode it builds the angular app, with the build artifacts being served by the Nginx container
  • angular-seed-nginx - This container is used only production mode. It serves the built angular app with Nginx.

Development build and deployment

Run the following:

$ docker-compose build
$ docker-compose up -d

Now open your browser at http://localhost:5555

Production build and deployment

Run the following:

$ docker-compose -f docker-compose.production.yml build
$ docker-compose -f docker-compose.production.yml up angular-seed   # Wait until this container has finished building, as the nginx container is dependent on the production build artifacts
$ docker-compose -f docker-compose.production.yml up -d angular-seed-nginx  # Start the nginx container in detached mode

Now open your browser at http://localhost:5555

Contributing

Please see the CONTRIBUTING file for guidelines.

Awesome Contributors

mgechev NathanWalker ludohenin d3viant0ne Shyam-Chen Nightapes
mgechev NathanWalker ludohenin d3viant0ne Shyam-Chen Nightapes
tarlepp robstoll TheDonDope m-abs hank-ehly nareshbhatia
tarlepp robstoll TheDonDope m-abs hank-ehly nareshbhatia
kiuka jesperronn daniru njs50 vyakymenko aboeglin
kiuka jesperronn daniru njs50 vyakymenko aboeglin
eppsilon netstart sasikumardr ivannugo gkalpak ryzy
eppsilon netstart sasikumardr ivannugo gkalpak ryzy
markwhitfeld jvitor83 sfabriece JakePartusch nosachamos pgrzeszczak
markwhitfeld jvitor83 sfabriece JakePartusch nosachamos pgrzeszczak
natarajanmca11 e-oz Kaffiend fulls1z3 jerryorta-dev LuxDie
natarajanmca11 e-oz Kaffiend fulls1z3 jerryorta-dev LuxDie
admosity JohnCashmore larsthorup ouq77 irsick StefanKoenen
admosity JohnCashmore larsthorup ouq77 irsick StefanKoenen
amedinavalencia troyanskiy tsm91 domfarolino juristr JayKan
amedinavalencia troyanskiy tsm91 domfarolino juristr JayKan
turbohappy devanp92 evanplaice hAWKdv JunaidZA c-ice
turbohappy devanp92 evanplaice hAWKdv JunaidZA c-ice
markharding ojacquemart Sn3b TuiKiken gotenxds edud69
markharding ojacquemart Sn3b TuiKiken gotenxds edud69
karlhaas kbrandwijk Yonet Green-Cat ip512 joshboley
karlhaas kbrandwijk Yonet Green-Cat ip512 joshboley
Marcelh29 Bigous robbatt divramod alexweber vakrilov
Marcelh29 Bigous robbatt divramod alexweber vakrilov
allenhwkim Falinor amaltsev nulldev07 taguan yassirh
allenhwkim Falinor amaltsev nulldev07 taguan yassirh
urmaul sonicparke brendanbenson brian428 briantopping ckapilla
urmaul sonicparke brendanbenson brian428 briantopping ckapilla
cadriel dszymczuk dmurat peah90 dstockhammer dwido
cadriel dszymczuk dmurat peah90 dstockhammer dwido
dcsw totev ericdoerheit ericli1018 Swiftwork fbascheper
dcsw totev ericdoerheit ericli1018 Swiftwork fbascheper
gsamokovarov koodikindral hpinsley NN77 isidroamv JohnnyQQQQ
gsamokovarov koodikindral hpinsley NN77 isidroamv JohnnyQQQQ
jeffbcross jlooper Jimmysh Drane johnjelinek fourctv
jeffbcross jlooper Jimmysh Drane johnjelinek fourctv
JunusErgin justindujardin lihaibh Brooooooklyn tandu inkidotcom
JunusErgin justindujardin lihaibh Brooooooklyn tandu inkidotcom
daixtrose MathijsHoogland mjwwit oferze ocombe gdi2290
daixtrose MathijsHoogland mjwwit oferze ocombe gdi2290
typekpb peter-norton philipooo pidupuis redian robertpenner
typekpb peter-norton philipooo pidupuis redian robertpenner
Sjiep RoxKilly SamVerschueren sclausen heavymery tjvantoll
Sjiep RoxKilly SamVerschueren sclausen heavymery tjvantoll
tapas4java gitter-badger valera-rozuvan miltador vincentpalita VladimirMakaev
tapas4java gitter-badger valera-rozuvan miltador vincentpalita VladimirMakaev
ghys Yalrafih arnaudvalle billsworld blackheart01 butterfieldcons
ghys Yalrafih arnaudvalle billsworld blackheart01 butterfieldcons
danielcrisp jgolla omerfarukyilmaz pbazurin-softheme ZuSe rossedfort
danielcrisp jgolla omerfarukyilmaz pbazurin-softheme ZuSe rossedfort
ruffiem savcha s-f-a-g ultrasonicsoft bbarry
ruffiem savcha s-f-a-g ultrasonicsoft bbarry

License

MIT

angular-seed-advanced's People

Contributors

aboeglin avatar ashishmondal avatar daniru avatar eppsilon avatar gkalpak avatar hankehly avatar jakepartusch avatar jesperronn avatar joshwiens avatar jvitor83 avatar kaffiend avatar karlhaas avatar kiuka avatar ludohenin avatar m-abs avatar markwhitfeld avatar mgechev avatar nareshbhatia avatar nathanwalker avatar netstart avatar nightapes avatar robstoll avatar ryzy avatar sasikumardr avatar sfabriece avatar shyam-chen avatar tarlepp avatar thedondope avatar troyanskiy avatar vyakymenko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.