Skip to content

Commit

Permalink
hackathon fixes (#54)
Browse files Browse the repository at this point in the history
* hackathon fixes

* fix: add module Main to main.aqua
  • Loading branch information
shamsartem authored Oct 13, 2022
1 parent 2f43989 commit 582a1d5
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ oclif.manifest.json
Cargo.lock
**/target/
.repl_history
vscode/settings.json
.vscode/settings.json
src/aqua/*.ts
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ Pull request and release process:
<!-- commands -->
* [`fluence aqua`](#fluence-aqua)
* [`fluence autocomplete [SHELL]`](#fluence-autocomplete-shell)
* [`fluence dep cargo i [PACKAGE-NAME | PACKAGE-NAME@VERSION]`](#fluence-dep-cargo-i-package-name--package-nameversion)
* [`fluence dep i`](#fluence-dep-i)
* [`fluence dep npm i [PACKAGE-NAME | PACKAGE-NAME@VERSION]`](#fluence-dep-npm-i-package-name--package-nameversion)
* [`fluence dependency cargo i [PACKAGE-NAME | PACKAGE-NAME@VERSION]`](#fluence-dependency-cargo-i-package-name--package-nameversion)
* [`fluence dependency cargo install [PACKAGE-NAME | PACKAGE-NAME@VERSION]`](#fluence-dependency-cargo-install-package-name--package-nameversion)
* [`fluence dependency i`](#fluence-dependency-i)
Expand Down Expand Up @@ -194,6 +197,87 @@ EXAMPLES
_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.3.0/src/commands/autocomplete/index.ts)_
## `fluence dep cargo i [PACKAGE-NAME | PACKAGE-NAME@VERSION]`
Install cargo project dependencies (all dependencies are cached inside .fluence/cargo directory of the current user)
```
USAGE
$ fluence dep cargo i [PACKAGE-NAME | PACKAGE-NAME@VERSION] [--no-input] [--toolchain <value>]

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: marine@0.12.4

FLAGS
--no-input Don't interactively ask for any input from the user
--toolchain=<toolchain_name> Rustup toolchain name (such as stable or nightly-x86_64)

DESCRIPTION
Install cargo project dependencies (all dependencies are cached inside .fluence/cargo directory of the current user)

ALIASES
$ fluence dependency cargo i
$ fluence dep cargo i

EXAMPLES
$ fluence dep cargo i
```
## `fluence dep i`
Install all project dependencies (dependencies are cached inside .fluence directory of the current user)
```
USAGE
$ fluence dep i [--recommended | --latest] [--no-input]

FLAGS
--latest Set recommended versions of @fluencelabs/aqua, marine and mrepl dependencies and install all
dependencies from fluence.yaml
--no-input Don't interactively ask for any input from the user
--recommended Set latest versions of @fluencelabs/aqua, marine and mrepl dependencies and install all dependencies
from fluence.yaml

DESCRIPTION
Install all project dependencies (dependencies are cached inside .fluence directory of the current user)

ALIASES
$ fluence dependency i
$ fluence dep i

EXAMPLES
$ fluence dep i
```
## `fluence dep npm i [PACKAGE-NAME | PACKAGE-NAME@VERSION]`
Install npm project dependencies (all dependencies are cached inside .fluence/npm directory of the current user)
```
USAGE
$ fluence dep npm i [PACKAGE-NAME | PACKAGE-NAME@VERSION] [--no-input]

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

FLAGS
--no-input Don't interactively ask for any input from the user

DESCRIPTION
Install npm project dependencies (all dependencies are cached inside .fluence/npm directory of the current user)

ALIASES
$ fluence dependency npm i
$ fluence dep npm i

EXAMPLES
$ fluence dep npm i
```
## `fluence dependency cargo i [PACKAGE-NAME | PACKAGE-NAME@VERSION]`
Install cargo project dependencies (all dependencies are cached inside .fluence/cargo directory of the current user)
Expand All @@ -216,6 +300,7 @@ DESCRIPTION

ALIASES
$ fluence dependency cargo i
$ fluence dep cargo i

EXAMPLES
$ fluence dependency cargo i
Expand Down Expand Up @@ -243,6 +328,7 @@ DESCRIPTION

ALIASES
$ fluence dependency cargo i
$ fluence dep cargo i

EXAMPLES
$ fluence dependency cargo install
Expand All @@ -268,6 +354,7 @@ DESCRIPTION

ALIASES
$ fluence dependency i
$ fluence dep i

EXAMPLES
$ fluence dependency i
Expand All @@ -293,6 +380,7 @@ DESCRIPTION

ALIASES
$ fluence dependency i
$ fluence dep i

EXAMPLES
$ fluence dependency install
Expand All @@ -319,6 +407,7 @@ DESCRIPTION

ALIASES
$ fluence dependency npm i
$ fluence dep npm i

EXAMPLES
$ fluence dependency npm i
Expand All @@ -345,6 +434,7 @@ DESCRIPTION

ALIASES
$ fluence dependency npm i
$ fluence dep npm i

EXAMPLES
$ fluence dependency npm install
Expand Down
4 changes: 4 additions & 0 deletions src/commands/aqua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { initFluenceConfig } from "../lib/configs/project/fluence";
import { NO_INPUT_FLAG } from "../lib/const";
import { ensureAquaImports } from "../lib/helpers/aquaImports";
import { getIsInteractive } from "../lib/helpers/getIsInteractive";
import { validatePath } from "../lib/paths";
import { input } from "../lib/prompt";

export default class Aqua extends Command {
Expand Down Expand Up @@ -94,12 +95,15 @@ export default class Aqua extends Command {
message:
"Enter path to an aqua file or an input directory that contains your .aqua files",
flagName: "input",
default: "./src/aqua/main.aqua",
validate: validatePath,
}),
output = await input({
isInteractive,
message:
"Enter path to the output directory. Will be created if it doesn't exists",
flagName: "input",
default: "./src/aqua",
}),
...aquaCliOptionalFlags
} = flags;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dependency/cargo/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { getIsInteractive } from "../../../lib/helpers/getIsInteractive";
import { ensureCargoDependency } from "../../../lib/rust";

export default class Install extends Command {
static override aliases = ["dependency:cargo:i"];
static override aliases = ["dependency:cargo:i", "dep:cargo:i"];
static override description = `Install cargo project dependencies (all dependencies are cached inside ${path.join(
FLUENCE_DIR_NAME,
CARGO_DIR_NAME
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dependency/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { installAllCargoDependenciesFromFluenceConfig } from "./cargo/install";
const REQUIRED_DEPENDENCIES = `${AQUA_NPM_DEPENDENCY}, ${MARINE_CARGO_DEPENDENCY} and ${MREPL_CARGO_DEPENDENCY}`;

export default class Install extends Command {
static override aliases = ["dependency:i"];
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)`;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dependency/npm/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { getIsInteractive } from "../../../lib/helpers/getIsInteractive";
import { ensureNpmDependency } from "../../../lib/npm";

export default class Install extends Command {
static override aliases = ["dependency:npm:i"];
static override aliases = ["dependency:npm:i", "dep:npm:i"];
static override description = `Install npm project dependencies (all dependencies are cached inside ${path.join(
FLUENCE_DIR_NAME,
NPM_DIR_NAME
Expand Down
7 changes: 6 additions & 1 deletion src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
FS_OPTIONS,
RECOMMENDED_GITIGNORE_CONTENT,
NO_INPUT_FLAG,
MAIN_AQUA_FILE_CONTENT,
} from "../lib/const";
import { ensureVSCodeSettingsJSON } from "../lib/helpers/aquaImports";
import { getIsInteractive } from "../lib/helpers/getIsInteractive";
Expand Down Expand Up @@ -194,7 +195,11 @@ export const init = async (options: InitArg): Promise<void> => {
try {
await fsPromises.access(srcMainAquaPath);
} catch {
await fsPromises.writeFile(srcMainAquaPath, "");
await fsPromises.writeFile(
srcMainAquaPath,
MAIN_AQUA_FILE_CONTENT,
FS_OPTIONS
);
}

await ensureVSCodeRecommendedExtensions();
Expand Down
8 changes: 6 additions & 2 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ export default class Run extends Command {
}));

const appConfig = await initReadonlyAppConfig(this);
const relay = flags.relay ?? getRandomRelayAddr(appConfig?.relays);
const fluenceConfig = await initFluenceConfig(this);

const relay =
flags.relay ??
getRandomRelayAddr(appConfig?.relays ?? fluenceConfig?.relays);

const data = await getRunData(flags, this);
const appJsonServicePath = await ensureFluenceTmpAppServiceJsonPath();
const jsonServicePaths = flags[JSON_SERVICE] ?? [];
Expand All @@ -150,7 +155,6 @@ export default class Run extends Command {
}

let result: string;
const fluenceConfig = await initFluenceConfig(this);
const aquaCli = await initAquaCli(this, fluenceConfig);

try {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/configs/project/fluence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import type { JSONSchemaType } from "ajv";

import { ajv } from "../../ajv";
import {
AQUA_LIB_NPM_DEPENDENCY,
AQUA_LIB_RECOMMENDED_VERSION,
AQUA_NPM_DEPENDENCY,
AQUA_RECOMMENDED_VERSION,
FLUENCE_CONFIG_FILE_NAME,
Expand Down Expand Up @@ -267,6 +269,7 @@ const configSchemaV2DefaultConfig: ConfigV2 = {
dependencies: {
npm: {
[AQUA_NPM_DEPENDENCY]: AQUA_RECOMMENDED_VERSION,
[AQUA_LIB_NPM_DEPENDENCY]: AQUA_LIB_RECOMMENDED_VERSION,
},
cargo: {
[MARINE_CARGO_DEPENDENCY]: MARINE_RECOMMENDED_VERSION,
Expand Down
54 changes: 53 additions & 1 deletion src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Command, Flags } from "@oclif/core";

export const AQUA_RECOMMENDED_VERSION = "0.7.5-342";
export const AQUA_LIB_RECOMMENDED_VERSION = "0.6.0";
export const MARINE_RECOMMENDED_VERSION = "0.12.4";
export const MREPL_RECOMMENDED_VERSION = "0.18.6";
export const MARINE_RS_SDK_TEMPLATE_VERSION = "0.6.15";
Expand Down Expand Up @@ -121,11 +122,62 @@ export const RECOMMENDED_GITIGNORE_CONTENT = `.idea
**/node_modules
**/target/
.repl_history
.vscode/settings.json`;
.vscode/settings.json
src/aqua/*.ts`;

export const IS_TTY = process.stdout.isTTY && process.stdin.isTTY;
export const IS_DEVELOPMENT = process.env["NODE_ENV"] === "development";

export const MARINE_CARGO_DEPENDENCY = "marine";
export const MREPL_CARGO_DEPENDENCY = "mrepl";
export const AQUA_NPM_DEPENDENCY = "@fluencelabs/aqua";
export const AQUA_LIB_NPM_DEPENDENCY = "@fluencelabs/aqua-lib";

export const MAIN_AQUA_FILE_CONTENT = `module Main
-- import App from "deployed.app.aqua"
import "@fluencelabs/aqua-lib/builtin.aqua"
-- export App
-- DOCUMENTATION:
-- https://fluence.dev
-- local
func hello_world(name: string) -> string:
<- Op.concat_strings("Hello, ", name)
-- remote
func hello_world_remote(name: string) -> string:
on HOST_PEER_ID:
hello_msg <- hello_world(name)
from_msg <- Op.concat_strings(hello_msg, "! From ")
from_peer_msg <- Op.concat_strings(from_msg, HOST_PEER_ID)
<- from_peer_msg
-- request response
func get_info() -> Info, PeerId:
on HOST_PEER_ID:
info <- Peer.identify()
<- info, HOST_PEER_ID
-- iterate through several peers
func get_infos(peers: []PeerId) -> []Info:
infos: *Info
for p <- peers:
on p:
infos <- Peer.identify()
<- infos
-- parallel computation
func get_infos_par(peers: []PeerId) -> []Info:
infos: *Info
for p <- peers par:
on p:
infos <- Peer.identify()
join infos[Op.array_length(peers) - 1] -- "-1" because it's 0-based
par Peer.timeout(PARTICLE_TTL / 2, "")
<- infos
`;
5 changes: 2 additions & 3 deletions src/lib/execPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import assert from "node:assert";
import { spawn } from "node:child_process";
import console from "node:console";

import color from "@oclif/color";
import { CliUx } from "@oclif/core";
Expand Down Expand Up @@ -92,7 +91,7 @@ export const execPromise = ({

childProcess.stdout?.on("data", (data): void => {
if (printOutput) {
console.log(String(data));
process.stdout.write(String(data));
}

stdout = `${stdout}${String(data)}`;
Expand All @@ -102,7 +101,7 @@ export const execPromise = ({

childProcess.stderr?.on("data", (data): void => {
if (printOutput) {
console.log(String(data));
process.stdout.write(String(data));
}

stderr = `${stderr}${String(data)}`;
Expand Down
7 changes: 6 additions & 1 deletion src/lib/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,19 @@ export const ensureNpmDependency = async ({
const npmDirPath = await ensureUserFluenceNpmDir(commandObj);
const [name, maybeVersion] = splitPackageNameAndVersion(nameAndVersion);

const version =
const resolvedVersion =
maybeVersion ??
(explicitInstallation
? undefined
: fluenceConfig?.dependencies?.npm?.[name] ??
fluenceNPMDependencies[name]?.recommendedVersion) ??
(await getLatestVersionOfNPMDependency(name, commandObj));

const version = await getLatestVersionOfNPMDependency(
`${name}@${resolvedVersion}`,
commandObj
);

const dependencyPath = path.join(npmDirPath, ...name.split("/"), version);

try {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ import {
VSCODE_DIR_NAME,
} from "./const";

export const validatePath = async (path: string): Promise<string | true> => {
try {
await fsPromises.access(path);
return true;
} catch (error) {
return String(error);
}
};

export const ensureDir = async (dirPath: string): Promise<string> => {
await fsPromises.mkdir(dirPath, { recursive: true });
return dirPath;
Expand Down

0 comments on commit 582a1d5

Please sign in to comment.