How to use the "version" property in package.json as the application directory in grunt?

I manage a project written in angularjs with the default directory structure, except for the directory of the application using version control (for example, app / 0.0.0 / "," app / 0.1.0 / ", etc.) ..

I'm trying to use the grunt property package.json file "version" to load the correct one, so I don’t have to manually change the application path in the gruntfile.js file but for some reason I keep getting "Can not GET /" when I start the "server grunt ".

To better explain this, here is an example of my gruntfile.js:

var yeomanConfig = { app: 'app/<% pkg.version %>/', dist: 'dist' ... grunt.initConfig({ yeoman: yeomanConfig, pkg: grunt.file.readJSON('package.json'), ... 

If I manually changed the application property to "application / 0.0.0", it works like a charm so I assume this has something to do with the templates.

Any ideas?

Thank you for help.

Edit: Thanks for fixing Andreas and Matthias, but this does not solve the problem and gives the same error ... This solves the problem for me, but without the template system:

 var pkgVersion = grunt.file.readJSON('package.json').version; // configurable paths var yeomanConfig = { app: 'app/'+pkgVersion, dist: 'dist' }; 

This is pretty ugly, but it works. Hoping for the right decision.

+7
angularjs gruntjs
source share
3 answers

The best way to handle the above scenario is to specify package.json in the grunt.initConfig file

 grunt.initConfig({ pkg: grunt.file.readJSON("package.json") }) 

After initialization, you can use the package.json properties in the grunt.js file.

 <%= pkg.version %> <%= pkg.homepage %> 
+13
source share

To use echo data <%= :

 <%= pkg.version %> 
+3
source share

I am extending appConfig with name and version:

 var appConfig = { app: require('./bower.json').appPath || 'app', name: require('./package.json').name || 'angularapp', version: require('./package.json').version || '1.0.0', dist: 'dist' }; 

Then you can access the following variables:

 <%= yeoman.name %> <%= yeoman.version %> 

For me, a clean solution with additional backup.

+2
source share

All Articles