-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.coffee
144 lines (121 loc) · 3.56 KB
/
Gruntfile.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
wd = './demo/img'
output = './demo/js/data.js'
ColorThief = require('color-thief')
#ColorThief = require('./src/color-bandit.js')
#Canvas = require('canvas')
#Image = Canvas.Image
fs = require 'fs'
getPalette = (sourceImage, colorCount, quality) ->
colorCount = 10 if typeof colorCount is "undefined"
quality = 10 if typeof quality is "undefined"
# Create custom CanvasImage object
image = new CanvasImage(sourceImage)
imageData = image.getImageData()
pixels = imageData.data
pixelCount = image.getPixelCount()
palette = @getPaletteFromPixels(pixels, pixelCount, colorCount, quality)
# Clean up
image.removeCanvas()
palette
module.exports = ->
grunt = @
# Project configuration
@initConfig
pkg: @file.readJSON 'package.json'
#componentbuild:
# 'gss-springs':
# options:
# name: 'gss-springs'
# src: '.'
# dest: 'browser'
# scripts: true
# styles: false
browserify:
dist:
files:
'dist/browser.js': ['src/springs.coffee']
options:
transform: ['coffeeify']
browserifyOptions:
extensions: ['.coffee']
fullPaths: false
standalone: 'GSSSprings'
# JavaScript minification for the browser
#uglify:
# options:
# report: 'min'
# chromatose:
# files:
# './browser/gss-springs.min.js': ['./browser/gss-springs.js']
#
# Automated recompilation and testing when developing
watch:
files: ['**/*.coffee']
tasks: ['build']
# BDD tests on Node.js
cafemocha:
nodejs:
src: ['spec/**/*.coffee']
options:
reporter: 'spec'
# CoffeeScript compilation
coffee:
spec:
options:
bare: true
expand: true
cwd: 'spec'
src: ['**/*.coffee']
dest: 'spec'
ext: '.js'
src:
options:
bare: true
expand: true
cwd: 'src'
src: ['**/*.coffee']
dest: 'lib'
ext: '.js'
demo:
options:
bare: true
expand: true
cwd: 'demo/js'
src: ['**/*.coffee']
dest: 'demo/js'
ext: '.js'
# BDD tests on browser
mocha_phantomjs:
all: ['spec/runner.html']
@registerTask 'colors', 'Extract Colors', () ->
#imgs = fs.readdirSync wd
#for img in imgs
#
# colorThief = new ColorThief()
# console.log colorThief.getColor "./demo/img/" + img
images = []
grunt.file.recurse wd, (abspath, rootdir, subdir, filename) ->
colorThief = new ColorThief()
#console.log abspath
colorThief.getPalette "./" + abspath, 5, 10, (colors)->
abs = abspath.split('/')
img =
url:'./img/' + abs[abs.length - 1]
colors:[]
for color in colors
img.colors.push "rgb(#{color[0]},#{color[1]},#{color[2]})"
images.push img
grunt.file.write output, "window.DEMO_DATA = {images:" + JSON.stringify( images, 1, 1) + "};"
#grunt.file.write output+"/manifest.json", JSON.stringify( manifest, 1, 1)
#grunt.file.write output+"/manifest.yml", yaml.safeDump manifest
# Grunt plugins used for building
@loadNpmTasks 'grunt-browserify'
@loadNpmTasks 'grunt-contrib-uglify'
# Grunt plugins used for testing
@loadNpmTasks 'grunt-cafe-mocha'
@loadNpmTasks 'grunt-contrib-coffee'
@loadNpmTasks 'grunt-mocha-phantomjs'
@loadNpmTasks 'grunt-contrib-watch'
@registerTask 'build', ['coffee', 'browserify', 'colors']
@registerTask 'test', ['build', 'mocha_phantomjs']
@registerTask 'default', ['build']