From 2c564a6973db7cd2e6009762d16dc656811309f6 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Sun, 12 Mar 2017 22:47:13 -0700 Subject: [PATCH] Move babel config descriptions to babel-cli. --- packages/babel-cli/src/babel/index.js | 62 +++++++++--------- .../src/transformation/file/options/config.js | 63 ++----------------- 2 files changed, 40 insertions(+), 85 deletions(-) diff --git a/packages/babel-cli/src/babel/index.js b/packages/babel-cli/src/babel/index.js index 8d39e17e5d..0159cf49d2 100755 --- a/packages/babel-cli/src/babel/index.js +++ b/packages/babel-cli/src/babel/index.js @@ -2,7 +2,6 @@ import fs from "fs"; import commander from "commander"; -import kebabCase from "lodash/kebabCase"; import { options, util, version } from "babel-core"; import uniq from "lodash/uniq"; import glob from "glob"; @@ -12,34 +11,41 @@ import fileCommand from "./file"; import pkg from "../../package.json"; -Object.keys(options).forEach(function (key) { - const option = options[key]; - if (option.hidden) return; - - let arg = kebabCase(key); - - if (option.type !== "boolean") { - arg += " [" + (option.type || "string") + "]"; - } - - if (option.type === "boolean" && option.default === true) { - arg = "no-" + arg; - } - - arg = "--" + arg; - - if (option.shorthand) { - arg = "-" + option.shorthand + ", " + arg; - } - - const desc = []; - if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated); - if (option.description) desc.push(option.description); - - commander.option(arg, desc.join(" ")); -}); - /* eslint-disable max-len */ +// Standard Babel input configs. +commander.option("-f, --filename [filename]", "filename to use when reading from stdin - this will be used in source-maps, errors etc"); +commander.option("--presets [list]", ""); +commander.option("--plugins [list]", ""); + +// Basic file input configuration. +commander.option("--source-type [string]", ""); +commander.option("--no-babelrc", "Whether or not to look up .babelrc and .babelignore files"); +commander.option("--ignore [list]", "list of glob paths to **not** compile"); +commander.option("--only [list]", "list of glob paths to **only** compile"); + +// Misc babel config. +commander.option("--no-highlight-code", "enable/disable ANSI syntax highlighting of code frames (on by default)"); + +// General output formatting. +commander.option("--no-comments", "write comments to generated output (true by default)"); +commander.option("--retain-lines", "retain line numbers - will result in really ugly code"); +commander.option("--compact [booleanString]", "do not include superfluous whitespace characters and line terminators [true|false|auto]"); +commander.option("--minified", "save as much bytes when printing [true|false]"); +commander.option("--auxiliary-comment-before [string]", "print a comment before any injected non-user code"); +commander.option("--auxiliary-comment-after [string]", "print a comment after any injected non-user code"); + +// General soucemap formatting. +commander.option("-s, --source-maps [booleanString]", "[true|false|inline]"); +commander.option("--source-map-target [string]", "set `file` on returned source map"); +commander.option("--source-file-name [string]", "set `sources[0]` on returned source map"); +commander.option("--source-root [filename]", "the root from which all sources are relative"); + +// Config params for certain module output formats. +commander.option("--module-root [filename]", "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions"); +commander.option("-M, --module-ids", "insert an explicit id for modules"); +commander.option("--module-id [string]", "specify a custom name for module ids"); + +// "babel" command specific arguments that are not passed to babel-core. commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]"); commander.option("-w, --watch", "Recompile files on changes"); commander.option("--skip-initial-build", "Do not compile files before watching"); diff --git a/packages/babel-core/src/transformation/file/options/config.js b/packages/babel-core/src/transformation/file/options/config.js index 8c8df2c0c9..61de15bebb 100644 --- a/packages/babel-core/src/transformation/file/options/config.js +++ b/packages/babel-core/src/transformation/file/options/config.js @@ -3,38 +3,27 @@ export default { filename: { type: "filename", - description: "filename to use when reading from stdin - this will be used in source-maps, errors etc", default: "unknown", - shorthand: "f", }, filenameRelative: { - hidden: true, type: "string", }, - inputSourceMap: { - hidden: true, - }, + inputSourceMap: {}, env: { - hidden: true, default: {}, }, - mode: { - description: "", - hidden: true, - }, + mode: {}, retainLines: { type: "boolean", default: false, - description: "retain line numbers - will result in really ugly code", }, highlightCode: { - description: "enable/disable ANSI syntax highlighting of code frames (on by default)", type: "boolean", default: true, }, @@ -42,172 +31,132 @@ export default { suppressDeprecationMessages: { type: "boolean", default: false, - hidden: true, }, presets: { type: "list", - description: "", default: [], }, plugins: { type: "list", default: [], - description: "", }, ignore: { type: "list", - description: "list of glob paths to **not** compile", default: [], }, only: { type: "list", - description: "list of glob paths to **only** compile", }, code: { - hidden: true, default: true, type: "boolean", }, metadata: { - hidden: true, default: true, type: "boolean", }, ast: { - hidden: true, default: true, type: "boolean", }, extends: { type: "string", - hidden: true, }, comments: { type: "boolean", default: true, - description: "write comments to generated output (true by default)", }, - shouldPrintComment: { - hidden: true, - description: "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored", - }, + shouldPrintComment: {}, - wrapPluginVisitorMethod: { - hidden: true, - description: "optional callback to wrap all visitor methods", - }, + wrapPluginVisitorMethod: {}, compact: { type: "booleanString", default: "auto", - description: "do not include superfluous whitespace characters and line terminators [true|false|auto]", }, minified: { type: "boolean", default: false, - description: "save as much bytes when printing [true|false]", }, sourceMap: { alias: "sourceMaps", - hidden: true, }, sourceMaps: { type: "booleanString", - description: "[true|false|inline]", default: false, - shorthand: "s", }, sourceMapTarget: { type: "string", - description: "set `file` on returned source map", }, sourceFileName: { type: "string", - description: "set `sources[0]` on returned source map", }, sourceRoot: { type: "filename", - description: "the root from which all sources are relative", }, babelrc: { - description: "Whether or not to look up .babelrc and .babelignore files", type: "boolean", default: true, }, sourceType: { - description: "", default: "module", }, auxiliaryCommentBefore: { type: "string", - description: "print a comment before any injected non-user code", }, auxiliaryCommentAfter: { type: "string", - description: "print a comment after any injected non-user code", }, - resolveModuleSource: { - hidden: true, - }, + resolveModuleSource: {}, - getModuleId: { - hidden: true, - }, + getModuleId: {}, moduleRoot: { type: "filename", - description: "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions", }, moduleIds: { type: "boolean", default: false, - shorthand: "M", - description: "insert an explicit id for modules", }, moduleId: { - description: "specify a custom name for module ids", type: "string", }, passPerPreset: { - description: "Whether to spawn a traversal pass per a preset. By default all presets are merged.", type: "boolean", default: false, - hidden: true, }, // Deprecate top level parserOpts parserOpts: { - description: "Options to pass into the parser, or to change parsers (parserOpts.parser)", default: false, }, // Deprecate top level generatorOpts generatorOpts: { - description: "Options to pass into the generator, or to change generators (generatorOpts.generator)", default: false, }, };