How to use the clap.create function in clap

To help you get started, we’ve selected a few clap examples, based on popular ways it is used in public projects.

github basisjs / basisjs-tools / lib / create / command.js View on Github external
default:
      options.output = path.resolve(options.output);
  }
  options.outputDir = path.normalize(options.output);

  // resolve input dir
  options.templates = (options.templates || [])
    .concat(__dirname + '/template/')
    .map(function(dir){
      return path.resolve(options._configPath || options.base, dir);
    });

  return options;
}

var command = clap.create('create')
  .description('Code generator')
  .option('-b, --base <path>', 'Base path for relative path resolving (current path by default)', '.')
  //.option('--output <folder_name>', 'folder for output')
  .option('-l, --l10n', 'Use localization')

  .init(function(){
    var config = this.context.config = this.root.getConfig();
    if (config)
      applyConfig(this, config.data[this.name] || {}, config.path);
  })
  .action(function(){
    this.showHelp();
  })
  .delegate(function(nextCommand){
    var config = this.context.config;
    if (config)
github basisjs / basisjs-tools / bin / basis.js View on Github external
{
    var cfgFile = curpath.join(path.sep) + path.sep + 'basis.config';

    if (fs.existsSync(cfgFile))
      return fetchConfig(cfgFile);

    curpath.pop();
  }
}


//
// main part
//

var program = cli.create('basis')
  .version(require('../package.json').version)
  .option('-n, --no-config', 'Don\'t use basis.config')
  .option('-c, --config-file <filename>', 'Specify path to config filename')
  .delegate(function(nextCommand){
    var options = this.values;
    if (options.config && nextCommand.name != 'completion')
    {
      var config = options.configFile
        ? fetchConfig(options.configFile)
        : searchConfig();

      if (config)
      {
        nextCommand.config = config.data;
        nextCommand.configFile = config.filename;
        nextCommand.configPath = config.path;
github aemoe / webpack-react-framework / node_modules / csso / lib / cli.js View on Github external
}

    // source map placed in external file
    if (inputMapFile) {
        inputMapContent = fs.readFileSync(inputMapFile, 'utf8');
    }

    return {
        input: inputMapContent,
        inputFile: inputMapFile || (inputMapContent ? '<inline>' : false),
        output: map,
        outputFile: outputMapFile
    };
}

var command = cli.create('csso', '[input] [output]')
    .version(require('../package.json').version)
    .option('-i, --input <filename>', 'Input file')
    .option('-o, --output <filename>', 'Output file (result outputs to stdout if not set)')
    .option('-m, --map <destination>', 'Generate source map: none (default), inline, file or <filename>', 'none')
    .option('-u, --usage <filenane>', 'Usage data file')
    .option('--input-map <source>', 'Input source map: none, auto (default) or <filename>', 'auto')
    .option('--restructure-off', 'Turns structure minimization off')
    .option('--stat', 'Output statistics in stderr')
    .option('--debug [level]', 'Output intermediate state of CSS during compression', debugLevel, 0)
    .action(function(args) {
        var options = this.values;
        var inputFile = options.input || args[0];
        var outputFile = options.output || args[1];
        var usageFile = options.usage;
        var usageData = false;
        var map = options.map;
github css / csso / lib / cli.js View on Github external
};
}

function processCommentsOption(value) {
    switch (value) {
        case 'exclamation':
        case 'first-exclamation':
        case 'none':
            return value;
    }

    console.error('Wrong value for `comments` option: %s', value);
    process.exit(2);
}

var command = cli.create('csso', '[input] [output]')
    .version(require('../package.json').version)
    .option('-i, --input <filename>', 'Input file')
    .option('-o, --output <filename>', 'Output file (result outputs to stdout if not set)')
    .option('-m, --map <destination>', 'Generate source map: none (default), inline, file or <filename>', 'none')
    .option('-u, --usage <filenane>', 'Usage data file')
    .option('--input-map <source>', 'Input source map: none, auto (default) or <filename>', 'auto')
    .option('--restructure-off', 'Turns structure minimization off')
    .option('--comments <value>', 'Comments to keep: exclamation (default), first-exclamation or none', 'exclamation')
    .option('--stat', 'Output statistics in stderr')
    .option('--debug [level]', 'Output intermediate state of CSS during compression', debugLevel, 0)
    .action(function(args) {
        var options = this.values;
        var inputFile = options.input || args[0];
        var outputFile = options.output || args[1];
        var usageFile = options.usage;
        var usageData = false;
github basisjs / basisjs-tools / lib / extract / command.js View on Github external
handlerList = [handlerList];
      else
        handlerList = [];

      options.preprocess[type] = handlerList;
    }

    options.preprocess[type] = handlerList.map(function(fn){
      return path.normalize(path.resolve(this.context.configPath || '.', fn));
    }, this);
  }

  return options;
}

module.exports = clap.create('extract', '[file]')
  .description('Extract file graph')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);
    if (config)
      applyConfig(this, config.data['build'] || {}, config.path);
  })

  .option('-b, --base <path>',
    'Base input path for path resolving (current path by default)',
    resolveCwd
  )
  .option('-f, --file <filename>',
    'File name of file to extract, resolve from base path (index.html by default)',
    resolveCwd
  )
github basisjs / basisjs-tools / lib / lint / command.js View on Github external
handlerList = [handlerList];
      else
        handlerList = [];

      options.preprocess[type] = handlerList;
    }

    options.preprocess[type] = handlerList.map(function(fn){
      return path.normalize(path.resolve(module.exports._configPath || '.', fn));
    });
  }

  return options;
}

module.exports = clap.create('lint', '[file]')
  .description('Lint files')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);
    if (config)
      applyConfig(this, config.data['build'] || {}, config.path);
  })

  .option('-b, --base <path>',
    'Base input path for path resolving (current path by default)',
    resolveCwd
  )
  .option('-f, --file <filename>',
    'File name of file to extract, resolve from base path (index.html by default)',
    resolveCwd,
    'index.html'
github basisjs / basisjs-tools / lib / server / command.js View on Github external
config.ignore = Array.isArray(config.ignore)
        ? config.ignore.map(function(fileMask){
            return options.configPath_ ? path.resolve(options.configPath_, fileMask) : fileMask;
          })
        : false;

    config.name = config.name || config.filename;
    config.filename = resolve.sync(config.filename || config.name, { basedir: process.cwd() });

    return config;
  }).filter(Boolean);

  return options;
}

module.exports = clap.create('server')
  .description('Launch dev-server')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);

    if (config)
    {
      applyConfig(this, config.data[this.name] || {}, config.path);
      if (config.data.plugins)
      {
        this.values.plugins = config.data.plugins;
        this.values.configPath_ = config.path;
      }
    }

    if (!config || !config.editor)
github basisjs / basisjs-tools / lib / build / command.js View on Github external
}

  for (var type in configPreprocess)
    addPreprocessors(type, configPreprocess[type]);

  /*if (options.jsCutDev)
  {
    if (!options.preprocess['script'])
      options.preprocess['script'] = [];
    options.preprocess['script'].push('./misc/preprocess/js-cut-dev.js');
  }*/

  return options;
}

module.exports = clap.create('build', '[file]')
  .description('Build an app')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);
    if (config)
      applyConfig(this, config.data['build'] || {}, config.path);
  })
  .args(function(filename){
    this.setOption('file', filename);
  })

  .option('-b, --base <path>',
    'Base input path for path resolving (current path by default)',
    resolveCwd
  )
  .option('-f, --file <filename>',
github css / csso-cli / index.js View on Github external
if (options.statistics) {
            var timeDiff = process.hrtime(time);
            showStat(
                relInputFilename,
                source.length,
                result.css.length,
                sourceMap.inputFile,
                sourceMapAnnotation.length,
                parseInt(timeDiff[0] * 1e3 + timeDiff[1] / 1e6, 10),
                process.memoryUsage().heapUsed - mem
            );
        }
    });
}

var command = cli.create('csso', '[input]')
    .version(require('csso/package.json').version)
    .option('-i, --input <filename>', 'Input file')
    .option('-o, --output <filename>', 'Output file (result outputs to stdout if not set)')
    .option('-s, --source-map <destination>', 'Generate source map: none (default), inline, file or <filename>', 'none')
    .option('-u, --usage <filename>', 'Usage data file')
    .option('--input-source-map <source>', 'Input source map: none, auto (default) or <filename>', 'auto')
    .option('-d, --declaration-list', 'Treat input as a declaration list')
    .option('--no-restructure', 'Disable structural optimisations')
    .option('--force-media-merge', 'Enable unsafe merge of @media rules')
    .option('--comments <value>', 'Comments to keep: exclamation (default), first-exclamation or none', 'exclamation')
    .option('--stat', 'Output statistics in stderr')
    .option('--debug [level]', 'Output intermediate state of CSS during a compression', debugLevel, 0)
    .option('--watch', 'Watch source file for changes')
    .action(function(args) {
        var options = processOptions(this.values, args);
github csstree / validator / lib / cli.js View on Github external
var cli = require('clap');
var reporters = require('./reporter');
var validatePath = require('./validate.js').validatePath;
var validateString = require('./validate.js').validateString;

var command = cli.create('csstree-validate', '[fileOrDir]')
    .version(require('../package.json').version)
    .option('-r, --reporter <name>', 'Format of output: console (default), checkstyle, json, gnu', function(name) {
        if (!reporters.hasOwnProperty(name)) {
            throw new cli.Error('Wrong value for reporter: ' + name);
        }
        return name;
    })
    .action(function(args) {
        var options = this.values;
        var inputPath = args[0];
        var reporter = reporters[options.reporter] || reporters.console;

        if (process.stdin.isTTY && !inputPath) {
            this.showHelp();
            return;
        }

clap

Command line argument parser

MIT
Latest version published 8 months ago

Package Health Score

67 / 100
Full package analysis

Popular clap functions

Similar packages