Skip to content

Commit

Permalink
Small fixes (#43)
Browse files Browse the repository at this point in the history
* Prompt user for module path when running fluence module new

Provide default secret key automatically when running fluence run

Generate .vscode/settings.json with relative import path and remove it from .gitignore because with VSCode aqua extension supporting relative paths now - it's ok to version control this file

* Remove the need to update package.json from README

* Add new line before the end of the settings.json and extensions files
  • Loading branch information
shamsartem committed Aug 30, 2022
1 parent eb42107 commit f03a753
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 21 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ oclif.manifest.json
Cargo.lock
**/target/
.repl_history
.vscode/settings.json
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"aquaSettings.imports": [
".fluence/aqua"
]
}
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ pre-commit runs each time before you commit. It includes prettier and generates
If you want README.md file to be correctly generated please don't forget to run `npm run build` before committing

Pull request and release process:
1. Update version in package.json
2. Run `npm run check` to make sure everything ok with the code
3. Only after that commit your changes to trigger pre-commit hook that updates `README.md`. Read `README.md` to make sure it is correctly updated
4. Push your changes
5. Create pull request and merge your changes to `main`
6. Switch to `main` locally and pull merged changes
7. Run `git tag -a v0.0.0 -m ""` with version number that you want instead of `0.0.0`
8. Run `git push origin v0.0.0` with version number that you want instead of `0.0.0` to trigger release
1. Run `npm run check` to make sure everything ok with the code
2. Only after that commit your changes to trigger pre-commit hook that updates `README.md`. Read `README.md` to make sure it is correctly updated
3. Push your changes
4. Create pull request and merge your changes to `main`
5. Switch to `main` locally and pull merged changes
6. Run `git tag -a v0.0.0 -m ""` with version number that you want instead of `0.0.0`
7. Run `git push origin v0.0.0` with version number that you want instead of `0.0.0` to trigger release

# Commands

Expand Down Expand Up @@ -312,7 +311,7 @@ USAGE
$ fluence module new [PATH] [--no-input]

ARGUMENTS
PATH Path to a module
PATH Module path

FLAGS
--no-input Don't interactively ask for any input from the user
Expand Down Expand Up @@ -375,11 +374,12 @@ Run aqua script
```
USAGE
$ fluence run [--relay <value>] [--data <value>] [--data-path <value>] [--import <value>]
[--json-service <value>] [--on <value>] [-i <value>] [-f <value>] [--timeout <value>] [--no-input]
[--json-service <value>] [--on <value>] [-i <value>] [-f <value>] [--timeout <value>] [--no-input] [-k <value>]

FLAGS
-f, --func=<function-call> Function call
-i, --input=<path> Path to an aqua file or to a directory that contains aqua files
-k, --key-pair-name=<name> Key pair name
--data=<json> JSON in { [argumentName]: argumentValue } format. You can call a function using these
argument names
--data-path=<path> Path to a JSON file in { [argumentName]: argumentValue } format. You can call a function
Expand Down
13 changes: 7 additions & 6 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import {
FS_OPTIONS,
RECOMMENDED_GITIGNORE_CONTENT,
NO_INPUT_FLAG,
AQUA_DIR_NAME,
FLUENCE_DIR_NAME,
} from "../lib/const";
import { getIsInteractive } from "../lib/helpers/getIsInteractive";
import { replaceHomeDir } from "../lib/helpers/replaceHomeDir";
import {
ensureFluenceAquaDir,
ensureVSCodeExtensionsJsonPath,
ensureVSCodeSettingsJsonPath,
ensureSrcAquaMainPath,
Expand Down Expand Up @@ -103,7 +104,7 @@ const ensureRecommendedExtensions = async (): Promise<void> => {
} catch {
await fsPromises.writeFile(
extensionsJsonPath,
JSON.stringify(extensionsConfig, null, 2),
JSON.stringify(extensionsConfig, null, 2) + "\n",
FS_OPTIONS
);

Expand Down Expand Up @@ -154,8 +155,8 @@ const settingsJsonSchema: JSONSchemaType<SettingsJson> = {

const validateSettingsJson = ajv.compile(settingsJsonSchema);

const initSettingsConfig = async (): Promise<SettingsJson> => ({
[AQUA_SETTINGS_IMPORTS]: [await ensureFluenceAquaDir()],
const initSettingsConfig = (): SettingsJson => ({
[AQUA_SETTINGS_IMPORTS]: [path.join(FLUENCE_DIR_NAME, AQUA_DIR_NAME)],
});

const ensureRecommendedSettings = async (): Promise<void> => {
Expand All @@ -168,7 +169,7 @@ const ensureRecommendedSettings = async (): Promise<void> => {
} catch {
await fsPromises.writeFile(
settingsJsonPath,
JSON.stringify(await initSettingsConfig(), null, 2),
JSON.stringify(initSettingsConfig(), null, 2) + "\n",
FS_OPTIONS
);

Expand All @@ -187,7 +188,7 @@ const ensureRecommendedSettings = async (): Promise<void> => {
parsedFileContent[AQUA_SETTINGS_IMPORTS] = [
...new Set([
...(parsedFileContent[AQUA_SETTINGS_IMPORTS] ?? []),
...((await initSettingsConfig())[AQUA_SETTINGS_IMPORTS] ?? []),
...(initSettingsConfig()[AQUA_SETTINGS_IMPORTS] ?? []),
]),
];

Expand Down
9 changes: 7 additions & 2 deletions src/commands/module/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from "../../lib/const";
import { ensureFluenceProject } from "../../lib/helpers/ensureFluenceProject";
import { getIsInteractive } from "../../lib/helpers/getIsInteractive";
import { input } from "../../lib/prompt";

const PATH = "PATH";

Expand All @@ -43,14 +44,18 @@ export default class New extends Command {
static override args = [
{
name: PATH,
description: "Path to a module",
description: "Module path",
},
];
async run(): Promise<void> {
const { args, flags } = await this.parse(New);
const isInteractive = getIsInteractive(flags);
await ensureFluenceProject(this, isInteractive);
const pathToModuleDir: unknown = args[PATH];

const pathToModuleDir: unknown =
args[PATH] ??
(await input({ isInteractive, message: "Enter module path" }));

assert(typeof pathToModuleDir === "string");
await generateNewModule(pathToModuleDir, this);

Expand Down
10 changes: 10 additions & 0 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import {
FS_OPTIONS,
NO_INPUT_FLAG,
TIMEOUT_FLAG,
KEY_PAIR_FLAG,
} from "../lib/const";
import { getAppJson } from "../lib/deployedApp";
import { ensureFluenceProject } from "../lib/helpers/ensureFluenceProject";
import { getIsInteractive } from "../lib/helpers/getIsInteractive";
import { getKeyPairFromFlags } from "../lib/keypairs";
import { getRandomRelayAddr } from "../lib/multiaddr";
import {
ensureFluenceTmpAppServiceJsonPath,
Expand Down Expand Up @@ -92,12 +94,19 @@ export default class Run extends Command {
}),
...TIMEOUT_FLAG,
...NO_INPUT_FLAG,
...KEY_PAIR_FLAG,
};
async run(): Promise<void> {
const { flags } = await this.parse(Run);
const isInteractive = getIsInteractive(flags);
await ensureFluenceProject(this, isInteractive);

const keyPair = await getKeyPairFromFlags(flags, this, isInteractive);

if (keyPair instanceof Error) {
this.error(keyPair.message);
}

const aqua = await ensureAquaPath(flags[INPUT_FLAG_NAME]);

const func =
Expand Down Expand Up @@ -145,6 +154,7 @@ export default class Run extends Command {
timeout: flags.timeout,
import: imports,
"json-service": jsonServicePaths,
sk: keyPair.secretKey,
...data,
},
},
Expand Down
4 changes: 3 additions & 1 deletion src/lib/aquaCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export type AquaCliInput =
| {
command: "run";
flags: Flags<"addr" | "input" | "func"> &
OptionalFlags<"on" | "timeout" | "data" | "import" | "json-service">;
OptionalFlags<
"on" | "timeout" | "data" | "import" | "json-service" | "sk"
>;
}
| {
command?: never;
Expand Down
1 change: 0 additions & 1 deletion src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export const RECOMMENDED_GITIGNORE_CONTENT = `.idea
.fluence
**/node_modules
**/target/
.vscode/settings.json
.repl_history`;

export const IS_TTY = process.stdout.isTTY && process.stdin.isTTY;
Expand Down

0 comments on commit f03a753

Please sign in to comment.