Skip to content

Commit

Permalink
Merge branch 'master' into dp/numbers-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiwat10 authored Feb 23, 2024
2 parents 8877468 + d386df1 commit a59a0f2
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 136 deletions.
13 changes: 13 additions & 0 deletions .changeset/dirty-guests-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"create-fuels": minor
---

feat: add new options to the `create-fuels` CLI:

-c, --contract Include contract program
-p, --predicate Include predicate program
-s, --script Include script program
--pnpm Use pnpm as the package manager
--npm Use npm as the package manager
-cs, -cp, -sp, -cps Shorthand to include combination of contract, script and predicate programs
-h, --help display help for command
2 changes: 2 additions & 0 deletions .changeset/shy-bottles-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/silent-hounds-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/tame-eels-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

remove unused connectors types
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"recommendations": [
"ZixuanChen.vitest-explorer",
"vitest.explorer",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint"
]
Expand Down
36 changes: 30 additions & 6 deletions apps/docs/src/guide/quickstart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,40 @@ You can quickly bootstrap a full-stack Fuel project locally with the following c

```sh [pnpm]
pnpm create fuels

# or, if you want to pass in your preferences directly from the command line:
pnpm create fuels [project-name] [options]

# eg. pnpm create fuels my-fuel-project --pnpm --contract --predicate
# Note: project-name and all other options are optional
Options:
-V, --version output the version number
-c, --contract Include contract program
-p, --predicate Include predicate program
-s, --script Include script program
--pnpm Use pnpm as the package manager
--npm Use npm as the package manager
-cs, -cp, -sp, -cps Shorthand to include combination of contract, script and predicate programs
-h, --help Display help for command
```

```sh [npm]
npm create fuels

# or, if you want to pass in your preferences directly from the command line:
npm create fuels [project-name] [options]

# eg. npm create fuels my-fuel-project --pnpm --contract --predicate
# Note: project-name and all other options are optional
Options:
-V, --version output the version number
-c, --contract Include contract program
-p, --predicate Include predicate program
-s, --script Include script program
--pnpm Use pnpm as the package manager
--npm Use npm as the package manager
-cs, -cp, -sp, -cps Shorthand to include combination of contract, script and predicate programs
-h, --help Display help for command
```

:::
Expand All @@ -19,17 +49,11 @@ This will setup a new full-stack Fuel project. To get things running, you'll nee
::: code-group

```sh [pnpm]
# (Make sure you cd into your new project directory first!)
pnpm install

# Start a local Fuel node and hot-reload for your Sway smart contracts
pnpm fuels:dev
```

```sh [npm]
# (Make sure you cd into your new project directory first!)
npm install

# Start a local Fuel node and hot-reload for your Sway smart contracts
npm run fuels:dev
```
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/connectors/fuel-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { EventEmitter } from 'events';

import type { TransactionRequestLike } from '../providers';
import type { Asset } from '../providers/assets/types';

import { FuelConnectorEventTypes } from './types';
import type {
Expand All @@ -11,7 +12,6 @@ import type {
Network,
FuelEventArg,
Version,
Asset,
} from './types';

/**
Expand Down
1 change: 0 additions & 1 deletion packages/account/src/connectors/types/asset.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/account/src/connectors/types/constants.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/account/src/connectors/types/data-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,3 @@ export type Network = {
* Read more at: https://docs.fuel.network/docs/specs/abi/json-abi-format/
*/
export type FuelABI = JsonAbi;

export enum MessageTypes {
ping = 'ping',
uiEvent = 'uiEvent',
event = 'event',
request = 'request',
response = 'response',
removeConnection = 'removeConnection',
}
46 changes: 2 additions & 44 deletions packages/account/src/connectors/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { Asset } from '@fuels/assets';
import type { JSONRPCRequest, JSONRPCResponse } from 'json-rpc-2.0';

import type { Asset } from '../../providers/assets/types';
import type { FuelConnector } from '../fuel-connector';

import type { FuelConnectorEventTypes } from './connector-types';
import type { MessageTypes, Network } from './data-type';
import type { MessageSender } from './message';
import type { Network } from './data-type';

/** **
* ========================================================================================
Expand All @@ -21,45 +18,6 @@ export type FuelEventArg<T extends FuelConnectorEvents['type']> = Extract<
{ type: T }
>['data'];

/** **
* ========================================================================================
* Events
* ========================================================================================
*/

export type BaseEvent<T> = {
readonly target: string;
readonly connectorName?: string;
readonly id?: string;
readonly sender?: MessageSender;
} & T;

export type UIEventMessage = BaseEvent<{
readonly type: MessageTypes.uiEvent;
readonly ready: boolean;
readonly session: string;
}>;

export type RequestMessage = BaseEvent<{
readonly type: MessageTypes.request;
readonly request: JSONRPCRequest;
}>;

export type ResponseMessage = BaseEvent<{
readonly type: MessageTypes.response;
readonly response: JSONRPCResponse;
}>;

export type EventMessageEvents = Array<{
event: string;
params: Array<unknown>;
}>;

export type EventMessage<T = EventMessageEvents> = BaseEvent<{
readonly type: MessageTypes.event;
readonly events: T;
}>;

/**
* Event trigger when the accounts available to the
* connection changes.
Expand Down
2 changes: 0 additions & 2 deletions packages/account/src/connectors/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ export * from './data-type';
export * from './events';
export * from './local-storage';
export * from './target-object';
export * from './message';
export * from './asset';
16 changes: 0 additions & 16 deletions packages/account/src/connectors/types/message.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/account/test/fixtures/mocked-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { setTimeout } from 'timers/promises';
import type {
TransactionRequestLike,
WalletUnlocked,
Asset,
FuelABI,
ConnectorMetadata,
Network,
} from '../../src';
import { FUEL_NETWORK_URL } from '../../src/configs';
import { FuelConnector } from '../../src/connectors/fuel-connector';
import { FuelConnectorEventTypes } from '../../src/connectors/types';
import type { Asset } from '../../src/providers/assets/types';

import { generateAccounts } from './generate-accounts';

Expand Down
3 changes: 2 additions & 1 deletion packages/create-fuels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"devDependencies": {
"@fuel-ts/versions": "workspace:*",
"@types/prompts": "^2.4.8"
"@types/prompts": "^2.4.8",
"glob": "^10.2.6"
}
}
86 changes: 71 additions & 15 deletions packages/create-fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const log = (...data: unknown[]) => {
process.stdout.write(`${data.join(' ')}\n`);
};

type ProgramsToInclude = {
export type ProgramsToInclude = {
contract: boolean;
predicate: boolean;
script: boolean;
Expand Down Expand Up @@ -56,15 +56,26 @@ async function promptForPackageManager() {
return packageManagerInput.packageManager as string;
}

async function promptForProgramsToInclude() {
async function promptForProgramsToInclude({
forceDisablePrompts = false,
}: {
forceDisablePrompts?: boolean;
}) {
if (forceDisablePrompts) {
return {
contract: false,
predicate: false,
script: false,
};
}
const programsToIncludeInput = await prompts({
type: 'multiselect',
name: 'programsToInclude',
message: 'Which Sway programs do you want?',
choices: [
{ title: 'Contract', value: 'contract', selected: true },
{ title: 'Predicate', value: 'predicate' },
{ title: 'Script', value: 'script' },
{ title: 'Predicate', value: 'predicate', selected: true },
{ title: 'Script', value: 'script', selected: true },
],
instructions: false,
});
Expand All @@ -88,15 +99,33 @@ function writeEnvFile(envFilePath: string, programsToInclude: ProgramsToInclude)
writeFileSync(envFilePath, newFileContents);
}

export const runScaffoldCli = async (
explicitProjectPath?: string,
explicitPackageManger?: string,
shouldInstallDeps = true,
explicitProgramsToInclude?: ProgramsToInclude
) => {
new Command(packageJson.name).version(packageJson.version);
export const setupProgram = () => {
const program = new Command(packageJson.name)
.version(packageJson.version)
.arguments('[projectDirectory]')
.option('-c, --contract', 'Include contract program')
.option('-p, --predicate', 'Include predicate program')
.option('-s, --script', 'Include script program')
.option('--pnpm', 'Use pnpm as the package manager')
.option('--npm', 'Use npm as the package manager')
.addHelpCommand()
.showHelpAfterError(true);
return program;
};

const projectPath = explicitProjectPath || (await promptForProjectPath());
export const runScaffoldCli = async ({
program,
args = process.argv,
shouldInstallDeps = false,
forceDisablePrompts = false,
}: {
program: Command;
args: string[];
shouldInstallDeps?: boolean;
forceDisablePrompts?: boolean;
}) => {
program.parse(args);
const projectPath = program.args[0] ?? (await promptForProjectPath());
if (existsSync(projectPath)) {
throw new Error(
`A folder already exists at ${projectPath}. Please choose a different project name.`
Expand All @@ -106,10 +135,37 @@ export const runScaffoldCli = async (
if (!projectPath) {
throw new Error('Please specify a project directory.');
}
const packageManager = explicitPackageManger || (await promptForPackageManager());

const programsToInclude: ProgramsToInclude =
explicitProgramsToInclude || (await promptForProgramsToInclude());
const cliPackageManagerChoices = {
pnpm: program.opts().pnpm,
npm: program.opts().npm,
};
if (Object.values(cliPackageManagerChoices).filter(Boolean).length > 1) {
throw new Error('You can only specify one package manager.');
}
const cliChosenPackageManager = Object.entries(cliPackageManagerChoices).find(([, v]) => v)?.[0];

let packageManager = cliChosenPackageManager ?? (await promptForPackageManager());

if (!packageManager) {
packageManager = 'pnpm';
}

const cliProgramsToInclude = {
contract: program.opts().contract,
predicate: program.opts().predicate,
script: program.opts().script,
};
const hasAnyCliProgramsToInclude = Object.values(cliProgramsToInclude).some((v) => v);

let programsToInclude: ProgramsToInclude;
if (hasAnyCliProgramsToInclude) {
programsToInclude = cliProgramsToInclude;
} else {
programsToInclude = await promptForProgramsToInclude({
forceDisablePrompts,
});
}

if (!programsToInclude.contract && !programsToInclude.predicate && !programsToInclude.script) {
throw new Error('You must include at least one Sway program.');
Expand Down
Loading

0 comments on commit a59a0f2

Please sign in to comment.