-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
117 lines (103 loc) · 3.23 KB
/
gulpfile.js
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
require('dotenv').config();
const fs = require('fs');
const os = require('os');
const path = require('path');
const gulp = require('gulp');
const runSequence = require('run-sequence');
const gutil = require('gulp-util');
const nodemon = require('gulp-nodemon');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const WebpackDevServer = require('webpack-dev-server');
const jsf = require('json-schema-faker');
const Promise = require('bluebird');
const Chance = require('chance');
const Faker = require('faker');
const gulpRequireTasks = require('gulp-require-tasks');
const axios = require('axios');
const chance = new Chance();
gulpRequireTasks();
/*
/
/
/ Database schema application and seeding
/
/
*/
jsf.extend('chance', () => chance);
jsf.extend('faker', () => Faker);
gulp.task('db', (cb) => {
runSequence('db:recreate',
['db:seed:users',
'db:seed:foodgenres',
'db:seed:locations'],
'db:seed:brands',
'db:seed:trucks',
['db:seed:locationtimelines',
'db:seed:menuitems',
'db:seed:brandcomments',
'db:seed:events:events'],
['db:seed:upvotes',
'db:seed:events:userattendees',
'db:seed:events:brandattendees',
'db:seed:events:eventcomments'], cb);
});
/*
/
/
/ Downloading DB/API schemas
/
/
*/
gulp.task('schema:db', (cb) => {
const axiosConf = { auth: { username: process.env.VERTABELO_KEY } };
axios.all([
axios.get(`https://my.vertabelo.com/api/sql/${process.env.VERTABELO_MODEL}`, axiosConf),
axios.get(`https://my.vertabelo.com/api/xml/${process.env.VERTABELO_MODEL}`, axiosConf),
])
.then(axios.spread((sql, xml) => {
fs.writeFileSync('config/database/Foodtrac.sql', sql.data);
fs.writeFileSync('config/database/Foodtrac.xml', xml.data);
}))
.then(() => { cb(); })
.catch((err) => { cb(err); });
});
gulp.task('schema:api', () => {
const pRename = Promise.promisify(fs.rename);
const apiFileSource = path.join(os.homedir(), 'Downloads', 'swagger20.json');
const apiFileTarget = path.join('server', 'api.json');
return pRename(apiFileSource, apiFileTarget)
.then(() => {
console.log(`API file copied from Downloads directory to ${apiFileTarget}`); // eslint-disable-line no-console
});
});
/*
/
/
/ Starting dev environment
/
/
*/
gulp.task('default', ['nodemon', 'webpackhot']);
gulp.task('nodemon', () => {
const stream = nodemon({ // eslint-disable-line no-unused-vars
script: 'server/index.js',
watch: ['./server/', './server/db'],
});
});
gulp.task('webpackhot', () => {
// Start a webpack-dev-server
webpackConfig.plugins = [new webpack.HotModuleReplacementPlugin()];
webpackConfig.entry.app = [
`webpack-dev-server/client?http://localhost:${process.env.WEBPACK_PORT}`,
'webpack/hot/dev-server',
].concat(webpackConfig.entry.app);
const compiler = webpack(webpackConfig);
new WebpackDevServer(compiler, webpackConfig.devServer).listen(process.env.WEBPACK_PORT, 'localhost', (err) => {
if (err) throw new gutil.PluginError('webpack-dev-server', err);
// Server listening
gutil.log('[webpack-dev-server]', `Dev server listening on http://localhost:${process.env.WEBPACK_PORT}`);
// keep the server alive or continue?
// callback();
});
});