Skip to content

Commit 109e45d

Browse files
committed
feat(app): dynamically generate angular constant appConfig
1 parent 1db9d00 commit 109e45d

File tree

6 files changed

+52
-25
lines changed

6 files changed

+52
-25
lines changed

Diff for: app/generator.js

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ export default class Generator extends Base {
371371

372372
ngModules: function() {
373373
var angModules = [
374+
`'${this.scriptAppName}.constants'`,
374375
"'ngCookies'",
375376
"'ngResource'",
376377
"'ngSanitize'"

Diff for: app/templates/Gruntfile.js

+42-22
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = function (grunt) {
1717
cdnify: 'grunt-google-cdn',
1818
protractor: 'grunt-protractor-runner',
1919
buildcontrol: 'grunt-build-control',
20-
istanbul_check_coverage: 'grunt-mocha-istanbul'
20+
istanbul_check_coverage: 'grunt-mocha-istanbul',
21+
ngconstant: 'grunt-ng-constant'
2122
});
2223

2324
// Time how long tasks take. Can help when optimizing build times
@@ -60,6 +61,10 @@ module.exports = function (grunt) {
6061
files: ['<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js'],
6162
tasks: ['newer:babel:client']
6263
},<% } %>
64+
ngconstant: {
65+
files: ['<%%= yeoman.server %>/config/environment/shared.js'],
66+
tasks: ['ngconstant']
67+
},
6368
injectJS: {
6469
files: [
6570
'<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js',
@@ -241,7 +246,7 @@ module.exports = function (grunt) {
241246
// Automatically inject Bower components into the app and karma.conf.js
242247
wiredep: {
243248
options: {
244-
exclude: [ <% if(filters.uibootstrap) { %>
249+
exclude: [<% if(filters.uibootstrap) { %>
245250
/bootstrap.js/,<% } %>
246251
'/json3/',
247252
'/es5-shim/'<% if(!filters.css) { %>,
@@ -326,6 +331,25 @@ module.exports = function (grunt) {
326331
}
327332
},
328333

334+
// Dynamically generate angular constant `appConfig` from
335+
// `server/config/environment/shared.js`
336+
ngconstant: {
337+
options: {
338+
name: '<%= scriptAppName %>.constants',
339+
dest: '<%%= yeoman.client %>/app/app.constant.js',
340+
deps: [],
341+
wrap: true,
342+
configPath: '<%%= yeoman.server %>/config/environment/shared'
343+
},
344+
app: {
345+
constants: function() {
346+
return {
347+
appConfig: require('./' + grunt.config.get('ngconstant.options.configPath'))
348+
};
349+
}
350+
}
351+
},
352+
329353
// Package all the html partials into a single javascript payload
330354
ngtemplates: {
331355
options: {
@@ -423,6 +447,12 @@ module.exports = function (grunt) {
423447

424448
// Run some tasks in parallel to speed up the build process
425449
concurrent: {
450+
pre: [<% if (filters.stylus) { %>
451+
'injector:stylus',<% } if (filters.less) { %>
452+
'injector:less',<% } if (filters.sass) { %>
453+
'injector:sass',<% } %>
454+
'ngconstant'
455+
],
426456
server: [<% if(filters.babel) { %>
427457
'newer:babel:client',<% } if(filters.jade) { %>
428458
'jade',<% } if(filters.stylus) { %>
@@ -747,10 +777,8 @@ module.exports = function (grunt) {
747777
if (target === 'debug') {
748778
return grunt.task.run([
749779
'clean:server',
750-
'env:all',<% if (filters.stylus) { %>
751-
'injector:stylus',<% } if (filters.less) { %>
752-
'injector:less',<% } if (filters.sass) { %>
753-
'injector:sass',<% } %>
780+
'env:all',
781+
'concurrent:pre',
754782
'concurrent:server',
755783
'injector',
756784
'wiredep:client',
@@ -761,10 +789,8 @@ module.exports = function (grunt) {
761789

762790
grunt.task.run([
763791
'clean:server',
764-
'env:all',<% if (filters.stylus) { %>
765-
'injector:stylus',<% } if (filters.less) { %>
766-
'injector:less',<% } if (filters.sass) { %>
767-
'injector:sass',<% } %>
792+
'env:all',
793+
'concurrent:pre',
768794
'concurrent:server',
769795
'injector',
770796
'wiredep:client',
@@ -794,10 +820,8 @@ module.exports = function (grunt) {
794820
else if (target === 'client') {
795821
return grunt.task.run([
796822
'clean:server',
797-
'env:all',<% if (filters.stylus) { %>
798-
'injector:stylus',<% } if (filters.less) { %>
799-
'injector:less',<% } if (filters.sass) { %>
800-
'injector:sass',<% } %>
823+
'env:all',
824+
'concurrent:pre',
801825
'concurrent:test',
802826
'injector',
803827
'postcss',
@@ -822,10 +846,8 @@ module.exports = function (grunt) {
822846
return grunt.task.run([
823847
'clean:server',
824848
'env:all',
825-
'env:test',<% if (filters.stylus) { %>
826-
'injector:stylus',<% } if (filters.less) { %>
827-
'injector:less',<% } if (filters.sass) { %>
828-
'injector:sass',<% } %>
849+
'env:test',
850+
'concurrent:pre',
829851
'concurrent:test',
830852
'injector',
831853
'wiredep:client',
@@ -878,10 +900,8 @@ module.exports = function (grunt) {
878900
});
879901

880902
grunt.registerTask('build', [
881-
'clean:dist',<% if (filters.stylus) { %>
882-
'injector:stylus',<% } if (filters.less) { %>
883-
'injector:less',<% } if (filters.sass) { %>
884-
'injector:sass',<% } %>
903+
'clean:dist',
904+
'concurrent:pre',
885905
'concurrent:dist',
886906
'injector',
887907
'wiredep:client',

Diff for: app/templates/_package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"grunt-jscs": "^2.0.0",
5858
"grunt-newer": "^1.1.1",
5959
"grunt-ng-annotate": "^1.0.1",
60+
"grunt-ng-constant": "^1.1.0",
6061
"grunt-filerev": "^2.3.1",
6162
"grunt-usemin": "^3.0.0",
6263
"grunt-env": "~0.4.1",

Diff for: app/templates/server/config/environment/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ var all = {
3232
session: '<%= lodash.slugify(lodash.humanize(appname)) + '-secret' %>'
3333
},
3434

35-
// List of user roles
36-
userRoles: ['guest', 'user', 'admin'],
37-
3835
// MongoDB connection options
3936
mongo: {
4037
options: {
@@ -67,4 +64,5 @@ var all = {
6764
// ==============================================
6865
module.exports = _.merge(
6966
all,
67+
require('./shared'),
7068
require('./' + process.env.NODE_ENV + '.js') || {});

Diff for: app/templates/server/config/environment/shared.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
exports = module.exports = {
4+
// List of user roles
5+
userRoles: ['guest', 'user', 'admin']
6+
};

Diff for: test/test-file-creation.js

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ describe('angular-fullstack generator', function () {
199199
'server/config/environment/development.js',
200200
'server/config/environment/production.js',
201201
'server/config/environment/test.js',
202+
'server/config/environment/shared.js',
202203
'server/views/404.' + markup,
203204
'e2e/main/main.po.js',
204205
'e2e/main/main.spec.js',

0 commit comments

Comments
 (0)