Files
old-spike/gulpfile.babel.js

88 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2016-02-22 14:36:07 -06:00
import gulp from 'gulp';
import yargs from 'yargs';
import webpack from 'webpack';
import gutil from 'gulp-util';
2016-03-08 15:21:16 -06:00
import gulpCopy from 'gulp-copy';
2016-03-05 16:53:29 -06:00
import fs from 'fs';
2016-02-22 14:36:07 -06:00
2016-03-01 13:16:31 -06:00
import FsHelper from './server/lib/fs_helper';
import ComponentMapWriter from './server/lib/tasks/component_map_writer';
2016-03-08 15:21:16 -06:00
import DesignDataGenerator from './server/lib/tasks/design_data_generator';
2016-03-05 16:53:29 -06:00
import BuildDashboardAssets from './server/lib/tasks/build_dashboard_assets';
2016-02-22 14:36:07 -06:00
import DB from './server/config/database';
import {PowerDataSeed, HouseSeed} from './server/lib/tasks/seed_data';
gulp.task('generate_power_csv', function(done){
DB.sync().then(()=>{
PowerDataSeed.generateCsv(yargs.argv, done);
});
});
gulp.task('save_power_csv', function(done){
DB.sync().then(()=>{
PowerDataSeed.saveCsv(yargs.argv, done);
});
});
gulp.task('save_house_csv', function(done){
DB.sync().then(()=>{
HouseSeed.saveCsv(yargs.argv, done);
});
});
2016-03-11 17:38:03 -06:00
gulp.task('generate_design_data', function(){
var house_ids = yargs.argv.house_ids.split(','),
start_date = parseInt(yargs.argv.start_date),
end_date = parseInt(yargs.argv.end_date),
data_generator = new DesignDataGenerator(house_ids, [start_date, end_date]);
return DB.sync()
.then(()=>{ return data_generator.exec(); });
});
2016-02-22 20:02:45 -06:00
// right now, build only available for design.
2016-02-22 14:36:07 -06:00
gulp.task('build', function(done) {
2016-03-05 16:53:29 -06:00
var config, env;
2016-02-22 14:36:07 -06:00
2016-02-22 20:02:45 -06:00
if (yargs.argv.design){
2016-03-01 13:16:31 -06:00
process.env.NODE_ENV = 'design';
2016-02-22 14:36:07 -06:00
} else {
2016-03-01 13:16:31 -06:00
throw new gutil.PluginError("webpack", "Must include '--design' option.");
2016-02-22 14:36:07 -06:00
}
2016-02-23 00:52:24 -06:00
2016-03-01 13:16:31 -06:00
// write template map.
ComponentMapWriter.write(__dirname + '/client/config/design/component_map.js')
.then(()=>{
// build assets/app.js and assets/style.css
config = require(`${__dirname}/client/config/${process.env.NODE_ENV}/webpack.js`);
webpack(config, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({}));
if (yargs.argv.design){
2016-03-05 16:53:29 -06:00
var path = 'client/build/design/dashboard';
2016-03-01 13:16:31 -06:00
// copy all react templates and their styles sheets into build/design/dashboard.
2016-03-05 16:53:29 -06:00
FsHelper.rmdirAsync(path, ()=>{
fs.mkdir(path, ()=>{
gulp.src([
`client/app.scss`
]).pipe(gulpCopy(path, {prefix: 1}));
2016-03-01 13:16:31 -06:00
2016-03-05 16:53:29 -06:00
FsHelper.walk('client/dashboard', (err, files)=>{
if (err){ console.log(err); done(); return false; }
var files_to_copy = files.filter((file)=>{
return /\.(rt|scss)$/.test(file)
});
gulp.src(files_to_copy)
.pipe(gulpCopy(path, {prefix: 2}));
done()
});
})
2016-03-01 13:16:31 -06:00
});
}
});
});
2016-02-22 14:36:07 -06:00
});