Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
6,726 additions
and
9,026 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,6 @@ vendor/ | |
build/ | ||
.idea/ | ||
|
||
javascript/node_modules/ | ||
javascript/phantomjs/renders/ | ||
|
||
composer.phar | ||
|
||
*.log | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
node_modules/ | ||
renders/*.png |
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import args from 'yargs'; | ||
import gulpif from 'gulp-if'; | ||
import source from 'vinyl-source-stream'; | ||
import notifier from 'node-notifier'; | ||
import browserify from 'browserify'; | ||
import uglify from 'gulp-uglify'; | ||
import babelify from 'babelify'; | ||
// import stripify from 'stripify'; | ||
import watchify from 'watchify'; | ||
import streamify from 'gulp-streamify'; | ||
import versionify from 'browserify-versionify'; | ||
import { dest } from 'gulp'; | ||
import { log } from 'gulp-util'; | ||
import { red, green } from 'chalk'; | ||
import { create } from 'browser-sync'; | ||
|
||
const browserSync = create(); | ||
|
||
export default function compile(prod, watch, sync) { | ||
let bundler = browserify({ | ||
debug: true, | ||
entries: ['./src/lava.entry.es6'], | ||
cache: {}, | ||
packageCache: {} | ||
}); | ||
|
||
bundler.transform(babelify, { presets: ['es2015'] }); | ||
bundler.transform(versionify); | ||
|
||
if (watch) { | ||
bundler = watchify(bundler); | ||
|
||
if (sync) { | ||
browserSync.init({ | ||
proxy: "localhost:" + args.port || 8000 | ||
}); | ||
} | ||
} | ||
|
||
if (prod) { | ||
bundler.transform('stripify'); | ||
} | ||
|
||
function rebundle() { | ||
return bundler.bundle() | ||
.on('error', err => { | ||
if (err instanceof SyntaxError) { | ||
log(red('Syntax Error')); | ||
log(err.message); | ||
// log(err.filename+":"+err.loc.line); | ||
log(err.codeFrame); | ||
} else { | ||
log(red('Error'), err.message); | ||
} | ||
|
||
this.emit('end'); | ||
}) | ||
.pipe(source('lava.js')) | ||
.pipe(gulpif(prod, streamify(uglify()))) | ||
.pipe(dest('dist')); | ||
} | ||
|
||
if (watch) { | ||
bundler.on('update', () => { | ||
const msg = 'lava.js re-bundling...'; | ||
|
||
log(green(msg)); | ||
|
||
notifier.notify({ | ||
title: 'Browserify', | ||
message:msg | ||
}); | ||
|
||
rebundle(); | ||
}); | ||
|
||
bundler.on('log', msg => { | ||
log(green(msg)); | ||
|
||
if (sync) { | ||
browserSync.reload(); | ||
} | ||
}); | ||
} | ||
|
||
return rebundle(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { map } from 'lodash'; | ||
import { cwd } from 'process'; | ||
import { resolve } from 'path'; | ||
import { sync as globSync } from 'glob'; | ||
|
||
export default function getChartTypes() { | ||
let chartTypes = globSync('*.php', { | ||
cwd: resolve(cwd(), '../src/Charts/'), | ||
nomount: true, | ||
ignore: [ | ||
'Chart.php', | ||
'ChartBuilder.php', | ||
'ChartFactory.php', | ||
] | ||
}); | ||
|
||
return map(chartTypes, chartType => { | ||
return chartType.slice(0, -4); | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import PortFinder from 'portfinder'; | ||
import PhpServer from 'gulp-connect-php'; | ||
import { cwd } from 'process'; | ||
import { resolve } from 'path'; | ||
|
||
function _createServer(port) { | ||
const base = resolve(cwd(), '../tests/Examples'); | ||
const server = new PhpServer(); | ||
|
||
return new Promise(resolve => { | ||
server.server({ | ||
base: base, | ||
port: port, | ||
ini: base + '/php.ini', | ||
router: base + '/renderer.php' | ||
}); | ||
|
||
resolve(server); | ||
}); | ||
} | ||
|
||
export default function getPhpServer() { | ||
return PortFinder | ||
.getPortPromise() | ||
.then(_createServer) | ||
.catch(err => { | ||
console.log(err); | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Nightmare from 'nightmare'; | ||
import getPhpServer from './PhpServer'; | ||
import { cwd } from 'process'; | ||
import { resolve } from 'path'; | ||
|
||
function _getNightmare(timeout) { | ||
return new Nightmare({ | ||
gotoTimeout: timeout, | ||
waitTimeout: timeout, | ||
loadTimeout: timeout, | ||
executionTimeout: timeout | ||
}); | ||
} | ||
|
||
export default function renderChart(chartType) { | ||
return getPhpServer() | ||
.then(server => { | ||
let chartUrl = 'http://localhost:' + server.port + '/' + chartType; | ||
let renderDir = resolve(cwd(), 'renders'); | ||
let chartImg = renderDir + '/' + chartType + '.png'; | ||
|
||
console.log('Nightmare opening ' + chartUrl); | ||
|
||
return _getNightmare(5000) | ||
.viewport(800, 600) | ||
.goto(chartUrl) | ||
.wait(3000) | ||
.screenshot(chartImg) | ||
.end(() => { | ||
console.log('Saved screenshot to ' + chartImg); | ||
|
||
server.closeServer(); | ||
}); | ||
}); | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* jshint node:true */ | ||
|
||
import gulp from 'gulp'; | ||
import yargs from 'yargs'; | ||
import bump from 'gulp-bump'; | ||
import replace from 'gulp-replace'; | ||
import compile from './gulp-functions/Compile'; | ||
import renderChart from './gulp-functions/Renderer'; | ||
import getChartTypes from './gulp-functions/GetChartTypes'; | ||
import { cpus } from 'os' | ||
import { map } from 'bluebird'; | ||
|
||
gulp.task('default', ['dev']); | ||
|
||
/** | ||
* Lava.js compilation tasks. | ||
* | ||
* The compile method accepts three boolean flags for the following signature: | ||
* compile(prod, watch, sync) | ||
*/ | ||
gulp.task('dev', () => { compile(false, false, false) }); | ||
gulp.task('prod', () => { compile(true, false, false) }); | ||
gulp.task('watch', () => { compile(false, true, false) }); | ||
gulp.task('sync', () => { compile(false, true, true) }); | ||
|
||
/** | ||
* Render a specific chart. | ||
* | ||
* Specify the type as the php class name | ||
* | ||
* Syntax: | ||
* gulp render --type [ AreaChart | LineChart | GeoChart | etc... ] | ||
*/ | ||
gulp.task('render', done => { | ||
const chartTypes = getChartTypes(); | ||
const args = yargs | ||
.fail(msg => { | ||
throw new Error(msg); | ||
}) | ||
.alias('t', 'type') | ||
.describe('t', 'choose the type of chart to render') | ||
.choices('t', chartTypes) | ||
.wrap(70) | ||
.help('help') | ||
.argv; | ||
|
||
renderChart(args.t) | ||
.then(() => { | ||
done(); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
}); | ||
}); | ||
|
||
/** | ||
* Render all of the available charts. | ||
* | ||
* The renders will be ran in batches equal to the number of processors. | ||
* | ||
* Syntax: | ||
* gulp renderAll | ||
*/ | ||
gulp.task('renderAll', done => { | ||
let batchSize = cpus().length; | ||
|
||
console.log('Rendering charts in batches of '+batchSize); | ||
|
||
map(getChartTypes(), chartType => { | ||
return renderChart(chartType); | ||
}, {concurrency: batchSize}) | ||
.then(() => { | ||
done(); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
}); | ||
}); | ||
|
||
/** | ||
* Get all available chart types | ||
* | ||
* Syntax: | ||
* gulp charts | ||
*/ | ||
gulp.task('charts', done => { | ||
console.log('Available charts for rendering:'); | ||
console.log(getChartTypes().join(', ')); | ||
done(); | ||
}); | ||
|
||
/** | ||
* Render all of the available charts. | ||
* | ||
* Syntax: | ||
* gulp version -v 4.0.0 | ||
*/ | ||
// gulp.task('version', done => { | ||
// let version = args.v; | ||
// let minorVersion = version.slice(0, -2); | ||
// | ||
// gulp.src('./package.json') | ||
// .pipe(bump({version:args.v})) | ||
// .pipe(gulp.dest('./')); | ||
// | ||
// gulp.src(['./README.md', './.travis.yml']) | ||
// .pipe(replace(/(["=\/-])[0-9]+\.[0-9]+/g, '$1'+minorVersion)) | ||
// .pipe(gulp.dest('./')); | ||
// | ||
// done(); | ||
// }); |
Oops, something went wrong.