Skip to content

Commit d0d9550

Browse files
added gulp support
1 parent 174dccf commit d0d9550

7 files changed

Lines changed: 93 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ sftp-config.json
5454

5555
#Documentation
5656
docs
57+
58+
# package-lock.json
59+
package-lock.json

gulpfile.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
3+
const Gulp = require('gulp')
4+
const RequireDir = require('require-dir')
5+
6+
// Load tasks
7+
RequireDir('./tasks')
8+
9+
Gulp.task('dev', ['dotenv', 'yaml2json', 'nodemon'])
10+
Gulp.task('prod', ['pm2'])
11+
12+
Gulp.task('default', ['dev'])

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"babel-preset-stage-0": "^6.5.0",
4040
"bcrypt": "^1.0.2",
4141
"glob": "^7.0.0",
42+
"gulp": "^3.9.1",
43+
"gulp-watch": "^4.3.11",
4244
"http2": "^3.3.6",
4345
"jsonwebtoken": "^7.1.9",
4446
"koa": "^2.2.0",
@@ -52,16 +54,21 @@
5254
"koa-router": "^7.0.1",
5355
"koa-static": "^3.0.0",
5456
"mongoose": "^4.4.3",
55-
"passport-local": "^1.0.0"
57+
"passport-local": "^1.0.0",
58+
"pm2": "^2.5.0",
59+
"require-dir": "^0.3.2"
5660
},
5761
"devDependencies": {
5862
"babel-eslint": "^7.2.2",
5963
"babel-register": "^6.5.1",
6064
"chai": "^3.5.0",
65+
"dotenv": "^4.0.0",
6166
"eslint": "^3.4.0",
6267
"eslint-config-standard": "^10.2.1",
6368
"eslint-plugin-promise": "^3.5.0",
6469
"eslint-plugin-standard": "^3.0.1",
70+
"gulp-nodemon": "^2.2.1",
71+
"gulp-yaml": "^1.0.1",
6572
"mocha": "^3.0.2",
6673
"nodemon": "^1.8.1",
6774
"supertest": "^3.0.0"

tasks/dotenv.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict'
2+
3+
const Gulp = require('gulp')
4+
const dotenv = require('dotenv')
5+
6+
Gulp.task('dotenv', function () {
7+
dotenv.config()
8+
})

tasks/nodemon.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
const Gulp = require('gulp')
3+
const Nodemon = require('gulp-nodemon')
4+
5+
Gulp.task('nodemon', function () {
6+
const nodeArgs = []
7+
if (process.env.DEBUGGER) {
8+
nodeArgs.push('--inspect')
9+
}
10+
11+
Nodemon({
12+
script: 'index.js',
13+
ignore: [
14+
'node_modules/',
15+
'test/'
16+
],
17+
nodeArgs: nodeArgs
18+
}).on('restart', function (files) {
19+
console.log('change detected:', files)
20+
})
21+
})

tasks/pm2.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
const Gulp = require('gulp')
3+
const pm2 = require('pm2')
4+
5+
Gulp.task('pm2', function () {
6+
pm2.connect(true, function (err) {
7+
if (err) {
8+
console.error(err)
9+
process.exit(2)
10+
}
11+
pm2.start({
12+
name: 'Koach',
13+
script: 'index.js', // Script to be run
14+
exec_mode: 'cluster', // Allow your app to be clustered
15+
instances: 4, // Optional: Scale your app by 4
16+
max_memory_restart: '500M' // Optional: Restart your app if it reaches 100Mo
17+
}, function (err, apps) {
18+
pm2.disconnect() // Disconnect from PM2
19+
if (err) {
20+
throw err
21+
}
22+
})
23+
})
24+
})

tasks/yaml2json.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
const Gulp = require('gulp')
4+
const yaml = require('gulp-yaml')
5+
const watch = require('gulp-watch')
6+
7+
Gulp.task('yaml2json', function () {
8+
Gulp.src('./swagger/swagger.yaml')
9+
.pipe(yaml({ space: 4 }))
10+
.pipe(Gulp.dest('./swagger'))
11+
12+
return watch('./swagger/swagger.yaml', function () {
13+
return Gulp.src('./swagger/swagger.yaml')
14+
.pipe(yaml({ space: 4 }))
15+
.pipe(Gulp.dest('./swagger'))
16+
})
17+
})

0 commit comments

Comments
 (0)