diff --git a/gulpfile.js b/gulpfile.js index 83fb0c2..420567e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,6 +2,7 @@ const gulp = require('gulp'); const gutil = require('gulp-util'); const webpack = require('webpack-stream'); const uglify = require('gulp-uglify'); +const header = require('gulp-header'); const path = require('path'); const fs = require('fs-extra'); const mochaPhantomJS = require('gulp-mocha-phantomjs'); @@ -9,25 +10,30 @@ const WrapperPlugin = require('wrapper-webpack-plugin'); const release = require('gulp-github-release'); const through = require('through2'); -var webpackModule = { - loaders: [ - { - test: /\.css$/, loader: "raw" - }, - { - test: /\.mustache$/, loader: "raw" - }, - { - test: /.js?$/, - loader: 'babel-loader', - query: { - presets: ['es2015'], - plugins: ["transform-object-assign"] +const config = require('./src/conf.js'); + + +const webpackConfig = { + module: { + loaders: [ + { + test: /.js?$/, + loader: 'babel-loader', + query: { + presets: ['es2015'], + plugins: ['transform-object-assign'] + } } - } + ] + }, + plugins: [ + new webpack.webpack.ProvidePlugin({ + Promise: 'es6-promise-promise' + }) ] }; + gulp.task('clean', () => { ['dist','temp','temp/screenshots'].map((dir)=>{ fs.removeSync(dir); @@ -35,6 +41,7 @@ gulp.task('clean', () => { }) }); + gulp.task('test', ['make'], function () { return gulp .src('test/index.html') @@ -84,59 +91,50 @@ gulp.task('test', ['make'], function () { })) }); + gulp.task('default', function() { return gulp.src('src/app.js') .pipe(webpack({ watch: true, devtool: 'source-map', output: { - filename: 'constellation.js', - library: 'constellation', + filename: config.webpack.filename.dev, + library: config.webpack.library, libraryTarget: 'umd' }, - plugins: [ - new webpack.webpack.ProvidePlugin({ - Promise: 'es6-promise-promise' - }), - new WrapperPlugin({ - header: '/* ✨ constellation ✨ – dev – https://github.com/lawwrr/constellation */' - }) - ], - module: webpackModule, + plugins: webpackConfig.plugins, + module: webpackConfig.module, resolve: { root: path.resolve('./src') } })) + .pipe(header(config.webpack.header+"\n")) .pipe(gulp.dest('dist/')); }); + gulp.task('make', ['clean'], function() { return gulp.src('src/app.js') .pipe(webpack({ output: { - filename: 'constellation.min.js', - library: 'constellation', + filename: config.webpack.filename.dist, + library: config.webpack.library, libraryTarget: 'umd' }, - plugins: [ - new webpack.webpack.ProvidePlugin({ - Promise: 'es6-promise-promise' - }), - new WrapperPlugin({ - header: '/* ✨ constellation ✨ – https://github.com/lawwrr/constellation */' - }) - ], - module: webpackModule, + plugins: webpackConfig.plugins, + module: webpackConfig.module, resolve: { root: path.resolve('./src') } })) .pipe(uglify()) + .pipe(header(config.webpack.header+"\n")) .pipe(gulp.dest('dist/')) }) + gulp.task('release', function(){ - return gulp.src('dist/constellation.min.js') + return gulp.src('dist/'+config.webpack.filename.dist) .pipe(release({ manifest: require('./package.json') }).on('error',function(e){ diff --git a/package.json b/package.json index c3cf2e7..fe57781 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "constelation-canvas", "description": "draws cute animated canvas constellations", - "version": "1.3.6", + "version": "1.4.0", "author": "Laura mayhem", "bugs": { "url": "https://github.com/walaura/constellation/issues", @@ -17,6 +17,7 @@ "es6-promise-promise": "1.0.0", "fs-extra": "^2.0.0", "gulp": "^3.9.1", + "gulp-header": "^1.8.8", "gulp-mocha-phantomjs": "^0.12.0", "gulp-uglify": "^1.5.4", "gulp-util": "^3.0.8", diff --git a/src/app.js b/src/app.js index 5b7f1a5..2215f26 100644 --- a/src/app.js +++ b/src/app.js @@ -2,32 +2,17 @@ import Canvas from 'class/Canvas'; import Puppis from 'worker-loader?inline!./worker/puppis.js'; import text from 'lib/text'; - - -const defaults = { - style: { - starSize: 4, - starPadding: 5, - starColor: '#000', - lineColor: 'rgba(0,0,0,.5)', - lineSize: 2 - }, - speed: { - active: .125, - passive: .075 - } -} +import config from 'conf'; const constellation = function ({ - size = [400,400], - element = undefined, - canvas = undefined, - starCount = 30, - lineCount = 70, - fuzziness = 100, - padding = [0,0], - scale = 2, + size = config.defaults.size, + canvas = config.defaults.canvas, + starCount = config.defaults.starCount, + lineCount = config.defaults.lineCount, + fuzziness = config.defaults.fuzziness, + padding = config.defaults.padding, + scale = config.defaults.scale, style = {}, speed = {}, onDraw = {} @@ -35,8 +20,8 @@ const constellation = function ({ if(padding[0] === 0 && padding[1] === 0) padding = [fuzziness,fuzziness] - style = Object.assign({}, defaults.style, style); - speed = Object.assign({}, defaults.speed, speed); + style = Object.assign({}, config.defaults.style, style); + speed = Object.assign({}, config.defaults.speed, speed); const puppis = new Puppis(); diff --git a/src/conf.js b/src/conf.js new file mode 100644 index 0000000..74f13a1 --- /dev/null +++ b/src/conf.js @@ -0,0 +1,31 @@ +module.exports = { + webpack: { + header: '/* ✨ constellation ✨ – https://github.com/walaura/constellation */', + library: 'constellation', + filename: { + dist: 'constellation.min.js', + dev: 'constellation.js' + } + }, + defaults: { + size: [400,400], + canvas: undefined, + starCount: 30, + lineCount: 70, + fuzziness: 100, + padding: [0,0], + scale: 2, + onDraw: {}, + style: { + starSize: 4, + starPadding: 5, + starColor: '#000', + lineColor: 'rgba(0,0,0,.5)', + lineSize: 2 + }, + speed: { + active: .125, + passive: .075 + } + } +}