diff --git a/README.md b/README.md index 10db7c9..1db36d6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# generator-es6-angular -================== +generator-es6-angular +====================== [![NPM version][npm-image]][npm-url] ![][david-url] ![][dt-url] ![][license-url] -Yeoman generator for es6 based angular skeleton with webpack +Yeoman generator for es6 based angular skeleton > You can view the online demo at: [http://leftstick.github.io/generator-es6-angular](http://leftstick.github.io/generator-es6-angular) @@ -14,8 +14,7 @@ Yeoman generator for es6 based angular skeleton with webpack ## Prerequisites ## 1. Install [yeoman](http://yeoman.io/): `npm install -g yo` -2. Install [gulp](http://gulpjs.com/): `npm install -g gulp` -3. Install __this__: `npm install -g generator-es6-angular` +2. Install __this__: `npm install -g generator-es6-angular` > prepend with `sudo` if you are running on `*nix` OS. @@ -29,55 +28,42 @@ Yeoman generator for es6 based angular skeleton with webpack And then, the [es6](https://github.com/lukehoban/es6features) based project generated. -## Debug your app ## +## Quick start ## -The full featured `gulp` and `webpack` are embedded, it's easy to start debugging your app. +### Debug your app ### + +The full featured `dev/dist` tools are provided, it's easy to start debugging your app. Just move into the created directory with the given `project name`. -Run `gulp dev` to start a debug web server for current working directory. +Run `npm start` to start a debug web server for the project. -Open [http://localhost:8080/webpack-dev-server/index.html](http://localhost:8080/webpack-dev-server/index.html), and have fun. +Open [http://localhost:8080/](http://localhost:8080/) to see the playable skeleton, and have fun. -## Release your app ## +### Release your app ### Move the root of the created project. -Run `gulp release` to compile all the source code into webpack bundles. And all required resources are generated into `{root}/build/`. +Run `npm run release` to compile all the source code into webpack bundles. And all required resources are generated into `{root}/build/`. You can copy the `build` folder to anywhere you like, it's the released app. -### Like have a try with the released app? ### +#### Like have a try with the released app? #### Install [sero-cli](https://github.com/leftstick/Sero-cli): `npm install -g sero-cli` Move into `{root}/build/` -Run `sero server -r . -p 8080`, a static web server launched at port 8080. +Run `sero server -p 8080 -h`, a static web server launched at port 8080. Open [http://localhost:8080](http://localhost:8080) to watch the released version. -## note ## - -If you'd like to add [jquery](http://jquery.com/) as replacement of `jqLite`, you have to modify the `webpack.config.dev.js` and `webpack.config.prod.js` with following plugin added: - -```javascript -new webpack.ProvidePlugin({ - $: 'jquery', - 'window.jQuery': 'jquery' -}), -``` +## More read ## -## References ## +Looking for detail? Check it [here](https://github.com/leftstick/generator-es6-angular/blob/master/docs/api.md) -1. [yeoman](http://yeoman.io/) -2. [gulp](http://gulpjs.com/) -3. [webpack](http://webpack.github.io/) -4. [es6-features](https://github.com/lukehoban/es6features) -5. [angular](https://angularjs.org/) -6. [angular-material](https://material.angularjs.org/latest/) ## LICENSE ## diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..949da26 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,48 @@ +## How to involve external library ## + +```bash +npm install --save +``` + +Open `js/fw/ext/main.js`, `import` it, and append the module name to `export` array if provided. + +## Why Dependency Injection looks so weird in this skeleton ## + +This is because [ng-annotate](https://github.com/olov/ng-annotate) is chosen for for providing quick DI. + +## How to add new route ## + +You will find a `Routes.js` in each "feature" folder, it's an `Array` to be exported, and each `object` in it is used to describe a `Route`. + +You can easily append more to an exist `feature`, or add a new `feature` with route. + +## Why `main.js` exist in each folder ## + +The `main.js` in each folder takes the responsibility for managing all modules in that folder, according to such concept, it's more robust to extend functionality without modifying other features. + +## How to use jquery ## + +```bash +npm install --save jquery +``` + +If you'd like to add [jquery](http://jquery.com/) as replacement of `jqLite`, you have to modify the `webpack.config.dev.js` and `webpack.config.prod.js` with following plugin added: + +```javascript +new webpack.ProvidePlugin({ + $: 'jquery', + 'window.jQuery': 'jquery' +}), +``` + +>This is because `AngularJS` internally check if `window.jQuery` provided + + +## References ## + +1. [yeoman](http://yeoman.io/) +2. [gulp](http://gulpjs.com/) +3. [webpack](http://webpack.github.io/) +4. [es6-features](https://github.com/lukehoban/es6features) +5. [angular](https://angularjs.org/) +6. [angular-material](https://material.angularjs.org/latest/) diff --git a/generators/app/index.js b/generators/app/index.js index 54d8304..fb61287 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -71,15 +71,16 @@ var gen = generators.Base.extend({ 'https://registry.npmjs.org' ] } - ], function(answers) { - require('date-util'); - this.answers = answers; - this.answers.date = new Date().format('mmm d, yyyy'); - this.obj = {answers: this.answers}; - done(); - }.bind(this)); + ]) + .then(function(answers) { + require('date-util'); + self.answers = answers; + self.answers.date = new Date().format('mmm d, yyyy'); + self.obj = {answers: self.answers}; + done(); + }); }, - configuring: function() { + configuring: function(answers) { var path = require('path'); var fs = require('fs'); var self = this; @@ -104,20 +105,21 @@ var gen = generators.Base.extend({ interpolate: /<%=([\s\S]+?)%>/g })(self.obj); }); - self.directory(self.templatePath('less'), self.destinationPath('less')); - self.directory(self.templatePath('font'), self.destinationPath('font')); - self.directory(self.templatePath('mock'), self.destinationPath('mock')); - self.copy(self.templatePath('gitignore'), self.destinationPath('.gitignore')); - self.copy(self.templatePath('gulpfile.js'), self.destinationPath('gulpfile.js')); - self.fs.copyTpl(self.templatePath('index.html_vm'), self.destinationPath('index.html'), self.obj); + self.directory(self.templatePath('css'), self.destinationPath('css')); + self.fs.copy(self.templatePath('eslintrc'), self.destinationPath('.eslintrc')); + self.fs.copy(self.templatePath('gitignore'), self.destinationPath('.gitignore')); + self.fs.copy(self.templatePath('index.html_vm'), self.destinationPath('index.html_vm')); + self.fs.copyTpl(self.templatePath('package.json_vm'), self.destinationPath('package.json'), self.obj); - self.copy(self.templatePath('webpack.config.dev.js'), self.destinationPath('webpack.config.dev.js')); - self.copy(self.templatePath('webpack.config.prod.js'), self.destinationPath('webpack.config.prod.js')); + + self.fs.copyTpl(self.templatePath('webpack.config.dev.js'), + self.destinationPath('webpack.config.dev.js'), self.obj); + + self.fs.copyTpl(self.templatePath('webpack.config.prod.js'), + self.destinationPath('webpack.config.prod.js'), self.obj); }, install: function() { - this.npmInstall(undefined, { - registry: this.answers.registry - }); + this.npmInstall(null, {registry: this.answers.registry}); }, end: function() { this.log.ok('Project ' + this.answers.name + ' generated!!!'); diff --git a/generators/app/templates/css/main.css b/generators/app/templates/css/main.css new file mode 100644 index 0000000..d6de91b --- /dev/null +++ b/generators/app/templates/css/main.css @@ -0,0 +1,177 @@ +/* body */ +*{ + box-sizing: border-box; +} + +html, body{ + margin: 0; + padding: 0; +} + +body{ + font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif; +} + +a[disabled]{ + pointer-events: none; + color: #7f8c8d; +} + +a{ + text-decoration: none; + color: #2E64FE; +} + +[ng-view]{ + text-align: center; +} + +/* nav */ +#nav { + list-style-type: none; + text-align: center; + padding: 0; + margin: 0; +} + +#nav li { + display: inline-block; + line-height: 40px; +} + +.nav-link { + color: #7f8c8d; + cursor: pointer; + text-decoration: none; + padding-bottom: 3px; + margin: 0 25px; +} + +.nav-link.active { + color: #424242; +} + +.nav-link:first-child { + margin-left: 0; +} + +.nav-link:hover { + border-bottom: 3px solid #dd1b16; +} + +/* logo */ +#logo-wrap { + margin: 55px 0 20px 0; +} + +#logo-wrap img{ + margin-bottom: 15px; +} + +#logo-wrap h1 { + font-family: 'Dosis', 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif; + font-weight: 400; + font-size: 27px; +} + +#desc { + max-width: 800px; + padding: 0 20px; + text-align: center; + margin: 10px auto; + color: #7f8c8d; +} + +#github{ + margin: 30px 0 30px 0; +} + +#todo-app{ + width: 250px; + margin: 0 auto; +} + +#todo-app input[type="text"]{ + width: 250px; + height: 35px; + font-size: 16px; + padding: 6px 12px; + border: 1px solid #ccc; + border-radius: 4px; + margin-bottom: 10px; +} + +#todo-app .todos{ + width: 100%; + list-style-type: none; + margin: 10px 0 10px 0 ; + padding: 0; + text-align: left; +} + +#todo-app .todos li{ + padding-top: 4px; +} + +#todo-app .todos li span{ + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + width: 225px; + display: inline-block; + line-height: 24px; + vertical-align: middle; +} + +#todo-app .archive{ + text-decoration: none; +} + +#why{ + width: 600px; + margin: 55px auto 15px auto; + padding: 5px; + text-align: left; + border: 1px solid #D8D8D8; + border-radius: 2px; + background-color: #f7f7f9; +} + +#why h4{ + margin-top: 0; +} + +#why ul li { + padding-top: 5px; +} + +#more{ + width: 600px; + margin: 30px auto 15px auto; + padding: 5px; +} + +#more .button{ + display: inline-block; + width: 150px; + height: 35px; + line-height: 35px; + color: #fff; + border-radius: 2px; + border-width: 0; + background-color: #FE2E2E; + box-shadow: 2px 2px 1px #a6120d; + transition: all 0.3s ease 0s; +} + +#more .button:hover{ + box-shadow: 4px 4px 2px #a6120d; +} + +/* footer */ +#footer{ + margin-top: 20px; + text-align: center; + padding: 20px 0; + background-color: #D8D8D8; +} diff --git a/generators/app/templates/eslintrc b/generators/app/templates/eslintrc new file mode 100644 index 0000000..be86970 --- /dev/null +++ b/generators/app/templates/eslintrc @@ -0,0 +1,196 @@ +{ + "parserOptions":{ + "ecmaVersion": 6, + "sourceType": "module", + "ecmaFeatures": { + "globalReturn": true, + "impliedStrict": false, + "jsx": false, + "experimentalObjectRestSpread": true + } + }, + "env": { + "shared-node-browser": true, + "browser": true, + "commonjs": true, + "node": true, + "es6": true, + "mocha": true, + "jquery": true + }, + "rules": { + "comma-dangle": [2, "never"], + "no-cond-assign": [2, "except-parens"], + "no-console": 0, + "no-constant-condition": 1, + "no-control-regex": 2, + "no-debugger": 2, + "no-dupe-args": 2, + "no-dupe-keys": 2, + "no-duplicate-case": 2, + "no-empty-character-class": 1, + "no-empty": 1, + "no-ex-assign": 2, + "no-extra-boolean-cast": 1, + "no-extra-parens": [1, "functions"], + "no-extra-semi": 2, + "no-func-assign": 2, + "no-inner-declarations": [1, "functions"], + "no-invalid-regexp": 2, + "no-irregular-whitespace": 1, + "no-negated-in-lhs": 2, + "no-obj-calls": 2, + "no-regex-spaces": 1, + "no-sparse-arrays": 2, + "no-unexpected-multiline": 2, + "no-unreachable": 2, + "use-isnan": 2, + "valid-jsdoc": 0, + "valid-typeof": 2, + "accessor-pairs": [1, { "getWithoutSet": true, "setWithoutGet": true }], + "array-callback-return": 1, + "block-scoped-var": 0, + "complexity": [1, 7], + "consistent-return": 0, + "curly": 1, + "default-case": 2, + "dot-location": [1, "property"], + "dot-notation": [1, { "allowKeywords": true}], + "eqeqeq": 2, + "guard-for-in": 0, + "no-alert": 2, + "no-caller": 2, + "no-case-declarations": 2, + "no-div-regex": 1, + "no-else-return": 1, + "no-empty-function": 0, + "no-empty-pattern": 2, + "no-eq-null": 2, + "no-eval": 2, + "no-extend-native": 1, + "no-extra-bind": 1, + "no-extra-label": 1, + "no-fallthrough": 2, + "no-floating-decimal": 2, + "no-implicit-coercion": 0, + "no-implicit-globals": 0, + "no-implied-eval": 2, + "no-invalid-this": 0, + "no-iterator": 1, + "no-labels": [2, {"allowLoop": false, "allowSwitch": false}], + "no-lone-blocks": 2, + "no-loop-func": 2, + "no-magic-numbers": 0, + "no-multi-spaces": 1, + "no-multi-str": 2, + "no-native-reassign": 2, + "no-new-func": 2, + "no-new-wrappers": 2, + "no-new": 1, + "no-octal-escape": 1, + "no-octal": 1, + "no-param-reassign": [2, {"props": false}], + "no-process-env": 0, + "no-proto": 2, + "no-redeclare": [2, { "builtinGlobals": true }], + "no-return-assign": [2, "except-parens"], + "no-script-url": 2, + "no-self-assign": 2, + "no-self-compare": 2, + "no-sequences": 2, + "no-throw-literal": 2, + "no-unmodified-loop-condition": 1, + "no-unused-expressions": [2, { "allowShortCircuit": true, "allowTernary": false }], + "no-unused-labels": 1, + "no-useless-call": 1, + "no-useless-concat": 1, + "no-void": 2, + "no-warning-comments": [1, { "terms": ["todo", "fix"], "location": "anywhere" }], + "no-with": 2, + "radix": [2, "as-needed"], + "vars-on-top": 0, + "wrap-iife": [2, "outside"], + "yoda": [1, "never", { "onlyEquality": true }], + "strict": [1, "safe"], + "init-declarations": 0, + "no-catch-shadow": 2, + "no-delete-var": 2, + "no-label-var": 2, + "no-shadow-restricted-names": 2, + "no-shadow": [2, {"builtinGlobals": false, "hoist": "functions"}], + "no-undef-init": 1, + "no-undef": [2, { "typeof": false }], + "no-undefined": 1, + "no-unused-vars": [1, { "vars": "all", "args": "none" }], + "no-use-before-define": [1, {"functions": true, "classes": true}], + "array-bracket-spacing": [1, "never"], + "block-spacing": [1, "always"], + "brace-style": [1, "1tbs", { "allowSingleLine": true }], + "camelcase": [1, {"properties": "never"}], + "comma-spacing": [2, {"before": false, "after": true}], + "comma-style": [1, "last"], + "computed-property-spacing": [1, "never"], + "consistent-this": [1, "_this", "self", "ctx"], + "eol-last": [1, "unix"], + "func-names": 0, + "func-style": [1, "expression", { "allowArrowFunctions": true }], + "id-length": [2, {"min": 1, "max": 35, "properties": "never"}], + "id-match": 0, + "id-blacklist": 0, + "indent": [1, 4, {"VariableDeclarator": 1, "SwitchCase": 1}], + "jsx-quotes": 0, + "key-spacing": [1, {"beforeColon": false, "afterColon": true}], + "keyword-spacing": [1, {"before": true, "after": true}], + "linebreak-style": [1, "unix"], + "lines-around-comment": [1, { "beforeBlockComment": true, "afterBlockComment": false, "beforeLineComment": true, "afterLineComment": false, "allowBlockStart": true, "allowBlockEnd": true, "allowObjectStart": true, "allowArrayStart": false, "allowArrayEnd": false }], + "max-depth": [1, 5], + "max-len": [1, {"code": 120, "comments": 120, "tabWidth": 4, "ignoreUrls": true}], + "max-nested-callbacks": [1, 5], + "max-params": [1, 10], + "max-statements": [1, 12, {"ignoreTopLevelFunctions": true}], + "new-cap": [1, {"newIsCap": true, "capIsNew": true, "properties": false}], + "new-parens": 1, + "newline-after-var": 0, + "newline-per-chained-call": 0, + "no-array-constructor": 1, + "no-bitwise": 0, + "no-continue": 0, + "no-inline-comments": 0, + "no-lonely-if": 1, + "no-mixed-spaces-and-tabs": 1, + "no-multiple-empty-lines": [1, {"max": 2}], + "no-negated-condition": 0, + "no-nested-ternary": 1, + "no-new-object": 1, + "no-plusplus": 0, + "no-restricted-syntax": [1, "WithStatement"], + "no-whitespace-before-property": 1, + "no-spaced-func": 1, + "no-ternary": 0, + "no-trailing-spaces": [1, { "skipBlankLines": true }], + "no-underscore-dangle": 0, + "no-unneeded-ternary": 1, + "object-curly-spacing": [1, "never"], + "one-var": 0, + "one-var-declaration-per-line": 0, + "operator-assignment": 0, + "operator-linebreak": 0, + "padded-blocks": 0, + "quote-props": [1, "as-needed"], + "quotes": [1, "single"], + "require-jsdoc": 0, + "semi-spacing": [2, { "before": false, "after": true }], + "semi": [1, "always"], + "sort-vars": 0, + "sort-imports": 0, + "space-before-blocks": [1, { "functions": "always", "keywords": "always", "classes": "always" }], + "space-before-function-paren": [1, {"anonymous": "never", "named": "never"}], + "space-in-parens": [1, "never"], + "space-infix-ops": 1, + "space-unary-ops": [1, { "words": true, "nonwords": false }], + "spaced-comment": 0, + "wrap-regex": 0 + }, + "globals": { + } +} diff --git a/generators/app/templates/etc/config.js b/generators/app/templates/etc/config.js index 194a808..f01a7b3 100644 --- a/generators/app/templates/etc/config.js +++ b/generators/app/templates/etc/config.js @@ -6,10 +6,5 @@ * @date <%= answers.date %> * **/ -'use strict'; -export default { - 'appname': '<%= answers.name %>', - 'version': '1.0.0', - 'api': 'mock' -}; +export default {appname: '<%= answers.name %>', version: '1.0.0'}; diff --git a/generators/app/templates/font/fontello.eot b/generators/app/templates/font/fontello.eot deleted file mode 100644 index 4301e3c..0000000 Binary files a/generators/app/templates/font/fontello.eot and /dev/null differ diff --git a/generators/app/templates/font/fontello.svg b/generators/app/templates/font/fontello.svg deleted file mode 100644 index 91684a2..0000000 --- a/generators/app/templates/font/fontello.svg +++ /dev/null @@ -1,29 +0,0 @@ - - - -Copyright (C) 2016 by original authors @ fontello.com - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/generators/app/templates/font/fontello.ttf b/generators/app/templates/font/fontello.ttf deleted file mode 100644 index b388a46..0000000 Binary files a/generators/app/templates/font/fontello.ttf and /dev/null differ diff --git a/generators/app/templates/font/fontello.woff b/generators/app/templates/font/fontello.woff deleted file mode 100644 index 083c4ea..0000000 Binary files a/generators/app/templates/font/fontello.woff and /dev/null differ diff --git a/generators/app/templates/gulpfile.js b/generators/app/templates/gulpfile.js deleted file mode 100644 index 49be644..0000000 --- a/generators/app/templates/gulpfile.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); -var gutil = require('gulp-util'); -var webpack = require('webpack'); -var del = require('del'); - -gulp.task('clean', function() { - return del(['./build/**/*']);; -}); - -gulp.task('copy', ['clean'], function() { - return gulp.src(['img/**/*', 'mock/**/*'], {'base': '.'}) - .pipe(gulp.dest('build/')); -}); - -gulp.task('release', ['copy'], function(callback) { - var path = require('path'); - var replace = require('gulp-replace'); - var config = require('./webpack.config.prod'); - - webpack(config, function(err, stats) { - if (err) { - throw new gutil.PluginError('webpack', err); - } - gutil.log('[webpack]', stats.toString()); - gulp.src(['index.html'], {'base': '.'}) - .pipe(replace('common.bundle.js', stats.hash + '.common.bundle.js')) - .pipe(replace('index.bundle.js', stats.hash + '.index.bundle.js')) - .pipe(gulp.dest('build/')) - .on('end', callback); - }); -}); - - -gulp.task('dev', function(callback) { - var WebpackDevServer = require('webpack-dev-server'); - var config = require('./webpack.config.dev'); - - new WebpackDevServer(webpack(config), { - historyApiFallback: true, - publicPath: '/js/' - }).listen(8080, 'localhost', function(err) { - if (err) { - throw new gutil.PluginError('webpack-dev-server', err); - } - // Server listening - gutil.log('[webpack-dev-server]', 'http://localhost:8080/webpack-dev-server/index.html'); - }); -}); diff --git a/generators/app/templates/img/AngularJS-large.png b/generators/app/templates/img/AngularJS-large.png new file mode 100644 index 0000000..d3beb67 Binary files /dev/null and b/generators/app/templates/img/AngularJS-large.png differ diff --git a/generators/app/templates/img/avatar.png b/generators/app/templates/img/avatar.png deleted file mode 100644 index 3d4eafa..0000000 Binary files a/generators/app/templates/img/avatar.png and /dev/null differ diff --git a/generators/app/templates/index.html_vm b/generators/app/templates/index.html_vm index 1da315f..c2106d8 100644 --- a/generators/app/templates/index.html_vm +++ b/generators/app/templates/index.html_vm @@ -1,13 +1,11 @@ -<% if (answers.pushState) { %><% } %> - + + <% if (htmlWebpackPlugin.options.pushState) { %><% } %> + + -
-
-
+
- - - + diff --git a/generators/app/templates/js/features/about/Routes.js b/generators/app/templates/js/features/about/Routes.js new file mode 100644 index 0000000..8563c99 --- /dev/null +++ b/generators/app/templates/js/features/about/Routes.js @@ -0,0 +1,21 @@ +/** + * + * Routes module expose route information used in about feature + * + * @author <%= answers.username %> + * @date <%= answers.date %> + * + */ + +import tpl from './partials/about.html'; + +export default [ + { + id: 'about', + isDefault: false, + when: '/about', + controller: 'AboutController', + controllerAs: 'about', + template: tpl + } +]; diff --git a/generators/app/templates/js/features/about/controller/AboutController.js b/generators/app/templates/js/features/about/controller/AboutController.js new file mode 100644 index 0000000..5f9c042 --- /dev/null +++ b/generators/app/templates/js/features/about/controller/AboutController.js @@ -0,0 +1,26 @@ +/** + * Defines the AboutController controller + * + * @author <%= answers.username %> + * @date <%= answers.date %> + * + */ + +class AboutController { + + /*@ngInject*/ + constructor($scope) { + this.$scope = $scope; + + this._init_(); + this._destroy_(); + } + + _init_() {} + + _destroy_() { + this.$scope.$on('$destroy', function() {}); + } +} + +export default AboutController; diff --git a/generators/app/templates/js/features/list/main.js b/generators/app/templates/js/features/about/main.js similarity index 71% rename from generators/app/templates/js/features/list/main.js rename to generators/app/templates/js/features/about/main.js index fc0aeac..56493be 100644 --- a/generators/app/templates/js/features/list/main.js +++ b/generators/app/templates/js/features/about/main.js @@ -8,11 +8,10 @@ * * ****************************************************************************************************** */ -'use strict'; + import FeatureBase from 'lib/FeatureBase'; import Routes from './Routes'; -import ListController from './controller/ListController'; -import ListService from './service/ListService'; +import AboutController from './controller/AboutController'; class Feature extends FeatureBase { @@ -22,8 +21,7 @@ class Feature extends FeatureBase { } execute() { - this.controller('ListController', ListController); - this.service('ListService', ListService); + this.controller('AboutController', AboutController); } } diff --git a/generators/app/templates/js/features/about/partials/about.html b/generators/app/templates/js/features/about/partials/about.html new file mode 100644 index 0000000..1c6523b --- /dev/null +++ b/generators/app/templates/js/features/about/partials/about.html @@ -0,0 +1,15 @@ +
+

You may choose it if you are looking for skeleton with:

+ +
+ +
+ + more read + +
diff --git a/generators/app/templates/js/features/common/logical/Header.html b/generators/app/templates/js/features/common/logical/Header.html new file mode 100644 index 0000000..3ca51c9 --- /dev/null +++ b/generators/app/templates/js/features/common/logical/Header.html @@ -0,0 +1,8 @@ + diff --git a/generators/app/templates/js/features/common/logical/Header.js b/generators/app/templates/js/features/common/logical/Header.js new file mode 100644 index 0000000..dfa7e2d --- /dev/null +++ b/generators/app/templates/js/features/common/logical/Header.js @@ -0,0 +1,45 @@ +/** + * Defines the Toolbar of whole application. + * + * @author <%= answers.username %> + * @date <%= answers.date %> + * + */ + +import FeatureBase from 'lib/FeatureBase'; +import HeaderTpl from './Header.html'; +import {element} from 'angular'; + +class Feature extends FeatureBase { + + constructor() { + super('HeaderModule'); + this.$body = element(document.body); + } + + beforeStart() { + this.$body.prepend(HeaderTpl); + } + + _HeaderController($scope, $rootScope) { + 'ngInject'; + + $scope.route = 'home'; + + $scope.activeRoute = function(name) { + $scope.route = name; + }; + + $rootScope.$on('$routeChangeSuccess', function(e, next) { + if (next.$$route && next.$$route.id) { + $scope.route = next.$$route.id; + } + }); + } + + execute() { + this.controller('HeaderController', this._HeaderController); + } +} + +export default Feature; diff --git a/generators/app/templates/js/features/common/logical/Sidebar.html b/generators/app/templates/js/features/common/logical/Sidebar.html deleted file mode 100644 index 69b3b03..0000000 --- a/generators/app/templates/js/features/common/logical/Sidebar.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - -

HOME

-
- - -

LIST

-
-
-
diff --git a/generators/app/templates/js/features/common/logical/Sidebar.js b/generators/app/templates/js/features/common/logical/Sidebar.js deleted file mode 100644 index dab4046..0000000 --- a/generators/app/templates/js/features/common/logical/Sidebar.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Defines the Sidebar of whole application. - * - * @author <%= answers.username %> - * @date <%= answers.date %> - * - */ -'use strict'; - -import FeatureBase from 'lib/FeatureBase'; -import SidebarTpl from './Sidebar.html'; -import { element } from 'angular'; - -class Feature extends FeatureBase { - - constructor() { - super('SidebarModule'); - } - - beforeStart() { - element(document.querySelector('#main')).prepend(SidebarTpl); - } - - /*@ngInject*/ - _SidebarController($scope, $mdSidenav, utils, $location) { - $scope.go = function($event, target) { - utils.stopEvent($event); - $location.path(target); - $mdSidenav('left-side').toggle(); - }; - } - - execute() { - this.controller('SidebarController', this._SidebarController); - } -} - -export default Feature; diff --git a/generators/app/templates/js/features/common/logical/Toolbar.html b/generators/app/templates/js/features/common/logical/Toolbar.html deleted file mode 100644 index adef72f..0000000 --- a/generators/app/templates/js/features/common/logical/Toolbar.html +++ /dev/null @@ -1,18 +0,0 @@ - -
- - - - - - - - - - - - - - -
-
diff --git a/generators/app/templates/js/features/common/logical/Toolbar.js b/generators/app/templates/js/features/common/logical/Toolbar.js deleted file mode 100644 index d2fec8a..0000000 --- a/generators/app/templates/js/features/common/logical/Toolbar.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Defines the Toolbar of whole application. - * - * @author <%= answers.username %> - * @date <%= answers.date %> - * - */ -'use strict'; - -import FeatureBase from 'lib/FeatureBase'; -import ToolbarTpl from './Toolbar.html'; -import { element } from 'angular'; - -class Feature extends FeatureBase { - - constructor() { - super('ToolbarModule'); - this.$body = element(document.body); - } - - beforeStart() { - this.$body.prepend(ToolbarTpl); - } - - /*@ngInject*/ - _ToolbarController($scope, $mdSidenav, utils, $location) { - $scope.toggleSidebar = function(componentId) { - $mdSidenav(componentId).toggle(); - }; - - $scope.go = function($event, target) { - utils.stopEvent($event); - $location.path(target); - }; - } - - execute() { - this.controller('ToolbarController', this._ToolbarController); - } -} - -export default Feature; diff --git a/generators/app/templates/js/features/common/logical/main.js b/generators/app/templates/js/features/common/logical/main.js index b9ed946..3390e1c 100644 --- a/generators/app/templates/js/features/common/logical/main.js +++ b/generators/app/templates/js/features/common/logical/main.js @@ -5,9 +5,7 @@ * @date <%= answers.date %> * */ -'use strict'; -import toolbar from './Toolbar'; -import sidebar from './Sidebar'; +import header from './Header'; -export default [sidebar, toolbar]; +export default [header]; diff --git a/generators/app/templates/js/features/common/main.js b/generators/app/templates/js/features/common/main.js index 461c84d..7893cf2 100644 --- a/generators/app/templates/js/features/common/main.js +++ b/generators/app/templates/js/features/common/main.js @@ -6,7 +6,7 @@ * @date <%= answers.date %> * */ -'use strict'; + import logical from './logical/main'; import ui from './ui/main'; diff --git a/generators/app/templates/js/features/common/ui/Autofocus.js b/generators/app/templates/js/features/common/ui/Autofocus.js index 283f59b..2422eb3 100644 --- a/generators/app/templates/js/features/common/ui/Autofocus.js +++ b/generators/app/templates/js/features/common/ui/Autofocus.js @@ -6,7 +6,6 @@ * @date <%= answers.date %> * */ -'use strict'; import FeatureBase from 'lib/FeatureBase'; @@ -16,7 +15,7 @@ class Feature extends FeatureBase { super('AutofocusModule'); } - autoFocus() { + _autoFocus() { return { restrict: 'A', link: function($scope, element) { @@ -26,7 +25,7 @@ class Feature extends FeatureBase { } execute() { - this.directive('autofocus', this.autoFocus); + this.directive('autofocus', this._autoFocus); } } diff --git a/generators/app/templates/js/features/common/ui/RouteIndicator.js b/generators/app/templates/js/features/common/ui/RouteIndicator.js index b0b5faa..43c22ca 100644 --- a/generators/app/templates/js/features/common/ui/RouteIndicator.js +++ b/generators/app/templates/js/features/common/ui/RouteIndicator.js @@ -6,9 +6,8 @@ * @date <%= answers.date %> * */ -'use strict'; -import { element } from 'angular'; +import {element} from 'angular'; import pluck from 'lib/Pluck'; import FeatureBase from 'lib/FeatureBase'; @@ -18,7 +17,7 @@ class Feature extends FeatureBase { super('RouteIndicator'); } - indicator($rootScope, Routes) { + _indicator($rootScope, Routes) { 'ngInject'; var $body = element(document.body); @@ -33,7 +32,7 @@ class Feature extends FeatureBase { } execute() { - this.run(this.indicator); + this.run(this._indicator); } } diff --git a/generators/app/templates/js/features/common/ui/main.js b/generators/app/templates/js/features/common/ui/main.js index 48cb39b..e4aadbf 100644 --- a/generators/app/templates/js/features/common/ui/main.js +++ b/generators/app/templates/js/features/common/ui/main.js @@ -5,7 +5,6 @@ * @date <%= answers.date %> * */ -'use strict'; import autofocus from './Autofocus'; import routeIndicator from './RouteIndicator'; diff --git a/generators/app/templates/js/features/home/Routes.js b/generators/app/templates/js/features/home/Routes.js index 68b4e1b..cdbd2aa 100644 --- a/generators/app/templates/js/features/home/Routes.js +++ b/generators/app/templates/js/features/home/Routes.js @@ -6,7 +6,6 @@ * @date <%= answers.date %> * */ -'use strict'; import tpl from './partials/home.html'; diff --git a/generators/app/templates/js/features/home/controller/HomeController.js b/generators/app/templates/js/features/home/controller/HomeController.js index ea2a9ff..afabe90 100644 --- a/generators/app/templates/js/features/home/controller/HomeController.js +++ b/generators/app/templates/js/features/home/controller/HomeController.js @@ -5,47 +5,48 @@ * @date <%= answers.date %> * */ -'use strict'; + +import logoUrl from 'img/AngularJS-large.png'; class HomeController { /*@ngInject*/ - constructor($scope, utils, HomeService, $mdToast, $mdDialog) { + constructor($scope, HomeService) { this.$scope = $scope; - this.utils = utils; this.HomeService = HomeService; - this.$mdToast = $mdToast; - this.$mdDialog = $mdDialog; this._init_(); this._destroy_(); } _init_() { - this.state = {}; - this.HomeService.getStates() - .success(data => this.states = data); + this.logoUrl = logoUrl; + this.todos = []; + this.HomeService + .getInitTodos() + .then(todos => { + this.todos = todos; + }); + } + + addTodo(e) { + if (e.keyCode !== 13) { + return; + } + this.todos.push({txt: e.target.value}); + e.target.value = ''; + } + + toggleTodo(todo) { + todo.finished = !todo.finished; } - toast() { - this.$mdToast.show( - this.$mdToast.simple() - .textContent('Simple Toast!') - .position('top') - .hideDelay(3000) - ); + remaining() { + return this.todos.reduce((n, todo) => n + Number(!todo.finished), 0); } - dialog($event) { - this.$mdDialog.show( - this.$mdDialog.alert() - .clickOutsideToClose(true) - .title('This is an alert title') - .textContent('You can specify some description text in here.') - .ariaLabel('Alert Dialog Demo') - .ok('Got it!') - .targetEvent($event) - ); + archive() { + this.todos = this.todos.filter(todo => !todo.finished); } _destroy_() { diff --git a/generators/app/templates/js/features/home/main.js b/generators/app/templates/js/features/home/main.js index d99a598..eaf238a 100644 --- a/generators/app/templates/js/features/home/main.js +++ b/generators/app/templates/js/features/home/main.js @@ -8,7 +8,7 @@ * * ****************************************************************************************************** */ -'use strict'; + import FeatureBase from 'lib/FeatureBase'; import Routes from './Routes'; import HomeController from './controller/HomeController'; diff --git a/generators/app/templates/js/features/home/partials/home.html b/generators/app/templates/js/features/home/partials/home.html index da042e0..09ab19a 100644 --- a/generators/app/templates/js/features/home/partials/home.html +++ b/generators/app/templates/js/features/home/partials/home.html @@ -1,93 +1,38 @@ - - - - - ES2015 AngularJS Skeleton - - - -

- This page demonstrate you the basis of this skeleton. And some common components were implemented for use. Feel free to register issue while encountering problems -

-
- - - - -
- - - - - - - {{ item }} - - - - - flat - raised button - - - - - - - toast - - - - dialog - - - - - - - - - Switch 1: {{ data.cb1 }} - - - - - - Checkbox 2 (md-warn)
- - You would never know what is this! But you can click it - -
- {{ state.checkbox }} -
-
- - - - - - - - - - - - - - - -
-
- - -
+
+ +

generator-es6-angular

+
+ +

+ Flexible, robust skeleton for AngularJS, including full featured dev/release process

+ Very welcome to give me feedbacks!

+ Stars would be the best^^!! +

+ +
+ + +
+ +
+

Simple TODO app

+ + + {{ home.remaining() }} of {{ home.todos.length }} remaining + + + + archive +
+ + diff --git a/generators/app/templates/js/features/home/service/HomeService.js b/generators/app/templates/js/features/home/service/HomeService.js index 8ea52c0..af7e3c9 100644 --- a/generators/app/templates/js/features/home/service/HomeService.js +++ b/generators/app/templates/js/features/home/service/HomeService.js @@ -5,7 +5,6 @@ * @date <%= answers.date %> * */ -'use strict'; class HomeService { @@ -15,8 +14,22 @@ class HomeService { this.utils = utils; } - getStates() { - return this.$http.get(this.utils.getApi('/states')); + getInitTodos() { + return Promise.resolve([ + { + finished: true, + txt: 'Learn JavaScript' + }, + { + txt: 'Learn AngularJS' + }, + { + txt: 'Learn webpack' + }, + { + txt: 'Learn node' + } + ]); } } diff --git a/generators/app/templates/js/features/list/Routes.js b/generators/app/templates/js/features/list/Routes.js deleted file mode 100644 index 4610928..0000000 --- a/generators/app/templates/js/features/list/Routes.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * - * Routes module expose route information used in list feature - * - * @author <%= answers.username %> - * @date <%= answers.date %> - * - */ -'use strict'; -import tpl from './partials/list.html'; - -export default [ - { - id: 'list', - isDefault: false, - when: '/list', - controller: 'ListController', - controllerAs: 'list', - template: tpl - } -]; diff --git a/generators/app/templates/js/features/list/controller/ListController.js b/generators/app/templates/js/features/list/controller/ListController.js deleted file mode 100644 index f33aec1..0000000 --- a/generators/app/templates/js/features/list/controller/ListController.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Defines the ListController controller - * - * @author <%= answers.username %> - * @date <%= answers.date %> - * - */ -'use strict'; - -class ListController { - - /*@ngInject*/ - constructor($scope, ListService) { - this.$scope = $scope; - this.ListService = ListService; - - this._init_(); - this._destroy_(); - } - - _init_() { - this.ListService - .getDemoList() - .success(data => this.demolist = data) - .error(err => console.log(err)); - } - - _destroy_() { - this.$scope.$on('$destroy', function() {}); - } -} - -export default ListController; diff --git a/generators/app/templates/js/features/list/partials/list.html b/generators/app/templates/js/features/list/partials/list.html deleted file mode 100644 index a5df596..0000000 --- a/generators/app/templates/js/features/list/partials/list.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - Listing here - - avatar -
-

{{ item.subjectId }}

-

{{ item.subjectName }}

-

{{ item.indexDelta }}

-
-
-
-
-
diff --git a/generators/app/templates/js/features/list/service/ListService.js b/generators/app/templates/js/features/list/service/ListService.js deleted file mode 100644 index ab463ab..0000000 --- a/generators/app/templates/js/features/list/service/ListService.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Defines the ListService - * - * @author <%= answers.username %> - * @date <%= answers.date %> - * - */ -'use strict'; -class ListService { - - /*@ngInject*/ - constructor($http, utils) { - this.$http = $http; - this.utils = utils; - } - - getDemoList() { - return this.$http.get(this.utils.getApi('/demolist')); - } - -} - -export default ListService; diff --git a/generators/app/templates/js/features/main.js b/generators/app/templates/js/features/main.js index 559beb3..b688f9d 100644 --- a/generators/app/templates/js/features/main.js +++ b/generators/app/templates/js/features/main.js @@ -5,9 +5,9 @@ * @date <%= answers.date %> * */ -'use strict'; + import common from './common/main'; import home from './home/main'; -import list from './list/main'; +import about from './about/main'; -export default [list, ...common, home]; +export default [about, ...common, home]; diff --git a/generators/app/templates/js/fw/config/MaterialConfig.js b/generators/app/templates/js/fw/config/MaterialConfig.js deleted file mode 100644 index fb97733..0000000 --- a/generators/app/templates/js/fw/config/MaterialConfig.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * MaterialConfig set angular-material needed configurations - * - * @author <%= answers.username %> - * @date <%= answers.date %> - * - */ -'use strict'; -import ConfiguratorBase from 'lib/ConfiguratorBase'; - -class Configurator extends ConfiguratorBase { - constructor(features, app) { - super(features, app); - } - - execute() { - this.config(function($mdThemingProvider) { - 'ngInject'; - - $mdThemingProvider - .theme('default') - .primaryPalette('indigo') - .accentPalette('green') - .warnPalette('red'); - }); - } -} - -export default Configurator; diff --git a/generators/app/templates/js/fw/config/RouterConfig.js b/generators/app/templates/js/fw/config/RouterConfig.js index f033b2f..83d584d 100644 --- a/generators/app/templates/js/fw/config/RouterConfig.js +++ b/generators/app/templates/js/fw/config/RouterConfig.js @@ -7,7 +7,6 @@ * @date <%= answers.date %> * */ -'use strict'; import ConfiguratorBase from 'lib/ConfiguratorBase'; import pluck from 'lib/Pluck'; import omit from 'lib/Omit'; @@ -17,7 +16,7 @@ class Configurator extends ConfiguratorBase { super(features, app); } - routeConfig($locationProvider, $routeProvider){ + _routeConfig($locationProvider, $routeProvider){ //config each router this.routes.forEach(function(ro) { $routeProvider @@ -25,9 +24,7 @@ class Configurator extends ConfiguratorBase { }); //config default page - var defaultRouter = this.routes.filter(function(route) { - return route.isDefault; - })[0]; + var defaultRouter = this.routes.filter(route => route.isDefault)[0]; if (defaultRouter) { $routeProvider.otherwise({ redirectTo: defaultRouter.when @@ -41,27 +38,14 @@ class Configurator extends ConfiguratorBase { $locationProvider.html5Mode(false); <% } %> } - execute() { - if (!this.features || this.features.length === 0) { - console.warn('No features loaded'); - return; - } - - this.routes = this.features - .filter(function(feature) { - return feature.routes && feature.routes.length > 0; - }) - .map(function(feature) { - return feature.routes; - }) - .reduce(function(previous, current) { - return previous.concat(current); - }, []); - - var defaultRoutes = this.routes.filter(function(route) { - return route.isDefault; - }); + _filterRoutes(){ + return this.features + .filter(feature => feature.routes && feature.routes.length > 0) + .map(feature => feature.routes) + .reduce((previous, current) => previous.concat(current), []); + } + _startupWarning(routes, defaultRoutes){ if (defaultRoutes.length === 0) { console.warn('There is no any default route set. Try setting isDefault to the route you preferred'); } else if (defaultRoutes.length > 1) { @@ -69,17 +53,30 @@ class Configurator extends ConfiguratorBase { console.warn('You have set [' + defaultRoutes.length + '] default routes, they are [' + defaultWhens.join(', ') + ']. Try to correct it'); } - var routeWhens = pluck(this.routes, 'when').sort(); + var routeWhens = pluck(routes, 'when').sort(); for (var i = 0; i < routeWhens.length - 1; i++) { if (routeWhens[i] === routeWhens[i + 1]) { throw new Error('Duplicated Route: [ ' + routeWhens[i] + ' ]'); } } + } + + execute() { + if (!this.features || this.features.length === 0) { + console.warn('No features loaded'); + return; + } + + this.routes = this._filterRoutes(); + + var defaultRoutes = this.routes.filter(route => route.isDefault); + + this._startupWarning(this.routes, defaultRoutes); this.constant('Routes', this.routes); - var routeConfig = this.routeConfig.bind(this); + var routeConfig = this._routeConfig.bind(this); routeConfig.$inject = ['$locationProvider', '$routeProvider']; this.config(routeConfig); diff --git a/generators/app/templates/js/fw/config/SSOConfig.js b/generators/app/templates/js/fw/config/SSOConfig.js index 28e6606..f29a626 100644 --- a/generators/app/templates/js/fw/config/SSOConfig.js +++ b/generators/app/templates/js/fw/config/SSOConfig.js @@ -5,7 +5,6 @@ * @date <%= answers.date %> * */ -'use strict'; import ConfiguratorBase from 'lib/ConfiguratorBase'; class Configurator extends ConfiguratorBase { @@ -13,7 +12,7 @@ class Configurator extends ConfiguratorBase { super(features, app); } - httpConfig($httpProvider) { + _httpConfig($httpProvider) { 'ngInject'; $httpProvider.defaults.headers.common.Accept = 'application/json;charset=utf-8'; @@ -21,7 +20,7 @@ class Configurator extends ConfiguratorBase { } execute() { - this.config(this.httpConfig); + this.config(this._httpConfig); } } diff --git a/generators/app/templates/js/fw/config/main.js b/generators/app/templates/js/fw/config/main.js index 5d7a15c..7a805c6 100644 --- a/generators/app/templates/js/fw/config/main.js +++ b/generators/app/templates/js/fw/config/main.js @@ -6,10 +6,8 @@ * @date <%= answers.date %> * */ -'use strict'; -import material from './MaterialConfig'; import router from './RouterConfig'; import sso from './SSOConfig'; -export default [material, router, sso]; +export default [router, sso]; diff --git a/generators/app/templates/js/fw/ext/main.js b/generators/app/templates/js/fw/ext/main.js index 0953f30..f4d92b0 100644 --- a/generators/app/templates/js/fw/ext/main.js +++ b/generators/app/templates/js/fw/ext/main.js @@ -5,20 +5,7 @@ * @date <%= answers.date %> * */ -'use strict'; -import 'angular-animate'; import 'angular-route'; -import 'angular-sanitize'; -import 'angular-aria'; -import 'angular-messages'; -import 'angular-material'; -export default [ - 'ngAnimate', - 'ngRoute', - 'ngSanitize', - 'ngAria', - 'ngMessages', - 'ngMaterial' -]; +export default ['ngRoute']; diff --git a/generators/app/templates/js/fw/init/Header.js b/generators/app/templates/js/fw/init/Header.js index 0e746ad..449d34e 100644 --- a/generators/app/templates/js/fw/init/Header.js +++ b/generators/app/templates/js/fw/init/Header.js @@ -6,9 +6,9 @@ * @date <%= answers.date %> * */ -'use strict'; + import InitBase from 'lib/InitBase'; -import { element } from 'angular'; +import {element} from 'angular'; import __config from 'etc/config'; class Initializer extends InitBase { diff --git a/generators/app/templates/js/fw/init/Validator.js b/generators/app/templates/js/fw/init/Validator.js index c1a2ca2..5d98ca0 100644 --- a/generators/app/templates/js/fw/init/Validator.js +++ b/generators/app/templates/js/fw/init/Validator.js @@ -6,7 +6,7 @@ * @date <%= answers.date %> * */ -'use strict'; + import InitBase from 'lib/InitBase'; import pluck from 'lib/Pluck'; @@ -17,8 +17,7 @@ class Initializer extends InitBase { execute() { if (!this.features || this.features.length === 0) { - console.warn('No features loaded'); - return; + return console.warn('No features loaded'); } var modNames = pluck(this.features, 'export').sort(); diff --git a/generators/app/templates/js/fw/init/main.js b/generators/app/templates/js/fw/init/main.js index 70e61ab..b0a6ffd 100644 --- a/generators/app/templates/js/fw/init/main.js +++ b/generators/app/templates/js/fw/init/main.js @@ -9,7 +9,7 @@ * @date <%= answers.date %> * */ -'use strict'; + import header from './Header'; import validator from './Validator'; diff --git a/generators/app/templates/js/fw/lib/ConfiguratorBase.js b/generators/app/templates/js/fw/lib/ConfiguratorBase.js index fc8c311..2e2d92f 100644 --- a/generators/app/templates/js/fw/lib/ConfiguratorBase.js +++ b/generators/app/templates/js/fw/lib/ConfiguratorBase.js @@ -6,7 +6,7 @@ * @date <%= answers.date %> * */ -'use strict'; + class ConfiguratorBase { constructor(features, app) { @@ -18,8 +18,7 @@ class ConfiguratorBase { this.value = app.value; } - execute() { - } + execute() {} } export default ConfiguratorBase; diff --git a/generators/app/templates/js/fw/lib/FeatureBase.js b/generators/app/templates/js/fw/lib/FeatureBase.js index 074f13b..4003a3d 100644 --- a/generators/app/templates/js/fw/lib/FeatureBase.js +++ b/generators/app/templates/js/fw/lib/FeatureBase.js @@ -6,14 +6,14 @@ * @date <%= answers.date %> * */ -'use strict'; -import angular from 'angular'; + +import {module} from 'angular'; class FeatureBase { constructor(name) { this.export = name; - this.mod = angular.module(this.export, []); + this.mod = module(this.export, []); this.controller = this.mod.controller; this.factory = this.mod.factory; @@ -24,11 +24,9 @@ class FeatureBase { this.run = this.mod.run; } - beforeStart() { - } + beforeStart() {} - execute() { - } + execute() {} } export default FeatureBase; diff --git a/generators/app/templates/js/fw/lib/InitBase.js b/generators/app/templates/js/fw/lib/InitBase.js index 6a990da..8aaa6d6 100644 --- a/generators/app/templates/js/fw/lib/InitBase.js +++ b/generators/app/templates/js/fw/lib/InitBase.js @@ -6,15 +6,14 @@ * @date <%= answers.date %> * */ -'use strict'; + class InitBase { constructor(features) { this.features = features; } - execute() { - } + execute() {} } export default InitBase; diff --git a/generators/app/templates/js/fw/lib/Omit.js b/generators/app/templates/js/fw/lib/Omit.js index 5a734a2..37aa77b 100644 --- a/generators/app/templates/js/fw/lib/Omit.js +++ b/generators/app/templates/js/fw/lib/Omit.js @@ -6,9 +6,8 @@ * @date <%= answers.date %> * */ -'use strict'; -import { isObject, isArray, isString } from 'angular'; +import {isObject, isArray, isString} from 'angular'; var clone = function(obj) { if (typeof obj !== 'object' || !obj) { diff --git a/generators/app/templates/js/fw/lib/Pluck.js b/generators/app/templates/js/fw/lib/Pluck.js index 010614d..7fd7d79 100644 --- a/generators/app/templates/js/fw/lib/Pluck.js +++ b/generators/app/templates/js/fw/lib/Pluck.js @@ -5,9 +5,8 @@ * @date <%= answers.date %> * */ -'use strict'; -import { isArray } from 'angular'; +import {isArray} from 'angular'; var pluck = function(arr, key) { if (!isArray(arr) || arr.length === 0) { diff --git a/generators/app/templates/js/fw/lib/ServiceBase.js b/generators/app/templates/js/fw/lib/ServiceBase.js index 9bc5a27..3b5c2ce 100644 --- a/generators/app/templates/js/fw/lib/ServiceBase.js +++ b/generators/app/templates/js/fw/lib/ServiceBase.js @@ -6,7 +6,7 @@ * @date <%= answers.date %> * */ -'use strict'; + class ServiceBase { constructor(features, app) { @@ -17,8 +17,7 @@ class ServiceBase { this.service = app.service; } - execute() { - } + execute() {} } export default ServiceBase; diff --git a/generators/app/templates/js/fw/service/Utils.js b/generators/app/templates/js/fw/service/Utils.js index bc6b088..f0a655c 100644 --- a/generators/app/templates/js/fw/service/Utils.js +++ b/generators/app/templates/js/fw/service/Utils.js @@ -7,7 +7,7 @@ * @date <%= answers.date %> * */ -'use strict'; + import ServiceBase from 'lib/ServiceBase'; import config from 'etc/config'; @@ -39,20 +39,6 @@ class Service extends ServiceBase { e.preventDefault(); } }; - - this.getApi = function(path) { - if (!path) { - return config.api; - } - var newPath = path; - if (path.indexOf('/') === 0) { - newPath = path.substring(1); - } - if (config.api.lastIndexOf('/') === (config.api.length - 1)) { - return config.api + newPath; - } - return config.api + '/' + newPath; - }; } execute() { diff --git a/generators/app/templates/js/fw/service/main.js b/generators/app/templates/js/fw/service/main.js index 3999c02..43d3059 100644 --- a/generators/app/templates/js/fw/service/main.js +++ b/generators/app/templates/js/fw/service/main.js @@ -5,7 +5,7 @@ * @date <%= answers.date %> * */ -'use strict'; + import utils from './Utils'; export default [utils]; diff --git a/generators/app/templates/js/index.js b/generators/app/templates/js/index.js index c22ea44..ad7dddf 100644 --- a/generators/app/templates/js/index.js +++ b/generators/app/templates/js/index.js @@ -5,16 +5,15 @@ * @date <%= answers.date %> * */ -'use strict'; require.ensure(['splash-screen/splash.min.css', 'splash-screen'], function(require) { require('splash-screen/splash.min.css').use(); require('splash-screen').enable('circular'); }); -require.ensure(['less/main.less', 'splash-screen', './main'], function(require) { +require.ensure(['css/main.css', 'splash-screen', './main'], function(require) { - require('less/main.less'); + require('css/main.css').use(); var App = require('./main').default; (new App()).run(); diff --git a/generators/app/templates/js/main.js b/generators/app/templates/js/main.js index 860dcb2..1edc9f5 100644 --- a/generators/app/templates/js/main.js +++ b/generators/app/templates/js/main.js @@ -5,7 +5,6 @@ * @date <%= answers.date %> * */ -'use strict'; import angular from 'angular'; import Initializers from 'init/main'; import Extensions from 'ext/main'; diff --git a/generators/app/templates/less/fontello.less b/generators/app/templates/less/fontello.less deleted file mode 100644 index c4a69e4..0000000 --- a/generators/app/templates/less/fontello.less +++ /dev/null @@ -1,74 +0,0 @@ -@font-face { - font-family: 'fontello'; - src: url('../font/fontello.eot?25657972'); - src: url('../font/fontello.eot?25657972#iefix') format('embedded-opentype'), - url('../font/fontello.woff?25657972') format('woff'), - url('../font/fontello.ttf?25657972') format('truetype'), - url('../font/fontello.svg?25657972#fontello') format('svg'); - font-weight: normal; - font-style: normal; -} -/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */ -/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */ -/* -@media screen and (-webkit-min-device-pixel-ratio:0) { - @font-face { - font-family: 'fontello'; - src: url('../font/fontello.svg?25657972#fontello') format('svg'); - } -} -*/ - - [class^="icon-"]:before, [class*=" icon-"]:before { - font-family: "fontello"; - font-style: normal; - font-weight: normal; - speak: none; - - display: inline-block; - text-decoration: inherit; - width: 1em; - margin-right: .2em; - text-align: center; - /* opacity: .8; */ - - /* For safety - reset parent styles, that can break glyph codes*/ - font-variant: normal; - text-transform: none; - - /* fix buttons height, for twitter bootstrap */ - line-height: 1em; - - /* Animation center compensation - margins should be symmetric */ - /* remove if not needed */ - margin-left: .2em; - - /* you can be more comfortable with increased icons size */ - /* font-size: 120%; */ - - /* Font smoothing. That was taken from TWBS */ - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - - /* Uncomment for 3D effect */ - /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */ -} - -.icon-menu:before { content: '\e800'; } /* '' */ -.icon-bell:before { content: '\e801'; } /* '' */ -.icon-attention-alt:before { content: '\e802'; } /* '' */ -.icon-paper-plane-empty:before { content: '\e803'; } /* '' */ -.icon-chart-bar:before { content: '\e804'; } /* '' */ -.icon-bicycle:before { content: '\e805'; } /* '' */ -.icon-wheelchair:before { content: '\e806'; } /* '' */ -.icon-skyatlas:before { content: '\e807'; } /* '' */ -.icon-reddit:before { content: '\e808'; } /* '' */ -.icon-ok:before { content: '\e809'; } /* '' */ -.icon-smile:before { content: '\e80a'; } /* '' */ -.icon-logout-1:before { content: '\e80b'; } /* '' */ -.icon-users:before { content: '\e80c'; } /* '' */ -.icon-user-add-outline:before { content: '\e80d'; } /* '' */ -.icon-home-outline:before { content: '\e80e'; } /* '' */ -.icon-th-outline:before { content: '\e80f'; } /* '' */ -.icon-user-outline:before { content: '\e810'; } /* '' */ -.icon-github:before { content: '\e811'; } /* '' */ \ No newline at end of file diff --git a/generators/app/templates/less/main.less b/generators/app/templates/less/main.less deleted file mode 100644 index 65655b8..0000000 --- a/generators/app/templates/less/main.less +++ /dev/null @@ -1,35 +0,0 @@ -@import "../node_modules/angular-material/angular-material.css"; -@import "./fontello"; - -html, body { - font-family: 'Roboto', sans-serif; - font-size:14px; - height:100%; - margin: 0px; - padding: 0px; -} - -md-toolbar{ - .logo{ - height: 64px; - } - - @media screen and (max-width: 1200px) { - .logo { - height: 48px; - } - } - - @media screen and (max-width: 450px) { - .logo { - display: none; - } - } - - .toolbar-icon{ - padding: 0 !important; - md-icon{ - font-size: 20px; - } - } -} diff --git a/generators/app/templates/mock/demolist b/generators/app/templates/mock/demolist deleted file mode 100644 index 6bfb658..0000000 --- a/generators/app/templates/mock/demolist +++ /dev/null @@ -1,62 +0,0 @@ -[ - { - "subjectId": 418, - "subjectName": "基因芯片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 417, - "subjectName": "大师芯片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 416, - "subjectName": "令过芯片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 415, - "subjectName": "更话芯片", - "indexDelta": 0.0453254 - }, - { - "subjectId": 414, - "subjectName": "动画芯片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 413, - "subjectName": "麻辣起片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 412, - "subjectName": "就花片", - "indexDelta": 0.0453254 - }, - { - "subjectId": 411, - "subjectName": "令过芯片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 410, - "subjectName": "更话芯片", - "indexDelta": 0.0453254 - }, - { - "subjectId": 409, - "subjectName": "动画芯片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 408, - "subjectName": "麻辣起片", - "indexDelta": -0.0453254 - }, - { - "subjectId": 407, - "subjectName": "就花片", - "indexDelta": 0.0453254 - } - ] diff --git a/generators/app/templates/mock/states b/generators/app/templates/mock/states deleted file mode 100644 index 3d74967..0000000 --- a/generators/app/templates/mock/states +++ /dev/null @@ -1,52 +0,0 @@ -[ - "Alabama", - "Alaska", - "Arizona", - "Arkansas", - "California", - "Colorado", - "Connecticut", - "Delaware", - "Florida", - "Georgia", - "Hawaii", - "Idaho", - "Illinois", - "Indiana", - "Iowa", - "Kansas", - "Kentucky", - "Louisiana", - "Maine", - "Maryland", - "Massachusetts", - "Michigan", - "Minnesota", - "Mississippi", - "Missouri", - "Montana", - "Nebraska", - "Nevada", - "New Hampshire", - "New Jersey", - "New Mexico", - "New York", - "North Dakota", - "North Carolina", - "Ohio", - "Oklahoma", - "Oregon", - "Pennsylvania", - "Rhode Island", - "South Carolina", - "South Dakota", - "Tennessee", - "Texas", - "Utah", - "Vermont", - "Virginia", - "Washington", - "West Virginia", - "Wisconsin", - "Wyoming" -] \ No newline at end of file diff --git a/generators/app/templates/package.json_vm b/generators/app/templates/package.json_vm index 38f82b2..5792d3f 100644 --- a/generators/app/templates/package.json_vm +++ b/generators/app/templates/package.json_vm @@ -2,14 +2,16 @@ "name": "<%= answers.name %>", "version": "1.0.0", "description": "<%= answers.description %>", + "scripts": { + "dev": "rm -rf build; webpack --config webpack.config.dev.js", + "release": "rm -rf build; webpack --config webpack.config.prod.js", + "start": "webpack-dev-server --content-base build/ --config webpack.config.dev.js --history-api-fallback --open http://localhost:8080/ --hot --inline" + }, "files": [ "etc", "img", "js", - "less", - "mock", - "test", - "gulpfile.js", + "css", "index.html", "webpack.config.dev.js", "webpack.config.prod.js" @@ -20,33 +22,23 @@ "author": "<%= answers.username %> <% if(answers.email){ %><<%= answers.email %>><% } %>", "license": "MIT", "dependencies":{ - "angular": "^1.4.9", - "angular-animate": "^1.4.9", - "angular-route": "^1.4.9", - "angular-sanitize": "^1.4.9", - "angular-aria": "^1.4.9", - "angular-messages": "^1.4.9", - "angular-material": "^1.0.4", - "splash-screen": "^2.2.2" + "angular": "^1.5.5", + "angular-route": "^1.5.5", + "splash-screen": "^2.3.3" }, "devDependencies": { - "autoprefixer": "^6.3.1", - "ng-annotate-loader": "^0.1.0", - "babel-core": "^6.4.5", - "babel-loader": "^6.2.1", - "babel-preset-es2015": "^6.3.13", + "autoprefixer": "^6.3.6", + "babel-core": "^6.7.7", + "babel-loader": "^6.2.4", + "babel-preset-es2015": "^6.6.0", "css-loader": "^0.23.1", - "del": "^2.2.0", "file-loader": "^0.8.5", - "gulp": "^3.9.0", - "gulp-replace": "^0.5.4", - "gulp-util": "^3.0.7", - "less": "^2.6.0", - "less-loader": "^2.2.2", - "postcss-loader": "^0.8.0", + "html-webpack-plugin": "^2.16.1", + "ng-annotate-loader": "^0.1.0", + "postcss-loader": "^0.9.1", "raw-loader": "^0.5.1", - "style-loader": "^0.13.0", - "webpack": "^1.12.12", + "style-loader": "^0.13.1", + "webpack": "^1.13.0", "webpack-dev-server": "^1.14.1" } } diff --git a/generators/app/templates/webpack.config.dev.js b/generators/app/templates/webpack.config.dev.js index d14275c..5337a82 100644 --- a/generators/app/templates/webpack.config.dev.js +++ b/generators/app/templates/webpack.config.dev.js @@ -1,17 +1,17 @@ -'use strict'; var path = require('path'); var webpack = require('webpack'); var autoprefixer = require('autoprefixer'); +var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: { index: './js/index.js' }, output: { - path: path.resolve(__dirname, 'build', 'js'), + path: path.resolve(__dirname, 'build'), filename: '[name].bundle.js', chunkFilename: '[id].bundle.js', - publicPath: 'js/' + publicPath: '/' }, debug: true, devtool: 'source-map', @@ -21,17 +21,13 @@ module.exports = { test: /\.css$/, loader: 'style/useable!css!postcss!' }, - { - test: /\.less$/, - loader: 'style!css!postcss!less!' - }, { test: /\.js$/, loader: 'ng-annotate!babel?{"presets":["es2015"]}', - exclude: /(node_modules|bower_components)/ + exclude: /(node_modules)/ }, { - test: /\.(eot|svg|ttf|woff|woff2)\w*/, + test: /\.(eot|svg|ttf|woff|woff2|png)\w*/, loader: 'file' }, { @@ -53,6 +49,14 @@ module.exports = { ] }, plugins: [ - new webpack.optimize.CommonsChunkPlugin('common.bundle.js') + new webpack.optimize.CommonsChunkPlugin('common.bundle.js'), + new HtmlWebpackPlugin({ + pushState: <%= answers.pushState %>, + filename: 'index.html', + inject: 'body', + template: 'index.html_vm', + favicon: 'img/favicon.ico', + hash: false + }) ] }; diff --git a/generators/app/templates/webpack.config.prod.js b/generators/app/templates/webpack.config.prod.js index 1acec3a..24fb68b 100644 --- a/generators/app/templates/webpack.config.prod.js +++ b/generators/app/templates/webpack.config.prod.js @@ -1,17 +1,17 @@ -'use strict'; var path = require('path'); var webpack = require('webpack'); var autoprefixer = require('autoprefixer'); +var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: { index: './js/index.js' }, output: { - path: path.resolve(__dirname, 'build', 'js'), + path: path.resolve(__dirname, 'build'), filename: '[hash].[name].bundle.js', chunkFilename: '[hash].[id].bundle.js', - publicPath: 'js/' + publicPath: '/' }, module: { loaders: [ @@ -19,17 +19,13 @@ module.exports = { test: /\.css$/, loader: 'style/useable!css!postcss!' }, - { - test: /\.less$/, - loader: 'style!css!postcss!less!' - }, { test: /\.js$/, loader: 'ng-annotate!babel?{"presets":["es2015"]}', - exclude: /(node_modules|bower_components)/ + exclude: /(node_modules)/ }, { - test: /\.(eot|svg|ttf|woff|woff2)\w*/, + test: /\.(eot|svg|ttf|woff|woff2|png)\w*/, loader: 'file' }, { @@ -56,6 +52,14 @@ module.exports = { warnings: false } }), - new webpack.optimize.CommonsChunkPlugin('[hash].common.bundle.js') + new webpack.optimize.CommonsChunkPlugin('[hash].common.bundle.js'), + new HtmlWebpackPlugin({ + pushState: <%= answers.pushState %>, + filename: 'index.html', + inject: 'body', + template: 'index.html_vm', + favicon: 'img/favicon.ico', + hash: false + }) ] }; diff --git a/package.json b/package.json index e50d9ea..19cd2c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-es6-angular", - "version": "4.0.2", + "version": "4.1.0", "description": "generator-es6-angular", "repository": { "type": "git", @@ -22,7 +22,7 @@ "license": "MIT", "dependencies": { "date-util": "^1.2.1", - "lodash": "^4.1.0", - "yeoman-generator": "^0.22.5" + "lodash": "^4.11.2", + "yeoman-generator": "^0.23.3" } }