{"size": 4134, "ext": "js", "max_stars_repo_path": "src/index.js", "max_stars_repo_name": "akmalviya003/udacimak", "max_stars_repo_stars_event_min_datetime": "2019-07-18T01:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-18T01:21:59.000Z", "max_issues_repo_path": "src/index.js", "max_issues_repo_name": "akmalviya003/udacimak", "max_issues_repo_issues_event_min_datetime": "2020-09-08T08:07:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T21:32:12.000Z", "max_forks_repo_path": "src/index.js", "max_forks_repo_name": "akmalviya003/udacimak", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 32.5511811024, "max_line_length": 120, "alphanum_fraction": 0.6775520077}
#!/usr/bin/env node
/**
 * Entry point for commander
 */
import process from 'process';
import program from 'commander';
import {
  download,
  listNanodegrees,
  render,
  renderdir,
  setToken,
} from './commands';
import {
  logger,
  getFullErrorMessage,
  getPkgInfo,
} from './commands/utils';
import { preCli } from './cli';


program
  .version(`v${getPkgInfo().version}`, '-v, --version')
  .usage('<command> <args> [options]');

program
  .command('download')
  .description('Fetch course/Nanodegree data from Udacity and save them locally as JSON files.')
  .arguments('[courseid...]')
  .option('-t, --targetdir <targetdir>', 'Target directory to save downloaded course JSON data')
  .action(async (courseids, options) => {
    await preCli();

    const targetdir = options.targetdir || process.cwd();
    download(courseids, targetdir);
  })
  .on('--help', () => {
    console.log('');
    console.log('Examples:');
    console.log('');
    console.log(' - Download a single course/Nanodegree');
    console.log('   $ udacimak download nd019');
    console.log(' - Download multiple courses/Nanodegrees');
    console.log('   $ udacimak download nd019 st101 ud611');
    console.log(' - Download multiple courses/Nanodegrees to a specified target directory');
    console.log('   $ udacimak download -t C:/downloads nd019 st101 ud611');
  });

program
  .command('listnd')
  .description('List user\'s enrolled and graduated Nanodegree')
  .action(async () => {
    await preCli();
    listNanodegrees();
  });

program
  .command('render')
  .description('Render downloaded json course content into HTML by downloading all videos, creating text content, etc.')
  .arguments('<path>')
  .option('-t, --targetdir <targetdir>', '(Optional) Target directory to save rendered course contents')
  .option('-v, --verbose', '(Optional) Force youtube-dl to log debugging information')
  .option('--userquizanswer', '(Optional) Force rendering user\'s Programming Question code answer')
  .action(async (path, options) => {
    await preCli();

    const targetdir = options.targetdir || process.cwd();
    global.ytVerbose = options.verbose;
    global.optRenderUserQuizAnswer = options.userquizanswer;
    render(path, targetdir);
  })
  .on('--help', () => {
    console.log('');
    console.log('Examples:');
    console.log('');
    console.log(' - Render a course/Nanodegree to the current working directory by not specifying -t or --targetdir');
    console.log('   $ udacimak render C:/React');
    console.log(' - Render a course/Nanodegree to a specified target directory');
    console.log('   $ udacimak render -t C:/Udacity C:/React');
  });

program
  .command('renderdir')
  .description('Render a whole directory of downloaded json course contents')
  .arguments('<path>')
  .option('-t, --targetdir <targetdir>', '(Optional) Target directory to save rendered course contents')
  .option('-v, --verbose', '(Optional) Force youtube-dl to log debugging information')
  .option('--userquizanswer', '(Optional) Force rendering user\'s Programming Question code answer')
  .action(async (path, options) => {
    await preCli();

    const targetdir = options.targetdir || process.cwd();
    global.ytVerbose = options.verbose;
    global.optRenderUserQuizAnswer = options.userquizanswer;
    renderdir(path, targetdir);
  });

program
  .command('settoken')
  .description('Save Udacity authentication token locally.')
  .arguments('<token>')
  .action(async (token) => {
    await preCli();

    setToken(token);
  })
  .on('--help', () => {
    console.log('');
    console.log('NOTE: Log in to Udacity website and find _jwt key in your browser\'s cookies to get the token');
  });

program
  .parse(process.argv);


// handle uncaught exceptions and uncaught promise rejections
process.on('uncaughtException', (err) => {
  const errorMsg = getFullErrorMessage(err);
  logger.error(`Uncaught Exception:\n${errorMsg}`);
  process.exit(1);
});
process.on('unhandledRejection', (err) => {
  const errorMsg = getFullErrorMessage(err);
  logger.error(`Unhandled Promise Rejection:\n${errorMsg}`);
  process.exit(1);
});
