Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the cli & src/index #2

Closed
tunnckoCore opened this issue Nov 22, 2018 · 0 comments
Closed

update the cli & src/index #2

tunnckoCore opened this issue Nov 22, 2018 · 0 comments
Labels

Comments

@tunnckoCore
Copy link
Owner

tunnckoCore commented Nov 22, 2018

cli

const allModulesPaths = require('all-module-paths');
const mod = require('module')

const dirs = allModulesPaths({ paths: mod._nodeModulePaths(proc.cwd()) });
const PATH = dirs.allPaths.binaries.join(':');

/* eslint-disable promise/always-return */
const env = { PATH: `${PATH}:${process.env.PATH}` };

cli(null, { env })

index

export default async function monora(cliArgv, options) {
  const argv = Array.isArray(cliArgv) ? cliArgv : proc.argv.slice(2)
  const { cwd, tasks, manager, nonStrictBehavior, env } = Object.assign(
    { cwd: proc.cwd() },
    options,
  );

  const pkgPath = resolve(cwd, 'package.json');
  const pkg = await import(pkgPath);

  const config = await loadConfig(cwd, manager);

  let scripts = Object.assign({}, pkg.scripts, pkg.monora, tasks, config);

  const cfgPresets = scripts.extends || scripts.preset || scripts.presets;

  if (cfgPresets) {
    const presetPath = cfgPresets.startsWith('.')
      ? resolve(cwd, cfgPresets)
      : cfgPresets;

    scripts = Object.assign({}, scripts, await import(presetPath));
  }

  // List all available scripts/tasks
  // if not one given, e.g. running `$ scripts`
  if (argv.length === 0) {
    return scripts;
  }

  const commands = normalizer(scripts, argv, nonStrictBehavior);
  return shell(commands, { env, stdio: 'inherit' });
}
@tunnckoCore tunnckoCore changed the title update the cli update the cli & src/index Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant