forked from gulpjs/gulp-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sttk
committed
Sep 4, 2016
1 parent
9b053ed
commit 5385b87
Showing
30 changed files
with
1,332 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
var camelCase = require('camelcase'); | ||
var pick = require('lodash.pick'); | ||
|
||
var cliFlags = {}; | ||
|
||
cliFlags.getNamesInArgv = function(argv, cliOptions) { | ||
return Object.keys(cliOptions).filter(isInArgv).map(toCamelCase); | ||
|
||
/* $lab:coverage:off$ */ | ||
function isInArgv(flag) { | ||
/* $lab:coverage:on$ */ | ||
if (argv[flag] !== undefined) { | ||
return true; | ||
} | ||
if (argv[cliOptions[flag].alias] !== undefined) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
|
||
// `camelCase` can receive multiple arguments. | ||
// So an error occurs when using with Array.map | ||
function toCamelCase(str) { | ||
return camelCase(str); | ||
} | ||
|
||
cliFlags.getOptsByNames = function(opts, optnames) { | ||
return pick(opts, optnames); | ||
}; | ||
|
||
cliFlags.getEnvByOptNames = function(env, optnames) { | ||
var result = {}; | ||
|
||
for (var i = 0, n = optnames.length; i < n; i++) { | ||
switch (optnames[i]) { | ||
|
||
case 'cwd': | ||
case 'gulpfile': { | ||
result.cwd = env.cwd; | ||
|
||
if (env.configPath) { | ||
result.configPath = env.configPath; | ||
} | ||
break; | ||
} | ||
|
||
case 'require': { | ||
result.require = env.require; | ||
break; | ||
} | ||
|
||
} | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
module.exports = cliFlags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
|
||
module.exports = function(value, spec, opts) { | ||
switch (spec.type) { | ||
|
||
case 'string': { | ||
if (spec.semtype === 'path') { | ||
return path.resolve(opts.basedir, value); | ||
} | ||
return value; | ||
} | ||
|
||
default: { | ||
return value; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
var validate = require('./validate'); | ||
var convert = require('./convert'); | ||
var getProp = require('lodash.get'); | ||
var setProp = require('lodash.set'); | ||
|
||
module.exports = function(src, dst, specs, propsFromTo, opts) { | ||
var keys = Object.keys(propsFromTo); | ||
for (var i = 0, n = keys.length; i < n; i++) { | ||
var srcKey = keys[i]; | ||
var dstKey = propsFromTo[srcKey]; | ||
|
||
var srcVal = getProp(src, srcKey); | ||
if (srcVal === undefined) { | ||
continue; | ||
} | ||
|
||
var spec = getProp(specs, srcKey); | ||
if (!spec) { | ||
continue; | ||
} | ||
|
||
if (!validate(srcVal, spec)) { | ||
throw new Error(srcKey); | ||
} | ||
|
||
srcVal = convert(srcVal, spec, opts); | ||
|
||
setProp(dst, dstKey, srcVal); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
var cliFlags = require('./cli-flags'); | ||
|
||
|
||
module.exports = { | ||
|
||
getSpecifiedFlags: cliFlags.getNamesInArgv, | ||
|
||
getSpecifiedOpts: cliFlags.getOptsByNames, | ||
|
||
getSpecifiedEnv: cliFlags.getEnvByOptNames, | ||
|
||
copyProps: require('./copy-props'), | ||
|
||
configSpecs: require('./specs'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
|
||
description: { | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
|
||
flags: { | ||
help: { | ||
type: 'boolean', | ||
}, | ||
|
||
gulpfile: { | ||
type: 'string', | ||
requiresArg: true, | ||
semtype: 'path', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
var isString = require('lodash.isstring'); | ||
|
||
module.exports = function(val, spec) { | ||
switch (spec.type) { | ||
|
||
case 'string': { | ||
if (!isString(val)) { | ||
return false; | ||
} | ||
|
||
if (spec.requiresArg && !val) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
default: { | ||
return (typeof val === spec.type); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.