I'm managing a project written in angularjs, with the default directory structure, excluding the app directory which uses versioning (ie. "app/0.0.0/", "app/0.1.0/" etc..).
I'm trying to use grunt's package.json file's "version" property to load the correct directory so I won't have to manually change the app path in gruntfile.js but for some reason I keep getting "Cannot GET /" when I run "grunt server".
To better explain this, here's a sample 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 change the app property to "app/0.0.0" it works like a charm so I'm guessing this has something to do with the templating.
Any ideas?
Thank you very much for the help.
Edit: Thank you for the correction Andreas and Matjaz, but this doesn't solve the problem and gives the same error... This solves the problem for me but without the templating system:
var pkgVersion = grunt.file.readJSON('package.json').version;
// configurable paths
var yeomanConfig = {
app: 'app/'+pkgVersion,
dist: 'dist'
};
It's pretty ugly but it works. Hoping for a proper solution.
json is a file in the root directory of a Node. js project that holds various information relevant to the project. This file gives information to npm that allows it to identify the project as well as handle the project's dependencies.
The Grunt community is still going strong and both tools look like they're going to be around for a while yet. I should mention that another up and coming alternative to task runners like Grunt and Gulp is simply using npm scripts with command-line tools.
The best way to handle above scenario is that, In the grunt.initConfig define the package.json
grunt.initConfig({
pkg: grunt.file.readJSON("package.json")
})
Once above initialized you can use the properties of the package.json throughout the grunt.js file.
<%= pkg.version %>
<%= pkg.homepage %>
To echo data use <%=
:
<%= pkg.version %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With