diff --git a/CUSTOMIZING.md b/CUSTOMIZING.md index e8e94f7..1293f0f 100755 --- a/CUSTOMIZING.md +++ b/CUSTOMIZING.md @@ -41,6 +41,7 @@ Here is an example configuration that matches the default behavior of the subgen ```js { "uirouter": false, + "jsstrict": false, "partialDirectory": "partial/", "directiveDirectory": "directive/", "serviceDirectory": "service/", diff --git a/app/index.js b/app/index.js index 89b987d..a398825 100755 --- a/app/index.js +++ b/app/index.js @@ -51,6 +51,22 @@ CgangularGenerator.prototype.askFor = function askFor() { }.bind(this)); }; +CgangularGenerator.prototype.askForStrict = function askFor() { + var cb = this.async(); + + var prompts = [{ + type: 'confirm', + name: 'jsstrict', + message: 'Would you like your AngularJS code to \'use strict\'?', + default: true + }]; + + this.prompt(prompts, function (props) { + this.config.set('jsstrict', !!props.jsstrict); + cb(); + }.bind(this)); +}; + CgangularGenerator.prototype.askForUiRouter = function askFor() { var cb = this.async(); diff --git a/app/templates/skeleton/app.js b/app/templates/skeleton/app.js index 4c70325..3389be6 100755 --- a/app/templates/skeleton/app.js +++ b/app/templates/skeleton/app.js @@ -1,21 +1,21 @@ angular.module('<%= _.camelize(appname) %>', ['ui.bootstrap','ui.utils','<%= routerModuleName %>','ngAnimate']); <% if (!uirouter) { %> angular.module('<%= _.camelize(appname) %>').config(function($routeProvider) { - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> /* Add New Routes Above */ $routeProvider.otherwise({redirectTo:'/home'}); }); <% } %><% if (uirouter) { %> angular.module('<%= _.camelize(appname) %>').config(function($stateProvider, $urlRouterProvider) { - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> /* Add New States Above */ $urlRouterProvider.otherwise('/home'); }); <% } %> angular.module('<%= _.camelize(appname) %>').run(function($rootScope) { - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> $rootScope.safeApply = function(fn) { var phase = $rootScope.$$phase; if (phase === '$apply' || phase === '$digest') { @@ -27,4 +27,4 @@ angular.module('<%= _.camelize(appname) %>').run(function($rootScope) { } }; -}); +}); \ No newline at end of file diff --git a/directive/templates/complex/directive.js b/directive/templates/complex/directive.js index 39d2759..fb08377 100755 --- a/directive/templates/complex/directive.js +++ b/directive/templates/complex/directive.js @@ -1,4 +1,5 @@ angular.module('<%= appname %>').directive('<%= _.camelize(name) %>', function() { + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> return { restrict: 'E', replace: true, diff --git a/directive/templates/simple/directive.js b/directive/templates/simple/directive.js index 3391aec..da5b483 100755 --- a/directive/templates/simple/directive.js +++ b/directive/templates/simple/directive.js @@ -1,4 +1,5 @@ angular.module('<%= appname %>').directive('<%= _.camelize(name) %>', function() { + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> return { restrict: 'A', link: function(scope, element, attrs, fn) { diff --git a/filter/templates/filter.js b/filter/templates/filter.js index 1993020..0088a03 100755 --- a/filter/templates/filter.js +++ b/filter/templates/filter.js @@ -1,4 +1,5 @@ angular.module('<%= appname %>').filter('<%= _.camelize(name) %>', function() { + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> return function(input,arg) { return 'output'; }; diff --git a/modal/templates/modal.js b/modal/templates/modal.js index 4704561..e626f4f 100755 --- a/modal/templates/modal.js +++ b/modal/templates/modal.js @@ -1,4 +1,4 @@ angular.module('<%= appname %>').controller('<%= ctrlname %>',function($scope){ - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> }); \ No newline at end of file diff --git a/module/templates/module.js b/module/templates/module.js index 3a34ce6..9fdab5b 100755 --- a/module/templates/module.js +++ b/module/templates/module.js @@ -1,13 +1,13 @@ angular.module('<%= _.camelize(name) %>', ['ui.bootstrap','ui.utils','<%= routerModuleName %>','ngAnimate']); <% if (!uirouter) { %> angular.module('<%= _.camelize(name) %>').config(function($routeProvider) { - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> /* Add New Routes Above */ }); <% } %><% if (uirouter) { %> angular.module('<%= _.camelize(name) %>').config(function($stateProvider) { - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> /* Add New States Above */ }); diff --git a/partial/templates/partial.js b/partial/templates/partial.js index 4704561..e626f4f 100755 --- a/partial/templates/partial.js +++ b/partial/templates/partial.js @@ -1,4 +1,4 @@ angular.module('<%= appname %>').controller('<%= ctrlname %>',function($scope){ - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> }); \ No newline at end of file diff --git a/service/templates/service.js b/service/templates/service.js index 6f5f88d..7a8b8a3 100755 --- a/service/templates/service.js +++ b/service/templates/service.js @@ -1,5 +1,5 @@ angular.module('<%= appname %>').factory('<%= _.camelize(name) %>',function() { - + <%= config.get('jsstrict') ? "'use strict';\n" : "" %> var <%= _.camelize(name) %> = {}; return <%= _.camelize(name) %>;