Created
February 6, 2016 11:55
-
-
Save statickidz/a1b9a621b01230c1959c to your computer and use it in GitHub Desktop.
Copy new file updates to directory with Grunt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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