New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option for coffeescript output, switch deprecated grunt.util._ to lodash #11
Conversation
Thanks for your push request. This feature looks handy even if I don't understand why you translate from js to coffee and then back again ;) An use case would be nice. I will take a look later today. |
No problem! I'm using Yeoman with generator-angular, and it just seemed easiest to generate a coffee file in my It's possible there was an easier way to integrate this with generator-angular, but here we are! |
So you check the generated file in with your other source? I don't use generator-angular but wouldn't it be possible to put the generated file somewhere in |
Ok I integrated it in the generator-angular workflow. I made following steps:
ngconstant: {
dist: {
dest: '.tmp/scripts/constants.js', // I think this is important
name: 'constants',
constants: {
'DATA': [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
]
}
}
}
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'ngconstant',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
'ngconstant',
'concurrent:test',
'autoprefixer',
'connect:test',
'karma'
]);
grunt.registerTask('build', [
'clean:dist',
'ngconstant',
'useminPrepare',
...
]);
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/angular-cookies/angular-cookies.js',
'app/bower_components/angular-sanitize/angular-sanitize.js',
'.tmp/scripts/*.js', // Add these two lines
'.tmp/scripts/**/*.js',
'app/scripts/*.js',
'app/scripts/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
],
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/constants.js"></script>
<script src="scripts/controllers/main.js"></script>
<!-- endbuild -->
angular.module('yeomanAngularTestApp')
.controller('MainCtrl', function ($scope, DATA) {
$scope.awesomeThings = DATA;
}); I hope this help. I would think the coffee script workflow should be the same. |
No, my Well, this is what I have now with my fork of ng-constant: ngconstant: {
options: {
coffee: true
},
dist: {
dest: 'app/scripts/services/config.LOCAL.coffee',
name: 'localConfig',
constants: {
'rootUrlWeb': 'http://production.url/',
'rootUrlApi': 'http://production.url/api/'
}
},
dev: {
dest: 'app/scripts/services/config.LOCAL.coffee',
name: 'localConfig',
constants: {
'rootUrlWeb': 'http://dev.url/',
'rootUrlApi': 'http://dev.url/api/'
}
}
}
// ...
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
}
// Development server
grunt.task.run([
'clean:server',
'ngconstant:dev', // <-- added this
// ...
// Prod build
grunt.registerTask('build', [
'clean:dist',
'ngconstant:dist', // <-- added this Both ways work, but IMO this is a cleaner, more Gruntish way. You define an |
Hmm I am not a fan of mixing up generated code with handwritten. But wouldn't it not work out of the box when changing the paths to Of course do you need to add the |
Fair point about mixing generated code with source. It doesn't bother me in my use case, as I'm just defining one module. Yeah, it would work just fine the way you describe. I still think that the example I'm using is slightly less disruptive to the generator-angular system, and requires less knowledge of its workings. I think the difference between our methods is minor, and either would work just fine. |
Ok, this is your choice. Then I have to talk about if ngconstant is the right place for such an integration or you shouldn't better use a separate grunt plugin like grunt-js2coffee which does excatly what you want. The integration would be as simple as the ngconstant integration by simply converting the file after you have created it. |
My pull request just has to do with outputting coffeescript instead of javascript for any build process. My example was just one of many situations where it could be useful for someone. Yes, using grunt-js2coffee would work, but as a user it's another plugin to configure and maintain in my Gruntfile instead of just passing in an option to ngconstant. |
Just wondering, are you considering accepting this pull request? You initially said that it looks like a handy feature to have. I'd like to move to the mainstream grunt-ng-constant package available on npm, rather than maintaining my own fork. If you have any issues with the PR, please let me know. |
Sorry for no further feedback I am currently a little bit busy. I will merge this feature and will take a look at the code in the following days maybe already today. |
Okay, I'll sit tight. Thanks. |
I made a little change to the configuration. You don't need the |
Great, thanks for merging this in. I just installed v0.4.5 from npm and everything works the way it should. |
Coffeescript output is false by default, can be enabled with
options.coffee
. Usesjs2coffee
to convert the built javascript string to coffeescript before saving the file to disk.Also, as per Grunt's docs, using
grunt.util._
has been deprecated in favour of installing lodash or underscore through npm and saving it inpackage.json
.