Skip to content

Commit

Permalink
feat: add cliVersion property and check for updates [fixes DXJ-358 DX…
Browse files Browse the repository at this point in the history
…J-363] (#242)

* feat: add cliVersion property and check for updates [fixes DXJ-358 DXJ-363]

* update config docs
  • Loading branch information
shamsartem authored Apr 17, 2023
1 parent 80c90ea commit add7abd
Show file tree
Hide file tree
Showing 25 changed files with 270 additions and 39 deletions.
8 changes: 4 additions & 4 deletions docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ EXAMPLES
$ fluence aqua
```

_See code: [dist/commands/aqua.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.6/dist/commands/aqua.ts)_
_See code: [dist/commands/aqua.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.8/dist/commands/aqua.ts)_

## `fluence aqua json [FUNC] [INPUT] [OUTPUT]`

Expand Down Expand Up @@ -172,7 +172,7 @@ EXAMPLES
$ fluence build
```

_See code: [dist/commands/build.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.6/dist/commands/build.ts)_
_See code: [dist/commands/build.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.8/dist/commands/build.ts)_

## `fluence deal deploy [WORKER-NAMES]`

Expand Down Expand Up @@ -437,7 +437,7 @@ EXAMPLES
$ fluence init
```

_See code: [dist/commands/init.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.6/dist/commands/init.ts)_
_See code: [dist/commands/init.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.8/dist/commands/init.ts)_

## `fluence key default [NAME]`

Expand Down Expand Up @@ -640,7 +640,7 @@ EXAMPLES
$ fluence run
```

_See code: [dist/commands/run.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.6/dist/commands/run.ts)_
_See code: [dist/commands/run.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.4.8/dist/commands/run.ts)_

## `fluence service add [PATH | URL]`

Expand Down
3 changes: 3 additions & 0 deletions docs/configs/config-properties-lastcheckforupdates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## lastCheckForUpdates Type

`string`
29 changes: 24 additions & 5 deletions docs/configs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

# config.yaml Properties

| Property | Type | Required | Nullable | Defined by |
| :-------------------------------- | :-------- | :------- | :------------- | :---------------------------------------------------------------------------------------------------------------------- |
| [countlyConsent](#countlyconsent) | `boolean` | Required | cannot be null | [config.yaml](config-properties-countlyconsent.md "https://fluence.dev/schemas/config.yaml#/properties/countlyConsent") |
| [dependencies](#dependencies) | `object` | Optional | cannot be null | [config.yaml](config-properties-dependencies.md "https://fluence.dev/schemas/config.yaml#/properties/dependencies") |
| [version](#version) | `number` | Required | cannot be null | [config.yaml](config-properties-version.md "https://fluence.dev/schemas/config.yaml#/properties/version") |
| Property | Type | Required | Nullable | Defined by |
| :------------------------------------------ | :-------- | :------- | :------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
| [countlyConsent](#countlyconsent) | `boolean` | Required | cannot be null | [config.yaml](config-properties-countlyconsent.md "https://fluence.dev/schemas/config.yaml#/properties/countlyConsent") |
| [dependencies](#dependencies) | `object` | Optional | cannot be null | [config.yaml](config-properties-dependencies.md "https://fluence.dev/schemas/config.yaml#/properties/dependencies") |
| [lastCheckForUpdates](#lastcheckforupdates) | `string` | Optional | cannot be null | [config.yaml](config-properties-lastcheckforupdates.md "https://fluence.dev/schemas/config.yaml#/properties/lastCheckForUpdates") |
| [version](#version) | `number` | Required | cannot be null | [config.yaml](config-properties-version.md "https://fluence.dev/schemas/config.yaml#/properties/version") |

## countlyConsent

Expand Down Expand Up @@ -46,6 +47,24 @@ Weather you consent to send usage data to Countly

`object` ([Details](config-properties-dependencies.md))

## lastCheckForUpdates

Last time when CLI checked for updates. Updates are checked daily unless this field is set to 'disabled'

`lastCheckForUpdates`

* is optional

* Type: `string`

* cannot be null

* defined in: [config.yaml](config-properties-lastcheckforupdates.md "https://fluence.dev/schemas/config.yaml#/properties/lastCheckForUpdates")

### lastCheckForUpdates Type

`string`

## version


Expand Down
3 changes: 3 additions & 0 deletions docs/configs/fluence-properties-cliversion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## cliVersion Type

`string`
19 changes: 19 additions & 0 deletions docs/configs/fluence.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| [chainNetwork](#chainnetwork) | `string` | Optional | cannot be null | [fluence.yaml](fluence-properties-chainnetwork.md "https://fluence.dev/schemas/fluence.yaml#/properties/chainNetwork") |
| [spells](#spells) | `object` | Optional | cannot be null | [fluence.yaml](fluence-properties-spells.md "https://fluence.dev/schemas/fluence.yaml#/properties/spells") |
| [aquaImports](#aquaimports) | `array` | Optional | cannot be null | [fluence.yaml](fluence-properties-aquaimports.md "https://fluence.dev/schemas/fluence.yaml#/properties/aquaImports") |
| [cliVersion](#cliversion) | `string` | Optional | cannot be null | [fluence.yaml](fluence-properties-cliversion.md "https://fluence.dev/schemas/fluence.yaml#/properties/cliVersion") |

## services

Expand Down Expand Up @@ -368,3 +369,21 @@ A list of path to be considered by aqua compiler to be used as imports. First de
### aquaImports Type

`string[]`

## cliVersion

The version of the CLI that is compatible with this project. Set this to enforce a particular set of versions of all fluence components

`cliVersion`

* is optional

* Type: `string`

* cannot be null

* defined in: [fluence.yaml](fluence-properties-cliversion.md "https://fluence.dev/schemas/fluence.yaml#/properties/cliVersion")

### cliVersion Type

`string`
5 changes: 3 additions & 2 deletions src/commands/aqua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
NO_INPUT_FLAG,
} from "../lib/const.js";
import { ensureAquaImports } from "../lib/helpers/aquaImports.js";
import { stringifyUnknown } from "../lib/helpers/jsonStringify.js";
import { initCli } from "../lib/lifeCycle.js";
import { projectRootDir, validatePath } from "../lib/paths.js";
import { input, type InputArg } from "../lib/prompt.js";
Expand Down Expand Up @@ -122,7 +123,7 @@ export default class Aqua extends Command {
maybeFluenceConfig?.aquaOutputJSPath,
inputArg: {
message:
"Enter path to the output directory. Will be created if it doesn't exists",
"Enter path to the output directory. Will be created if it doesn't exists (press Enter to use the current working directory)",
flagName: "output",
},
});
Expand Down Expand Up @@ -185,7 +186,7 @@ export default class Aqua extends Command {
watchingNotification();
})
.catch((error): void => {
commandObj.log(String(error));
commandObj.log(stringifyUnknown(error));
return watchingNotification();
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/commands/deal/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
DIAL_TIMEOUT_FLAG_NAME,
} from "../../lib/const.js";
import { parseWorkers } from "../../lib/deployWorkers.js";
import { stringifyUnknown } from "../../lib/helpers/jsonStringify.js";
import { initFluenceClient } from "../../lib/jsClient.js";
import { initCli } from "../../lib/lifeCycle.js";

Expand Down Expand Up @@ -69,7 +70,7 @@ export default class Logs extends BaseCommand<typeof Logs> {
logs = await get_logs_deal(Object.keys(dealIdWorkerNameMap));
} catch (e) {
commandObj.error(
`Wasn't able to get logs. You can try increasing --${TTL_FLAG_NAME} and --${DIAL_TIMEOUT_FLAG_NAME}: ${String(
`Wasn't able to get logs. You can try increasing --${TTL_FLAG_NAME} and --${DIAL_TIMEOUT_FLAG_NAME}: ${stringifyUnknown(
e
)}`
);
Expand Down
1 change: 1 addition & 0 deletions src/commands/dependency/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class Versions extends BaseCommand<typeof Versions> {
"",
{},
{
"cli version": commandObj.config.version,
"rust-peer version": versions["rust-peer"],
"rust toolchain": versions["rust-toolchain"],
"npm dependencies that can be overridden with 'fluence dependency npm install <name>@<version>'":
Expand Down
6 changes: 5 additions & 1 deletion src/commands/legacy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
generateRegisterApp,
} from "../../lib/deployedApp.js";
import { getMessageWithKeyValuePairs } from "../../lib/helpers/getMessageWithKeyValuePairs.js";
import { stringifyUnknown } from "../../lib/helpers/jsonStringify.js";
import type { JSONModuleConfOld } from "../../lib/helpers/moduleToJSONModuleConfig.js";
import { replaceHomeDir } from "../../lib/helpers/replaceHomeDir.js";
import { getExistingKeyPairFromFlags } from "../../lib/keyPairs.js";
Expand Down Expand Up @@ -353,7 +354,10 @@ const deployService = async ({
keyValuePairs
);
} catch (error) {
commandObj.warn(`Wasn't able to deploy service\n${String(error)}`);
commandObj.warn(
`Wasn't able to deploy service\n${stringifyUnknown(error)}`
);

return null;
}

Expand Down
13 changes: 5 additions & 8 deletions src/commands/service/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
FS_OPTIONS,
MREPL_CARGO_DEPENDENCY,
NO_INPUT_FLAG,
SEPARATOR,
} from "../../lib/const.js";
import { haltCountly } from "../../lib/countly.js";
import { getModuleWasmPath } from "../../lib/helpers/downloadFile.js";
Expand Down Expand Up @@ -112,19 +113,15 @@ export default class REPL extends Command {

const mreplPath = join(mreplDirPath, BIN_DIR_NAME, "mrepl");

this.log(`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Execute ${color.yellow("help")} inside repl to see available commands.
this.log(`${SEPARATOR}Execute ${color.yellow(
"help"
)} inside repl to see available commands.
Current service <module_name> is: ${color.yellow(facadeModuleConfig.name)}
Call ${facadeModuleConfig.name} service functions in repl like this:
${color.yellow(
`call ${facadeModuleConfig.name} <function_name> [<arg1>, <arg2>]`
)}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`);
)}${SEPARATOR}}`);

await haltCountly();

Expand Down
3 changes: 2 additions & 1 deletion src/commands/workers/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
DIAL_TIMEOUT_FLAG_NAME,
} from "../../lib/const.js";
import { parseWorkers } from "../../lib/deployWorkers.js";
import { stringifyUnknown } from "../../lib/helpers/jsonStringify.js";
import { initFluenceClient } from "../../lib/jsClient.js";
import { initCli } from "../../lib/lifeCycle.js";
import { input } from "../../lib/prompt.js";
Expand Down Expand Up @@ -89,7 +90,7 @@ export default class Logs extends BaseCommand<typeof Logs> {
logs = await get_logs(logsArg);
} catch (e) {
commandObj.error(
`Wasn't able to get logs. You can try increasing --${TTL_FLAG_NAME} and --${DIAL_TIMEOUT_FLAG_NAME}: ${String(
`Wasn't able to get logs. You can try increasing --${TTL_FLAG_NAME} and --${DIAL_TIMEOUT_FLAG_NAME}: ${stringifyUnknown(
e
)}`
);
Expand Down
7 changes: 7 additions & 0 deletions src/lib/configs/project/fluence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ type ConfigV2 = Omit<ConfigV1, "version"> & {
chainNetwork?: ChainNetwork;
spells?: Record<string, FluenceConfigSpell>;
aquaImports?: Array<string>;
cliVersion?: string;
};

const configSchemaV2: JSONSchemaType<ConfigV2> = {
Expand Down Expand Up @@ -496,6 +497,12 @@ const configSchemaV2: JSONSchemaType<ConfigV2> = {
items: { type: "string" },
nullable: true,
},
cliVersion: {
type: "string",
description:
"The version of the CLI that is compatible with this project. Set this to enforce a particular set of versions of all fluence components",
nullable: true,
},
},
};

Expand Down
8 changes: 8 additions & 0 deletions src/lib/configs/user/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ import {
type ConfigValidateFunction,
} from "../initConfig.js";

export const CHECK_FOR_UPDATES_DISABLED = "disabled";

type ConfigV0 = {
version: 0;
countlyConsent: boolean;
dependencies?: {
npm?: Record<string, string>;
cargo?: Record<string, string>;
};
lastCheckForUpdates?: string;
};

const configSchemaV0: JSONSchemaType<ConfigV0> = {
Expand Down Expand Up @@ -74,6 +77,11 @@ const configSchemaV0: JSONSchemaType<ConfigV0> = {
nullable: true,
required: [],
},
lastCheckForUpdates: {
type: "string",
description: `Last time when CLI checked for updates. Updates are checked daily unless this field is set to '${CHECK_FOR_UPDATES_DISABLED}'`,
nullable: true,
},
version: { type: "number", const: 0 },
},
required: ["version", "countlyConsent"],
Expand Down
7 changes: 7 additions & 0 deletions src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import oclifColor from "@oclif/color";
const color = oclifColor.default;
import { Flags } from "@oclif/core";
import type {
Flag,
Expand All @@ -33,6 +35,7 @@ export const TYPESCRIPT_RECOMMENDED_VERSION = "4.8.4";
export const RUST_WASM32_WASI_TARGET = "wasm32-wasi";

export const U32_MAX = 4_294_967_295;
export const CHECK_FOR_UPDATES_INTERVAL = 1000 * 60 * 60 * 24; // 1 day

export const CHAIN_NETWORKS = [
"local",
Expand Down Expand Up @@ -352,6 +355,10 @@ export const isFluenceCargoDependency = getIsStringUnion(
fluenceCargoDependencies
);

export const SEPARATOR = `\n\n${color.yellow(
`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`
)}\n\n`;

export const MAIN_AQUA_FILE_STATUS_TEXT = `export status
service Console("run-console"):
Expand Down
13 changes: 13 additions & 0 deletions src/lib/countly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ export const addCountlyLog = (message: string): void => {
Countly.add_log(message);
};

/**
* Add error log
* @param message - message to be logged
* @returns void
*/
export const logErrorToCountly = (message: string): void => {
if (!isCountlyInitialized()) {
return;
}

Countly.log_error(message);
};

export const haltCountly = async (): Promise<void> => {
if (!isCountlyInitialized()) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/helpers/jsToAqua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { commandObj } from "../commandObj.js";

import { capitalize } from "./capitilize.js";
import { cleanAquaName, validateAquaName } from "./downloadFile.js";
import { stringifyUnknown } from "./jsonStringify.js";

export const jsToAqua = (
v: unknown,
Expand Down Expand Up @@ -65,7 +66,7 @@ export const jsToAquaImpl = (
commandObj.error(
`Failed converting to aqua. ${message}. At ${color.yellow(
currentNesting === "" ? "" : `${currentNesting}.`
)}${color.yellow(fieldName)}: ${String(v)}`
)}${color.yellow(fieldName)}: ${stringifyUnknown(v)}`
);

if (typeof v === "string") {
Expand Down
28 changes: 26 additions & 2 deletions src/lib/helpers/jsonStringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,29 @@
* limitations under the License.
*/

export const jsonStringify = (unknown: unknown): string =>
JSON.stringify(unknown, null, 2);
import { CLIError } from "@oclif/core/lib/errors/index.js";

export const jsonStringify = (
unknown: unknown,
replacer: Parameters<typeof JSON.stringify>[1] = null
): string => JSON.stringify(unknown, replacer, 2);

export const stringifyUnknown = (unknown: unknown): string => {
try {
if (unknown instanceof CLIError) {
return String(unknown);
}

if (unknown instanceof Error) {
return jsonStringify(unknown, Object.getOwnPropertyNames(unknown));
}

if (unknown === undefined) {
return "undefined";
}

return jsonStringify(unknown);
} catch {
return String(unknown);
}
};
Loading

0 comments on commit add7abd

Please sign in to comment.