Skip to content

Instantly share code, notes, and snippets.

@statickidz
Created February 6, 2016 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statickidz/a1b9a621b01230c1959c to your computer and use it in GitHub Desktop.
Save statickidz/a1b9a621b01230c1959c to your computer and use it in GitHub Desktop.
Copy new file updates to directory with Grunt
var date = new Date();
module.exports = function(grunt) {
grunt.initConfig({
watch: {
models: {
files: ['application/models/**/*.php'],
tasks: ['copyTask'],
options: {
spawn: false,
},
},
views: {
files: ['application/views/**/**/*.tpl'],
tasks: ['copyTask'],
options: {
spawn: false,
},
},
controllers: {
files: ['application/controllers/**/*.php'],
tasks: ['copyTask'],
options: {
spawn: false,
},
},
language: {
files: ['application/language/**/*.php'],
tasks: ['copyTask'],
options: {
spawn: false,
},
},
},
copy: {
main: {
src: '',
dest: 'updates/',
},
},
compress: {
main: {
options: {
archive: 'updates/update-'
+date.getDate()+'-'
+(date.getMonth()+1)+'-'
+date.getFullYear()+'-'
+date.getHours()+'.'
+date.getMinutes()
+'.zip',
},
files: [
{
expand: true,
cwd: 'updates/',
src: ['**'],
dest: 'updates/',
}
]
}
}
});
var newFile = '';
grunt.event.on('watch', function(action, filepath, target) {
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
newFile = filepath;
newFile = newFile.replace('\\', "/");
});
grunt.registerTask('copyTask', function() {
grunt.config.set('copy.main.src', newFile);
grunt.task.run('copy:main');
});
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', 'watch');
grunt.registerTask('build-update', 'compress:main');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment