Skip to content

Commit

Permalink
Merge branch 'master' of github.com:FuelLabs/fuels-ts into ps/chore/a…
Browse files Browse the repository at this point in the history
…dd-permissions-for-pr-labeller
  • Loading branch information
petertonysmith94 committed Jun 21, 2024
2 parents 55d672a + 0206568 commit 33ddf9b
Show file tree
Hide file tree
Showing 45 changed files with 900 additions and 594 deletions.
4 changes: 4 additions & 0 deletions .changeset/big-ears-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

build(deps): bump uuid from 9.0.0 to 10.0.0
4 changes: 4 additions & 0 deletions .changeset/calm-taxis-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

build(deps-dev): bump typedoc from 0.25.3 to 0.25.13
4 changes: 4 additions & 0 deletions .changeset/dirty-guests-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

build(deps): bump @types/bn.js from 5.1.1 to 5.1.5
4 changes: 4 additions & 0 deletions .changeset/new-horses-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

build(deps): bump @noble/curves from 1.3.0 to 1.4.0
5 changes: 5 additions & 0 deletions .changeset/quick-avocados-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": patch
---

fix: passing arguments with NPM
5 changes: 5 additions & 0 deletions .changeset/quiet-toes-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": patch
---

chore: remove some choices from `create-fuels` CLI
5 changes: 5 additions & 0 deletions .changeset/strong-ducks-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/program": patch
---

fix: added docs for `isReadOnly` function
5 changes: 5 additions & 0 deletions .changeset/stupid-steaks-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/logger": minor
---

chore!: add debug logger for fuel-ts ecosystem
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"markdown-it": "^13.0.1",
"nodemon": "^3.0.3",
"replace": "^1.2.2",
"typedoc": "^0.25.1",
"typedoc": "^0.25.13",
"typedoc-plugin-merge-modules": "^5.1.0",
"vitepress": "1.2.2",
"vitepress-plugin-search": "1.0.4-alpha.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ If you run your frontend now, you should be able to interact with your contract
To deploy your frontend to the cloud, you can use any service like [Vercel](https://vercel.com/). Make sure that you setup your environment variables correctly and that your contract ID is correct. Your environment variables should look something like this:

```md
NEXT_PUBLIC_HAS_CONTRACT=true
NEXT_PUBLIC_DAPP_ENVIRONMENT=testnet
NEXT_PUBLIC_TESTNET_CONTRACT_ID=0x8342d413de2a678245d9ee39f020795800c7e6a4ac5ff7daae275f533dc05e08

Expand Down
18 changes: 1 addition & 17 deletions apps/docs/src/guide/creating-a-fuel-dapp/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pnpm create fuels@{{fuels}} [project-name] [options]
```

```sh-vue [npm]
npm create fuels@{{fuels}} [project-name] [options]
npm create fuels@{{fuels}} -- [project-name] [options]
```

```sh-vue [bun]
Expand All @@ -23,18 +23,6 @@ bunx --bun create-fuels@{{fuels}} [project-name] [options]

:::

## `-c, --contract`

Notifies the tool to include a Sway contract program in your project.

## `-p, --predicate`

Notifies the tool to include a Sway predicate program in your project.

## `-s, --script`

Notifies the tool to include a Sway script program in your project.

## `--pnpm`

Notifies the tool to use pnpm as the package manager to install the necessary dependencies.
Expand All @@ -47,10 +35,6 @@ Notifies the tool to use npm as the package manager to install the necessary dep

Notifies the tool to use bun as the package manager to install the necessary dependencies.

## `-cs, -cp, -sp, -cps`

Shorthand to include a combination of contract, script and predicate programs.

## `--verbose`

Enables verbose logging. Useful when debugging issues with the tool.
Expand Down
4 changes: 2 additions & 2 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
"@fuel-ts/utils": "workspace:*",
"@fuel-ts/versions": "workspace:*",
"@fuels/vm-asm": "0.54.0",
"@noble/curves": "^1.3.0",
"@noble/curves": "^1.4.0",
"events": "^3.3.0",
"graphql": "^16.8.1",
"graphql-request": "5.0.0",
"graphql-tag": "^2.12.6",
"portfinder": "^1.0.32",
"ramda": "^0.29.0",
"tree-kill": "^1.2.2",
"uuid": "^9.0.0"
"uuid": "^10.0.0"
},
"devDependencies": {
"type-fest": "^4.6.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/create-fuels/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ To learn how to deploy your Fuel dApp to the testnet, you can follow our [Deploy
- To make changes to the template locally, you will need to have a `.env.local` file in the `templates/nextjs` directory with the following contents:

```bash
NEXT_PUBLIC_HAS_CONTRACT=true
NEXT_PUBLIC_HAS_PREDICATE=true
NEXT_PUBLIC_HAS_SCRIPT=true
NEXT_PUBLIC_FUEL_NETWORK_URL=http://127.0.0.1:4000/v1/graphql
```

Expand Down
1 change: 0 additions & 1 deletion packages/create-fuels/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { runScaffoldCli, setupProgram } from './cli';
runScaffoldCli({
program: setupProgram(),
args: process.argv,
shouldInstallDeps: true,
})
.then(() => process.exit(0))
.catch((e) => {
Expand Down
88 changes: 14 additions & 74 deletions packages/create-fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import toml from '@iarna/toml';
import chalk from 'chalk';
import { execSync } from 'child_process';
import type { Command } from 'commander';
import { existsSync, readFileSync, rmSync, writeFileSync } from 'fs';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { cp, mkdir, rename } from 'fs/promises';
import ora from 'ora';
import { join } from 'path';
Expand All @@ -12,35 +12,23 @@ import { tryInstallFuelUp } from './lib';
import { getPackageManager } from './lib/getPackageManager';
import { getPackageVersion } from './lib/getPackageVersion';
import type { ProgramOptions } from './lib/setupProgram';
import { promptForProgramsToInclude, promptForProjectPath } from './prompts';
import { promptForProjectPath } from './prompts';
import { error, log } from './utils/logger';

export { setupProgram } from './lib/setupProgram';

export type ProgramsToInclude = Pick<ProgramOptions, 'contract' | 'predicate' | 'script'>;

const processWorkspaceToml = (fileContents: string, programsToInclude: ProgramsToInclude) => {
const processWorkspaceToml = (fileContents: string) => {
const parsed = toml.parse(fileContents) as {
workspace: {
members: ('predicate' | 'contract' | 'script')[];
};
};

parsed.workspace.members = parsed.workspace.members.filter((m) => programsToInclude[m]);

return toml.stringify(parsed);
};

function writeEnvFile(envFilePath: string, programsToInclude: ProgramsToInclude) {
/*
* Should be like:
* NEXT_PUBLIC_HAS_CONTRACT=true
* NEXT_PUBLIC_HAS_PREDICATE=false
* NEXT_PUBLIC_HAS_SCRIPT=true
*/
let newFileContents = Object.entries(programsToInclude)
.map(([program, include]) => `NEXT_PUBLIC_HAS_${program.toUpperCase()}=${include}`)
.join('\n');
function writeEnvFile(envFilePath: string) {
let newFileContents = '';

newFileContents += `\nNEXT_PUBLIC_FUEL_NODE_PORT=4000`;
newFileContents += `\nNEXT_PUBLIC_DAPP_ENVIRONMENT=local`;
Expand All @@ -51,21 +39,17 @@ function writeEnvFile(envFilePath: string, programsToInclude: ProgramsToInclude)
export const runScaffoldCli = async ({
program,
args = process.argv,
shouldInstallDeps = false,
forceDisablePrompts = false,
}: {
program: Command;
args: string[];
shouldInstallDeps?: boolean;
forceDisablePrompts?: boolean;
}) => {
program.parse(args);

let projectPath = program.args[0] ?? (await promptForProjectPath());

const opts = program.opts<ProgramOptions>();
const verboseEnabled = opts.verbose ?? false;
const packageManager = await getPackageManager(opts);
const packageManager = getPackageManager(opts);

if (!process.env.VITEST) {
await tryInstallFuelUp(verboseEnabled);
Expand Down Expand Up @@ -93,35 +77,6 @@ export const runScaffoldCli = async ({
projectPath = await promptForProjectPath();
}

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

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

while (!programsToInclude.contract && !programsToInclude.predicate && !programsToInclude.script) {
error('You must include at least one Sway program.');

// Exit the program if we are testing to prevent hanging
if (process.env.VITEST) {
throw new Error();
}

programsToInclude = await promptForProgramsToInclude({
forceDisablePrompts,
});
}

const fileCopySpinner = ora({
text: 'Copying template files..',
color: 'green',
Expand All @@ -135,25 +90,11 @@ export const runScaffoldCli = async ({
});
await rename(join(projectPath, 'gitignore'), join(projectPath, '.gitignore'));
await rename(join(projectPath, 'env'), join(projectPath, '.env.local'));
writeEnvFile(join(projectPath, '.env.local'), programsToInclude);

// delete the programs that are not to be included
if (!programsToInclude.contract) {
rmSync(join(projectPath, 'sway-programs/contract'), { recursive: true });
}
if (!programsToInclude.predicate) {
rmSync(join(projectPath, 'sway-programs/predicate'), { recursive: true });
rmSync(join(projectPath, 'src/pages/predicate.tsx'), { recursive: true });
}
if (!programsToInclude.script) {
rmSync(join(projectPath, 'sway-programs/script'), { recursive: true });
rmSync(join(projectPath, 'src/pages/script.tsx'), { recursive: true });
}
writeEnvFile(join(projectPath, '.env.local'));

// remove the programs that are not included from the Forc.toml members field and rewrite the file
const forcTomlPath = join(projectPath, 'sway-programs', 'Forc.toml');
const forcTomlContents = readFileSync(forcTomlPath, 'utf-8');
const newForcTomlContents = processWorkspaceToml(forcTomlContents, programsToInclude);
const newForcTomlContents = processWorkspaceToml(forcTomlContents);
writeFileSync(forcTomlPath, newForcTomlContents);

// Rewrite the package.json file
Expand All @@ -177,18 +118,17 @@ export const runScaffoldCli = async ({

fileCopySpinner.succeed('Copied template files!');

const installDepsSpinner = ora({
text: 'Installing dependencies..',
color: 'green',
}).start();
if (opts['no-install'] === false) {
const installDepsSpinner = ora({
text: 'Installing dependencies..',
color: 'green',
}).start();

if (shouldInstallDeps) {
process.chdir(projectPath);
execSync(packageManager.install, { stdio: verboseEnabled ? 'inherit' : 'pipe' });
installDepsSpinner.succeed('Installed dependencies!');
}

installDepsSpinner.succeed('Installed dependencies!');

log();
log();
log(chalk.green(`⚡️ Success! Created a fullstack Fuel dapp at ${projectPath}`));
Expand Down
Loading

0 comments on commit 33ddf9b

Please sign in to comment.