This repository was archived by the owner on Jan 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgulpfile.js
More file actions
112 lines (88 loc) · 2.18 KB
/
gulpfile.js
File metadata and controls
112 lines (88 loc) · 2.18 KB
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
'use strict';
var argv = require('yargs').argv; // Using instead of deprecated `gulp.env`.
var inquirer = require('inquirer');
var stylish = require('jshint-stylish');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var runSequence = require('run-sequence');
var shell = require('gulp-shell');
var settings = require('./settings');
var internals = {
dbUrl: settings.POSTGRES_URL,
dbName: settings.POSTGRES_URL.substring(
settings.POSTGRES_URL.lastIndexOf('/') + 1
),
sources: {
scripts: [
'**/*.js',
'!./node_modules/**/*.js',
'!./migrations/*.js',
]
}
};
gulp.task('lint', function () {
return gulp.src(internals.sources.scripts)
.pipe(jshint({esnext: true}))
.pipe(jshint.reporter(stylish));
});
gulp.task('createdb', shell.task([
'createdb ' + internals.dbName
]));
gulp.task('dropdb', shell.task([
'dropdb --if-exists ' + internals.dbName
]));
gulp.task('migratedb', ['migratedb-up']);
// Sample usage:
//
// gulp migrate-up
// gulp migrate-up --num 3
//
gulp.task('migratedb-up', shell.task([
'DATABASE_URL="' + internals.dbUrl + '" ' +
'node node_modules/.bin/pg-migrate up ' +
(argv.num || argv.number || argv.n || '')
]));
// Sample usage:
//
// gulp migrate-down
// gulp migrate-down --num 3
//
gulp.task('migratedb-down', shell.task([
'DATABASE_URL="' + internals.dbUrl + '" ' +
'node node_modules/.bin/pg-migrate down ' +
(argv.num || argv.number || argv.n || '')
]));
// Sample usage:
//
// gulp migrate-down
// gulp migrate-down --name addTimestampColumn
//
gulp.task('migratedb-create', shell.task([
'DATABASE_URL="' + internals.dbUrl + '" ' +
'node node_modules/.bin/pg-migrate create ' +
(argv.name || argv.n || '')
]));
gulp.task('refreshdb', function (cb) {
var runNow = function () {
return runSequence(
'dropdb',
'createdb',
'migratedb',
cb
);
};
if (process.argv.indexOf('--no-prompt') !== -1) {
return runNow();
}
inquirer.prompt({
type: 'confirm',
name: 'val',
message: 'Are you sure you want to drop the database?',
default: false
}, function (res) {
if (!res.val) {
return cb();
}
runNow();
});
});