Skip to content

Commit

Permalink
fix: fix warning when type is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkr00t committed Mar 11, 2021
1 parent 93e08a7 commit 6e8aa44
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 55 deletions.
2 changes: 1 addition & 1 deletion examples/multicli/cli/commands/hello-world.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 4 additions & 4 deletions examples/multicli/cli/commands/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
28 changes: 14 additions & 14 deletions examples/multicli/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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");
Expand All @@ -33,7 +33,7 @@ let config = {
}

return command;
}
},
},
index: {
commandName: "index",
Expand All @@ -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");
Expand All @@ -65,7 +65,7 @@ let config = {
}

return command;
}
},
},
runner: {
commandName: "runner",
Expand All @@ -75,7 +75,7 @@ let config = {
usage: "",
examples: [],
shouldPassInputs: false,
options: {}
options: {},
},
load: () => {
let command = require("./commands/runner");
Expand All @@ -85,9 +85,9 @@ let config = {
}

return command;
}
}
}
},
},
},
};

cli(process.argv, config);
4 changes: 2 additions & 2 deletions packages/core/cli/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var compiler = require("./compiler-6ab9a100.js");
var compiler = require("./compiler-45579224.js");
require("path");
require("fs");
require("util");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion packages/core/cli/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
4 changes: 2 additions & 2 deletions packages/core/cli/commands/dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var compiler = require("./compiler-6ab9a100.js");
var compiler = require("./compiler-45579224.js");
require("path");
require("fs");
require("util");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>", got: "${printType}" instead`
Expand Down
7 changes: 4 additions & 3 deletions packages/core/commands/compiler/commands-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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" &&
Expand Down Expand Up @@ -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<commentParser.Tag>).reduce((acc, tag) => {
if (tag.name === "$inputs") {
verify$InputsType(tag, commandPath);
}
Expand All @@ -137,7 +138,7 @@ export function getMetaFromJSDoc({
: defaultValue,
};
return acc;
}, {} as any),
}, {} as Record<string, OpalineCommandOptions>),
};
}

Expand Down
42 changes: 20 additions & 22 deletions packages/core/commands/compiler/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -91,15 +91,13 @@ export function OP008_warningInputsNotArrayOrString(
applications: Array<string>,
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<string>", got: "${printType}" instead`
),
"",
chalk.dim(`– File: ${commandPath}`)
chalk.dim(`– File: ${commandPath}`),
];
}
//#endregion
Expand All @@ -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 "), "");
Expand Down Expand Up @@ -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)}`
),
""
"",
];
}

Expand All @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,3 @@ function help({ helpFormatter, config, commandName }) {
});
process.exit(0);
}
// TODO: logging
// TODO: command aliases

0 comments on commit 6e8aa44

Please sign in to comment.