We have the following structure (shown just some relevant components) for our yeoman
(grunt
) based Ember.js
project:
myapp/
├── app
├── component.json
├── package.json
├── Gruntfile.js
├── README.md
│ ├── adapters
│ ├── application.js
│ ├── components
│ ├── controllers
│ ├── generated
│ ├── images
│ ├── models
│ ├── routes
│ ├── scripts
│ ├── styles
│ ├── templates
│ └── views
├── dist
├── node_modules
└── test
We need to access, in application.js
, some of the values in package.json
and component.json
. We would like to access this during the deploy process (as a grunt
task?). Is this possible? How can this be implemented?
You can also use a ready to use grunt package like this https://github.com/outaTiME/grunt-replace for this kind of task, most common use case is for example to extract the version number and stamp your javascript files with it during a grunt run
example implementation (haven't tested it):
in your Gruntfile.js:
...
replace: {
dist: {
options: {
variables: {
version: '<%= pkg.version %>'
}
},
prefix: '@@',
files: [
{expand: true, flatten: true, src: ['app/application.js', 'app/README.md'], dest: 'dist/'}
]
}
}
...
application.js
...
var App = Framework.Application.create({
VERSION: @@version,
...
Use grunt.file.readJSON('package.json')
to read json from a file for a grunt task.
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