From 6e8aa44382ea592e42197f636b9b11babbac3c69 Mon Sep 17 00:00:00 2001 From: Stanislav Sysoev Date: Thu, 11 Mar 2021 18:41:05 +1100 Subject: [PATCH] fix: fix warning when type is incorrect --- examples/multicli/cli/commands/hello-world.js | 2 +- examples/multicli/cli/commands/runner.js | 8 ++-- examples/multicli/cli/index.js | 28 ++++++------- packages/core/cli/commands/build.js | 4 +- ...piler-6ab9a100.js => compiler-45579224.js} | 2 +- packages/core/cli/commands/create.js | 2 +- packages/core/cli/commands/dev.js | 4 +- ...sages-7db741fc.js => messages-3b678966.js} | 4 +- .../core/commands/compiler/commands-parser.ts | 7 ++-- packages/core/commands/compiler/messages.ts | 42 +++++++++---------- packages/core/dist/index.js | 2 - 11 files changed, 50 insertions(+), 55 deletions(-) rename packages/core/cli/commands/{compiler-6ab9a100.js => compiler-45579224.js} (99%) rename packages/core/cli/commands/{messages-7db741fc.js => messages-3b678966.js} (98%) diff --git a/examples/multicli/cli/commands/hello-world.js b/examples/multicli/cli/commands/hello-world.js index 063e6c3..92257d3 100644 --- a/examples/multicli/cli/commands/hello-world.js +++ b/examples/multicli/cli/commands/hello-world.js @@ -5,7 +5,7 @@ * * @usage $ {cliName} hello-world --name john * - * @param {string} $inputs + * @param {number} $inputs * @param {string} [name="john"] Some important flag * @short name=n * diff --git a/examples/multicli/cli/commands/runner.js b/examples/multicli/cli/commands/runner.js index dd756d3..d47223a 100644 --- a/examples/multicli/cli/commands/runner.js +++ b/examples/multicli/cli/commands/runner.js @@ -5,14 +5,14 @@ const createCommand = require("@opaline/runner").createCommand; let task1 = { title: "Task 1: doing something...", async task() { - await new Promise(resolve => setTimeout(resolve, 4000)); - } + await new Promise((resolve) => setTimeout(resolve, 4000)); + }, }; let task2 = { title: "Task 2: doing something else ...", async task() { - await new Promise(resolve => setTimeout(resolve, 4000)); - } + await new Promise((resolve) => setTimeout(resolve, 4000)); + }, }; async function runnerCommand() { diff --git a/examples/multicli/cli/index.js b/examples/multicli/cli/index.js index 41d4768..cc93169 100755 --- a/examples/multicli/cli/index.js +++ b/examples/multicli/cli/index.js @@ -5,7 +5,7 @@ let pkg = require("../package.json"); let config = { cliName: "multicli", cliVersion: pkg.version, - cliDescription: pkg.description, + cliDescription: "Prints inputs and flags" || pkg.description, isSingleCommand: false, commands: { "hello-world": { @@ -21,9 +21,9 @@ let config = { title: "Some important flag", type: "string", alias: "n", - default: '"john"' - } - } + default: "john", + }, + }, }, load: () => { let command = require("./commands/hello-world"); @@ -33,7 +33,7 @@ let config = { } return command; - } + }, }, index: { commandName: "index", @@ -47,15 +47,15 @@ let config = { name: { title: "Some important flag", type: "string", - default: '"john"' + default: "john", }, age: { title: "Some important flag", type: "number", alias: "a", - default: 20 - } - } + default: 20, + }, + }, }, load: () => { let command = require("./commands/index"); @@ -65,7 +65,7 @@ let config = { } return command; - } + }, }, runner: { commandName: "runner", @@ -75,7 +75,7 @@ let config = { usage: "", examples: [], shouldPassInputs: false, - options: {} + options: {}, }, load: () => { let command = require("./commands/runner"); @@ -85,9 +85,9 @@ let config = { } return command; - } - } - } + }, + }, + }, }; cli(process.argv, config); diff --git a/packages/core/cli/commands/build.js b/packages/core/cli/commands/build.js index fad3cfc..f3d8f5a 100644 --- a/packages/core/cli/commands/build.js +++ b/packages/core/cli/commands/build.js @@ -1,6 +1,6 @@ "use strict"; -var compiler = require("./compiler-6ab9a100.js"); +var compiler = require("./compiler-45579224.js"); require("path"); require("fs"); require("util"); @@ -11,7 +11,7 @@ require("@rollup/plugin-node-resolve"); require("rimraf"); require("@opaline/core"); require("read-pkg-up"); -require("./messages-7db741fc.js"); +require("./messages-3b678966.js"); require("chalk"); require("@babel/parser"); require("@babel/traverse"); diff --git a/packages/core/cli/commands/compiler-6ab9a100.js b/packages/core/cli/commands/compiler-45579224.js similarity index 99% rename from packages/core/cli/commands/compiler-6ab9a100.js rename to packages/core/cli/commands/compiler-45579224.js index f6b41e3..fb8509d 100644 --- a/packages/core/cli/commands/compiler-6ab9a100.js +++ b/packages/core/cli/commands/compiler-45579224.js @@ -10,7 +10,7 @@ var resolve = require("@rollup/plugin-node-resolve"); var rimraf = require("rimraf"); var core = require("@opaline/core"); var readPkgUp = require("read-pkg-up"); -var messages = require("./messages-7db741fc.js"); +var messages = require("./messages-3b678966.js"); var parser = require("@babel/parser"); var traverse = require("@babel/traverse"); var commentParser = require("comment-parser"); diff --git a/packages/core/cli/commands/create.js b/packages/core/cli/commands/create.js index 1de1ea2..7237395 100644 --- a/packages/core/cli/commands/create.js +++ b/packages/core/cli/commands/create.js @@ -9,7 +9,7 @@ var chalk = require("chalk"); var mkdirp = require("mkdirp"); var core = require("@opaline/core"); var runner = require("@opaline/runner"); -var messages = require("./messages-7db741fc.js"); +var messages = require("./messages-3b678966.js"); function _interopDefaultLegacy(e) { return e && typeof e === "object" && "default" in e ? e : { default: e }; diff --git a/packages/core/cli/commands/dev.js b/packages/core/cli/commands/dev.js index 09fb846..f698eea 100644 --- a/packages/core/cli/commands/dev.js +++ b/packages/core/cli/commands/dev.js @@ -1,6 +1,6 @@ "use strict"; -var compiler = require("./compiler-6ab9a100.js"); +var compiler = require("./compiler-45579224.js"); require("path"); require("fs"); require("util"); @@ -11,7 +11,7 @@ require("@rollup/plugin-node-resolve"); require("rimraf"); require("@opaline/core"); require("read-pkg-up"); -require("./messages-7db741fc.js"); +require("./messages-3b678966.js"); require("chalk"); require("@babel/parser"); require("@babel/traverse"); diff --git a/packages/core/cli/commands/messages-7db741fc.js b/packages/core/cli/commands/messages-3b678966.js similarity index 98% rename from packages/core/cli/commands/messages-7db741fc.js rename to packages/core/cli/commands/messages-3b678966.js index d51c3cc..665c86b 100644 --- a/packages/core/cli/commands/messages-7db741fc.js +++ b/packages/core/cli/commands/messages-3b678966.js @@ -116,9 +116,7 @@ function OP007_errorProjectFolderExists(dir) { //#region Warning Messages function OP008_warningInputsNotArrayOrString(type, applications, commandPath) { - let printType = applications.length - ? `Array<${applications.join(" | ")}>` - : type; + let printType = applications.length ? applications.join(" | ") : type; return [ chalk__default["default"].yellow( `${warningBadge()} OP008: Type of $inputs must be "string | Array", got: "${printType}" instead` diff --git a/packages/core/commands/compiler/commands-parser.ts b/packages/core/commands/compiler/commands-parser.ts index b678466..4595e9b 100644 --- a/packages/core/commands/compiler/commands-parser.ts +++ b/packages/core/commands/compiler/commands-parser.ts @@ -8,6 +8,7 @@ import { ProjectInfo } from "./project-info"; import { print } from "@opaline/core"; import { OpalineCommandMeta } from "../../src/types"; import { OP008_warningInputsNotArrayOrString } from "./messages"; +import { OpalineCommandOptions } from "../../dist/types"; let readFile = promisify(fs.readFile); @@ -52,7 +53,7 @@ export function getCommandJSDoc(content: string) { AssignmentExpression(path) { if ( path.node.left.type !== "MemberExpression" || - path.node.left.property.name !== "exports" || + (path.node.left.property as any).name !== "exports" || !path.node.left.object.hasOwnProperty("name") || (path.node.left.object as any).name !== "module" || (path.node.right.type !== "FunctionExpression" && @@ -117,7 +118,7 @@ export function getMetaFromJSDoc({ (tag) => tag.tag === "param" && tag.name === "$inputs" ), - options: jsdoc.tags.reduce((acc, tag) => { + options: (jsdoc.tags as Array).reduce((acc, tag) => { if (tag.name === "$inputs") { verify$InputsType(tag, commandPath); } @@ -137,7 +138,7 @@ export function getMetaFromJSDoc({ : defaultValue, }; return acc; - }, {} as any), + }, {} as Record), }; } diff --git a/packages/core/commands/compiler/messages.ts b/packages/core/commands/compiler/messages.ts index d301687..369be45 100644 --- a/packages/core/commands/compiler/messages.ts +++ b/packages/core/commands/compiler/messages.ts @@ -13,8 +13,8 @@ export function OP001_errorBinIsEmpty() { ...codeSnippet(['"bin": {', ' "mycli": "./cli/cli.js"', "}"]), "", chalk`Choose any path and name for {yellow "cli.js"}, don't need to create this file,`, - chalk`{yellow opaline} will generate it for you at provided path.` - ] + chalk`{yellow opaline} will generate it for you at provided path.`, + ], ] as const; } @@ -25,8 +25,8 @@ export function OP002_errorNoPackageJson() { "", `Please add one manually or by running:`, "", - ...codeSnippet("λ npm init --yes") - ] + ...codeSnippet("λ npm init --yes"), + ], ] as const; } @@ -37,15 +37,15 @@ export function OP003_errorNoCommandsFolder(commandsDirPath: string) { ), [ "", - chalk`Please create {yellow "commands"} folder, because this is where {yellow opaline} is expecting to find cli commands to compile.` - ] + chalk`Please create {yellow "commands"} folder, because this is where {yellow opaline} is expecting to find cli commands to compile.`, + ], ] as const; } export function OP004_errorEmptyCommandsFolder(commandsDirPath: string) { return [ chalk.red(`${errorBadge()} OP004: Commands folder is empty`), - ["", chalk`Add files to {yellow "${commandsDirPath}"}.`] + ["", chalk`Add files to {yellow "${commandsDirPath}"}.`], ] as const; } @@ -65,22 +65,22 @@ export function OP005_errorSrcEqDest( ...codeSnippet([ '"bin": {', ' "mycli": "./my-output-folder/cli.js"', - "}" - ]) - ] + "}", + ]), + ], ] as const; } export function OP006_errorProjectNameIsRequired() { return [ chalk.red(`${errorBadge()} OP006: A project name is required!`), - ["", ...codeSnippet([`λ opaline create app`])] + ["", ...codeSnippet([`λ opaline create app`])], ] as const; } export function OP007_errorProjectFolderExists(dir: string) { return [ - chalk.red(`${errorBadge()} OP007: Folder "${dir}" already exists`) + chalk.red(`${errorBadge()} OP007: Folder "${dir}" already exists`), ] as const; } //#endregion @@ -91,15 +91,13 @@ export function OP008_warningInputsNotArrayOrString( applications: Array, commandPath: string ) { - let printType = applications.length - ? `Array<${applications.join(" | ")}>` - : type; + let printType = applications.length ? applications.join(" | ") : type; return [ chalk.yellow( `${warningBadge()} OP008: Type of $inputs must be "string | Array", got: "${printType}" instead` ), "", - chalk.dim(`– File: ${commandPath}`) + chalk.dim(`– File: ${commandPath}`), ]; } //#endregion @@ -124,7 +122,7 @@ export function MSG_buildSuccess( )}ms!` ), "", - chalk`{green Successfully compiled into {blue "${outputPath}"} folder.}` + chalk`{green Successfully compiled into {blue "${outputPath}"} folder.}`, ]; message.push("", chalk.bgMagenta.black(" OUTPUTS "), ""); @@ -158,10 +156,10 @@ export function MSG_watchStarted( )} Watching commands {grey [+all of their dependencies]}}`, "", ...commands.map( - command => + (command) => `${chalk.grey("– " + relativePathToCommands)}${chalk.magenta(command)}` ), - "" + "", ]; } @@ -174,17 +172,17 @@ export function MSG_watchUpdated( blueBadge("UPDATED"), "", ...commands.map( - command => + (command) => `${chalk.grey("– " + relativePathToCommands)}${chalk.magenta(command)}` ), - "" + "", ]; } //#endregion //#region Message helpers export function codeSnippet(code: string | string[]) { - return ([] as string[]).concat(code).map(line => chalk.dim(line)); + return ([] as string[]).concat(code).map((line) => chalk.dim(line)); } export function greenBadge(label: string): string { diff --git a/packages/core/dist/index.js b/packages/core/dist/index.js index 4a7e4fa..ace42c7 100644 --- a/packages/core/dist/index.js +++ b/packages/core/dist/index.js @@ -177,5 +177,3 @@ function help({ helpFormatter, config, commandName }) { }); process.exit(0); } -// TODO: logging -// TODO: command aliases