- Notifications
You must be signed in to change notification settings - Fork440
Advanced Angular seed project with support for ngrx/store, ngrx/effects, ngx-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
License
NathanWalker/angular-seed-advanced
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Please readthis notice first before continuing.
This is anadvanced seed project for Angular apps based onMinko Gechev'sangular-seed that expands on all of its great features to include core support for:
- ngrx/store RxJS powered state management, inspired byRedux
- ngrx/effects Side effect model for @ngrx/store
- ngx-translate for i18n
- Usage is optional but on by default
- Up to you and your team how you want to utilize it. It can be easily removed if not needed.
- angulartics2 Vendor-agnostic analytics for Angular applications.
- Out of box support forSegment
- When using the seed, be sure to change your
write_keyhere
- When using the seed, be sure to change your
- Can be changed to any vendor,learn more here
- Out of box support forSegment
- lodash Helps reduce blocks of code down to single lines and enhances readability
- NativeScript cross platform mobile (w/ native UI) apps.Setup instructions here.
- Electron cross platform desktop apps (Mac, Windows and Linux).Setup instructions here.
| The zen of multiple platforms. Chrome, Android and iPhone all running the same code. |
| Programming Nirvana. Mac and Windows desktop both running the same code. |
- Prerequisites
- How to start
- How to start with AoT
- Mobile app
- Desktop app
- Running tests
- Web configuration options
- Code organization overview
- How-tos
- General best practice guide to sharing code
- Integration guides
- How best to use for your project
- Dockerization
- Contributing
- License
Advice: If your project is intended to target a single platform (i.e, web only), thenangular-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.
Too Much?!: Don't worry it's ok, I completely understand. There is a simplified version of this seed which still allows web + mobile + desktopwithout the extra libraries and features like ngrx or analytics. Give this a shot:https://github.com/jlooper/angular-starter
It's built with a lot of the same structure found here so things work the same but is definitely easier to start with if just getting into multi-platform development.
Note you should havenode v6.5.0 or higher andnpm 3.10.3 or higher.
- To run the NativeScript app (currently supports 3.x):
npm install -g nativescript# 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
Note that AoT compilation requiresnode v6.5.0 or higher andnpm 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
The mobile app is provided viaNativeScript, an open source framework for building truly native mobile apps.
npm install -g nativescriptYou can make changes to files insrc/client/app ornativescript/src/app folders. A symbolic link exists between the websrc/client/app and thenativescript/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 theapp.component.html as aNativeScript view file here.
The root module for the mobile app isnativescript/src/native.module.ts:NativeModule.
iOS: npm run start.ios iOS (device): npm run start.ios.device// or...Android: npm run start.androidAndroid (device): npm run start.android.device- Requires an image setup via AVD Manager.Learn more here andhere.
OR...
Create AoT builds for deployment to App Store and Google Play.
Android: npm run build.androidiOS: npm run build.iosThe desktop app is provided viaElectron, cross platform desktop appswith JavaScript, HTML, and CSS.
Mac: npm run start.desktopWindows: npm run start.desktop.windowsMac: npm run start.livesync.desktopWindows: npm run start.livesync.desktop.windowsMac: npm run build.desktop.macWindows: npm run build.desktop.windowsLinux: npm run build.desktop.linux$ npmtest# 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 aboutProtractor Interactive Mode here
Default application server configuration
varPORT=5555;varLIVE_RELOAD_PORT=4002;varDOCS_PORT=4003;varAPP_BASE='/';
Configure at runtime
npm start -- --port 8080 --reload-port 4000 --base /my-app/
If you have different environments and you need to configure them to use different end points, settings, etc. you can use the filesdev.ts orprod.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 theENV_NAMEs aredev,prod,staging, but you can simply add a different file"ENV_NAME.ts". file in order to alter extra such environments.
A documentation of the provided tools can be found intools/README.md.
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.scssand 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 definedhere and extended in your own app's customizedproject.config.ts.
- tsconfig.json: Used bycompodoc - 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 to add a language?
src/client/assets/i18n/- add
[language code].json(copy existing one and adapt the translation strings)
- add
https://github.com/NathanWalker/angular-seed-advanced/blob/master/src/client/web.module.ts#L98-L101- Configure
LanguagesInjectionToken with array of supported languages
- Configure
src/client/app/modules/i18n/components/lang-switcher.component.spec.ts- fix test
what is the basic API surface around logging?
LogServiceis the main class that consumer code should use to write diagnostic information to one or more configured targetsLogTargetis an abstraction of where the log output is written. (e.g.ConsoleTargetwrites diagnostics to theconsole)LogTargetBaseis a base abstract class that makes it easier to implement custom log target. It provides a way for inheritors to filter messages by importance.LogLevelis level of importance associated with every log message (e.g.Debug,Info,Warning,Error)
how to control amount of information logged?
- If a log target is derrived from
LogTargetBasethe target can be configured to filter messages by importance. You can passminLogLevelasLogTargetOptions LogServiceadditionally usesConfig.Debugswitches as a global treshhold to further filter verbosity of the log messages.
- If a log target is derrived from
how to implement custom log target?
- Derrive from
LogTargetBaseclass and implementwriteToLogmethod (seeConsoleTarget). You can configure several log targets at a time inside main application module. For example:
CoreModule.forRoot([{provide:WindowService,useFactory:(win)},{provide:ConsoleService,useFactory:(cons)},{provide:LogTarget,useFactory:(consoleLogTarget),deps:[ConsoleService],multi:true},{provide:LogTarget,useFactory:()=>newLogStashTarget({minLogLevel:LogLevel.Debug})}]),
- Derrive from
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
InjectionToken's.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 inthis wiki article: How to integrate Firebase across all platforms written by the awesomeScott 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, seehere.
- Don’t use window global. Inject the
WindowServiceprovided by the seed instead. This includes usage ofalert,confirm, etc. For example:
If you were thinking about doing:alert('Something happened!');,Don't.Instead injectWindowService:
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 nativedialogs module will be used.
- Lastly, understand this video:http://www.nativescriptsnacks.com/videos/2016/06/13/zoned-callbacks.html … As far as dealing with {N} and 3rd party plugins, you want to understand that.
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 useuseValue vs.useClass, and other times may need to useuseFactory. Readthe Angular docs here to learn more about which you may need for your use case.
NOTE: This should be done first before you start making any changes and building out your project.
git clone https://github.com/NathanWalker/angular-seed-advanced.git [your-project-name]cd [your-project-name]git remote set-url origin [your-project-git-repo]- This will setuporiginproperly.git remote add upstream https://github.com/NathanWalker/angular-seed-advanced.git- This will setupupstreamproperly to merge in upstream changes later.git push- Go ahead and push up the initial project.- Now you have
gitsetup and ready to develop your app as well as merge in upstream changes in the future. npm install(and all other usage docs in thisREADMEapply) - continue following instructionshere.- Create a new folder (or several sub-folders) for your app in
src/client/app/sharedto build your codebase out. Say your app is calledAwesomeApp, then createawesomeappand start building out all your components and services in there. Create other frameworks as you see fit to organize.
git fetch upstream- This will fetch latestupstream.git merge upstream/master- This will merge in upstream changes.- Handle any conflicts to get latest upstream into your app.
- Continue building your app.
You can read more aboutsyncing a fork here.
If you have any suggestions to this workflow, please posthere.
The application provides full Docker support. You can use it for both development as well as production builds and deployments.
The Dockerization infrastructure is described in thedocker-compose.yml (respectivelydocker-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 containerangular-seed-nginx- This container is used only production mode. It serves the built angular app with Nginx.
Run the following:
$ docker-compose build$ docker-compose up -d
Now open your browser athttp://localhost:5555
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 athttp://localhost:5555
Please see theCONTRIBUTING file for guidelines.
| mgechev | NathanWalker | ludohenin | d3viant0ne | Shyam-Chen | Nightapes |
| tarlepp | karlhaas | m-abs | robstoll | TheDonDope | nareshbhatia |
| hank-ehly | kiuka | vyakymenko | jesperronn | daniru | aboeglin |
| nulldev07 | eppsilon | netstart | sasikumardr | gkalpak | sfabriece |
| JakePartusch | ryzy | markwhitfeld | jvitor83 | fulls1z3 | ivannugo |
| pgrzeszczak | treyrich | natarajanmca11 | e-oz | Kaffiend | nosachamos |
| jerryorta-dev | alllx | LuxDie | JayKan | JohnCashmore | larsthorup |
| ouq77 | admosity | Karasuni | irsick | StefanKoenen | llwt |
| amedinavalencia | odk211 | troyanskiy | tsm91 | hellofornow | domfarolino |
| VladimirMakaev | juristr | 730alchemy | turbohappy | devanp92 | DmitriyPotapov |
| evanplaice | JunaidZA | c-ice | markharding | ojacquemart | patrickmichalina |
| rajeev-tripathi | sanderbos1402 | Sn3b | TuiKiken | gotenxds | divramod |
| edud69 | idready | kbrandwijk | Yonet | smac89 | Green-Cat |
| ip512 | joshboley | Marcelh1983 | Bigous | robbatt | yavin5 |
| alexweber | vakrilov | allenhwkim | Falinor | amaltsev | yassirh |
| bbarry | urmaul | sonicparke | brendanbenson | brian428 | briantopping |
| ckapilla | cadriel | Cselt | dszymczuk | dmurat | peah90 |
| dstockhammer | dwido | dcsw | totev | EddyVerbruggen | ericdoerheit |
| ericli1018 | Swiftwork | fbascheper | gsamokovarov | koodikindral | hpinsley |
| NN77 | isidroamv | JohnnyQQQQ | jeffbcross | jlooper | Jimmysh |
| Drane | johnjelinek | fourctv | JunusErgin | justindujardin | karlhiramoto |
| lihaibh | Brooooooklyn | tandu | inkidotcom | mpetkov | daixtrose |
| Doehl | MathijsHoogland | mjwwit | oferze | ocombe | gdi2290 |
| typekpb | peter-norton | pavlovich | philipooo | pidupuis | redian |
| robertpenner | Sjiep | RoxKilly | siovene | SamVerschueren | sclausen |
| heavymery | tjvantoll | tapas4java | gitter-badger | tsvetomir | valera-rozuvan |
| vogloblinsky | vincentpalita | ghys | Yalrafih | arioth | arnaudvalle |
| billsworld | blackheart01 | butterfieldcons | danielcrisp | gforceg | guilhebl |
| jgolla | omerfarukyilmaz | pbazurin-softheme | ZuSe | rossedfort | ruffiem |
| savcha | s-f-a-g | ultrasonicsoft | taguan |
MIT
About
Advanced Angular seed project with support for ngrx/store, ngrx/effects, ngx-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.