Skip to content

Instantly share code, notes, and snippets.

@raine
Last active September 23, 2015 05:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raine/f1a6a784743a711f88f4 to your computer and use it in GitHub Desktop.
Save raine/f1a6a784743a711f88f4 to your computer and use it in GitHub Desktop.
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