diff --git a/.changeset/olive-buses-count.md b/.changeset/olive-buses-count.md new file mode 100644 index 00000000000..b00887a3979 --- /dev/null +++ b/.changeset/olive-buses-count.md @@ -0,0 +1,5 @@ +--- +"fuels": patch +--- + +feat: add support for `--fuel-core-port` flag in `fuels init` diff --git a/apps/docs/src/guide/fuels-cli/commands.md b/apps/docs/src/guide/fuels-cli/commands.md index f842abd7a72..97e936c676f 100644 --- a/apps/docs/src/guide/fuels-cli/commands.md +++ b/apps/docs/src/guide/fuels-cli/commands.md @@ -15,11 +15,17 @@ npx fuels@{{fuels}} help init ```console Options: - -w, --workspace Relative dir path to Forc workspace - -c, --contracts Relative path/globals to Contracts - -s, --scripts Relative path/globals to Scripts - -p, --predicates Relative path/globals to Predicates - -o, --output Relative dir path for Typescript generation + --path Path to project root (default: current directory) + -w, --workspace 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 Relative dir path for Typescript generation output + --forc-path Path to the `forc` binary + --fuel-core-path Path to the `fuel-core` binary + --auto-start-fuel-core Auto-starts a `fuel-core` node during `dev` command + --fuel-core-port Port to use when starting a local `fuel-core` node for dev mode + -h, --help Display help ``` Creating a sample `fuel.config.ts` file: diff --git a/packages/fuels/src/cli.ts b/packages/fuels/src/cli.ts index 0299c304750..9a716cbfb7d 100644 --- a/packages/fuels/src/cli.ts +++ b/packages/fuels/src/cli.ts @@ -65,6 +65,10 @@ export const configureCli = () => { .option('--forc-path ', 'Path to the `forc` binary') .option('--fuel-core-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 to use when starting a local `fuel-core` node for dev mode' + ) .action(withProgram(command, Commands.init, init)); (command = program.command(Commands.dev)) diff --git a/packages/fuels/src/cli/commands/init/index.ts b/packages/fuels/src/cli/commands/init/index.ts index 0f537c5431a..cf15d11af49 100644 --- a/packages/fuels/src/cli/commands/init/index.ts +++ b/packages/fuels/src/cli/commands/init/index.ts @@ -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; @@ -61,6 +61,7 @@ export function init(program: Command) { forcPath, fuelCorePath, autoStartFuelCore, + fuelCorePort, }); writeFileSync(fuelsConfigPath, renderedConfig); diff --git a/packages/fuels/src/cli/templates/fuels.config.hbs b/packages/fuels/src/cli/templates/fuels.config.hbs index dc351121c38..33ceaa33b18 100644 --- a/packages/fuels/src/cli/templates/fuels.config.hbs +++ b/packages/fuels/src/cli/templates/fuels.config.hbs @@ -36,6 +36,9 @@ export default createConfig({ {{#if (isDefined autoStartFuelCore)}} autoStartFuelCore: {{autoStartFuelCore}}, {{/if}} + {{#if (isDefined fuelCorePort)}} + fuelCorePort: {{fuelCorePort}}, + {{/if}} }); /** diff --git a/packages/fuels/src/cli/templates/fuels.config.ts b/packages/fuels/src/cli/templates/fuels.config.ts index 71930e975a9..cda74e22e1a 100644 --- a/packages/fuels/src/cli/templates/fuels.config.ts +++ b/packages/fuels/src/cli/templates/fuels.config.ts @@ -16,6 +16,7 @@ export function renderFuelsConfigTemplate(props: { forcPath?: string; fuelCorePath?: string; autoStartFuelCore?: boolean; + fuelCorePort?: string; }) { const renderTemplate = Handlebars.compile(fuelsConfigTemplate, { strict: true, diff --git a/packages/fuels/test/features/init.test.ts b/packages/fuels/test/features/init.test.ts index f55d512d68b..0e3d7d0d292 100644 --- a/packages/fuels/test/features/init.test.ts +++ b/packages/fuels/test/features/init.test.ts @@ -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(); diff --git a/packages/fuels/test/utils/runCommands.ts b/packages/fuels/test/utils/runCommands.ts index b1f10eab728..f5a052d81a8 100644 --- a/packages/fuels/test/utils/runCommands.ts +++ b/packages/fuels/test/utils/runCommands.ts @@ -102,6 +102,7 @@ export type InitParams = BaseParams & { autoStartFuelCore?: boolean; build?: boolean; privateKey?: string; + fuelCorePort?: string; }; export type BuildParams = BaseParams & { @@ -120,6 +121,7 @@ export async function runInit(params: InitParams) { fuelCorePath, workspace, privateKey, + fuelCorePort, } = params; const flag = ( @@ -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);