forked from yahoo/fluxible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
110 lines (99 loc) · 3.51 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
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';
import {cd, exec, rm} from 'shelljs';
import {argv} from 'yargs';
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('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.output.replace('\n', '').replace('v', '');
// Commit and tag
exec('git add ' + packages[packageName] + '/package.json');
let message = packageName + '@' + bumpedVersion;
exec('git commit -m "' + message + '"');
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');
});