This repository has been archived by the owner on Dec 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Gulpfile.js
120 lines (97 loc) · 3.15 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
118
119
120
'use strict';
const gulp = require('gulp');
const glob = require('glob');
const gutil = require('gulp-util');
const merge = require('merge2');
const {argv} = require('yargs');
const {spawn} = require('child_process');
const gsequence = require('gulp-sequence');
const mkdirp = require("mkdirp");
const {join, dirname} = require('path');
const {writeFileSync} = require('fs');
const {keys, intersection} = require('lodash');
gulp.task('default', ['build']);
const PACKAGE_DIRS = [
...glob.sync('./packages/*')
];
const PACKAGE_NAMES = PACKAGE_DIRS.map(dir => dir.split('/').pop());
const NODE_MODULES_DIR = join(__dirname, 'node_modules');
const NODE_MODULES_BIN_DIR = join(NODE_MODULES_DIR, '.bin');
const WATCH = argv.watch != null;
const GREP = argv.grep;
const gulpSpawn = (command, args, options) => {
gutil.log([command, ...args, options.cwd].join(' '));
const proc = spawn(command, args, options);
proc.stdout.setEncoding('utf8');
proc.stderr.setEncoding('utf8');
proc.stdout.on('data', data => {
gutil.log(data.trim());
});
proc.stderr.on('data', data => {
gutil.log(gutil.colors.red(data.trim()));
gutil.beep();
});
return proc.stdout;
};
// extraArgs(WATCH, watchArgs, GREP, grepArgs)
const extraArgs = function() {
let extra = [];
for (let i = 0; i < arguments.length; i += 2) {
const flag = arguments[i];
const arg = arguments[i + 1];
if (flag) extra.push(...[].concat((typeof arg === 'function' ? arg() : arg)));
}
return extra.length ? ['--', ...extra] : [];
};
gulp.task('build', () => {
return merge(PACKAGE_DIRS.map((dir) => (
gulpSpawn('npm', ['run', 'build', ...(WATCH ? ['--', '--watch'] : [])], { cwd: dir })
)));
});
gulp.task('build:docs', () => {
return merge(PACKAGE_DIRS.map((dir) => (
gulpSpawn('npm', ['run', 'build:docs', ...(WATCH ? ['--', '--watch'] : [])], { cwd: dir })
)));
});
gulp.task('clean', () => {
return merge(PACKAGE_DIRS.map((dir) => (
gulpSpawn('npm', ['run', 'clean'], { cwd: dir })
)));
});
gulp.task('test', () => {
return merge(PACKAGE_DIRS.map((dir) => (
gulpSpawn('npm', ['test', ...extraArgs(WATCH, '--watch', GREP, ['--grep', GREP])], { cwd: dir })
)));
});
gulp.task('yarn:link', gsequence('yarn:link:criss', 'yarn:link:cross'));
/**
* Link packages globally
*/
gulp.task('yarn:link:criss', () => {
return merge(PACKAGE_DIRS.map((dir) => (
gulpSpawn('yarn', ['link'], { cwd: dir })
)));
});
/**
* Link package dependencies
*/
gulp.task('yarn:link:cross', () => {
return merge(
PACKAGE_DIRS.map(dir => {
const pkg = require(join(__dirname, dir, 'package.json'));
return merge(intersection(keys(Object.assign({}, pkg.dependencies || {}, pkg.devDependencies || {})), PACKAGE_NAMES).map((dep) => {
return gulpSpawn('yarn', ['link', dep], { cwd: dir });
}));
})
);
});
gulp.task('npm:patch', () => {
return merge(PACKAGE_DIRS.map((dir) => (
gulpSpawn('npm', ['version', 'patch'], { cwd: dir })
)));
});
gulp.task('npm:publish', () => {
return merge(PACKAGE_DIRS.map((dir) => (
gulpSpawn('npm', ['publish'], { cwd: dir })
)));
});