Last active
September 23, 2015 05:58
-
-
Save raine/f1a6a784743a711f88f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const { Future, IO } = require('ramda-fantasy'); | |
const join2 = curryN(2, require('path').join); | |
const npa = require('npm-package-arg'); | |
const ALIAS = /:([^!]+)/; | |
const EXTEND = /!$/; | |
const parseAlias = pipe( | |
S.match(ALIAS), chain(nth(1))); | |
const parseExtend = pipe( | |
S.match(EXTEND), map(T)); | |
const rm = replace(__, ''); | |
const cleanArg = pipe(...map(rm, [ EXTEND, ALIAS ])); | |
const orEmpty = S.fromMaybe({}); | |
const parseArg = (arg) => { | |
const cleaned = cleanArg(arg); | |
const { raw } = npa(cleaned); | |
return mergeAll([ | |
orEmpty(map(createMapEntry('alias'), parseAlias(arg))), | |
orEmpty(map(createMapEntry('extend'), parseExtend(arg))), | |
{ raw } | |
]); | |
}; | |
const parseArgv = (process) => | |
minimist(process.argv.slice(2), { | |
alias: { h: 'help' } | |
}); | |
const main = (process) => { | |
const processIO = IO.of(process); | |
const env = map(prop('env'), processIO); | |
const home = map(prop('home'), env); | |
const replemPath = map(join2(__, '.replem'), home); | |
const replemModules = map(join2(__, 'node_modules'), replemPath); | |
const rrequire = IO.of(compose(require, join2)).ap(replemModules); | |
const argv = map(parseArgv, processIO); | |
const parsedArgs = map(pipe(prop('_'), map(parseArg)), argv); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment