-
-
Save bright-spark/74a3c9702c76fd7ebabd to your computer and use it in GitHub Desktop.
desktop (node-webkit) & mobile (cordova) static app
This file contains hidden or 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
'use strict'; | |
module.exports = function(grunt) { | |
var pkg = grunt.file.readJSON('package.json'); | |
grunt.initConfig({ | |
'pkg': pkg, | |
'connect': { | |
'dev': { | |
'options': { | |
'port': 9000, | |
'base': 'app', | |
'keepalive': true, | |
'hostname':'*' | |
} | |
}, | |
'prod': { | |
'options': { | |
'port': 9000, | |
'base': 'webroot', | |
'keepalive': true, | |
'hostname':'*' | |
} | |
} | |
}, | |
'imagemin': { | |
'default': { | |
'files': [{ | |
'expand': true, | |
'cwd': 'app/', | |
'src': ['img/**/*.{png,jpg,gif}', 'apple-touch-icon-precomposed.png'], | |
'dest': 'webroot/' | |
}] | |
} | |
}, | |
'useminPrepare': { | |
'html': ['app/index.html','app/glossary.html'], | |
'options': { | |
'dest': 'webroot/' | |
} | |
}, | |
'usemin': { | |
'html': ['webroot/index.html'], | |
'assetsDirs': ['img/', 'fonts/'] | |
}, | |
// needed for angular dependency injection | |
'uglify': { | |
'options': { | |
'mangle': false | |
} | |
}, | |
'clean': { | |
'default': ['webroot/', '.tmp/mobile', '.tmp/desktop/releases', '.tmp/desktop/www'] | |
}, | |
'copy': { | |
'default': { | |
'files': [{ | |
'expand': true, | |
'cwd': 'app/', | |
'src': ['index.html', 'views/**', 'favicon.ico', 'config.xml', 'fonts/**/*.ttf', 'fonts/**/*.woff', 'fonts/**/*.svg'], | |
'dest': 'webroot/' | |
}] | |
}, | |
'cordova_webroot': { | |
'expand': true, | |
'cwd': 'webroot/', | |
'src': ['**/*'], | |
'dest': '.tmp/mobile/www/' | |
}, | |
'desktop':{ | |
'expand': true, | |
'cwd': 'webroot/', | |
'src': ['**/*'], | |
'dest': '.tmp/desktop/www/' | |
}, | |
'desktop_release':{ | |
'expand': true, | |
'cwd': '.tmp/desktop/releases/' + pkg.friendlyname, | |
'src': ['**'], | |
'dest': 'release/' | |
}, | |
'mobile_release':{ | |
'expand': true, | |
'flatten':true, | |
'cwd': '.tmp/mobile/platforms/', | |
'src': ['android/bin/*.apk'], | |
'dest': 'release/' | |
} | |
}, | |
'mkdir': { | |
'cordova': { | |
'options': { | |
'create': ['.tmp/mobile/platforms/', '.tmp/mobile/hooks/', '.tmp/mobile/merges/', '.tmp/mobile/plugins/'] | |
} | |
} | |
}, | |
'bowerInstall': { | |
'default':{ | |
'src': ['app/index.html', 'app/glossary.html'], | |
'ignorePath': 'app/' | |
} | |
}, | |
'cordovacli': { | |
'options': { | |
'path': '.tmp/mobile/', | |
'id': 'com.intel.' + pkg.name, | |
'name': pkg.friendlyname.replace(/\s/g, '') | |
}, | |
'create': { | |
'options': { | |
'command': 'create' | |
} | |
}, | |
'platform': { | |
'options': { | |
'command': 'platform', | |
'action': 'add', | |
'platforms': ['android','ios'] | |
} | |
}, | |
'plugins': { | |
'options': { | |
'command': 'plugin', | |
'action': 'add', | |
'plugins': [], | |
} | |
}, | |
'build': { | |
'options': { | |
'command': 'build', | |
'args': ['--release'] | |
} | |
}, | |
'emulate_android': { | |
'options': { | |
'command': 'emulate', | |
'platforms': ['android'], | |
//'args': ['--target', 'Nexus10'] | |
} | |
} | |
}, | |
'nodewebkit': { | |
'options': { | |
'version':'0.9.2', | |
'build_dir': '.tmp/desktop', | |
'mac': true, | |
'win': false, | |
'linux32': false, | |
'linux64': false, | |
'app_name': pkg.friendlyname | |
}, | |
'src': ['.tmp/desktop/www/**/*'] | |
}, | |
'nwgenpkg': { | |
'desktop': { | |
'file':'.tmp/desktop/www/package.json', | |
'package': { | |
'main': 'index.html', | |
'name': pkg.name, | |
'icon': 'apple-touch-icon-precomposed.png', | |
'description': pkg.description, | |
'version': pkg.version, | |
'window': { | |
'title': pkg.friendlyname, | |
'toolbar': false, | |
'frame': true, | |
'width': 1024, | |
'height': 768, | |
'position': 'center', | |
'resizable':false, | |
'fullscreen':false | |
}, | |
'webkit':{ | |
'plugin': false, | |
'java': false, | |
'page-cache': true | |
} | |
} | |
} | |
} | |
}); | |
grunt.registerMultiTask('nwgenpkg', 'Generate a node-webkit package.json file', function() { | |
var options = this.data[this.target] ? this.data[this.target] : this.data; | |
grunt.file.write(options.file, JSON.stringify(options.package)); | |
}); | |
require('load-grunt-tasks')(grunt); | |
grunt.registerTask('bower', 'Setup bower dependencies', ['bowerInstall']); | |
grunt.registerTask('server', 'Start a local static webserver', ['connect:dev']); | |
grunt.registerTask('server:prod', 'Start a local static webserver', ['connect:prod']); | |
grunt.registerTask('default', 'Minify & optimize all files in app/, output goes in webroot/', [ | |
'clean', | |
'imagemin', | |
'bowerInstall', | |
'useminPrepare', | |
'concat', | |
'uglify', | |
'cssmin', | |
'copy:default', | |
'usemin' | |
]); | |
grunt.registerTask('mobile', 'Minify & generate native app for large-screen Android', [ | |
'default', | |
'mkdir:cordova', | |
'copy:cordova_webroot', | |
'cordovacli:platform', | |
'cordovacli:plugins', | |
'cordovacli:build', | |
'copy:mobile_release' | |
]); | |
grunt.registerTask('desktop', 'Minify & generate native app for mac, windows, & linux', [ | |
'default', | |
'copy:desktop', | |
'nwgenpkg:desktop', | |
'nodewebkit', | |
'copy:desktop_release' | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment