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

chore: remove some choices from create-fuels CLI #2444

Merged
merged 27 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
46049e8
remove some choices
Dhaiwat10 Jun 4, 2024
bb6bd42
enable pr release
Dhaiwat10 Jun 4, 2024
86dc280
delete unnecessary files, make npm default
Dhaiwat10 Jun 12, 2024
597810a
Merge branch 'master' into dp/create-fuels-remove-extra-choices
Dhaiwat10 Jun 12, 2024
33c51d6
fix merge conflicts
Dhaiwat10 Jun 12, 2024
95b1615
remove old exports
Dhaiwat10 Jun 12, 2024
e377d6b
fix lint errors
Dhaiwat10 Jun 12, 2024
297dbbe
add changeset
Dhaiwat10 Jun 12, 2024
5e1770f
fix changeset
Dhaiwat10 Jun 12, 2024
347dfee
fix test
Dhaiwat10 Jun 12, 2024
7ed719d
fix lint errors
Dhaiwat10 Jun 12, 2024
2916ba3
fix lint error
Dhaiwat10 Jun 12, 2024
60f7fd8
Merge branch 'master' into dp/create-fuels-remove-extra-choices
Dhaiwat10 Jun 13, 2024
d956767
remove outdated test
Dhaiwat10 Jun 13, 2024
e78406a
Merge branch 'dp/create-fuels-remove-extra-choices' of https://github…
Dhaiwat10 Jun 13, 2024
d75c0cb
fix failing test, remove unnecessary awaits
Dhaiwat10 Jun 13, 2024
e330021
remove asyncs
Dhaiwat10 Jun 13, 2024
a34e74e
Merge branch 'master' into dp/create-fuels-remove-extra-choices
Dhaiwat10 Jun 17, 2024
8f42989
Merge branch 'master' into dp/create-fuels-remove-extra-choices
Dhaiwat10 Jun 18, 2024
1af40ca
remove from docs
Dhaiwat10 Jun 18, 2024
c90a345
remove env vars, fix up tests
Dhaiwat10 Jun 18, 2024
e5a8da5
disable pr release
Dhaiwat10 Jun 18, 2024
e13eef3
Merge branch 'master' into dp/create-fuels-remove-extra-choices
petertonysmith94 Jun 19, 2024
2280d6c
Merge branch 'master' into dp/create-fuels-remove-extra-choices
maschad Jun 19, 2024
0b149d2
Merge branch 'master' into dp/create-fuels-remove-extra-choices
petertonysmith94 Jun 20, 2024
8a23dbb
Merge branch 'master' into dp/create-fuels-remove-extra-choices
petertonysmith94 Jun 20, 2024
e183684
Merge branch 'master' into dp/create-fuels-remove-extra-choices
petertonysmith94 Jun 20, 2024
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/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
2 changes: 1 addition & 1 deletion .github/workflows/pr-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: "Release PR to npm"
runs-on: ubuntu-latest
# comment out if:false to enable release PR to npm
if: false
# if: false
Dhaiwat10 marked this conversation as resolved.
Show resolved Hide resolved
permissions: write-all
steps:
- name: Checkout
Expand Down
18 changes: 7 additions & 11 deletions packages/create-fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { join } from 'path';
import { tryInstallFuelUp } from './lib';
import { getPackageManager } from './lib/getPackageManager';
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';
Expand Down Expand Up @@ -50,20 +50,18 @@ 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 @@ -102,9 +100,11 @@ export const runScaffoldCli = async ({
if (hasAnyCliProgramsToInclude) {
programsToInclude = cliProgramsToInclude;
} else {
programsToInclude = await promptForProgramsToInclude({
forceDisablePrompts,
});
programsToInclude = {
contract: true,
predicate: true,
script: true,
};
}

while (!programsToInclude.contract && !programsToInclude.predicate && !programsToInclude.script) {
Expand All @@ -114,10 +114,6 @@ export const runScaffoldCli = async ({
if (process.env.VITEST) {
throw new Error();
}

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

const fileCopySpinner = ora({
Expand Down
48 changes: 13 additions & 35 deletions packages/create-fuels/src/lib/getPackageManager.test.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};

Expand All @@ -35,20 +30,20 @@ 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);
}
);

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;

Expand All @@ -58,50 +53,33 @@ 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);

expect(run).toEqual(expectedRunCommand);
}
);

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);
});
});
8 changes: 2 additions & 6 deletions packages/create-fuels/src/lib/getPackageManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { promptForPackageManager } from '../prompts';
import { warn } from '../utils/logger';

import type { ProgramOptions } from './setupProgram';
Expand Down Expand Up @@ -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,
Expand All @@ -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];
};
6 changes: 3 additions & 3 deletions packages/create-fuels/src/lib/setupProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const setupProgram = () => {
.option('-c, --contract', 'Include contract program')
.option('-p, --predicate', 'Include predicate program')
.option('-s, --script', 'Include script program')
Dhaiwat10 marked this conversation as resolved.
Show resolved Hide resolved
.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')
arboleya marked this conversation as resolved.
Show resolved Hide resolved
.option('--verbose', 'Enable verbose logging')
.addHelpCommand()
.showHelpAfterError(true);
Expand Down
2 changes: 0 additions & 2 deletions packages/create-fuels/src/prompts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from './promptFuelUpInstall';
export * from './promptForProjectPath';
export * from './promptForPackageManager';
export * from './promptForProgramsToInclude';

This file was deleted.

21 changes: 0 additions & 21 deletions packages/create-fuels/src/prompts/promptForPackageManager.ts

This file was deleted.

Loading
Loading