<commit_before>#!/usr/bin/env node
import path from 'path';
import fs from 'fs-extra';
import program from 'commander';
import pkginfo from 'pkginfo';
import resolve from 'resolve';
import loadConfig from 'config-attendant';
import argParser from 'commander-rc-adapter';
import glob from 'glob';
import postcss from 'postcss';
import topdoc from 'postcss-topdoc';

pkginfo(module, 'description', 'version');

/**
 *  Private: Coercion for comma delimited lists
 *
 *  * `val` {String} a string or comma delimited list.
 *
 *  Returns {Array} of strings
 */
function _list(val) {
  return val.split(',');
}
/**
 *  Private: Coercion for false string to false boolean
 *
 *  * `val` {String}
 *
 *  Returns {String} when `val` is not a Boolean.
 *  Returns {Bool} when `val` is Boolean or Boolean String like 'false'.
 */
function _valOrFalse(val) {
  if (val === 'false' || !val) return false;
  return val;
}

program
  .description(module.exports.description)
  .usage('topdoc [<css-file> | <directory> [default: src]] [options]')
  .option('-d, --destination <directory> [default: docs]',
    `directory where the usage guides will be written.
    Like all the options, source can be definied in the config or package.json file.`)
  .option('-s, --stdout', 'outputs the parsed topdoc information as json in the console.', true)
  .option('-t, --template <directory> | <npm-package-name> [default: topdoc-default-template]',
    `path to template directory or package name.
    Note: Template argument is resolved using the 'resolve' package.`, 'topdoc-default-template')
  .option('-p, --project <title> [default: <cwd name>]', 'title for your project.')
  .option('-c, --clobber', 'Deletes destination directory before running.')
  .option('-i, --ignore-assets [<file> | <list of files>]',
    `A file or comma delimeted list of files in the asset directory that should be
    ignored when copying them over.`, _list,
    [/^\./, /^node_modules/, /\.pug/, /\.jade/, '/**/*.json'])
  .option('-a, --asset-directory [path]',
    `Path to directory of assets to copy to destination. Defaults to template directory.
    Set to false to not copy any assets.`, _valOrFalse)
  .version(module.exports.version)
  .parse(process.argv);

if (program.assetDirectory === true) program.assetDirectory = program.template;

const options = loadConfig('topdoc', {
  title: program.project || false,
  source: program.source || program.args[0] || 'src',
  destination: program.destination || path.resolve(process.cwd(), 'docs'),
  template: program.template,
  templateData: null, // only added via config file (rc or package.json).
  clobber: program.clobber || false,
  version: module.exports.version,
  ignoreAssets: program.ignoreAssets,
  assetDirectory: program.assetDirectory || false,
  stdout: program.stdout || false,
}, argParser(program));

const template = require(resolve.sync(options.template, { basedir: process.cwd() }));
if (options.assetDirectory && !path.isAbsolute(options.assetDirectory)) {
  try {
    if (fs.statSync(options.assetDirectory).isDirectory()) {
      options.assetDirectory = path.resolve(options.assetDirectory);
    } else {
      options.assetDirectory = path.dirname(options.assetDirectory);
    }
  } catch (err) {
    try {
      let templateDirectory = false;
      const mainFile = resolve.sync(options.assetDirectory, {
        basedir: process.cwd(),
        packageFilter: (pkg, resolvePath) => {
          templateDirectory = resolvePath;
          return pkg;
        },<commit_msg>:bug: fix(bug): fixes #51 problem with asset copy<commit_after>#!/usr/bin/env node
import path from 'path';
import fs from 'fs-extra';
import program from 'commander';
import pkginfo from 'pkginfo';
import resolve from 'resolve';
import loadConfig from 'config-attendant';
import argParser from 'commander-rc-adapter';
import glob from 'glob';
import postcss from 'postcss';
import topdoc from 'postcss-topdoc';

pkginfo(module, 'description', 'version');

/**
 *  Private: Coercion for comma delimited lists
 *
 *  * `val` {String} a string or comma delimited list.
 *
 *  Returns {Array} of strings
 */
function _list(val) {
  return val.split(',');
}
/**
 *  Private: Coercion for false string to false boolean
 *
 *  * `val` {String}
 *
 *  Returns {String} when `val` is not a Boolean.
 *  Returns {Bool} when `val` is Boolean or Boolean String like 'false'.
 */
function _valOrFalse(val) {
  if (val === 'false' || !val) return false;
  return val;
}

program
  .description(module.exports.description)
  .usage('topdoc [<css-file> | <directory> [default: src]] [options]')
  .option('-d, --destination <directory> [default: docs]',
    `directory where the usage guides will be written.
    Like all the options, source can be definied in the config or package.json file.`)
  .option('-s, --stdout', 'outputs the parsed topdoc information as json in the console.', true)
  .option('-t, --template <directory> | <npm-package-name> [default: topdoc-default-template]',
    `path to template directory or package name.
    Note: Template argument is resolved using the 'resolve' package.`, 'topdoc-default-template')
  .option('-p, --project <title> [default: <cwd name>]', 'title for your project.')
  .option('-c, --clobber', 'Deletes destination directory before running.')
  .option('-i, --ignore-assets [<file> | <list of files>]',
    `A file or comma delimeted list of files in the asset directory that should be
    ignored when copying them over.`, _list,
    [/^\./, /^node_modules/, /\.pug/, /\.jade/, '/**/*.json'])
  .option('-a, --asset-directory [path]',
    `Path to directory of assets to copy to destination. Defaults to template directory.
    Set to false to not copy any assets.`, _valOrFalse, true)
  .version(module.exports.version)
  .parse(process.argv);

if (program.assetDirectory === true) program.assetDirectory = program.template;

const options = loadConfig('topdoc', {
  title: program.project || false,
  source: program.source || program.args[0] || 'src',
  destination: program.destination || path.resolve(process.cwd(), 'docs'),
  template: program.template,
  templateData: null, // only added via config file (rc or package.json).
  clobber: program.clobber || false,
  version: module.exports.version,
  ignoreAssets: program.ignoreAssets,
  assetDirectory: program.assetDirectory || false,
  stdout: program.stdout || false,
}, argParser(program));

const template = require(resolve.sync(options.template, { basedir: process.cwd() }));
if (options.assetDirectory && !path.isAbsolute(options.assetDirectory)) {
  try {
    if (fs.statSync(options.assetDirectory).isDirectory()) {
      options.assetDirectory = path.resolve(options.assetDirectory);
    } else {
      options.assetDirectory = path.dirname(options.assetDirectory);
    }
  } catch (err) {
    try {
      let templateDirectory = false;
      const mainFile = resolve.sync(options.assetDirectory, {
        basedir: process.cwd(),
        packageFilter: (pkg, resolvePath) => {
          templateDirectory = path.resolve(resolvePath, 'lib');
          return pkg;
        },
{'fraction_non_alphanumeric': 0.14378256583579777, 'fraction_numerical': 0.0005633009435290804, 'mean_word_length': 3.9013112491373363, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '459986', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2095, 'n_words': 671}