From 342d42b16e2834914ac3b507229c736cb6968d9a Mon Sep 17 00:00:00 2001 From: Simon Korn Date: Tue, 20 Oct 2015 19:32:08 +0200 Subject: [PATCH 01/12] renamed test -> demo --- app/templates/base/{test => demo}/index.html | 0 app/templates/base/{test => demo}/main.css | 0 app/templates/base/gulp/tasks/server.js | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename app/templates/base/{test => demo}/index.html (100%) rename app/templates/base/{test => demo}/main.css (100%) diff --git a/app/templates/base/test/index.html b/app/templates/base/demo/index.html similarity index 100% rename from app/templates/base/test/index.html rename to app/templates/base/demo/index.html diff --git a/app/templates/base/test/main.css b/app/templates/base/demo/main.css similarity index 100% rename from app/templates/base/test/main.css rename to app/templates/base/demo/main.css diff --git a/app/templates/base/gulp/tasks/server.js b/app/templates/base/gulp/tasks/server.js index 6b51986..2a6005e 100644 --- a/app/templates/base/gulp/tasks/server.js +++ b/app/templates/base/gulp/tasks/server.js @@ -3,7 +3,7 @@ var connect = require('gulp-connect'); gulp.task('connect', function() { connect.server({ - root: ['test', './'], + root: ['demo', './'], livereload: true }); }); @@ -13,5 +13,5 @@ gulp.task('reload', ['minify'], function() { }); gulp.task('watch', function() { - gulp.watch(['./src/**', './test/**'], ['reload']); + gulp.watch(['./src/**', './demo/**'], ['reload']); }); From 988bf7e050e83427063b42eb98830f67ff742cf1 Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Fri, 23 Oct 2015 22:06:04 +0200 Subject: [PATCH 02/12] keywords to bower.json --- app/templates/base/bower.json | 8 ++++++++ app/templates/base/package.json | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/templates/base/bower.json b/app/templates/base/bower.json index 947a693..b994ab8 100644 --- a/app/templates/base/bower.json +++ b/app/templates/base/bower.json @@ -2,6 +2,14 @@ "name": "<%= paramName %>", "version": "1.0.0", "license": "MIT", + "keywords": [ + "angular-schema-form", + "schema-form", + "form", + "json", + "json-schema", + "schema" + ], "ignore": [ "**/.*", "node_modules", diff --git a/app/templates/base/package.json b/app/templates/base/package.json index d7f1dc6..425a70b 100644 --- a/app/templates/base/package.json +++ b/app/templates/base/package.json @@ -1,11 +1,7 @@ { "name": "<%= paramName %>", "version": "1.0.0", - "description": "", - "main": "gulpfile.js", - "directories": { - "test": "test" - }, + "description": "Angular Schema Form Add-On.", "author": "", "license": "MIT", "devDependencies": {} From 57b798e0e0d876c0d3bae8d6bde3e34b60deeb29 Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Fri, 23 Oct 2015 22:17:17 +0200 Subject: [PATCH 03/12] comment fixing --- app/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/index.js b/app/index.js index f9fa97e..35b2c9e 100644 --- a/app/index.js +++ b/app/index.js @@ -81,14 +81,16 @@ module.exports = generators.Base.extend({ var schema = this.fs.read(this.templatePath(this.addon.type + '/schema.json')); var form = this.fs.read(this.templatePath(this.addon.type + '/form.json')); - /* Just a fast and easy fix.. because current version isn't working */ + /* TODO: Just a fast and easy fix for now.. + */ form = JSON.parse(form); if (form[0].hasOwnProperty('type')) { form[0].type = this.addon.typeName; } this.addon.files.base.forEach(function(file) { - // what to inject in the test controller + /* What to inject in the test controller + */ var testModule = ['schemaForm']; var dest = file.replace('_', '.') .replace('module.js', this.addon.paramName + '.js'); From 790a388d82d0588df38beb78632e7e6e5464f36d Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Fri, 23 Oct 2015 22:30:53 +0200 Subject: [PATCH 04/12] Better bower.json and package.json --- app/index.js | 10 +++++++++- app/templates/base/bower.json | 4 ++++ app/templates/base/package.json | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/index.js b/app/index.js index 35b2c9e..cbc9149 100644 --- a/app/index.js +++ b/app/index.js @@ -41,12 +41,19 @@ module.exports = generators.Base.extend({ message: 'What kind of form type do you want?', choices: ['Input' /*, 'Radio', 'Checkbox', 'Array'*/, 'Empty' ], default: 'Input' + }, + { + type : 'input', + name : 'username', + message : 'What\'s your Github username?', + store : true }], function(answers) { /* Nice, we now have the answers. let's put it in our config. */ this.addon.name = answers.name; this.addon.type = answers.type; + this.addon.username = answers.username; /* Changing cases */ @@ -110,7 +117,8 @@ module.exports = generators.Base.extend({ typeName: this.addon.typeName, paramName: this.addon.paramName, schema: schema, - form: JSON.stringify(form) + form: JSON.stringify(form), + username: this.addon.username } ); }.bind(this)); diff --git a/app/templates/base/bower.json b/app/templates/base/bower.json index b994ab8..a133dac 100644 --- a/app/templates/base/bower.json +++ b/app/templates/base/bower.json @@ -2,6 +2,10 @@ "name": "<%= paramName %>", "version": "1.0.0", "license": "MIT", + "author": "<%= username %>", + "main": [ + "dist/<%= paramName %>.min.js" + ], "keywords": [ "angular-schema-form", "schema-form", diff --git a/app/templates/base/package.json b/app/templates/base/package.json index 425a70b..7c2aa46 100644 --- a/app/templates/base/package.json +++ b/app/templates/base/package.json @@ -1,8 +1,8 @@ { "name": "<%= paramName %>", "version": "1.0.0", - "description": "Angular Schema Form Add-On.", - "author": "", + "description": "<%= name %> add-on for Angular Schema Form.", + "author": "<%= username %>", "license": "MIT", "devDependencies": {} } From dc48034dc3b1fd5db6f33df1033564ca136ce1d1 Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Mon, 9 Nov 2015 21:14:03 +0100 Subject: [PATCH 05/12] minify task now looks at source.json --- app/index.js | 26 ++++++++++++++++--------- app/templates/base/gulp/tasks/minify.js | 9 +++++---- app/templates/base/sources.json | 1 + app/templates/input/src/module.js | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 app/templates/base/sources.json diff --git a/app/index.js b/app/index.js index cbc9149..c365257 100644 --- a/app/index.js +++ b/app/index.js @@ -42,6 +42,12 @@ module.exports = generators.Base.extend({ choices: ['Input' /*, 'Radio', 'Checkbox', 'Array'*/, 'Empty' ], default: 'Input' }, + { + type: 'confirm', + name: 'useDirective', + message: 'Do you want a directive added to your addon?', + default: true + }, { type : 'input', name : 'username', @@ -53,12 +59,13 @@ module.exports = generators.Base.extend({ */ this.addon.name = answers.name; this.addon.type = answers.type; + this.addon.useDirective = answers.useDirective; this.addon.username = answers.username; /* Changing cases */ this.addon.type = this.addon.type.toLowerCase(); // ex. Input > input - this.addon.directive = camelcase(this.addon.name); // ex. add on > addOn + this.addon.module = camelcase(this.addon.name); // ex. add on > addOn this.addon.typeName = this.addon.name.replace(/ /g, ''); // ex. add on > addon this.addon.paramName = this.addon.name.replace(/ /g, '-'); // ex. add on > add-on @@ -99,11 +106,12 @@ module.exports = generators.Base.extend({ /* What to inject in the test controller */ var testModule = ['schemaForm']; - var dest = file.replace('_', '.') - .replace('module.js', this.addon.paramName + '.js'); + var sources = []; + var dest = file.replace('_', '.'); if (this.addon.type !== 'empty') { - testModule.push(this.addon.directive); + testModule.push(this.addon.module); + sources.push('src/module.js'); } /* Base files */ @@ -112,13 +120,14 @@ module.exports = generators.Base.extend({ this.destinationPath('./') + dest, { name: this.addon.name, - directive: this.addon.directive, + module: this.addon.module, testModuleInj: JSON.stringify(testModule), typeName: this.addon.typeName, paramName: this.addon.paramName, schema: schema, form: JSON.stringify(form), - username: this.addon.username + username: this.addon.username, + sources: JSON.stringify(sources) } ); }.bind(this)); @@ -126,15 +135,14 @@ module.exports = generators.Base.extend({ /* Type files */ this.addon.files[this.addon.type].forEach(function(file) { var dest = file.replace('_', '.') - .replace('template.html', this.addon.paramName + '.html') - .replace('module.js', this.addon.paramName + '.js'); + .replace('template.html', this.addon.paramName + '.html'); this.fs.copyTpl( this.templatePath(this.templatePath(this.addon.type + '/src/') + file), this.destinationPath('./src/') + dest, { name: this.addon.name, - directive: this.addon.directive, + module: this.addon.module, typeName: this.addon.typeName, paramName: this.addon.paramName } diff --git a/app/templates/base/gulp/tasks/minify.js b/app/templates/base/gulp/tasks/minify.js index 738ddaf..09b6ac9 100644 --- a/app/templates/base/gulp/tasks/minify.js +++ b/app/templates/base/gulp/tasks/minify.js @@ -1,3 +1,4 @@ +var fs = require('fs'); var gulp = require('gulp'); var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); @@ -6,18 +7,18 @@ var templateCache = require('gulp-angular-templatecache'); var streamqueue = require('streamqueue'); gulp.task('minify', function() { - + var files = JSON.parse(fs.readFileSync('sources.json', 'utf-8')); var stream = streamqueue({objectMode: true}, gulp.src(['src/templates/**/*.html']).pipe(templateCache({ standalone: true, root: 'src/templates/' })), - gulp.src(['src/*.js']) + gulp.src(files) ) - .pipe(concat('<%= paramName %>.js')) + .pipe(concat('asf-addon.js')) .pipe(gulp.dest('./dist')) .pipe(uglify()) - .pipe(rename('<%= paramName %>.min.js')) + .pipe(rename('asf-addon.min.js')) .pipe(gulp.dest('./dist')); return stream; diff --git a/app/templates/base/sources.json b/app/templates/base/sources.json new file mode 100644 index 0000000..3f7325d --- /dev/null +++ b/app/templates/base/sources.json @@ -0,0 +1 @@ +<%- sources -%> diff --git a/app/templates/input/src/module.js b/app/templates/input/src/module.js index e70e024..2900a7f 100644 --- a/app/templates/input/src/module.js +++ b/app/templates/input/src/module.js @@ -1,4 +1,4 @@ -angular.module('<%= directive %>', [ +angular.module('<%= module %>', [ 'schemaForm', 'templates' ]).config(function(schemaFormDecoratorsProvider, sfBuilderProvider) { From 67dd753f374b946aa407bbeb351c20ef867a16e7 Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Mon, 9 Nov 2015 21:17:06 +0100 Subject: [PATCH 06/12] angular copy on debug values --- app/templates/base/demo/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/base/demo/index.html b/app/templates/base/demo/index.html index 295bde3..4baf743 100644 --- a/app/templates/base/demo/index.html +++ b/app/templates/base/demo/index.html @@ -21,7 +21,7 @@ $scope.model = {}; - $scope.debug = {schema: $scope.schema, form: $scope.form}; + $scope.debug = {schema: angular.copy($scope.schema), form: angular.copy($scope.form)}; }); From 34f28fba0be7b00ac567447d8ef8841d58889bab Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Sat, 14 Nov 2015 18:38:03 +0100 Subject: [PATCH 07/12] new files for input directive --- .../input/update-on-blur-directive.html | 1 + .../directives/input/update-on-blur.js | 19 +++++++++++++++++++ .../input/src/templates/template.html | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/templates/directives/input/update-on-blur-directive.html create mode 100644 app/templates/directives/input/update-on-blur.js diff --git a/app/templates/directives/input/update-on-blur-directive.html b/app/templates/directives/input/update-on-blur-directive.html new file mode 100644 index 0000000..749e734 --- /dev/null +++ b/app/templates/directives/input/update-on-blur-directive.html @@ -0,0 +1 @@ + diff --git a/app/templates/directives/input/update-on-blur.js b/app/templates/directives/input/update-on-blur.js new file mode 100644 index 0000000..f809e0b --- /dev/null +++ b/app/templates/directives/input/update-on-blur.js @@ -0,0 +1,19 @@ +angular.module('asfAddon').directive('updateOnBlur', [function() { + return { + require: 'ngModel', + restrict: 'E', + scope: {}, + templateUrl: 'src/templates/update-on-blur-directive.html', + link: function(scope, element, attrs, ngModel) { + + ngModel.$render(function() { + scope.modelValue = ngModel.$viewValue(); + }); + + scope.updateModel = function(value) { + ngModel.$setViewValue(value); + }; + + } + }; +}]); diff --git a/app/templates/input/src/templates/template.html b/app/templates/input/src/templates/template.html index 3903559..53dafb1 100644 --- a/app/templates/input/src/templates/template.html +++ b/app/templates/input/src/templates/template.html @@ -5,8 +5,11 @@

{{form.myOwnFormOption}}

- + <% if (directive) { %> + + <% } else { %> + <% } %> From aa281c5348c650703da517ba6a9a43a45a188a9b Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Sat, 14 Nov 2015 18:45:07 +0100 Subject: [PATCH 08/12] added useDirective for esj templating --- app/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index c365257..7b1e21f 100644 --- a/app/index.js +++ b/app/index.js @@ -144,7 +144,8 @@ module.exports = generators.Base.extend({ name: this.addon.name, module: this.addon.module, typeName: this.addon.typeName, - paramName: this.addon.paramName + paramName: this.addon.paramName, + directive: this.addon.useDirective } ); }.bind(this)); From 4722d2da2812c2aa2cfdc27ed8283997f462ec64 Mon Sep 17 00:00:00 2001 From: kornosaurus Date: Sat, 14 Nov 2015 18:48:43 +0100 Subject: [PATCH 09/12] typeName -> formType for better understanding --- app/index.js | 8 ++++---- app/templates/input/src/module.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/index.js b/app/index.js index 7b1e21f..81264fd 100644 --- a/app/index.js +++ b/app/index.js @@ -66,7 +66,7 @@ module.exports = generators.Base.extend({ */ this.addon.type = this.addon.type.toLowerCase(); // ex. Input > input this.addon.module = camelcase(this.addon.name); // ex. add on > addOn - this.addon.typeName = this.addon.name.replace(/ /g, ''); // ex. add on > addon + this.addon.formType = this.addon.name.replace(/ /g, ''); // ex. add on > addon this.addon.paramName = this.addon.name.replace(/ /g, '-'); // ex. add on > add-on /* We are done here... Let's continue @@ -99,7 +99,7 @@ module.exports = generators.Base.extend({ */ form = JSON.parse(form); if (form[0].hasOwnProperty('type')) { - form[0].type = this.addon.typeName; + form[0].type = this.addon.formType; } this.addon.files.base.forEach(function(file) { @@ -122,7 +122,7 @@ module.exports = generators.Base.extend({ name: this.addon.name, module: this.addon.module, testModuleInj: JSON.stringify(testModule), - typeName: this.addon.typeName, + formType: this.addon.formType, paramName: this.addon.paramName, schema: schema, form: JSON.stringify(form), @@ -143,7 +143,7 @@ module.exports = generators.Base.extend({ { name: this.addon.name, module: this.addon.module, - typeName: this.addon.typeName, + formType: this.addon.formType, paramName: this.addon.paramName, directive: this.addon.useDirective } diff --git a/app/templates/input/src/module.js b/app/templates/input/src/module.js index 2900a7f..7cd33d5 100644 --- a/app/templates/input/src/module.js +++ b/app/templates/input/src/module.js @@ -5,7 +5,7 @@ angular.module('<%= module %>', [ schemaFormDecoratorsProvider.defineAddOn( 'bootstrapDecorator', // Name of the decorator you want to add to. - '<%= typeName %>', // Form type that should render this add-on + '<%= formType %>', // Form type that should render this add-on 'src/templates/<%= paramName %>.html', // Template name in $templateCache sfBuilderProvider.stdBuilders // List of builder functions to apply. ); From 9a228be9198d905e7d7f040a857d1b7bdd640e28 Mon Sep 17 00:00:00 2001 From: Simon Korn Date: Thu, 25 Feb 2016 22:46:22 +0100 Subject: [PATCH 10/12] es6 change is complete, moving on to directive additions --- .gitignore | 2 + .jscsrc | 3 +- .jshintrc | 2 +- .npmignore | 1 + LICENSE | 3 +- app/index.js | 321 +++++++++--------- app/templates/base/demo/index.html | 2 +- app/templates/base/gulp/index.js | 7 - app/templates/base/gulp/tasks/default.js | 3 - app/templates/base/gulp/tasks/minify.js | 25 -- app/templates/base/gulp/tasks/server.js | 17 - app/templates/base/gulpfile.js | 44 ++- .../input/src/directives/template.js | 15 + .../input/src/templates/template.html | 1 + index.js | 181 ++++++++++ package.json | 22 +- 16 files changed, 435 insertions(+), 214 deletions(-) create mode 100644 .npmignore delete mode 100644 app/templates/base/gulp/index.js delete mode 100644 app/templates/base/gulp/tasks/default.js delete mode 100644 app/templates/base/gulp/tasks/minify.js delete mode 100644 app/templates/base/gulp/tasks/server.js create mode 100644 app/templates/input/src/directives/template.js create mode 100644 index.js diff --git a/.gitignore b/.gitignore index 3c3629e..0034f75 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +app/index.js +app/index.js.map diff --git a/.jscsrc b/.jscsrc index 1797133..796ffa0 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,3 +1,4 @@ { - + "preset": "airbnb", + "esnext": true } diff --git a/.jshintrc b/.jshintrc index 1797133..a5aaaed 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,3 +1,3 @@ { - + "esnext": true } diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..012a3cd --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +index.js diff --git a/LICENSE b/LICENSE index e55c56d..44d361c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Textalk +Copyright (c) 2015 Simon Korn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/app/index.js b/app/index.js index 81264fd..5a46b61 100644 --- a/app/index.js +++ b/app/index.js @@ -1,187 +1,202 @@ -var generators = require('yeoman-generator'); -var chalk = require('chalk'); -var path = require('path'); -var fsp = require('fs-promise'); -var q = require('q'); -var read = require('fs-readdir-recursive'); -var camelcase = require('camelcase'); +'use strict'; -module.exports = generators.Base.extend({ +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - init: function() { +require('babel-polyfill'); - /* Welcome the user!! - */ - this.log(chalk.blue.bold('.-========================-.')); - this.log(chalk.blue.bold('|| ||')); - this.log(chalk.blue.bold('|| ' + chalk.yellow('Angular schema form') + ' ||')); - this.log(chalk.blue.bold('|| ' + chalk.yellow('Add-on generator') + ' ||')); - this.log(chalk.blue.bold('|| ||')); - this.log(chalk.blue.bold('\'-========================-\'\n')); +var _yeomanGenerator = require('yeoman-generator'); - /* Setting up our config object - */ - this.addon = {files: {}}; - }, +var _yosay = require('yosay'); - prompting: function() { - /* We tell yeoman we don't want to continue until we run our done(). - */ - var done = this.async(); - - this.prompt([{ - type: 'input', - name: 'name', - message: 'Your add-on name', - default: this.appname - }, - { - type: 'list', - name: 'type', - message: 'What kind of form type do you want?', - choices: ['Input' /*, 'Radio', 'Checkbox', 'Array'*/, 'Empty' ], - default: 'Input' - }, - { - type: 'confirm', - name: 'useDirective', - message: 'Do you want a directive added to your addon?', - default: true - }, - { - type : 'input', - name : 'username', - message : 'What\'s your Github username?', - store : true - }], function(answers) { - - /* Nice, we now have the answers. let's put it in our config. - */ - this.addon.name = answers.name; - this.addon.type = answers.type; - this.addon.useDirective = answers.useDirective; - this.addon.username = answers.username; +var _yosay2 = _interopRequireDefault(_yosay); - /* Changing cases - */ - this.addon.type = this.addon.type.toLowerCase(); // ex. Input > input - this.addon.module = camelcase(this.addon.name); // ex. add on > addOn - this.addon.formType = this.addon.name.replace(/ /g, ''); // ex. add on > addon - this.addon.paramName = this.addon.name.replace(/ /g, '-'); // ex. add on > add-on +var _camelcase = require('camelcase'); - /* We are done here... Let's continue - */ - done(); - }.bind(this)); +var _camelcase2 = _interopRequireDefault(_camelcase); - }, +var _chalk = require('chalk'); - configure: function() { +var _chalk2 = _interopRequireDefault(_chalk); - var done = this.async(); +var _fsReaddirRecursive = require('fs-readdir-recursive'); - /* Let's get a list of our base files and type specific files. - */ - this.addon.files.base = read(this.templatePath() + '/base'); - this.addon.files[this.addon.type] = read(this.templatePath() + '/' + this.addon.type + '/src'); +var _fsReaddirRecursive2 = _interopRequireDefault(_fsReaddirRecursive); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - done(); - }, +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - writing: function() { +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - var done = this.async(); +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - var schema = this.fs.read(this.templatePath(this.addon.type + '/schema.json')); - var form = this.fs.read(this.templatePath(this.addon.type + '/form.json')); +var asfAddOnGenerator = function (_Base) { + _inherits(asfAddOnGenerator, _Base); - /* TODO: Just a fast and easy fix for now.. + function asfAddOnGenerator() { + var _Object$getPrototypeO; + + _classCallCheck(this, asfAddOnGenerator); + + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + /* Setting up our config object */ - form = JSON.parse(form); - if (form[0].hasOwnProperty('type')) { - form[0].type = this.addon.formType; + + var _this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(asfAddOnGenerator)).call.apply(_Object$getPrototypeO, [this].concat(args))); + + _this.addon = {}; + return _this; + } + + _createClass(asfAddOnGenerator, [{ + key: 'prompting', + value: function prompting() { + var _this2 = this; + + /* Welcome the user!! + */ + this.log((0, _yosay2.default)('Hello and welcome to the Angular Schema Form Add-on Generator!')); + + /* We tell yeoman we don't want to continue until we run our done(). + */ + var done = this.async(); + + this.prompt([{ + type: 'input', + name: 'name', + message: 'Your add-on name', + default: this.appname + }, { + type: 'list', + name: 'type', + message: 'What kind of form type do you want?', + choices: ['input', 'empty'], /*, 'Radio', 'Checkbox', 'Array'*/ + default: 'input' + }, { + type: 'confirm', + name: 'useDirective', + message: 'Do you want a directive added to your addon?', + default: true + }, { + type: 'input', + name: 'username', + message: 'What\'s your Github username?', + store: true + }], function (answers) { + + /* Nice, we now have all the answers. + */ + Object.assign(_this2.addon, answers); + + /* Changing cases + */ + _this2.addon.module = (0, _camelcase2.default)(_this2.addon.name); // ex. add on > addOn + _this2.addon.formType = _this2.addon.name.replace(/ /g, ''); // ex. add on > addon + _this2.addon.paramName = _this2.addon.name.replace(/ /g, '-'); // ex. add on > add-on + + /* We are done here... Let's continue + */ + done(); + }); } + }, { + key: 'configure', + value: function configure() { - this.addon.files.base.forEach(function(file) { - /* What to inject in the test controller + /* Let's get a list of our base files and type specific files. */ - var testModule = ['schemaForm']; - var sources = []; - var dest = file.replace('_', '.'); + this.addon.files = {}; + + /* I do not like this, it looks ugly too me. but hell, it works for now. + */ + this.addon.files.base = (0, _fsReaddirRecursive2.default)(this.templatePath() + '/base'); + this.addon.files[this.addon.type] = (0, _fsReaddirRecursive2.default)(this.templatePath() + '/' + this.addon.type + '/src'); + } + }, { + key: 'writing', + value: function writing() { + var _this3 = this; - if (this.addon.type !== 'empty') { - testModule.push(this.addon.module); - sources.push('src/module.js'); + var done = this.async(); + var schema = this.fs.read(this.templatePath(this.addon.type + '/schema.json')); + var form = this.fs.read(this.templatePath(this.addon.type + '/form.json')); + + /* TODO: Just a fast and easy fix for now.. + */ + form = JSON.parse(form); + if (form[0].hasOwnProperty('type')) { + form[0].type = this.addon.formType; } - /* Base files */ - this.fs.copyTpl( - this.templatePath(this.templatePath('base/') + file), - this.destinationPath('./') + dest, - { - name: this.addon.name, - module: this.addon.module, + this.addon.files.base.forEach(function (file) { + /* What to inject in the test controller + */ + var testModule = ['schemaForm']; + var sources = []; + var dest = file.replace('_', '.'); + + if (_this3.addon.type !== 'empty') { + testModule.push(_this3.addon.module); + + /* This needs to reflect files inside the chosen types folder. + */ + sources.push('src/module.js'); + } + + /* Base files */ + _this3.fs.copyTpl(_this3.templatePath(_this3.templatePath('base/') + file), _this3.destinationPath('./') + dest, { + name: _this3.addon.name, + module: _this3.addon.module, testModuleInj: JSON.stringify(testModule), - formType: this.addon.formType, - paramName: this.addon.paramName, + formType: _this3.addon.formType, + paramName: _this3.addon.paramName, schema: schema, form: JSON.stringify(form), - username: this.addon.username, + username: _this3.addon.username, sources: JSON.stringify(sources) - } - ); - }.bind(this)); - - /* Type files */ - this.addon.files[this.addon.type].forEach(function(file) { - var dest = file.replace('_', '.') - .replace('template.html', this.addon.paramName + '.html'); - - this.fs.copyTpl( - this.templatePath(this.templatePath(this.addon.type + '/src/') + file), - this.destinationPath('./src/') + dest, - { - name: this.addon.name, - module: this.addon.module, - formType: this.addon.formType, - paramName: this.addon.paramName, - directive: this.addon.useDirective - } - ); - }.bind(this)); - - done(); - - }, + }); + }); + + /* Type files */ + this.addon.files[this.addon.type].forEach(function (file) { + var dest = file.replace('_', '.').replace('template.html', _this3.addon.paramName + '.html'); + + _this3.fs.copyTpl(_this3.templatePath(_this3.templatePath(_this3.addon.type + '/src/') + file), _this3.destinationPath('./src/') + dest, { + name: _this3.addon.name, + module: _this3.addon.module, + formType: _this3.addon.formType, + paramName: _this3.addon.paramName, + directive: _this3.addon.useDirective + }); + }); - install: function() { - var npmDevDeps = [ - "gulp", - "gulp-angular-templatecache", - "gulp-concat", - "gulp-connect", - "gulp-livereload", - "gulp-rename", - "gulp-server-livereload", - "gulp-uglify", - "streamqueue" - ]; + done(); + } + }, { + key: 'install', + value: function install() { + var npmDevDeps = ['gulp', 'gulp-angular-templatecache', 'gulp-concat', 'gulp-connect', 'gulp-livereload', 'gulp-rename', 'gulp-server-livereload', 'gulp-uglify', 'streamqueue']; - var bowerDevDeps = [ - 'angular-schema-form', - 'angular-schema-form-bootstrap', - 'bootstrap' - ]; + var bowerDevDeps = ['angular-schema-form', 'angular-schema-form-bootstrap', 'bootstrap']; - console.log(chalk.white('\nAlmost done! Just running ' + chalk.green.bold('npm install') + ' and ' + chalk.green.bold('bower install') + ' for you!\n')); + this.log(_chalk2.default.white('\nAlmost done! Just running ' + _chalk2.default.green.bold('npm install') + ' and ' + _chalk2.default.green.bold('bower install') + ' for you!\n')); - this.npmInstall(npmDevDeps, { 'saveDev': true }); - this.bowerInstall(bowerDevDeps, { 'saveDev': true }); + this.npmInstall(npmDevDeps, { saveDev: true }); + this.bowerInstall(bowerDevDeps, { saveDev: true }); + } + }, { + key: 'end', + value: function end() { + this.log(_chalk2.default.green('\nEverything is done! \nJust run ' + _chalk2.default.bold.green('gulp') + ' to start a livereload server to test your addon.')); + } + }]); - }, + return asfAddOnGenerator; +}(_yeomanGenerator.Base); - end: function() { - console.log(chalk.green('\nEverything is done! \nJust run ' + chalk.bold.green('gulp') + ' to start a livereload server to test your addon.')); - } +module.exports = asfAddOnGenerator; -}); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/app/templates/base/demo/index.html b/app/templates/base/demo/index.html index 4baf743..fc18632 100644 --- a/app/templates/base/demo/index.html +++ b/app/templates/base/demo/index.html @@ -6,7 +6,7 @@ - + diff --git a/app/templates/base/gulp/index.js b/app/templates/base/gulp/index.js deleted file mode 100644 index 5c6165a..0000000 --- a/app/templates/base/gulp/index.js +++ /dev/null @@ -1,7 +0,0 @@ -var fs = require('fs'); -var tasks = fs.readdirSync('./gulp/tasks'); -var gulp = require('gulp'); - -tasks.forEach(function(task) { - require('./tasks/' + task); -}); diff --git a/app/templates/base/gulp/tasks/default.js b/app/templates/base/gulp/tasks/default.js deleted file mode 100644 index 02baec4..0000000 --- a/app/templates/base/gulp/tasks/default.js +++ /dev/null @@ -1,3 +0,0 @@ -var gulp = require('gulp'); - -gulp.task('default', ['minify', 'connect', 'watch']); diff --git a/app/templates/base/gulp/tasks/minify.js b/app/templates/base/gulp/tasks/minify.js deleted file mode 100644 index 09b6ac9..0000000 --- a/app/templates/base/gulp/tasks/minify.js +++ /dev/null @@ -1,25 +0,0 @@ -var fs = require('fs'); -var gulp = require('gulp'); -var uglify = require('gulp-uglify'); -var concat = require('gulp-concat'); -var rename = require('gulp-rename'); -var templateCache = require('gulp-angular-templatecache'); -var streamqueue = require('streamqueue'); - -gulp.task('minify', function() { - var files = JSON.parse(fs.readFileSync('sources.json', 'utf-8')); - var stream = streamqueue({objectMode: true}, - gulp.src(['src/templates/**/*.html']).pipe(templateCache({ - standalone: true, - root: 'src/templates/' - })), - gulp.src(files) - ) - .pipe(concat('asf-addon.js')) - .pipe(gulp.dest('./dist')) - .pipe(uglify()) - .pipe(rename('asf-addon.min.js')) - .pipe(gulp.dest('./dist')); - - return stream; -}); diff --git a/app/templates/base/gulp/tasks/server.js b/app/templates/base/gulp/tasks/server.js deleted file mode 100644 index 2a6005e..0000000 --- a/app/templates/base/gulp/tasks/server.js +++ /dev/null @@ -1,17 +0,0 @@ -var gulp = require('gulp'); -var connect = require('gulp-connect'); - -gulp.task('connect', function() { - connect.server({ - root: ['demo', './'], - livereload: true - }); -}); - -gulp.task('reload', ['minify'], function() { - gulp.src('./dist/**/*.*').pipe(connect.reload()); -}); - -gulp.task('watch', function() { - gulp.watch(['./src/**', './demo/**'], ['reload']); -}); diff --git a/app/templates/base/gulpfile.js b/app/templates/base/gulpfile.js index 06249eb..2255e1a 100644 --- a/app/templates/base/gulpfile.js +++ b/app/templates/base/gulpfile.js @@ -1 +1,43 @@ -require('./gulp'); +var gulp = require('gulp'); +var connect = require('gulp-connect'); +var uglify = require('gulp-uglify'); +var concat = require('gulp-concat'); +var rename = require('gulp-rename'); +var templateCache = require('gulp-angular-templatecache'); +var streamqueue = require('streamqueue'); +var fs = require('fs'); + +gulp.task('default', ['minify', 'connect', 'watch']); + +gulp.task('connect', function () { + connect.server({ + root: ['demo', './'], + livereload: true, + }); +}); + +gulp.task('reload', ['minify'], function () { + gulp.src('./dist/**/*.*').pipe(connect.reload()); +}); + +gulp.task('watch', function () { + gulp.watch(['./src/**', './demo/**'], ['reload']); +}); + +gulp.task('minify', function () { + var files = JSON.parse(fs.readFileSync('sources.json', 'utf-8')); + var stream = streamqueue({ objectMode: true }, + gulp.src(['src/templates/**/*.html']).pipe(templateCache({ + standalone: true, + root: 'src/templates/', + })), + gulp.src(files) + ) + .pipe(concat('asf-addon.js')) + .pipe(gulp.dest('./dist')) + .pipe(uglify()) + .pipe(rename('asf-addon.min.js')) + .pipe(gulp.dest('./dist')); + + return stream; +}); diff --git a/app/templates/input/src/directives/template.js b/app/templates/input/src/directives/template.js new file mode 100644 index 0000000..0111530 --- /dev/null +++ b/app/templates/input/src/directives/template.js @@ -0,0 +1,15 @@ +angular.module('<%= module %>').directive('updateOnBlur', function () { + return { + restrict: 'E', + require: 'ngModel', + scope: {}, + template: '', + link: function (scope, element, attrs, ngModel) { + scope.modelValue = ngModel.$viewValue; + + scope.updateModel = function (modelValue) { + ngModel.$setViewValue(modelValue); + }; + }, + }; +}); diff --git a/app/templates/input/src/templates/template.html b/app/templates/input/src/templates/template.html index 53dafb1..fcc82de 100644 --- a/app/templates/input/src/templates/template.html +++ b/app/templates/input/src/templates/template.html @@ -7,6 +7,7 @@

{{form.myOwnFormOption}}

<% if (directive) { %> + Blur this field to update the model. <% } else { %> <% } %> diff --git a/index.js b/index.js new file mode 100644 index 0000000..061e7d7 --- /dev/null +++ b/index.js @@ -0,0 +1,181 @@ +import 'babel-polyfill'; +import { Base } from 'yeoman-generator'; +import yosay from 'yosay'; +import camelcase from 'camelcase'; +import chalk from 'chalk'; +import read from 'fs-readdir-recursive'; + +class asfAddOnGenerator extends Base { + + constructor(...args) { + super(...args); + + /* Setting up our config object + */ + this.addon = {}; + } + + prompting() { + /* Welcome the user!! + */ + this.log(yosay(`Hello and welcome to the Angular Schema Form Add-on Generator!`)); + + /* We tell yeoman we don't want to continue until we run our done(). + */ + const done = this.async(); + + this.prompt([ + { + type: 'input', + name: 'name', + message: 'Your add-on name', + default: this.appname, + }, + { + type: 'list', + name: 'type', + message: 'What kind of form type do you want?', + choices: ['input', 'empty'], /*, 'Radio', 'Checkbox', 'Array'*/ + default: 'input', + }, + { + type: 'confirm', + name: 'useDirective', + message: 'Do you want a directive added to your addon?', + default: true, + }, + { + type: 'input', + name: 'username', + message: 'What\'s your Github username?', + store: true, + }, + ], (answers) => { + + /* Nice, we now have all the answers. + */ + Object.assign(this.addon, answers); + + /* Changing cases + */ + this.addon.module = camelcase(this.addon.name); // ex. add on > addOn + this.addon.formType = this.addon.name.replace(/ /g, ''); // ex. add on > addon + this.addon.paramName = this.addon.name.replace(/ /g, '-'); // ex. add on > add-on + + /* We are done here... Let's continue + */ + done(); + }); + } + + configure() { + + /* Let's get a list of our base files and type specific files. + */ + this.addon.files = {}; + + /* I do not like this, it looks ugly too me. but hell, it works for now. + */ + this.addon.files.base = read(`${this.templatePath()}/base`); + this.addon.files[this.addon.type] = read(`${this.templatePath()}/${this.addon.type}/src`); + + } + + writing() { + const done = this.async(); + const schema = this.fs.read(this.templatePath(`${this.addon.type}/schema.json`)); + let form = this.fs.read(this.templatePath(`${this.addon.type}/form.json`)); + + /* TODO: Just a fast and easy fix for now.. + */ + form = JSON.parse(form); + if (form[0].hasOwnProperty('type')) { + form[0].type = this.addon.formType; + } + + this.addon.files.base.forEach((file) => { + /* What to inject in the test controller + */ + const testModule = ['schemaForm']; + const sources = []; + const dest = file.replace('_', '.'); + + if (this.addon.type !== 'empty') { + testModule.push(this.addon.module); + + /* This needs to reflect files inside the chosen types folder. + */ + sources.push('src/module.js'); + } + + /* Base files */ + this.fs.copyTpl( + this.templatePath(this.templatePath('base/') + file), + this.destinationPath('./') + dest, + { + name: this.addon.name, + module: this.addon.module, + testModuleInj: JSON.stringify(testModule), + formType: this.addon.formType, + paramName: this.addon.paramName, + schema: schema, + form: JSON.stringify(form), + username: this.addon.username, + sources: JSON.stringify(sources), + } + ); + }); + + /* Type files */ + this.addon.files[this.addon.type].forEach((file) => { + const dest = file.replace('_', '.') + .replace('template.html', `${this.addon.paramName}.html`); + + this.fs.copyTpl( + this.templatePath(this.templatePath(`${this.addon.type}/src/`) + file), + this.destinationPath('./src/') + dest, + { + name: this.addon.name, + module: this.addon.module, + formType: this.addon.formType, + paramName: this.addon.paramName, + directive: this.addon.useDirective, + } + ); + }); + + done(); + } + + install() { + const npmDevDeps = [ + 'gulp', + 'gulp-angular-templatecache', + 'gulp-concat', + 'gulp-connect', + 'gulp-livereload', + 'gulp-rename', + 'gulp-server-livereload', + 'gulp-uglify', + 'streamqueue', + ]; + + const bowerDevDeps = [ + 'angular-schema-form', + 'angular-schema-form-bootstrap', + 'bootstrap', + ]; + + this.log(chalk.white(`\nAlmost done! Just running ${chalk.green.bold('npm install')} and ${chalk.green.bold('bower install')} for you!\n`)); + + this.npmInstall(npmDevDeps, { saveDev: true }); + this.bowerInstall(bowerDevDeps, { saveDev: true }); + } + + end() { + this.log(chalk.green(`\nEverything is done! \nJust run ${chalk.bold.green('gulp')} to start a livereload server to test your addon.`)); + } + +} + +module.exports = asfAddOnGenerator; diff --git a/package.json b/package.json index cb2ebfc..b13dc48 100644 --- a/package.json +++ b/package.json @@ -2,20 +2,36 @@ "name": "generator-angular-schema-form-add-on", "version": "0.1.3", "description": "A Yeoman generator for Angular Schema Form Add-Ons.", + "main": "app/index.js", "files": [ "app" ], "keywords": [ "yeoman-generator" ], - "repository": "textalk/generator-angular-schema-form-add-on", + "scripts": { + "compile": "babel index.js --out-file app/index.js --source-maps", + "watch": "babel index.js --watch --out-file app/index.js --source-maps", + "prepublish": "npm run compile" + }, + "babel": { + "presets": [ + "es2015" + ] + }, + "repository": "json-schema-form/generator-angular-schema-form-add-on", "dependencies": { + "babel-polyfill": "^6.5.0", "camelcase": "^1.2.1", "chalk": "^1.1.1", "fs-promise": "^0.3.1", "fs-readdir-recursive": "^0.1.2", "q": "^1.4.1", - "yeoman-generator": "^0.20.3" + "yeoman-generator": "^0.20.3", + "yosay": "^1.1.0" }, - "license": "MIT" + "license": "MIT", + "devDependencies": { + "babel-cli": "^6.5.1" + } } From 705c60d9fb32b449145c43caed8d4fed5f1569b1 Mon Sep 17 00:00:00 2001 From: Simon Korn Date: Thu, 25 Feb 2016 22:48:12 +0100 Subject: [PATCH 11/12] removed generated js file --- app/index.js | 202 --------------------------------------------------- 1 file changed, 202 deletions(-) delete mode 100644 app/index.js diff --git a/app/index.js b/app/index.js deleted file mode 100644 index 5a46b61..0000000 --- a/app/index.js +++ /dev/null @@ -1,202 +0,0 @@ -'use strict'; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -require('babel-polyfill'); - -var _yeomanGenerator = require('yeoman-generator'); - -var _yosay = require('yosay'); - -var _yosay2 = _interopRequireDefault(_yosay); - -var _camelcase = require('camelcase'); - -var _camelcase2 = _interopRequireDefault(_camelcase); - -var _chalk = require('chalk'); - -var _chalk2 = _interopRequireDefault(_chalk); - -var _fsReaddirRecursive = require('fs-readdir-recursive'); - -var _fsReaddirRecursive2 = _interopRequireDefault(_fsReaddirRecursive); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var asfAddOnGenerator = function (_Base) { - _inherits(asfAddOnGenerator, _Base); - - function asfAddOnGenerator() { - var _Object$getPrototypeO; - - _classCallCheck(this, asfAddOnGenerator); - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - /* Setting up our config object - */ - - var _this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(asfAddOnGenerator)).call.apply(_Object$getPrototypeO, [this].concat(args))); - - _this.addon = {}; - return _this; - } - - _createClass(asfAddOnGenerator, [{ - key: 'prompting', - value: function prompting() { - var _this2 = this; - - /* Welcome the user!! - */ - this.log((0, _yosay2.default)('Hello and welcome to the Angular Schema Form Add-on Generator!')); - - /* We tell yeoman we don't want to continue until we run our done(). - */ - var done = this.async(); - - this.prompt([{ - type: 'input', - name: 'name', - message: 'Your add-on name', - default: this.appname - }, { - type: 'list', - name: 'type', - message: 'What kind of form type do you want?', - choices: ['input', 'empty'], /*, 'Radio', 'Checkbox', 'Array'*/ - default: 'input' - }, { - type: 'confirm', - name: 'useDirective', - message: 'Do you want a directive added to your addon?', - default: true - }, { - type: 'input', - name: 'username', - message: 'What\'s your Github username?', - store: true - }], function (answers) { - - /* Nice, we now have all the answers. - */ - Object.assign(_this2.addon, answers); - - /* Changing cases - */ - _this2.addon.module = (0, _camelcase2.default)(_this2.addon.name); // ex. add on > addOn - _this2.addon.formType = _this2.addon.name.replace(/ /g, ''); // ex. add on > addon - _this2.addon.paramName = _this2.addon.name.replace(/ /g, '-'); // ex. add on > add-on - - /* We are done here... Let's continue - */ - done(); - }); - } - }, { - key: 'configure', - value: function configure() { - - /* Let's get a list of our base files and type specific files. - */ - this.addon.files = {}; - - /* I do not like this, it looks ugly too me. but hell, it works for now. - */ - this.addon.files.base = (0, _fsReaddirRecursive2.default)(this.templatePath() + '/base'); - this.addon.files[this.addon.type] = (0, _fsReaddirRecursive2.default)(this.templatePath() + '/' + this.addon.type + '/src'); - } - }, { - key: 'writing', - value: function writing() { - var _this3 = this; - - var done = this.async(); - var schema = this.fs.read(this.templatePath(this.addon.type + '/schema.json')); - var form = this.fs.read(this.templatePath(this.addon.type + '/form.json')); - - /* TODO: Just a fast and easy fix for now.. - */ - form = JSON.parse(form); - if (form[0].hasOwnProperty('type')) { - form[0].type = this.addon.formType; - } - - this.addon.files.base.forEach(function (file) { - /* What to inject in the test controller - */ - var testModule = ['schemaForm']; - var sources = []; - var dest = file.replace('_', '.'); - - if (_this3.addon.type !== 'empty') { - testModule.push(_this3.addon.module); - - /* This needs to reflect files inside the chosen types folder. - */ - sources.push('src/module.js'); - } - - /* Base files */ - _this3.fs.copyTpl(_this3.templatePath(_this3.templatePath('base/') + file), _this3.destinationPath('./') + dest, { - name: _this3.addon.name, - module: _this3.addon.module, - testModuleInj: JSON.stringify(testModule), - formType: _this3.addon.formType, - paramName: _this3.addon.paramName, - schema: schema, - form: JSON.stringify(form), - username: _this3.addon.username, - sources: JSON.stringify(sources) - }); - }); - - /* Type files */ - this.addon.files[this.addon.type].forEach(function (file) { - var dest = file.replace('_', '.').replace('template.html', _this3.addon.paramName + '.html'); - - _this3.fs.copyTpl(_this3.templatePath(_this3.templatePath(_this3.addon.type + '/src/') + file), _this3.destinationPath('./src/') + dest, { - name: _this3.addon.name, - module: _this3.addon.module, - formType: _this3.addon.formType, - paramName: _this3.addon.paramName, - directive: _this3.addon.useDirective - }); - }); - - done(); - } - }, { - key: 'install', - value: function install() { - var npmDevDeps = ['gulp', 'gulp-angular-templatecache', 'gulp-concat', 'gulp-connect', 'gulp-livereload', 'gulp-rename', 'gulp-server-livereload', 'gulp-uglify', 'streamqueue']; - - var bowerDevDeps = ['angular-schema-form', 'angular-schema-form-bootstrap', 'bootstrap']; - - this.log(_chalk2.default.white('\nAlmost done! Just running ' + _chalk2.default.green.bold('npm install') + ' and ' + _chalk2.default.green.bold('bower install') + ' for you!\n')); - - this.npmInstall(npmDevDeps, { saveDev: true }); - this.bowerInstall(bowerDevDeps, { saveDev: true }); - } - }, { - key: 'end', - value: function end() { - this.log(_chalk2.default.green('\nEverything is done! \nJust run ' + _chalk2.default.bold.green('gulp') + ' to start a livereload server to test your addon.')); - } - }]); - - return asfAddOnGenerator; -}(_yeomanGenerator.Base); - -module.exports = asfAddOnGenerator; - -//# sourceMappingURL=index.js.map \ No newline at end of file From 6d7f4954313f8424057026dd254ac3178c329296 Mon Sep 17 00:00:00 2001 From: Simon Korn Date: Sat, 27 Feb 2016 13:05:16 +0100 Subject: [PATCH 12/12] Added optional directive to the input example --- .npmignore | 1 + app/templates/base/demo/index.html | 2 +- app/templates/base/gulpfile.js | 4 +-- .../input/update-on-blur-directive.html | 1 - .../directives/input/update-on-blur.js | 19 -------------- .../{template.js => update-on-blur.js} | 0 index.js | 25 +++++++++++-------- package.json | 1 + 8 files changed, 19 insertions(+), 34 deletions(-) delete mode 100644 app/templates/directives/input/update-on-blur-directive.html delete mode 100644 app/templates/directives/input/update-on-blur.js rename app/templates/input/src/directives/{template.js => update-on-blur.js} (100%) diff --git a/.npmignore b/.npmignore index 012a3cd..f1faa39 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,2 @@ index.js +node_modules diff --git a/app/templates/base/demo/index.html b/app/templates/base/demo/index.html index fc18632..4baf743 100644 --- a/app/templates/base/demo/index.html +++ b/app/templates/base/demo/index.html @@ -6,7 +6,7 @@ - + diff --git a/app/templates/base/gulpfile.js b/app/templates/base/gulpfile.js index 2255e1a..95414ba 100644 --- a/app/templates/base/gulpfile.js +++ b/app/templates/base/gulpfile.js @@ -33,10 +33,10 @@ gulp.task('minify', function () { })), gulp.src(files) ) - .pipe(concat('asf-addon.js')) + .pipe(concat('<%= paramName %>.js')) .pipe(gulp.dest('./dist')) .pipe(uglify()) - .pipe(rename('asf-addon.min.js')) + .pipe(rename('<%= paramName %>.min.js')) .pipe(gulp.dest('./dist')); return stream; diff --git a/app/templates/directives/input/update-on-blur-directive.html b/app/templates/directives/input/update-on-blur-directive.html deleted file mode 100644 index 749e734..0000000 --- a/app/templates/directives/input/update-on-blur-directive.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/app/templates/directives/input/update-on-blur.js b/app/templates/directives/input/update-on-blur.js deleted file mode 100644 index f809e0b..0000000 --- a/app/templates/directives/input/update-on-blur.js +++ /dev/null @@ -1,19 +0,0 @@ -angular.module('asfAddon').directive('updateOnBlur', [function() { - return { - require: 'ngModel', - restrict: 'E', - scope: {}, - templateUrl: 'src/templates/update-on-blur-directive.html', - link: function(scope, element, attrs, ngModel) { - - ngModel.$render(function() { - scope.modelValue = ngModel.$viewValue(); - }); - - scope.updateModel = function(value) { - ngModel.$setViewValue(value); - }; - - } - }; -}]); diff --git a/app/templates/input/src/directives/template.js b/app/templates/input/src/directives/update-on-blur.js similarity index 100% rename from app/templates/input/src/directives/template.js rename to app/templates/input/src/directives/update-on-blur.js diff --git a/index.js b/index.js index 061e7d7..083dff3 100644 --- a/index.js +++ b/index.js @@ -79,6 +79,10 @@ class asfAddOnGenerator extends Base { this.addon.files.base = read(`${this.templatePath()}/base`); this.addon.files[this.addon.type] = read(`${this.templatePath()}/${this.addon.type}/src`); + if (!this.addon.useDirective) { + this.addon.files[this.addon.type] = this.addon.files[this.addon.type].filter(dir => !dir.includes('directives')) + } + } writing() { @@ -93,21 +97,19 @@ class asfAddOnGenerator extends Base { form[0].type = this.addon.formType; } + const sources = []; + const testModule = ['schemaForm']; + + if (this.addon.type !== 'empty') { + testModule.push(this.addon.module); + sources.push('src/module.js', 'src/**/*.js'); + } + this.addon.files.base.forEach((file) => { /* What to inject in the test controller */ - const testModule = ['schemaForm']; - const sources = []; const dest = file.replace('_', '.'); - if (this.addon.type !== 'empty') { - testModule.push(this.addon.module); - - /* This needs to reflect files inside the chosen types folder. - */ - sources.push('src/module.js'); - } - /* Base files */ this.fs.copyTpl( this.templatePath(this.templatePath('base/') + file), @@ -129,7 +131,8 @@ class asfAddOnGenerator extends Base { /* Type files */ this.addon.files[this.addon.type].forEach((file) => { const dest = file.replace('_', '.') - .replace('template.html', `${this.addon.paramName}.html`); + .replace('template.html', `${this.addon.paramName}.html`) + .replace('template.js', `${this.addon.paramName}.js`); this.fs.copyTpl( this.templatePath(this.templatePath(`${this.addon.type}/src/`) + file), diff --git a/package.json b/package.json index b13dc48..72e8ea5 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "repository": "json-schema-form/generator-angular-schema-form-add-on", "dependencies": { "babel-polyfill": "^6.5.0", + "babel-preset-es2015": "^6.5.0", "camelcase": "^1.2.1", "chalk": "^1.1.1", "fs-promise": "^0.3.1",