Skip to content

Commit

Permalink
Moved most constants to a unified file
Browse files Browse the repository at this point in the history
Moved most constants to a unified file
  • Loading branch information
Laura González authored Feb 15, 2017
2 parents 8679a3f + 34c26c6 commit 5ff4358
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 64 deletions.
74 changes: 36 additions & 38 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,46 @@ 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');
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);
fs.mkdirSync(dir);
})
});


gulp.task('test', ['make'], function () {
return gulp
.src('test/index.html')
Expand Down Expand Up @@ -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){
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
35 changes: 10 additions & 25 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,26 @@ 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 = {}
} = {}) {


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();
Expand Down
31 changes: 31 additions & 0 deletions src/conf.js
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 5ff4358

Please sign in to comment.