forked from yahoo/fluxible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
131 lines (120 loc) · 4.22 KB
/
gulpfile.babel.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
121
122
123
124
125
126
127
128
129
130
131
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';
import {cd, exec, rm} from 'shelljs';
import {argv} from 'yargs';
import babel from 'gulp-babel';
const ROOT_PATH = path.resolve(__dirname);
const PACKAGES_PATH = path.resolve(__dirname, './packages');
const packages = fs.readdirSync(PACKAGES_PATH).filter((file) => {
return fs.statSync(path.resolve(PACKAGES_PATH, file)).isDirectory();
}).reduce((acc, file) => {
return {
...acc,
[file]: path.resolve(PACKAGES_PATH, file)
};
}, {});
packages['fluxible.io'] = path.resolve(PACKAGES_PATH, '..', 'site');
packages['fluxible-examples'] = path.resolve(PACKAGES_PATH, '..', 'examples');
const sharedDeps = [
'react',
'react-dom'
];
gulp.task('install', () => {
return Promise.all(
// Link all packages to the root
Object.keys(packages).map((packageName) => {
return new Promise((resolve) => {
cd(packages[packageName]);
exec('npm link');
cd(ROOT_PATH);
exec('npm link ' + packageName);
resolve();
});
})
).then(() => {
// Remove duplicated packages and shared dependencies so they are loaded
// from the top
return Promise.all(
Object.keys(packages).map((packageName) => {
return Promise.all(
Object.keys(packages).concat(sharedDeps).map((dependencyName) => {
return new Promise((resolve) => {
rm('-rf', path.resolve(packages[packageName], 'node_modules', dependencyName));
resolve();
});
})
);
})
);
});
});
gulp.task('dist', () => {
let pwd = process.env.PWD;
let pwdPackageName = Object.keys(packages).reduce((prev, name) => {
return packages[name] === pwd ? name : prev;
}, undefined);
let packageName = argv.pkg || argv.p || pwdPackageName;
if (!packageName) {
throw new Error('Usage: gulp dist -p <package>');
}
var src = packages[packageName] + '/src/**/*';
var dest = path.resolve(packages[packageName], 'dist')
rm('-rf', dest);
gulp.src(src)
.pipe(babel({
babelrc: false,
presets: ['es2015', 'react'],
plugins: ['transform-class-properties']
}))
.pipe(gulp.dest(dest))
});
gulp.task('clean', () => {
// Remove package node_modules
return Promise.all(
Object.keys(packages).map((packageName) => {
return new Promise((resolve) => {
rm('-rf', path.resolve(packages[packageName], 'node_modules'));
resolve();
});
})
);
});
gulp.task('version', () => {
// Try to derive package name from directory where this was run from
let pwd = process.env.PWD;
let pwdPackageName = Object.keys(packages).reduce((prev, name) => {
return packages[name] === pwd ? name : prev;
}, undefined);
// Check params
let packageName = argv.pkg || argv.p || pwdPackageName;
let version = argv.version || argv.v;
if (!packageName || !version) {
throw new Error('Usage: gulp version -p <package> -v <version>');
}
// Bump the version
cd(packages[packageName]);
let execResult = exec('npm version ' + version);
let bumpedVersion = execResult.stdout.replace('\n', '').replace('v', '');
// Commit and tag
exec('git add ' + packages[packageName] + '/package.json');
let message = packageName + '@' + bumpedVersion;
exec('git commit -m "' + message + '" --no-verify');
let tagName = packageName + '-v' + bumpedVersion;
exec('git tag ' + tagName);
});
gulp.task('publish', () => {
// Try to derive package name from directory where this was run from
let pwd = process.env.PWD;
let pwdPackageName = Object.keys(packages).reduce((prev, name) => {
return packages[name] === pwd ? name : prev;
}, undefined);
// Check params
let packageName = argv.pkg || argv.p || pwdPackageName;
if (!packageName) {
throw new Error('Usage: gulp publish -p <package>');
}
// Publish
cd(packages[packageName]);
exec('npm publish');
});