Skip to content

Commit

Permalink
fix(aqua-run): stringify fluence run output as JSON [DXJ-224] (#86)
Browse files Browse the repository at this point in the history
* fix(aqua-run): stringify fluence run output as JSON [DXJ-224]

* fix: remove color from descriptions
  • Loading branch information
shamsartem authored Jan 11, 2023
1 parent 5372452 commit ea46c1e
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 67 deletions.
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,15 @@ USAGE

# Contributing

To run cli in development mode use: `./bin/dev`

To run cli in production mode run `npm run build` first, then use: `./bin/run`

If you are using nvm and want to commit using VSCode - place `.huskyrc` file to your Home directory

Don't name arguments or flags with names that contain underscore symbols, because autogenerated links in markdown will not work

pre-commit runs each time before you commit. It includes prettier and generates this README.md file.
If you want README.md file to be correctly generated please don't forget to run `npm run build` before committing

Don't export anything from commands except for commands themselves. If you need to share code between commands - create a separate file

Use `this.error` (or `commandObj.error`) for human readable errors. They will be reported to analytics as events. Use `throw new Error` (or `assert`) for unexpected errors. They will be reported to analytics as crashes.
- To run cli in development mode use: `./bin/dev`
- To run cli in production mode run `npm run build` first, then use: `./bin/run`. If you wanna make sure you are running the actual package the users will use - do `npm run build`, `npm pack` and install this tar package (this approach is used for tests)
- If you are using nvm and want to commit using VSCode - place `.huskyrc` file to your Home directory
- Don't name arguments or flags with names that contain underscore symbols, because autogenerated links in markdown will not work
- pre-commit runs each time before you commit. It includes prettier and generates this README.md file that you are reading right now.
- If you want README.md file to be correctly generated please don't forget to run `npm run build` before committing
- Don't export anything from command files except for the command itself. If you need to share code between commands - create a separate file
- Use `this.error` (or `commandObj.error`) for human readable errors. They will be reported to analytics as events. Use `throw new Error` (or `assert`) for unexpected errors. They will be reported to analytics as crashes.
- Don't use colors inside commands descriptions. They can't be rendered to markdown and they will not be rendered to users of the packaged CLI anyway, when they run --help

Pull request and release process:
1. Run `npm run check` to make sure everything ok with the code
Expand Down Expand Up @@ -286,7 +281,7 @@ USAGE
ARGUMENTS
PACKAGE-NAME | PACKAGE-NAME@VERSION Package name. Installs the latest version of the package by default. If you want
to install a specific version, you can do so by appending @ and the version to
the package name. For example: @fluencelabs/aqua@0.7.5-342
the package name. For example: "@fluencelabs/aqua-lib@0.6.0"

FLAGS
--force Force install even if the dependency/dependencies is/are already installed
Expand Down Expand Up @@ -426,7 +421,7 @@ USAGE
ARGUMENTS
PACKAGE-NAME | PACKAGE-NAME@VERSION Package name. Installs the latest version of the package by default. If you want
to install a specific version, you can do so by appending @ and the version to
the package name. For example: @fluencelabs/aqua@0.7.5-342
the package name. For example: "@fluencelabs/aqua-lib@0.6.0"

FLAGS
--force Force install even if the dependency/dependencies is/are already installed
Expand Down Expand Up @@ -454,7 +449,7 @@ USAGE
ARGUMENTS
PACKAGE-NAME | PACKAGE-NAME@VERSION Package name. Installs the latest version of the package by default. If you want
to install a specific version, you can do so by appending @ and the version to
the package name. For example: @fluencelabs/aqua@0.7.5-342
the package name. For example: "@fluencelabs/aqua-lib@0.6.0"

FLAGS
--force Force install even if the dependency/dependencies is/are already installed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test": "shx rm -rf tmp && shx mkdir tmp && npm pack --pack-destination ./tmp && cd tmp && npm init -y && npm i ./fluencelabs-cli-0.0.0.tgz && cd .. && jest",
"posttest": "npm run lint",
"prepare": "husky install",
"check": "npm run build && npm run lint-fix && npm run gen-config-docs",
"check": "npm run build && npm run lint-fix",
"pre-commit": "oclif readme && git add README.md",
"clean": "shx rm -rf .fluence && shx rm -rf fluence-lock.yaml && shx rm -rf fluence.yaml && shx rm -rf src/aqua && shx rm -rf src/ts && shx rm -rf src/js",
"gen-config-docs": "shx rm -rf schemas && shx rm -rf docs/configs && ts-node ./src/schemas.ts && jsonschema2md -d schemas -o docs/configs -h false -f yaml -x schemas -n && ts-node ./src/schemas.ts -f"
Expand Down
6 changes: 1 addition & 5 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

import color from "@oclif/color";

import { BaseCommand } from "../baseCommand";
import { build } from "../lib/build";
import { initFluenceLockConfig } from "../lib/configs/project/fluenceLock";
Expand All @@ -25,9 +23,7 @@ import { initCli } from "../lib/lifecyle";
import { initMarineCli } from "../lib/marineCli";

export default class Build extends BaseCommand<typeof Build> {
static override description = `Build all application services, described in ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)}`;
static override description = `Build all application services, described in ${FLUENCE_CONFIG_FILE_NAME}`;
static override examples = ["<%= config.bin %> <%= command.id %>"];
async run(): Promise<void> {
const { isInteractive, commandObj, fluenceConfig } = await initCli(
Expand Down
5 changes: 1 addition & 4 deletions src/commands/dependency/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import color from "@oclif/color";
import { Flags } from "@oclif/core";

import { BaseCommand } from "../../baseCommand";
Expand Down Expand Up @@ -47,9 +46,7 @@ const REQUIRED_DEPENDENCIES = `${AQUA_NPM_DEPENDENCY}, ${MARINE_CARGO_DEPENDENCY

export default class Install extends BaseCommand<typeof Install> {
static override aliases = ["dependency:i", "dep:i"];
static override description = `Install all project dependencies (dependencies are cached inside ${color.yellow(
FLUENCE_DIR_NAME
)} directory of the current user)`;
static override description = `Install all project dependencies (dependencies are cached inside ${FLUENCE_DIR_NAME} directory of the current user)`;
static override examples = ["<%= config.bin %> <%= command.id %>"];
static override flags = {
recommended: Flags.boolean({
Expand Down
5 changes: 1 addition & 4 deletions src/commands/dependency/npm/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import assert from "node:assert";
import path from "node:path";

import color from "@oclif/color";
import { Flags } from "@oclif/core";

import { BaseCommand } from "../../../baseCommand";
Expand Down Expand Up @@ -54,9 +53,7 @@ export default class Install extends BaseCommand<typeof Install> {
static override args = [
{
name: PACKAGE_NAME_AND_VERSION_ARG_NAME,
description: `Package name. Installs the latest version of the package by default. If you want to install a specific version, you can do so by appending @ and the version to the package name. For example: ${color.yellow(
"@fluencelabs/[email protected]"
)}`,
description: `Package name. Installs the latest version of the package by default. If you want to install a specific version, you can do so by appending @ and the version to the package name. For example: "@fluencelabs/[email protected]"`,
},
];
async run(): Promise<void> {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ import { removeApp } from "../lib/removeApp";
import { hasKey } from "../lib/typeHelpers";

export default class Deploy extends BaseCommand<typeof Deploy> {
static override description = `Deploy application, described in ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)}`;
static override description = `Deploy application, described in ${FLUENCE_CONFIG_FILE_NAME}`;
static override examples = ["<%= config.bin %> <%= command.id %>"];
static override flags = {
relay: Flags.string({
Expand Down
8 changes: 2 additions & 6 deletions src/commands/module/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ import { hasKey } from "../../lib/typeHelpers";
const PATH_OR_URL = "PATH | URL";

export default class Add extends BaseCommand<typeof Add> {
static override description = `Add module to ${color.yellow(
SERVICE_CONFIG_FILE_NAME
)}`;
static override description = `Add module to ${SERVICE_CONFIG_FILE_NAME}`;
static override examples = ["<%= config.bin %> <%= command.id %>"];
static override flags = {
[NAME_FLAG_NAME]: Flags.string({
description: "Override module name",
helpValue: "<name>",
}),
service: Flags.directory({
description: `Service name from ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)} or path to the service directory`,
description: `Service name from ${FLUENCE_CONFIG_FILE_NAME} or path to the service directory`,
helpValue: "<name | path>",
}),
};
Expand Down
12 changes: 3 additions & 9 deletions src/commands/module/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,18 @@ import { hasKey } from "../../lib/typeHelpers";
const NAME_OR_PATH_OR_URL = "NAME | PATH | URL";

export default class Remove extends BaseCommand<typeof Remove> {
static override description = `Remove module from ${color.yellow(
SERVICE_CONFIG_FILE_NAME
)}`;
static override description = `Remove module from ${SERVICE_CONFIG_FILE_NAME}`;
static override examples = ["<%= config.bin %> <%= command.id %>"];
static override flags = {
service: Flags.directory({
description: `Service name from ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)} or path to the service directory`,
description: `Service name from ${FLUENCE_CONFIG_FILE_NAME} or path to the service directory`,
helpValue: "<name | path>",
}),
};
static override args = [
{
name: NAME_OR_PATH_OR_URL,
description: `Module name from ${color.yellow(
SERVICE_CONFIG_FILE_NAME
)}, path to a module or url to .tar.gz archive`,
description: `Module name from ${SERVICE_CONFIG_FILE_NAME}, path to a module or url to .tar.gz archive`,
},
];
async run(): Promise<void> {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export default class Run extends BaseCommand<typeof Run> {
? aquaRun(runArgs)
: fluenceRun(runArgs));

const stringResult = String(result);
const stringResult = JSON.stringify(result);

if (flags.quiet) {
console.log(stringResult);
Expand Down Expand Up @@ -633,7 +633,7 @@ const fluenceRun = async ({
]);

if (errors.length > 0) {
throw new Error(errors.join("\n"));
commandObj.error(errors.join("\n"));
}

const { funcDef, script } = functionCall;
Expand All @@ -651,6 +651,5 @@ const fluenceRun = async ({
);

await fluencePeer.stop();

return result;
};
4 changes: 1 addition & 3 deletions src/commands/service/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ import { input } from "../../lib/prompt";
const PATH_OR_URL = "PATH | URL";

export default class Add extends BaseCommand<typeof Add> {
static override description = `Add service to ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)}`;
static override description = `Add service to ${FLUENCE_CONFIG_FILE_NAME}`;
static override examples = ["<%= config.bin %> <%= command.id %>"];
static override flags = {
[NAME_FLAG_NAME]: Flags.string({
Expand Down
8 changes: 2 additions & 6 deletions src/commands/service/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ import { input } from "../../lib/prompt";
const NAME_OR_PATH_OR_URL = "NAME | PATH | URL";

export default class Remove extends BaseCommand<typeof Remove> {
static override description = `Remove service from ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)}`;
static override description = `Remove service from ${FLUENCE_CONFIG_FILE_NAME}`;
static override examples = ["<%= config.bin %> <%= command.id %>"];
static override args = [
{
name: NAME_OR_PATH_OR_URL,
description: `Service name from ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)}, path to a service or url to .tar.gz archive`,
description: `Service name from ${FLUENCE_CONFIG_FILE_NAME}, path to a service or url to .tar.gz archive`,
},
];
async run(): Promise<void> {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/service/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export default class REPL extends Command {
static override args = [
{
name: NAME_OR_PATH_OR_URL,
description: `Service name from ${color.yellow(
FLUENCE_CONFIG_FILE_NAME
)}, path to a service or url to .tar.gz archive`,
description: `Service name from ${FLUENCE_CONFIG_FILE_NAME}, path to a service or url to .tar.gz archive`,
},
];
async run(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const hook: Hook<"init"> = async function (): Promise<void> {
const { version } = platform;

if (version === undefined) {
throw new Error("Unknown platform");
return this.error("Unknown platform");
}

const majorVersion = Number(version.split(".")[0]);

if (majorVersion < 16) {
throw new Error(
return this.error(
`Fluence CLI requires node.js version >= "16.x"; Detected ${version}. Please update node.js to version 16 or higher.\nYou can use https://nvm.sh utility to update node.js version: "nvm install 17 && nvm use 17 && nvm alias default 17"`
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const resolveServiceInfos = async ({
fluenceConfig.services === undefined ||
Object.keys(fluenceConfig.services).length === 0
) {
throw new Error(
return commandObj.error(
`Use ${color.yellow(
"fluence service add"
)} command to add services to ${color.yellow(FLUENCE_CONFIG_FILE_NAME)}`
Expand Down

0 comments on commit ea46c1e

Please sign in to comment.