Skip to content

Commit

Permalink
Remove cargo-generate
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem authored Aug 9, 2022
1 parent 80b404e commit cf3721d
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 96 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ npm install -g @fluencelabs/cli
$ fluence COMMAND
running command...
$ fluence (--version)
@fluencelabs/cli/0.2.2 linux-x64 node-v16.14.0
@fluencelabs/cli/0.0.0 linux-x64 node-v16.14.0
$ fluence --help [COMMAND]
USAGE
$ fluence COMMAND
Expand Down Expand Up @@ -154,7 +154,7 @@ EXAMPLES
$ fluence aqua
```
_See code: [dist/commands/aqua.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.2/dist/commands/aqua.ts)_
_See code: [dist/commands/aqua.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.0.0/dist/commands/aqua.ts)_
## `fluence autocomplete [SHELL]`
Expand Down Expand Up @@ -194,8 +194,8 @@ USAGE
$ fluence dependency [NAME] [-v | --use <value>] [--no-input]

ARGUMENTS
NAME Dependency name. One of: aqua, marine, mrepl, cargo-generate. If you omit NAME argument and include --use
recommended - all dependencies will be reset to recommended versions
NAME Dependency name. One of: aqua, marine, mrepl. If you omit NAME argument and include --use recommended - all
dependencies will be reset to recommended versions

FLAGS
-v, --version Show current version of the dependency
Expand All @@ -211,7 +211,7 @@ EXAMPLES
$ fluence dependency
```
_See code: [dist/commands/dependency.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.2/dist/commands/dependency.ts)_
_See code: [dist/commands/dependency.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.0.0/dist/commands/dependency.ts)_
## `fluence deploy`
Expand All @@ -235,7 +235,7 @@ EXAMPLES
$ fluence deploy
```
_See code: [dist/commands/deploy.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.2/dist/commands/deploy.ts)_
_See code: [dist/commands/deploy.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.0.0/dist/commands/deploy.ts)_
## `fluence help [COMMAND]`
Expand Down Expand Up @@ -278,7 +278,7 @@ EXAMPLES
$ fluence init
```
_See code: [dist/commands/init.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.2/dist/commands/init.ts)_
_See code: [dist/commands/init.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.0.0/dist/commands/init.ts)_
## `fluence module add [PATH | URL]`
Expand Down Expand Up @@ -366,7 +366,7 @@ EXAMPLES
$ fluence remove
```
_See code: [dist/commands/remove.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.2/dist/commands/remove.ts)_
_See code: [dist/commands/remove.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.0.0/dist/commands/remove.ts)_
## `fluence run`
Expand Down Expand Up @@ -398,7 +398,7 @@ EXAMPLES
$ fluence run
```
_See code: [dist/commands/run.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.2/dist/commands/run.ts)_
_See code: [dist/commands/run.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.0.0/dist/commands/run.ts)_
## `fluence service add [PATH | URL]`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fluencelabs/cli",
"version": "0.2.2",
"version": "0.0.0",
"description": "CLI for working with Fluence network",
"author": "Fluence Labs",
"bin": {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
import {
AQUA_NPM_DEPENDENCY,
cargoDependencyList,
CARGO_GENERATE_CARGO_DEPENDENCY,
CommandObj,
FLUENCE_DIR_NAME,
MARINE_CARGO_DEPENDENCY,
Expand Down Expand Up @@ -243,8 +242,7 @@ const ensureDependency = async (
break;
}
case MARINE_CARGO_DEPENDENCY:
case MREPL_CARGO_DEPENDENCY:
case CARGO_GENERATE_CARGO_DEPENDENCY: {
case MREPL_CARGO_DEPENDENCY: {
await ensureCargoDependency({
name: dependencyName,
commandObj,
Expand Down
58 changes: 50 additions & 8 deletions src/commands/module/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ import color from "@oclif/color";
import { Command } from "@oclif/core";

import { initNewReadonlyModuleConfig } from "../../lib/configs/project/module";
import { CommandObj, NO_INPUT_FLAG } from "../../lib/const";
import {
CommandObj,
FS_OPTIONS,
MARINE_RS_SDK_TEMPLATE_VERSION,
MARINE_RS_SDK_TEST_TEMPLATE_VERSION,
NO_INPUT_FLAG,
} from "../../lib/const";
import { ensureFluenceProject } from "../../lib/helpers/ensureFluenceProject";
import { getIsInteractive } from "../../lib/helpers/getIsInteractive";
import { initMarineCli } from "../../lib/marineCli";

const PATH = "PATH";

Expand Down Expand Up @@ -62,14 +67,51 @@ export const generateNewModule = async (
commandObj: CommandObj
): Promise<void> => {
await fsPromises.mkdir(pathToModuleDir, { recursive: true });
const marineCli = await initMarineCli(commandObj);
const name = path.basename(pathToModuleDir);

await marineCli({
command: "generate",
flags: { init: true, name },
workingDir: pathToModuleDir,
});
const newModuleSrcDirPath = path.join(pathToModuleDir, "src");
await fsPromises.mkdir(newModuleSrcDirPath, { recursive: true });

await fsPromises.writeFile(
path.join(newModuleSrcDirPath, "main.rs"),
MAIN_RS_CONTENT,
FS_OPTIONS
);

await fsPromises.writeFile(
path.join(pathToModuleDir, "Cargo.toml"),
getCargoTomlContent(name),
FS_OPTIONS
);

await initNewReadonlyModuleConfig(pathToModuleDir, commandObj, name);
};

const MAIN_RS_CONTENT = `use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest;
module_manifest!();
pub fn main() {}
#[marine]
pub fn greeting(name: String) -> String {
format!("Hi, {}", name)
}
`;

const getCargoTomlContent = (name: string): string => `[package]
name = "${name}"
version = "0.1.0"
edition = "2018"
[[bin]]
name = "${name}"
path = "src/main.rs"
[dependencies]
marine-rs-sdk = "${MARINE_RS_SDK_TEMPLATE_VERSION}"
[dev-dependencies]
marine-rs-sdk-test = "${MARINE_RS_SDK_TEST_TEMPLATE_VERSION}"
`;
57 changes: 56 additions & 1 deletion src/commands/service/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import {
AQUA_NAME_REQUIREMENTS,
ensureValidAquaName,
validateAquaName,
} from "../../lib/helpers/downloadFile";
import { getIsInteractive } from "../../lib/helpers/getIsInteractive";
import { confirm, input } from "../../lib/prompt";
Expand Down Expand Up @@ -65,7 +66,11 @@ export default class New extends Command {
assert(typeof servicePath === "string");

const serviceName = await ensureValidAquaName({
stringToValidate: flags[NAME_FLAG_NAME],
stringToValidate: await getServiceName({
isInteractive,
nameFromFlags: flags[NAME_FLAG_NAME],
servicePath,
}),
message: "Enter service name",
flagName: NAME_FLAG_NAME,
isInteractive,
Expand Down Expand Up @@ -105,3 +110,53 @@ export default class New extends Command {
}
}
}

type GetServiceNameArg = {
nameFromFlags: undefined | string;
servicePath: string;
isInteractive: boolean;
};

const getServiceName = async ({
isInteractive,
nameFromFlags,
servicePath,
}: GetServiceNameArg): Promise<string | undefined> => {
if (typeof nameFromFlags === "string") {
return nameFromFlags;
}

const withoutTrailingSlash = servicePath.replace(/\/$/, "");

const lastPortionOfPath =
withoutTrailingSlash
.split(withoutTrailingSlash.includes("/") ? "/" : "\\")
.slice(-1)[0] ?? "";

const cleanLastPortionOfPath = lastPortionOfPath.replace(/\W/, "");
const indexOfTheFirstLetter = cleanLastPortionOfPath.search(/[A-Za-z]/);

const startingFromLetter = cleanLastPortionOfPath.slice(
indexOfTheFirstLetter
);

const serviceName =
startingFromLetter.charAt(0).toLocaleLowerCase() +
startingFromLetter.slice(1);

const serviceNameValidity = validateAquaName(serviceName);

if (
serviceNameValidity !== true ||
!(await confirm({
isInteractive,
message: `Do you want to use ${color.yellow(
serviceName
)} as the name of your new service?`,
}))
) {
return undefined;
}

return serviceName;
};
2 changes: 0 additions & 2 deletions src/lib/configs/user/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type { JSONSchemaType } from "ajv";
import {
AQUA_NPM_DEPENDENCY,
cargoDependencyList,
CARGO_GENERATE_CARGO_DEPENDENCY,
CommandObj,
DEPENDENCY_CONFIG_FILE_NAME,
MARINE_CARGO_DEPENDENCY,
Expand Down Expand Up @@ -73,7 +72,6 @@ const configSchemaV0: JSONSchemaType<ConfigV0> = {
[AQUA_NPM_DEPENDENCY]: { type: "string", nullable: true },
[MARINE_CARGO_DEPENDENCY]: { type: "string", nullable: true },
[MREPL_CARGO_DEPENDENCY]: { type: "string", nullable: true },
[CARGO_GENERATE_CARGO_DEPENDENCY]: { type: "string", nullable: true },
},
required: [],
nullable: true,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import type { stringify } from "yaml";
export const AQUA_RECOMMENDED_VERSION = "0.7.4-332";
export const MARINE_RECOMMENDED_VERSION = "0.12.1";
export const MREPL_RECOMMENDED_VERSION = "0.18.0";
export const CARGO_GENERATE_RECOMMENDED_VERSION = "0.15.2";
export const MARINE_RS_SDK_TEMPLATE_VERSION = "0.6.15";
export const MARINE_RS_SDK_TEST_TEMPLATE_VERSION = "0.5.0";
export const RUST_TOOLCHAIN_REQUIRED_TO_INSTALL_MARINE = "nightly-x86_64";
export const RUST_WASM32_WASI_TARGET = "wasm32-wasi";

Expand Down Expand Up @@ -136,11 +137,9 @@ export const IS_DEVELOPMENT = process.env["NODE_ENV"] === "development";

export const MARINE_CARGO_DEPENDENCY = "marine";
export const MREPL_CARGO_DEPENDENCY = "mrepl";
export const CARGO_GENERATE_CARGO_DEPENDENCY = "cargo-generate";
export const cargoDependencyList = [
MARINE_CARGO_DEPENDENCY,
MREPL_CARGO_DEPENDENCY,
CARGO_GENERATE_CARGO_DEPENDENCY,
] as const;
export type CargoDependency = typeof cargoDependencyList[number];

Expand Down
16 changes: 1 addition & 15 deletions src/lib/marineCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
* limitations under the License.
*/

import {
CARGO_GENERATE_CARGO_DEPENDENCY,
CommandObj,
MARINE_CARGO_DEPENDENCY,
} from "./const";
import { CommandObj, MARINE_CARGO_DEPENDENCY } from "./const";
import { execPromise } from "./execPromise";
import { getMessageWithKeyValuePairs } from "./helpers/getMessageWithKeyValuePairs";
import { unparseFlags } from "./helpers/unparseFlags";
Expand All @@ -27,11 +23,6 @@ import { ensureCargoDependency } from "./rust";
import type { Flags } from "./typeHelpers";

export type MarineCliInput =
| {
command: "generate";
flags: Flags<"init" | "name">;
args?: never;
}
| {
command: "aqua";
flags?: never;
Expand Down Expand Up @@ -63,11 +54,6 @@ export const initMarineCli = async (

const projectRootDir = getProjectRootDir();

await ensureCargoDependency({
name: CARGO_GENERATE_CARGO_DEPENDENCY,
commandObj,
});

return async ({
command,
flags,
Expand Down
20 changes: 4 additions & 16 deletions src/lib/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,14 @@ export const ensureUserFluenceNpmDir = async (
ensureDir(path.join(await ensureUserFluenceDir(commandObj), NPM_DIR_NAME));

export const ensureUserFluenceCargoDir = async (
commandObj: CommandObj,
isGlobalDependency: true | undefined
commandObj: CommandObj
): Promise<string> =>
ensureDir(
isGlobalDependency === true
? path.join(
path.dirname(await ensureUserFluenceDir(commandObj)),
`.${CARGO_DIR_NAME}`
)
: path.join(await ensureUserFluenceDir(commandObj), CARGO_DIR_NAME)
);
ensureDir(path.join(await ensureUserFluenceDir(commandObj), CARGO_DIR_NAME));

export const ensureUserFluenceCargoCratesPath = async (
commandObj: CommandObj,
isGlobalDependency: true | undefined
commandObj: CommandObj
): Promise<string> =>
path.join(
await ensureUserFluenceCargoDir(commandObj, isGlobalDependency),
CRATES_TOML
);
path.join(await ensureUserFluenceCargoDir(commandObj), CRATES_TOML);

// Project paths:

Expand Down
Loading

0 comments on commit cf3721d

Please sign in to comment.