1
- var _ = require ( 'lodash' ) ;
1
+ var defaults = require ( 'defaults' )
2
+ var capitalize = require ( 'capitalize' )
3
+ var camelCase = require ( 'camelcase' )
2
4
3
- /**
4
- * Check that a compatible version of gulp is available in the project
5
- */
6
-
7
- function fatal ( ) {
8
- var msg = '\n\n' ;
9
- for ( var i = 0 ; i < arguments . length ; i ++ ) {
10
- msg += arguments [ i ] + '\n\n' ;
11
- }
12
- console . log ( msg ) ;
13
- process . exit ( 1 ) ;
14
- }
15
-
16
- try {
17
- var projectGulpVersion = require ( module . parent . paths [ 0 ] + '/gulp/package.json' ) . version ;
18
- } catch ( e ) {
19
- // If we can't find gulp in the parent project, it's a fatal problem.
20
- fatal (
21
- 'You do not seem to have Gulp installed in your project.' ,
22
- 'Please add gulp ^' + packageGulpVersion + ' to your package.json, npm install and try again.'
23
- ) ;
24
- }
25
- try {
26
- // Check to make sure the local gulp and the project gulp match.
27
- var packageGulpVersion = require ( './node_modules/gulp/package.json' ) . version ;
28
- if ( ! semver . satisfies ( projectGulpVersion , '^' + packageGulpVersion ) ) {
29
- fatal (
30
- 'You have an incompatible version of Gulp installed (' + projectGulpVersion + ').' ,
31
- 'Please add gulp ^' + packageGulpVersion + ' to your package.json, npm install and try again.'
32
- ) ;
33
- }
34
- } catch ( e ) {
35
- // Assume gulp has been loaded from ../node_modules and it matches the requirements.
36
- }
37
-
38
- /**
39
- * Helper method to extract metadata from package.json
40
- */
41
-
42
- function readPackageJSON ( ) {
5
+ // Extract package.json metadata
6
+ function readPackageJSON ( ) {
43
7
var pkg = JSON . parse ( require ( 'fs' ) . readFileSync ( './package.json' ) ) ;
44
- var deps = [ ] ;
45
- if ( pkg . dependencies ) {
46
- Object . keys ( pkg . dependencies ) . forEach ( function ( i ) {
47
- deps . push ( i ) ;
48
- } ) ;
49
- }
50
- if ( pkg . peerDependencies ) {
51
- Object . keys ( pkg . peerDependencies ) . forEach ( function ( i ) {
52
- deps . push ( i ) ;
53
- } ) ;
54
- }
8
+ var dependencies = Object . keys ( pkg . dependencies ) ;
9
+ var peerDependencies = Object . keys ( pkg . peerDependencies ) ;
10
+
55
11
return {
56
12
name : pkg . name ,
57
- deps : deps ,
13
+ deps : dependencies . concat ( peerDependencies ) ,
58
14
aliasify : pkg . aliasify
59
15
} ;
60
16
}
@@ -63,50 +19,30 @@ function readPackageJSON() {
63
19
* This package exports a function that binds tasks to a gulp instance
64
20
* based on the provided config.
65
21
*/
66
-
67
- function initTasks ( gulp , config ) {
68
-
22
+ function initTasks ( gulp , config ) {
69
23
var pkg = readPackageJSON ( ) ;
24
+ var name = capitalize ( camelCase ( config . component . pkgName || pkg . name ) )
70
25
71
- if ( ! config ) config = { } ;
72
- if ( ! config . component ) config . component = { } ;
73
-
74
- if ( ! config . component . pkgName || ! config . component . deps ) {
75
- _ . defaults ( config . component , {
76
- pkgName : pkg . name ,
77
- dependencies : pkg . deps
78
- } ) ;
79
- }
80
-
81
- if ( ! config . component . name ) {
82
- config . component . name = _ . capitalize ( _ . camelCase ( config . component . pkgName ) ) ;
83
- }
84
-
85
- if ( ! config . aliasify ) {
86
- config . aliasify = pkg . aliasify ;
87
- }
88
-
89
- _ . defaults ( config . component , {
26
+ config = defaults ( config , { aliasify : pkg . aliasify } )
27
+ config . component = defaults ( config . component , {
28
+ pkgName : pkg . name ,
29
+ dependencies : pkg . deps ,
30
+ name : name ,
90
31
src : 'src' ,
91
32
lib : 'lib' ,
92
33
dist : 'dist' ,
93
- file : config . component . name + '.js'
34
+ file : ( config . component . name || name ) + '.js'
94
35
} ) ;
95
36
96
37
if ( config . example ) {
97
38
if ( config . example === true ) config . example = { } ;
98
- _ . defaults ( config . example , {
39
+
40
+ defaults ( config . example , {
99
41
src : 'example/src' ,
100
42
dist : 'example/dist' ,
101
- files : [
102
- 'index.html'
103
- ] ,
104
- scripts : [
105
- 'example.js'
106
- ] ,
107
- less : [
108
- 'example.less'
109
- ]
43
+ files : [ 'index.html' ] ,
44
+ scripts : [ 'example.js' ] ,
45
+ less : [ 'example.less' ]
110
46
} ) ;
111
47
}
112
48
@@ -132,7 +68,6 @@ function initTasks(gulp, config) {
132
68
133
69
gulp . task ( 'build' , buildTasks ) ;
134
70
gulp . task ( 'clean' , cleanTasks ) ;
135
-
136
71
}
137
72
138
73
module . exports = initTasks ;
0 commit comments