-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
105 lines (92 loc) · 3.06 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
/**
* @autor Laisson R. Silveira<[email protected]>
*
* Created on 23/05/2019
*/
const { join } = require('path');
const { writeFileSync } = require('fs');
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const apidoc = require('gulp-api-doc');
const clean = require('gulp-clean');
const tar = require('gulp-tar');
const gzip = require('gulp-gzip');
const install = require('gulp-install');
const rename = require('gulp-rename');
// // Files & Paths
const DIST_PATH = 'build/';
const PROJECT_NAME = 'cpf-validate';
const packageFile = require('./package.json');
const TESTS_PATH = './test/**/*.test.js';
const ROUTES_API = './src/routes';
const DIST_DOCS = './docs';
gulp.task('clean', () => {
return gulp.src(DIST_PATH + '*').pipe(clean());
});
gulp.task('copy', () => {
return gulp.src(['package*', 'src/**/*', 'bin/*'], { base: './' })
.pipe(gulp.dest(DIST_PATH));
});
gulp.task('compress', () => {
return gulp.src(`${DIST_PATH}**/*`)
.pipe(tar(PROJECT_NAME))
.pipe(gzip())
.pipe(rename(`${PROJECT_NAME}.tgz`))
.pipe(gulp.dest('dist/'));
});
gulp.task('install-dependencies', () => {
const pathPackage = join(__dirname, DIST_PATH);
return gulp.src(join(pathPackage, 'package.json'))
.pipe(gulp.dest(pathPackage))
.pipe(install({ production: true }));
});
gulp.task('remove-files', () => {
return gulp.src(DIST_PATH + 'package*').pipe(clean());
});
gulp.task('build',
gulp.series(
'clean',
'copy',
'install-dependencies',
'remove-files',
'compress',
'clean',
)
);
// =============================================== DOC ====================================================
gulp.task('set-version-api', done => {
const apidocCrawler = {
name: 'Validação de CPF - Documentação',
description: 'Documentação de cpf-validate',
title: 'Doc cpf-validate',
version: require('./package').version
};
const DIST_APIDOC_API = join(__dirname, `./${DIST_DOCS}/apidoc.json`);
writeFileSync(DIST_APIDOC_API, JSON.stringify(apidocCrawler, null, 4));
done();
});
gulp.task('make-doc', () => {
return gulp.src(`${ROUTES_API}/**/*.js`)
.pipe(apidoc({ markdown: false, template: DIST_DOCS, config: `${DIST_DOCS}` }))
.pipe(gulp.dest(DIST_DOCS));
});
gulp.task('doc', gulp.parallel('set-version-api', 'make-doc'));
// =============================================== TEST ====================================================
gulp.task('test', done => {
process.env.NODE_ENV = 'test';
return gulp.src(TESTS_PATH, { read: false })
.pipe(mocha({
timeout: 10000000,
exit: true,
reporter: 'mochawesome',
reporterOptions: {
reportDir: join('test/coverage'),
reportTitle: `Relatório de testes cpf-validate v${packageFile.version}`,
reportPageTitle: 'Testes cpf-validate'
}
}))
.on('error', err => {
done(err);
process.exit(1);
});
});