Skip to content

Instantly share code, notes, and snippets.

@sorrycc
Created December 25, 2012 08:03
Show Gist options
  • Save sorrycc/4372204 to your computer and use it in GitHub Desktop.
Save sorrycc/4372204 to your computer and use it in GitHub Desktop.
helper = require "./_grunt_helper"
_config = require "./_config"
path = require "path"
fs = require "fs"
ModuleCompiler = require "module-compiler"
JS_SRC = path.join __dirname, "./src/javascripts/"
CSS_SRC = path.join __dirname, "./src/stylesheets/"
BUILD_SRC = path.join __dirname, "./build/#{_config.timestamp}/hy/"
module.exports = (grunt) ->
# Load npm tasks.
grunt.loadNpmTasks "grunt-contrib"
grunt.loadNpmTasks "grunt-contrib-clean"
grunt.loadNpmTasks "grunt-compass"
grunt.loadNpmTasks "grunt-contrib-mincss"
# Basic config.
config =
kissy:
packages: [
{
"name": "hy"
"path": JS_SRC
}
]
coffee: {}
compass:
compile:
src : "./src/stylesheets/"
dest: "./src/stylesheets/"
debugsass: true
watch:
compass:
files: ["./src/stylesheets/*.scss", "./src/stylesheets/foundation/*.scss", "./src/stylesheets/library/*.scss"]
tasks: "compass:compile"
clean:
build: ["#{BUILD_SRC}*"]
copy : {css: {files:{}}}
uglify: {codegen:{ascii_only:true}}
min : {}
mincss: {css: {files:{}}}
# Add Config Infos.
for file in _config.cssPages
config.copy.css.files["#{BUILD_SRC}#{file}.css"] = "./src/stylesheets/#{file}.css"
config.mincss.css.files["#{BUILD_SRC}#{file}-min.css"] = "#{BUILD_SRC}#{file}.css"
for file in _config.jsPages
config.min[file] =
src : "#{BUILD_SRC}#{file}.js"
dest: "#{BUILD_SRC}#{file}.js"
helper.addCoffee "./src/", config
# Init.
grunt.initConfig config
# KISSY build.
grunt.registerTask "kissybuild", ->
ModuleCompiler.config config.kissy
ModuleCompiler.build "#{JS_SRC}hy/#{file}.js", "#{BUILD_SRC}#{file}.js" for file in _config.jsPages
# Prepare.
grunt.registerTask "prepare", ->
helper.mkdir BUILD_SRC.replace "hy/", ""
helper.mkdir BUILD_SRC
# Register.
grunt.registerTask "default", "clean prepare kissybuild copy min mincss"
fs = require "fs"
path = require "path"
module.exports =
addCoffee: (targetPath, config) ->
for file in fs.readdirSync targetPath
@addCoffeeItem file, targetPath, config
addCoffeeItem: (file, targetPath, config) ->
# 过滤.
return if file == "node_modules"
return if file == "bin"
return if file.indexOf("_") == 0
# 支持多级目录.
src = targetPath + file
if fs.statSync(src).isDirectory()
@addCoffee src + "/", config
return
return if path.extname(file) != ".coffee"
# 添加到 Coffee 配置.
dest = src.replace ".coffee", ".js"
# dest = dest.replace "src/", "compiled/"
config.coffee[src] = {files:{},options:{bare:true}}
config.coffee[src]["files"][dest] = src
# 添加到 Watch.
config.watch[src] =
files: src
tasks: "coffee:#{src}"
mkdir: (path) ->
fs.mkdirSync path if !fs.existsSync path
require("coffee-script");
module.exports = require("./_grunt");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment