UNPKG

canonical

Version:

Canonical code style linter and formatter for JavaScript, SCSS and CSS.

107 lines (79 loc) 2.78 kB
#! /usr/bin/env node 'use strict'; var _getStdin = require('get-stdin'); var _getStdin2 = _interopRequireDefault(_getStdin); var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); var _ = require('./../'); var _yargs = require('yargs'); var _yargs2 = _interopRequireDefault(_yargs); var _getTargetPaths = require('./../utilities/bin/getTargetPaths'); var _getTargetPaths2 = _interopRequireDefault(_getTargetPaths); var _outputReport = require('./../utilities/bin/outputReport'); var _outputReport2 = _interopRequireDefault(_outputReport); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var targetPaths = undefined; process.on('unhandledRejection', function (reason, promise) { /* eslint-disable no-console */ console.log(_chalk2.default.red('Unhandled'), reason, promise); /* eslint-enable */ throw reason; }); /* eslint-disable no-unused-expressions */ _yargs2.default /* eslint-enable */ /* eslint-enable */ /* eslint-enable */ .help('help').fail(function (message) { /* eslint-disable no-console */ console.log(_chalk2.default.red('Error'), message); /* eslint-enable */ /* eslint-disable no-process-exit */ process.exit(1); /* eslint-enable */ }).strict().options({ 'file-path': { default: '<text>', describe: 'Name of the file being linted with stdin (if any). Used in reporting.', type: 'string' }, linter: { // @todo This need to be true when using stdin. choices: ['js', 'scss'], demand: false, describe: 'The type of input.' }, 'output-format': { choices: ['json', 'checkstyle', 'table'], default: 'table' }, stdin: { default: false, describe: 'Used to indicate that subject body will be read from stdin.', type: 'boolean' } }).argv; if (_yargs.argv.stdin) { /* eslint-disable no-unused-expressions */ _yargs2.default.demand(0, 0).argv; (0, _getStdin2.default)().then(function (stdin) { var report = undefined; report = (0, _.lintText)(stdin, { filePath: _yargs.argv.filePath, linter: _yargs.argv.linter }); (0, _outputReport2.default)({ errorCount: report.errorCount, results: [report], warningCount: report.warningCount }, _yargs.argv.outputFormat); }); } else { var report = undefined; /* eslint-disable no-unused-expressions */ _yargs2.default.demand(1).argv; targetPaths = (0, _getTargetPaths2.default)(_yargs.argv._); report = (0, _.lintFiles)(targetPaths); (0, _outputReport2.default)(report, _yargs.argv.outputFormat); } //# sourceMappingURL=index.js.map