Last active
August 29, 2015 14:08
-
-
Save darkoverlordofdata/090a993a30480ca84328 to your computer and use it in GitHub Desktop.
dart-like workflow
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
#+--------------------------------------------------------------------+ | |
#| Gruntfile.coffee | |
#+--------------------------------------------------------------------+ | |
#| Copyright DarkOverlordOfData (c) 2014 | |
#+--------------------------------------------------------------------+ | |
#| | |
#| dart-like workflow | |
#| | |
#| dart-like is free software; you can copy, modify, and distribute | |
#| it under the terms of the MIT License | |
#| | |
#+--------------------------------------------------------------------+ | |
# | |
# Tasks: | |
# | |
# grunt test - run tests | |
# grunt build - build lib sources to web/packages/{{lib}} | |
# grunt deploy - create build/{{project}}.zip and copy to device | |
# bower install - get dependencies | |
# npm install - get dependencies | |
# | |
# manually copy required bits from packages/module to web/packages/module | |
# | |
# project | |
# | -- build output folder for zip | |
# | -- lib defines this package | |
# | -- node_modules npm external modules | |
# | -- packages bower external packages | |
# | -- (tmp) | |
# | -- web source | |
# | | -- packages packages + lib | |
# | | -- index.html | |
# | + -- main.js starts lib.main() | |
# | | |
# | -- .bowerrc define ./packages | |
# | -- .gitignore build, node_modules, tmp, packages | |
# | -- bower.json module name | |
# | -- Gruntfile.coffee this workflow | |
# | -- license.md | |
# | -- package.json output package name | |
# + -- readme.md | |
# | |
# | |
$package = require("./package.json") | |
$bower = require("./bower.json") | |
$projectName = $package.name | |
$libName = $bower.name | |
$packageName = $libName.toLowerCase() | |
module.exports = -> | |
@initConfig | |
pkg: '<json:package.json>' | |
### | |
Compile lib to tmp | |
### | |
coffee: | |
compile: | |
options: | |
bare: true | |
sourceMap: true | |
expand: true | |
flatten: false | |
cwd: __dirname | |
src: ["lib/**/*.coffee"] | |
dest: 'tmp/' | |
ext: ".js" | |
### | |
Package up tmp | |
### | |
browserify: | |
dist: | |
options: | |
browserifyOptions: | |
debug: true | |
standalone: $libName | |
cwd: __dirname | |
src: ["tmp/lib/index.js"] | |
dest: "web/packages/#{$packageName}/#{$packageName}.js" | |
### | |
Minify | |
### | |
uglify: | |
dist: | |
cwd: __dirname | |
src: ["web/packages/#{$packageName}/#{$packageName}.js"] | |
dest: "web/packages/#{$packageName}/#{$packageName}.min.js" | |
### | |
Run the tests | |
### | |
simplemocha: | |
test: | |
src: 'test/**/*.coffee' | |
options: | |
globals: ['expect'] | |
timeout: 3000 | |
ui: 'bdd' | |
reporter: 'tap' | |
### | |
Delete temporary files | |
### | |
clean: | |
build: | |
["tmp/"] | |
### | |
Create archive package | |
### | |
compress: | |
cocoonjs: | |
options: | |
archive: "build/#{$projectName}.zip" | |
expand: true | |
cwd: "web/" | |
src: ["**/*.*"] | |
dest: "/" | |
### | |
Copy archive to device | |
### | |
adbPush: | |
cocoonjs: | |
cwd: __dirname | |
src: ["build/#{$projectName}.zip"] | |
dest: "/sdcard/" | |
### | |
get packages | |
ex: add to bower.json | |
"packages": { | |
"jquery": "jquery/dist/*.js" | |
} | |
### | |
bowercopy: | |
options: | |
destPrefix: 'web/packages/' | |
packages: | |
files: $bower.packages | |
### | |
Load grunt plugins | |
### | |
@loadNpmTasks 'grunt-adb-tools' | |
@loadNpmTasks 'grunt-browserify' | |
@loadNpmTasks 'grunt-bowercopy' | |
@loadNpmTasks 'grunt-contrib-clean' | |
@loadNpmTasks 'grunt-contrib-coffee' | |
@loadNpmTasks 'grunt-contrib-compress' | |
@loadNpmTasks 'grunt-contrib-uglify' | |
@loadNpmTasks 'grunt-simple-mocha' | |
### | |
Register task aliases | |
### | |
@registerTask 'test', 'simplemocha' | |
@registerTask 'build', ['clean','coffee', 'browserify', 'uglify'] | |
@registerTask 'deploy', ['compress', 'adbPush'] | |
@registerTask 'get', 'bowercopy' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment