diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c71d366 --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "plugins": ["transform-runtime"], + "presets": ["es2015", "stage-0"] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cd01f84 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +# Force Unix-style newlines with a newline ending every file & trim trailing whitespace +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{js,html,css,styl}] +indent_style = space +indent_size = 2 + +[*.md] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = false + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f31eec2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.DS_Store +.tmp +.git +node_modules +.settings +*.log +dist/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a53c61 --- /dev/null +++ b/README.md @@ -0,0 +1,179 @@ +
+ + + +
+ +--- + ++ + + + +
+ +# NG6 [![Join Slack](https://img.shields.io/badge/slack-join-brightgreen.svg)](https://angularclass.com/slack-join) [![Join the chat at https://gitter.im/angularclass/NG6-starter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/angularclass/NG6-starter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +> The de facto starter repo for building scalable apps with [Angular](https://angularjs.org), [ES6](https://git.io/es6features), and [Webpack](http://webpack.github.io/) + +This repo serves as a minimal starter for those looking to get up-and-running with Angular and ES6, using [Gulp](http://gulpjs.com/) and [Webpack](http://webpack.github.io/) for the build process. +**This seed is not a Yeoman generator.** It's a minimal starter with tasks for building the boilerplate. **These are its features**: +* The best practice in directory/file organization for Angular (allowing for infinite horizontal app scaling) +* A ready-to-go build system for working with [ES6](https://git.io/es6features) +* Tasks for generating additional boilerplate Angular components +* A full testing system in place +* [Stylus](https://learnboost.github.io/stylus/) support + +**Check out the [JSPM version](https://github.com/angularclass/NG6-starter/tree/jspm)--an alternative to Webpack as an ES6 build system.** + +> If you're looking for a preliminary [Angular 2](https://angular.io/) build, please use the [angular2-webpack-starter](https://github.com/angularclass/angular2-webpack-starter). +___ + +# Table of Contents +* [Walkthrough](#walkthrough) + * [Build System](#build-system) + * [File Structure](#file-structure) + * [Testing Setup](#testing-setup) +* [Getting Started](#getting-started) + * [Dependencies](#dependencies) + * [Installing](#installing) + * [Running the App](#running-the-app) + * [Gulp Tasks](#gulp-tasks) + * [Testing](#testing) + * [Generating Components](#generating-components) +* [Starter Kit Support and Questions](#starter-kit-support-and-questions) + +# Walkthrough +## Build System +NG6 uses Gulp and Webpack together for its build system. Yes, you don't need Gulp if you're using Webpack. This is true if your build system is only responsible for file manipulation. However, ours is not. + +`Webpack` handles all file-related concerns: +* Transpiling from ES6 to ES5 with `Babel` +* Loading HTML files as modules +* Transpiling stylesheets and appending them to the DOM +* Refreshing the browser and rebuilding on file changes +* Hot module replacement for transpiled stylesheets +* Bundling the app +* Loading all modules +* Doing all of the above for `*.spec.js` files as well + +`Gulp` is the orchestrator: +* Starting and calling Webpack +* Starting a development server (yes, Webpack can do this too) +* Generating boilerplate for the Angular app + +**Check out the [JSPM version](https://github.com/angularclass/NG6-starter/tree/jspm)--an alternative to Webpack as an ES6 build system.** + +## File Structure +We use a componentized approach with NG6. This will be the eventual standard (and particularly helpful, if using Angular's new router) as well as a great way to ensure a tasteful transition to Angular 2, when the time is ripe. Everything--or mostly everything, as we'll explore (below)--is a component. A component is a self-contained concern--may it be a feature or strictly-defined, ever-present element of the UI (such as a header, sidebar, or footer). Also characteristic of a component is that it harnesses its own stylesheets, templates, controllers, routes, services, and specs. This encapsulation allows us the comfort of isolation and structural locality. Here's how it looks: +``` +client +⋅⋅app/ +⋅⋅⋅⋅app.js * app entry file +⋅⋅⋅⋅app.html * app template +⋅⋅⋅⋅common/ * functionality pertinent to several components propagate into this directory +⋅⋅⋅⋅components/ * where components live +⋅⋅⋅⋅⋅⋅components.js * components entry file +⋅⋅⋅⋅⋅⋅home/ * home component +⋅⋅⋅⋅⋅⋅⋅⋅home.js * home entry file (routes, configurations, and declarations occur here) +⋅⋅⋅⋅⋅⋅⋅⋅home.component.js * home "directive" +⋅⋅⋅⋅⋅⋅⋅⋅home.controller.js * home controller +⋅⋅⋅⋅⋅⋅⋅⋅home.styl * home styles +⋅⋅⋅⋅⋅⋅⋅⋅home.html * home template +⋅⋅⋅⋅⋅⋅⋅⋅home.spec.js * home specs (for entry, component, and controller) +``` + +## Testing Setup +All tests are also written in ES6. We use Webpack to take care of the logistics of getting those files to run in the various browsers, just like with our client files. This is our testing stack: +* Karma +* Webpack + Babel +* Mocha +* Chai + +To run tests, type `npm test` or `karma start` in the terminal. Read more about testing [below](#testing). + +# Getting Started +## Dependencies +Tools needed to run this app: +* `node` and `npm` +Once you have these, install the following as globals: +`npm install -g gulp karma karma-cli webpack` + +## Installing +* `fork` this repo +* `clone` your fork +* `npm install -g gulp karma karma-cli webpack` install global cli dependencies +* `npm install` to install dependencies + +## Running the App +NG6 uses Gulp to build and launch the development environment. After you have installed all dependencies, you may run the app. Running `gulp` will bundle the app with `webpack`, launch a development server, and watch all files. The port will be displayed in the terminal. + +### Gulp Tasks +Here's a list of available tasks: +* `webpack` + * runs Webpack, which will transpile, concatenate, and compress (collectively, "bundle") all assets and modules into `dist/bundle.js`. It also prepares `index.html` to be used as application entry point, links assets and created dist version of our application. +* `serve` + * starts a dev server via `webpack-dev-server`, serving the client folder. +* `watch` + * alias of `serve` +* `default` (which is the default task that runs when typing `gulp` without providing an argument) + * runs `serve`. +* `component` + * scaffolds a new Angular component. [Read below](#generating-components) for usage details. + +### Testing +To run the tests, run `npm test` or `karma start`. + +`Karma` combined with Webpack runs all files matching `*.spec.js` inside the `app` folder. This allows us to keep test files local to the component--which keeps us in good faith with continuing to build our app modularly. The file `spec.bundle.js` is the bundle file for **all** our spec files that Karma will run. + +Be sure to define your `*.spec.js` files within their corresponding component directory. You must name the spec file like so, `[name].spec.js`. If you don't want to use the `.spec.js` suffix, you must change the `regex` in `spec.bundle.js` to look for whatever file(s) you want. +`Mocha` is the testing suite and `Chai` is the assertion library. If you would like to change this, see `karma.conf.js`. + +### Examples + +It's always easier to learn something if you have an examples. Here is a list of repos which based on this starter: + + - [TodoMVC Example App](https://github.com/AngularClass/NG6-todomvc-starter) + +### Generating Components +Following a consistent directory structure between components offers us the certainty of predictability. We can take advantage of this certainty by creating a gulp task to automate the "instantiation" of our components. The component boilerplate task generates this: +``` +⋅⋅⋅⋅⋅⋅componentName/ +⋅⋅⋅⋅⋅⋅⋅⋅componentName.js // entry file where all its dependencies load +⋅⋅⋅⋅⋅⋅⋅⋅componentName.component.js +⋅⋅⋅⋅⋅⋅⋅⋅componentName.controller.js +⋅⋅⋅⋅⋅⋅⋅⋅componentName.html +⋅⋅⋅⋅⋅⋅⋅⋅componentName.styl // scoped to affect only its own template +⋅⋅⋅⋅⋅⋅⋅⋅componentName.spec.js // contains passing demonstration tests +``` + +You may, of course, create these files manually, every time a new module is needed, but that gets quickly tedious. +To generate a component, run `gulp component --name componentName`. + +The parameter following the `--name` flag is the name of the component to be created. Ensure that it is unique or it will overwrite the preexisting identically-named component. + +The component will be created, by default, inside `client/app/components`. To change this, apply the `--parent` flag, followed by a path relative to `client/app/components/`. + +For example, running `gulp component --name signup --parent auth` will create a `signup` component at `client/app/components/auth/signup`. + +Running `gulp component --name footer --parent ../common` creates a `footer` component at `client/app/common/footer`. + +Because the argument to `--name` applies to the folder name **and** the actual component name, make sure to camelcase the component names. + +# Starter Kit Support and Questions +> Contact us, anytime, regarding anything about this project. + +* [Gitter: angularclass/NG6-starter](https://gitter.im/angularclass/NG6-starter) +* [Twitter: @AngularClass](https://twitter.com/AngularClass) + +___ + +enjoy — **AngularClass** + +