forked from JedWatson/react-component-gulp-tasks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
74 lines (62 loc) · 1.89 KB
/
index.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
var defaults = require('defaults');
var capitalize = require('capitalize');
var camelCase = require('camelcase');
// Extract package.json metadata
function readPackageJSON () {
var pkg = JSON.parse(require('fs').readFileSync('./package.json'));
var dependencies = pkg.dependencies ? Object.keys(pkg.dependencies) : [];
var peerDependencies = pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [];
return {
name: pkg.name,
deps: dependencies.concat(peerDependencies),
aliasify: pkg.aliasify
};
}
/**
* This package exports a function that binds tasks to a gulp instance
* based on the provided config.
*/
function initTasks (gulp, config) {
var pkg = readPackageJSON();
var name = capitalize(camelCase(config.component.pkgName || pkg.name));
config = defaults(config, { aliasify: pkg.aliasify });
config.component = defaults(config.component, {
pkgName: pkg.name,
dependencies: pkg.deps,
name: name,
src: 'src',
lib: 'lib',
dist: 'dist',
file: (config.component.name || name) + '.js'
});
if (config.example) {
if (config.example === true) config.example = {};
defaults(config.example, {
src: 'example/src',
dist: 'example/dist',
files: ['index.html'],
scripts: ['example.js'],
less: ['example.less']
});
}
require('./tasks/bump')(gulp, config);
require('./tasks/dev')(gulp, config);
require('./tasks/dist')(gulp, config);
require('./tasks/release')(gulp, config);
var buildTasks = ['build:dist'];
var cleanTasks = ['clean:dist'];
if (config.component.lib) {
require('./tasks/lib')(gulp, config);
buildTasks.push('build:lib');
cleanTasks.push('clean:lib');
}
if (config.example) {
require('./tasks/examples')(gulp, config);
buildTasks.push('build:examples');
cleanTasks.push('clean:examples');
}
gulp.task('build', buildTasks);
gulp.task('clean', cleanTasks);
}
module.exports = initTasks;
module.exports.readPackageJSON = readPackageJSON;