1- var _ = require ( 'lodash' ) ;
1+ var defaults = require ( 'defaults' )
2+ var capitalize = require ( 'capitalize' )
3+ var camelCase = require ( 'camelcase' )
24
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 ( ) {
437 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+
5511 return {
5612 name : pkg . name ,
57- deps : deps ,
13+ deps : dependencies . concat ( peerDependencies ) ,
5814 aliasify : pkg . aliasify
5915 } ;
6016}
@@ -63,50 +19,30 @@ function readPackageJSON() {
6319 * This package exports a function that binds tasks to a gulp instance
6420 * based on the provided config.
6521 */
66-
67- function initTasks ( gulp , config ) {
68-
22+ function initTasks ( gulp , config ) {
6923 var pkg = readPackageJSON ( ) ;
24+ var name = capitalize ( camelCase ( config . component . pkgName || pkg . name ) )
7025
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 ,
9031 src : 'src' ,
9132 lib : 'lib' ,
9233 dist : 'dist' ,
93- file : config . component . name + '.js'
34+ file : ( config . component . name || name ) + '.js'
9435 } ) ;
9536
9637 if ( config . example ) {
9738 if ( config . example === true ) config . example = { } ;
98- _ . defaults ( config . example , {
39+
40+ defaults ( config . example , {
9941 src : 'example/src' ,
10042 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' ]
11046 } ) ;
11147 }
11248
@@ -132,7 +68,6 @@ function initTasks(gulp, config) {
13268
13369 gulp . task ( 'build' , buildTasks ) ;
13470 gulp . task ( 'clean' , cleanTasks ) ;
135-
13671}
13772
13873module . exports = initTasks ;
0 commit comments