Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for --fuel-core-port flag in fuels init #3531

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-buses-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

feat: add support for `--fuel-core-port` flag in `fuels init`
16 changes: 11 additions & 5 deletions apps/docs/src/guide/fuels-cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ npx fuels@{{fuels}} help init

```console
Options:
-w, --workspace <path> Relative dir path to Forc workspace
-c, --contracts <path|global> Relative path/globals to Contracts
-s, --scripts <path|global> Relative path/globals to Scripts
-p, --predicates <path|global> Relative path/globals to Predicates
-o, --output <path> Relative dir path for Typescript generation
--path <path> Path to project root (default: current directory)
-w, --workspace <path> Relative dir path to Forc workspace
-c, --contracts [paths...] Relative paths to Contracts
-s, --scripts [paths...] Relative paths to Scripts
-p, --predicates [paths...] Relative paths to Predicates
-o, --output <path> Relative dir path for Typescript generation output
--forc-path <path> Path to the `forc` binary
--fuel-core-path <path> Path to the `fuel-core` binary
--auto-start-fuel-core Auto-starts a `fuel-core` node during `dev` command
--fuel-core-port <port> Port to use when starting a local `fuel-core` node for dev mode
nedsalk marked this conversation as resolved.
Show resolved Hide resolved
-h, --help Display help
```

Creating a sample `fuel.config.ts` file:
Expand Down
4 changes: 4 additions & 0 deletions packages/fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export const configureCli = () => {
.option('--forc-path <path>', 'Path to the `forc` binary')
.option('--fuel-core-path <path>', 'Path to the `fuel-core` binary')
.option('--auto-start-fuel-core', 'Auto-starts a `fuel-core` node during `dev` command')
.option(
'--fuel-core-port <port>',
'Port to use when starting a local `fuel-core` node for dev mode'
)
.action(withProgram(command, Commands.init, init));

(command = program.command(Commands.dev))
Expand Down
3 changes: 2 additions & 1 deletion packages/fuels/src/cli/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { log } from '../../utils/logger';
export function init(program: Command) {
const options = program.opts();

const { path, autoStartFuelCore, forcPath, fuelCorePath } = options;
const { path, autoStartFuelCore, forcPath, fuelCorePath, fuelCorePort } = options;

let workspace: string | undefined;
let absoluteWorkspace: string | undefined;
Expand Down Expand Up @@ -61,6 +61,7 @@ export function init(program: Command) {
forcPath,
fuelCorePath,
autoStartFuelCore,
fuelCorePort,
});

writeFileSync(fuelsConfigPath, renderedConfig);
Expand Down
3 changes: 3 additions & 0 deletions packages/fuels/src/cli/templates/fuels.config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default createConfig({
{{#if (isDefined autoStartFuelCore)}}
autoStartFuelCore: {{autoStartFuelCore}},
{{/if}}
{{#if (isDefined fuelCorePort)}}
fuelCorePort: {{fuelCorePort}},
{{/if}}
});

/**
Expand Down
1 change: 1 addition & 0 deletions packages/fuels/src/cli/templates/fuels.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function renderFuelsConfigTemplate(props: {
forcPath?: string;
fuelCorePath?: string;
autoStartFuelCore?: boolean;
fuelCorePort?: string;
}) {
const renderTemplate = Handlebars.compile(fuelsConfigTemplate, {
strict: true,
Expand Down
12 changes: 12 additions & 0 deletions packages/fuels/test/features/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ describe('init', () => {
expect(fuelsContents).toMatch(`fuelCorePath: 'fuels-core',`);
});

it('should run `init` command with custom fuel-core-port', async () => {
await runInit({
root: paths.root,
workspace: paths.workspaceDir,
output: paths.outputDir,
fuelCorePort: '1234',
});

const fuelsContents = readFileSync(paths.fuelsConfigPath, 'utf-8');
expect(fuelsContents).toMatch(`fuelCorePort: 1234,`);
});

it('should run `init` command and throw for existent config file', async () => {
const { error } = mockLogger();

Expand Down
3 changes: 3 additions & 0 deletions packages/fuels/test/utils/runCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export type InitParams = BaseParams & {
autoStartFuelCore?: boolean;
build?: boolean;
privateKey?: string;
fuelCorePort?: string;
};

export type BuildParams = BaseParams & {
Expand All @@ -120,6 +121,7 @@ export async function runInit(params: InitParams) {
fuelCorePath,
workspace,
privateKey,
fuelCorePort,
} = params;

const flag = (
Expand All @@ -137,6 +139,7 @@ export async function runInit(params: InitParams) {
flag(['--forc-path', forcPath], forcPath),
flag(['--fuel-core-path', fuelCorePath], fuelCorePath),
flag(['--auto-start-fuel-core'], autoStartFuelCore),
flag(['--fuel-core-port', fuelCorePort], fuelCorePort),
].flat();

const command = await runCommand(Commands.init, flags);
Expand Down
Loading