diff --git a/.changeset/quiet-toes-chew.md b/.changeset/quiet-toes-chew.md new file mode 100644 index 00000000000..39579bf14f3 --- /dev/null +++ b/.changeset/quiet-toes-chew.md @@ -0,0 +1,5 @@ +--- +"create-fuels": patch +--- + +chore: remove some choices from `create-fuels` CLI diff --git a/apps/docs/src/guide/creating-a-fuel-dapp/deploying-a-dapp-to-testnet.md b/apps/docs/src/guide/creating-a-fuel-dapp/deploying-a-dapp-to-testnet.md index 9900770fa00..4dd7379e5a3 100644 --- a/apps/docs/src/guide/creating-a-fuel-dapp/deploying-a-dapp-to-testnet.md +++ b/apps/docs/src/guide/creating-a-fuel-dapp/deploying-a-dapp-to-testnet.md @@ -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 diff --git a/apps/docs/src/guide/creating-a-fuel-dapp/options.md b/apps/docs/src/guide/creating-a-fuel-dapp/options.md index 0b74dcdd9c2..e4deea28b5e 100644 --- a/apps/docs/src/guide/creating-a-fuel-dapp/options.md +++ b/apps/docs/src/guide/creating-a-fuel-dapp/options.md @@ -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. @@ -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. diff --git a/packages/create-fuels/README.md b/packages/create-fuels/README.md index bc76f1077aa..837a7b6c39c 100644 --- a/packages/create-fuels/README.md +++ b/packages/create-fuels/README.md @@ -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 ``` diff --git a/packages/create-fuels/src/cli.ts b/packages/create-fuels/src/cli.ts index 3f6e2bf1a32..4d05f54c286 100644 --- a/packages/create-fuels/src/cli.ts +++ b/packages/create-fuels/src/cli.ts @@ -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'; @@ -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; - -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`; @@ -52,12 +40,10 @@ export const runScaffoldCli = async ({ program, args = process.argv, shouldInstallDeps = false, - forceDisablePrompts = false, }: { program: Command; args: string[]; shouldInstallDeps?: boolean; - forceDisablePrompts?: boolean; }) => { program.parse(args); @@ -65,7 +51,7 @@ export const runScaffoldCli = async ({ const opts = program.opts(); const verboseEnabled = opts.verbose ?? false; - const packageManager = await getPackageManager(opts); + const packageManager = getPackageManager(opts); if (!process.env.VITEST) { await tryInstallFuelUp(verboseEnabled); @@ -93,35 +79,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', @@ -135,25 +92,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 diff --git a/packages/create-fuels/src/lib/getPackageManager.test.ts b/packages/create-fuels/src/lib/getPackageManager.test.ts index 2c9a1b70f31..9fb4b0fb780 100644 --- a/packages/create-fuels/src/lib/getPackageManager.test.ts +++ b/packages/create-fuels/src/lib/getPackageManager.test.ts @@ -1,18 +1,13 @@ import { mockLogger } from '../../test/utils/mockLogger'; -import * as promptsMod from '../prompts'; import type { PackageManager } from './getPackageManager'; import { availablePackageManagers, getPackageManager, packageMangers } from './getPackageManager'; -const mockAllDeps = (opts: { packageManager?: PackageManager } = {}) => { +const mockAllDeps = () => { const { warn } = mockLogger(); - const promptForPackageManager = vi - .spyOn(promptsMod, 'promptForPackageManager') - .mockResolvedValue(opts.packageManager); return { warn, - promptForPackageManager, }; }; @@ -35,11 +30,11 @@ const runScenarios: [PackageManager, string][] = [ describe('getPackageManager', () => { it.each(availablePackageManagers)( `should get the correct package manager for %s`, - async (packageManager: PackageManager) => { + (packageManager: PackageManager) => { const expectedPackageManager = packageMangers[packageManager]; const opts = { [packageManager]: true }; - const result = await getPackageManager(opts); + const result = getPackageManager(opts); expect(result).toEqual(expectedPackageManager); } @@ -47,8 +42,8 @@ describe('getPackageManager', () => { it.each(installScenarios)( 'should have the correct install commands', - async (packageManager, expectedInstallCommand) => { - const command = await getPackageManager({ [packageManager]: true }); + (packageManager, expectedInstallCommand) => { + const command = getPackageManager({ [packageManager]: true }); const install = command.install; @@ -58,8 +53,8 @@ describe('getPackageManager', () => { it.each(runScenarios)( 'should have the correct run commands', - async (packageManager, expectedRunCommand) => { - const command = await getPackageManager({ [packageManager]: true }); + (packageManager, expectedRunCommand) => { + const command = getPackageManager({ [packageManager]: true }); const run = command.run(runCommand); @@ -67,41 +62,24 @@ describe('getPackageManager', () => { } ); - it('should warn the user if more than one package manager selected', async () => { - const { warn, promptForPackageManager } = mockAllDeps(); + it('should warn the user if more than one package manager selected', () => { + const { warn } = mockAllDeps(); const opts = { pnpm: true, npm: true }; - await getPackageManager(opts); + getPackageManager(opts); - expect(promptForPackageManager).toBeCalled(); expect(warn).toBeCalledWith('More than one package manager was selected.'); }); - it('should allow inputting of a package manager via prompt', async () => { + it('should default to npm if no package manager is selected', () => { const packageManager = 'npm'; const expectedPackageManager = packageMangers[packageManager]; - const { warn, promptForPackageManager } = mockAllDeps({ - packageManager, - }); + const { warn } = mockAllDeps(); const opts = {}; - const result = await getPackageManager(opts); + const result = getPackageManager(opts); expect(warn).not.toBeCalled(); - expect(promptForPackageManager).toBeCalled(); - expect(result).toEqual(expectedPackageManager); - }); - - it('should default to pnpm if no package manager is selected', async () => { - const packageManager = 'pnpm'; - const expectedPackageManager = packageMangers[packageManager]; - const { warn, promptForPackageManager } = mockAllDeps(); - const opts = {}; - - const result = await getPackageManager(opts); - - expect(warn).not.toBeCalled(); - expect(promptForPackageManager).toBeCalled(); expect(result).toEqual(expectedPackageManager); }); }); diff --git a/packages/create-fuels/src/lib/getPackageManager.ts b/packages/create-fuels/src/lib/getPackageManager.ts index 4cf917ec723..f1982f13b84 100644 --- a/packages/create-fuels/src/lib/getPackageManager.ts +++ b/packages/create-fuels/src/lib/getPackageManager.ts @@ -1,4 +1,3 @@ -import { promptForPackageManager } from '../prompts'; import { warn } from '../utils/logger'; import type { ProgramOptions } from './setupProgram'; @@ -26,7 +25,7 @@ export const packageMangers = { }, } as const; -export const getPackageManager = async (opts: ProgramOptions) => { +export const getPackageManager = (opts: ProgramOptions) => { const packageMangerOpts = { pnpm: opts.pnpm, npm: opts.npm, @@ -41,12 +40,9 @@ export const getPackageManager = async (opts: ProgramOptions) => { if (cliChosenPackageManagerSelected.length > 1) { warn('More than one package manager was selected.'); } - if (cliChosenPackageManagerSelected.length !== 1) { - packageManager = await promptForPackageManager(); - } if (!packageManager) { - packageManager = 'pnpm'; + packageManager = 'npm'; // default to npm if the user has not specified a package manager (eg. --pnpm, --bun) } return packageMangers[packageManager]; }; diff --git a/packages/create-fuels/src/lib/setupProgram.test.ts b/packages/create-fuels/src/lib/setupProgram.test.ts index 85df84267a0..215edfa0367 100644 --- a/packages/create-fuels/src/lib/setupProgram.test.ts +++ b/packages/create-fuels/src/lib/setupProgram.test.ts @@ -6,28 +6,18 @@ import { setupProgram } from './setupProgram'; describe('setupProgram', () => { test('setupProgram takes in args properly', () => { const program = setupProgram(); - program.parse(['', '', 'test-project-name', '-c', '-p', '-s', '--pnpm', '--npm']); + program.parse(['', '', 'test-project-name', '--pnpm', '--npm']); expect(program.args[0]).toBe('test-project-name'); - expect(program.opts().contract).toBe(true); - expect(program.opts().predicate).toBe(true); - expect(program.opts().script).toBe(true); expect(program.opts().pnpm).toBe(true); expect(program.opts().npm).toBe(true); - }); - - test('setupProgram takes in combined args properly', () => { - const program = setupProgram(); - program.parse(['', '', '-cps']); - expect(program.opts().contract).toBe(true); - expect(program.opts().predicate).toBe(true); - expect(program.opts().script).toBe(true); + expect(program.opts().bun).toBe(undefined); }); test('setupProgram - no args', () => { const program = setupProgram(); program.parse([]); - expect(program.opts().contract).toBe(undefined); - expect(program.opts().predicate).toBe(undefined); - expect(program.opts().script).toBe(undefined); + expect(program.opts().pnpm).toBe(undefined); + expect(program.opts().npm).toBe(undefined); + expect(program.opts().bun).toBe(undefined); }); }); diff --git a/packages/create-fuels/src/lib/setupProgram.ts b/packages/create-fuels/src/lib/setupProgram.ts index efc41ba9057..c47e64cb63d 100644 --- a/packages/create-fuels/src/lib/setupProgram.ts +++ b/packages/create-fuels/src/lib/setupProgram.ts @@ -16,12 +16,9 @@ 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') - .option('--bun', 'Use bun as the package manager') + .option('--pnpm', 'Use pnpm to install dependencies') + .option('--npm', 'Use npm to install dependencies') + .option('--bun', 'Use bun to install dependencies') .option('--verbose', 'Enable verbose logging') .addHelpCommand() .showHelpAfterError(true); diff --git a/packages/create-fuels/src/prompts/index.ts b/packages/create-fuels/src/prompts/index.ts index fa7d1cd8f50..0b847f39728 100644 --- a/packages/create-fuels/src/prompts/index.ts +++ b/packages/create-fuels/src/prompts/index.ts @@ -1,4 +1,2 @@ export * from './promptFuelUpInstall'; export * from './promptForProjectPath'; -export * from './promptForPackageManager'; -export * from './promptForProgramsToInclude'; diff --git a/packages/create-fuels/src/prompts/promptForPackageManager.test.ts b/packages/create-fuels/src/prompts/promptForPackageManager.test.ts deleted file mode 100644 index c6454aeae65..00000000000 --- a/packages/create-fuels/src/prompts/promptForPackageManager.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -import * as promptsMod from 'prompts'; - -import { promptForPackageManager } from './promptForPackageManager'; - -vi.mock('prompts', async () => { - const mod = await vi.importActual('prompts'); - return { - __esModule: true, - ...mod, - }; -}); - -const mockPrompts = (params: { results: unknown[] }) => { - promptsMod.default.inject(params.results); - const prompts = vi.spyOn(promptsMod, 'default'); - const exit = vi.spyOn(process, 'exit').mockReturnValue({} as never); - - return { - prompts, - exit, - }; -}; - -const responses = ['pnpm', 'npm', 'bun']; - -/** - * @group node - */ -describe('promptForPackageManager', () => { - afterEach(() => { - vi.restoreAllMocks(); - }); - - it('should prompt the user to select a package manger', async () => { - // Arrange - const { prompts } = mockPrompts({ results: [0] }); - - // Act - await promptForPackageManager(); - - // Assert - expect(prompts).toBeCalledWith( - expect.objectContaining({ - type: 'select', - message: expect.stringContaining(`Select a package manager`), - choices: [ - { title: 'pnpm', value: 'pnpm' }, - { title: 'npm', value: 'npm' }, - { title: 'bun', value: 'bun' }, - ], - }), - expect.any(Object) - ); - }); - - it.each(responses)('should handle "%s" response', async (response) => { - // Arrange - const { prompts, exit } = mockPrompts({ results: [response] }); - - // Act - const result = await promptForPackageManager(); - - // Assert - expect(result).toBe(response); - expect(prompts).toBeCalledTimes(1); - expect(exit).not.toBeCalled(); - }); - - it('should exit the process when user cancels the prompt', async () => { - // Arrange - const { prompts, exit } = mockPrompts({ results: [new Error()] }); - - // Act - const result = await promptForPackageManager(); - - // Assert - const expectedExitCode = 0; - expect(exit).toBeCalledWith(expectedExitCode); - expect(result).toBeUndefined(); - expect(prompts).toBeCalledTimes(1); - }); -}); diff --git a/packages/create-fuels/src/prompts/promptForPackageManager.ts b/packages/create-fuels/src/prompts/promptForPackageManager.ts deleted file mode 100644 index e38c32e3bd0..00000000000 --- a/packages/create-fuels/src/prompts/promptForPackageManager.ts +++ /dev/null @@ -1,21 +0,0 @@ -import prompts from 'prompts'; - -import type { PackageManager } from '../lib/getPackageManager'; - -export const promptForPackageManager = async (): Promise => { - const packageManagerInput = await prompts( - { - type: 'select', - name: 'packageManager', - message: 'Select a package manager', - choices: [ - { title: 'pnpm', value: 'pnpm' }, - { title: 'npm', value: 'npm' }, - { title: 'bun', value: 'bun' }, - ], - initial: 0, - }, - { onCancel: () => process.exit(0) } - ); - return packageManagerInput.packageManager as PackageManager; -}; diff --git a/packages/create-fuels/src/prompts/promptForProgramsToInclude.test.ts b/packages/create-fuels/src/prompts/promptForProgramsToInclude.test.ts deleted file mode 100644 index 0b1073fb732..00000000000 --- a/packages/create-fuels/src/prompts/promptForProgramsToInclude.test.ts +++ /dev/null @@ -1,109 +0,0 @@ -import * as promptsMod from 'prompts'; - -import { promptForProgramsToInclude } from './promptForProgramsToInclude'; - -vi.mock('prompts', async () => { - const mod = await vi.importActual('prompts'); - return { - __esModule: true, - ...mod, - }; -}); - -const mockPrompts = (params: { results: unknown[] } = { results: [] }) => { - promptsMod.default.inject(params.results); - const prompts = vi.spyOn(promptsMod, 'default'); - const exit = vi.spyOn(process, 'exit').mockReturnValue({} as never); - - return { - prompts, - exit, - }; -}; - -/** - * @group node - */ -describe('promptForProgramsToInclude', () => { - afterEach(() => { - vi.restoreAllMocks(); - }); - - it('should prompt the user to include Sway programs', async () => { - // Arrange - const { prompts } = mockPrompts({ - results: [[]], - }); - - // Act - await promptForProgramsToInclude({ forceDisablePrompts: false }); - - // Assert - expect(prompts).toBeCalledWith( - expect.objectContaining({ - type: 'multiselect', - message: expect.stringContaining(`Which Sway programs do you want?`), - choices: [ - { title: 'Contract', value: 'contract', selected: true }, - { title: 'Predicate', value: 'predicate', selected: true }, - { title: 'Script', value: 'script', selected: true }, - ], - }), - expect.any(Object) - ); - }); - - it('should handle all user responses', async () => { - // Arrange - const { prompts, exit } = mockPrompts({ - results: [['contract', 'predicate', 'script']], - }); - - // Act - const result = await promptForProgramsToInclude({ forceDisablePrompts: false }); - - // Assert - expect(result).toStrictEqual({ - contract: true, - predicate: true, - script: true, - }); - expect(prompts).toBeCalledTimes(1); - expect(exit).not.toBeCalled(); - }); - - it('should handle no selected programs', async () => { - // Arrange - const { prompts, exit } = mockPrompts({ - results: [[]], - }); - - // Act - const result = await promptForProgramsToInclude({ forceDisablePrompts: false }); - - // Assert - expect(result).toStrictEqual({ - contract: false, - predicate: false, - script: false, - }); - expect(prompts).toBeCalledTimes(1); - expect(exit).not.toBeCalled(); - }); - - it('should return the default programs when prompts are disabled', async () => { - // Arrange - const { prompts } = mockPrompts(); - - // Act - const result = await promptForProgramsToInclude({ forceDisablePrompts: true }); - - // Assert - expect(result).toStrictEqual({ - contract: false, - predicate: false, - script: false, - }); - expect(prompts).not.toBeCalled(); - }); -}); diff --git a/packages/create-fuels/src/prompts/promptForProgramsToInclude.ts b/packages/create-fuels/src/prompts/promptForProgramsToInclude.ts deleted file mode 100644 index 3fa7ba35644..00000000000 --- a/packages/create-fuels/src/prompts/promptForProgramsToInclude.ts +++ /dev/null @@ -1,35 +0,0 @@ -import prompts from 'prompts'; - -export const promptForProgramsToInclude = async ({ - 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', selected: true }, - { title: 'Script', value: 'script', selected: true }, - ], - instructions: false, - }, - { onCancel: () => process.exit(0) } - ); - - return { - contract: programsToIncludeInput.programsToInclude.includes('contract'), - predicate: programsToIncludeInput.programsToInclude.includes('predicate'), - script: programsToIncludeInput.programsToInclude.includes('script'), - }; -}; diff --git a/packages/create-fuels/test/cli.test.ts b/packages/create-fuels/test/cli.test.ts index 6a24cb36213..88775a972dc 100644 --- a/packages/create-fuels/test/cli.test.ts +++ b/packages/create-fuels/test/cli.test.ts @@ -1,7 +1,6 @@ import { mkdirSync, readFileSync } from 'fs'; import { join } from 'path'; -import type { ProgramsToInclude } from '../src/cli'; import { runScaffoldCli, setupProgram } from '../src/cli'; import type { ProjectPaths } from './utils/bootstrapProject'; @@ -15,16 +14,6 @@ import { generateArgv } from './utils/generateArgs'; import { mockLogger } from './utils/mockLogger'; import { filterOriginalTemplateFiles, getAllFiles } from './utils/templateFiles'; -const possibleProgramsToInclude: ProgramsToInclude[] = [ - { contract: true, predicate: false, script: false }, - { contract: false, predicate: true, script: false }, - { contract: false, predicate: false, script: true }, - { contract: true, predicate: true, script: false }, - { contract: true, predicate: false, script: true }, - { contract: false, predicate: true, script: true }, - { contract: true, predicate: true, script: true }, -]; - /** * @group node */ @@ -47,36 +36,25 @@ describe('CLI', () => { cleanupFilesystem(); }); - test.each(possibleProgramsToInclude)( - 'create-fuels extracts the template to the specified directory', - async (programsToInclude) => { - const args = generateArgv(programsToInclude, paths.root); + test('create-fuels extracts the template to the specified directory', async () => { + const args = generateArgv(paths.root); - await runScaffoldCli({ - program: setupProgram(), - args, - shouldInstallDeps: false, - }); + await runScaffoldCli({ + program: setupProgram(), + args, + shouldInstallDeps: false, + }); - let originalTemplateFiles = await getAllFiles(paths.template); - originalTemplateFiles = filterOriginalTemplateFiles(originalTemplateFiles, programsToInclude); + let originalTemplateFiles = await getAllFiles(paths.template); + originalTemplateFiles = filterOriginalTemplateFiles(originalTemplateFiles); - const testProjectFiles = await getAllFiles(paths.root); + const testProjectFiles = await getAllFiles(paths.root); - expect(originalTemplateFiles.sort()).toEqual(testProjectFiles.sort()); - } - ); + expect(originalTemplateFiles.sort()).toEqual(testProjectFiles.sort()); + }); test('should rewrite for the appropriate package manager', async () => { - const args = generateArgv( - { - contract: true, - predicate: true, - script: true, - }, - paths.root, - 'bun' - ); + const args = generateArgv(paths.root, 'bun'); await runScaffoldCli({ program: setupProgram(), @@ -95,14 +73,7 @@ describe('CLI', () => { }); test('create-fuels reports an error if the project directory already exists', async () => { - const args = generateArgv( - { - contract: true, - predicate: true, - script: true, - }, - paths.root - ); + const args = generateArgv(paths.root); // Generate the project once mkdirSync(paths.root, { recursive: true }); @@ -120,28 +91,4 @@ describe('CLI', () => { expect.stringContaining(`A folder already exists at ${paths.root}`) ); }); - - test('create-fuels reports an error if no programs are chosen to be included', async () => { - const args = generateArgv( - { - contract: false, - predicate: false, - script: false, - }, - paths.root - ); - - await runScaffoldCli({ - program: setupProgram(), - args, - shouldInstallDeps: false, - forceDisablePrompts: true, - }).catch((e) => { - expect(e).toBeInstanceOf(Error); - }); - - expect(error).toHaveBeenCalledWith( - expect.stringContaining('You must include at least one Sway program.') - ); - }); }); diff --git a/packages/create-fuels/test/e2e.test.ts b/packages/create-fuels/test/e2e.test.ts index 165c45faa7d..9c66b0479e6 100644 --- a/packages/create-fuels/test/e2e.test.ts +++ b/packages/create-fuels/test/e2e.test.ts @@ -16,7 +16,6 @@ import { const { log } = console; const PUBLISHED_NPM_VERSION = process.env.PUBLISHED_NPM_VERSION; -const programsToInclude = { contract: true, predicate: true, script: true }; const packageManagerCreateCommands: [PackageManager, string, string[]][] = [ ['pnpm', 'pnpm --ignore-workspace create fuels', []], ['bun', 'bunx --bun create-fuels', ['/bun.lockb']], @@ -51,11 +50,9 @@ describe('`create fuels` package integrity', () => { return; } - const args = generateArgs(programsToInclude, paths.root, packageManager).join(' '); + const args = generateArgs(paths.root, packageManager).join(' '); const expectedTemplateFiles = await getAllFiles(paths.sourceTemplate).then((files) => - filterOriginalTemplateFiles(files, programsToInclude) - .filter(filterForcBuildFiles) - .concat(additionalFiles) + filterOriginalTemplateFiles(files).filter(filterForcBuildFiles).concat(additionalFiles) ); const { error: createFuelsError } = await safeExec(() => diff --git a/packages/create-fuels/test/utils/generateArgs.ts b/packages/create-fuels/test/utils/generateArgs.ts index 710eba58128..f6ac54cf344 100644 --- a/packages/create-fuels/test/utils/generateArgs.ts +++ b/packages/create-fuels/test/utils/generateArgs.ts @@ -1,29 +1,14 @@ -import type { ProgramsToInclude } from '../../src/cli'; - -export const generateArgs = ( - programsToInclude: ProgramsToInclude, - projectName?: string, - packageManager: string = 'pnpm' -): string[] => { +export const generateArgs = (projectName?: string, packageManager: string = 'pnpm'): string[] => { const args = []; if (projectName) { args.push(projectName); } - if (programsToInclude.contract) { - args.push('-c'); - } - if (programsToInclude.predicate) { - args.push('-p'); - } - if (programsToInclude.script) { - args.push('-s'); - } args.push(`--${packageManager}`); return args; }; -export const generateArgv = ( - programsToInclude: ProgramsToInclude, - projectName?: string, - packageManager: string = 'pnpm' -): string[] => ['', '', ...generateArgs(programsToInclude, projectName, packageManager)]; +export const generateArgv = (projectName?: string, packageManager: string = 'pnpm'): string[] => [ + '', + '', + ...generateArgs(projectName, packageManager), +]; diff --git a/packages/create-fuels/test/utils/templateFiles.ts b/packages/create-fuels/test/utils/templateFiles.ts index 3121ec7b0fe..e2af21ca9e4 100644 --- a/packages/create-fuels/test/utils/templateFiles.ts +++ b/packages/create-fuels/test/utils/templateFiles.ts @@ -1,7 +1,5 @@ import { glob } from 'glob'; -import type { ProgramsToInclude } from '../../src/cli'; - export const getAllFiles = async (pathToDir: string) => { const files = await glob(`${pathToDir}/**/*`, { ignore: ['**/node_modules/**', '**/.next/**', '**/sway-api/**'], @@ -10,25 +8,13 @@ export const getAllFiles = async (pathToDir: string) => { return filesWithoutPrefix; }; -export const filterOriginalTemplateFiles = ( - files: string[], - programsToInclude: ProgramsToInclude -) => { +export const filterOriginalTemplateFiles = (files: string[]) => { let newFiles = [...files]; newFiles = newFiles.filter((file) => { if (file.includes('CHANGELOG')) { return false; } - if (!programsToInclude.contract && file.includes('contract')) { - return false; - } - if (!programsToInclude.predicate && file.includes('predicate')) { - return false; - } - if (!programsToInclude.script && file.includes('script')) { - return false; - } if (['/gitignore', '/env'].includes(file)) { return false; } diff --git a/templates/nextjs/.env.example b/templates/nextjs/.env.example index ba57c6e837e..2c6ac505fa1 100644 --- a/templates/nextjs/.env.example +++ b/templates/nextjs/.env.example @@ -1,5 +1,2 @@ -NEXT_PUBLIC_HAS_CONTRACT=true -NEXT_PUBLIC_HAS_PREDICATE=true -NEXT_PUBLIC_HAS_SCRIPT=true NEXT_PUBLIC_FUEL_NODE_PORT=4000 NEXT_PUBLIC_DAPP_ENVIRONMENT=local \ No newline at end of file diff --git a/templates/nextjs/src/pages/index.tsx b/templates/nextjs/src/pages/index.tsx index 75505c0ded7..e49dfbab13c 100644 --- a/templates/nextjs/src/pages/index.tsx +++ b/templates/nextjs/src/pages/index.tsx @@ -16,10 +16,6 @@ const contractId = ? contractIds.testContract : (process.env.NEXT_PUBLIC_TESTNET_CONTRACT_ID as string); // Testnet Contract ID -const hasContract = process.env.NEXT_PUBLIC_HAS_CONTRACT === "true"; -const hasPredicate = process.env.NEXT_PUBLIC_HAS_PREDICATE === "true"; -const hasScript = process.env.NEXT_PUBLIC_HAS_SCRIPT === "true"; - export default function Home() { const { wallet, walletBalance, refreshWalletBalance } = useActiveWallet(); const [contract, setContract] = useState(); @@ -30,7 +26,7 @@ export default function Home() { * See: https://github.com/streamich/react-use/blob/master/docs/useAsync.md */ useAsync(async () => { - if (hasContract && wallet) { + if (wallet) { const testContract = TestContractAbi__factory.connect(contractId, wallet); setContract(testContract); const { value } = await testContract.functions.get_count().get(); @@ -63,12 +59,10 @@ export default function Home() {

Welcome to Fuel

- {hasContract && ( - - Get started by editing sway-programs/contract/main.sw or{" "} - src/pages/index.tsx. - - )} + + Get started by editing sway-programs/contract/main.sw or{" "} + src/pages/index.tsx. + This template uses the new{" "} @@ -78,32 +72,25 @@ export default function Home() { to enable type-safe hot-reloading for your Sway programs. - {hasContract && ( - <> -

Counter

+ <> +

Counter

- - {counter} - - - - - )} + + {counter} + - {hasPredicate && ( - - Predicate Example - - )} + + - {hasScript && ( - - Script Example - - )} + + Predicate Example + + + Script Example + Fuel Docs