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

feat: optionally auto-install fuelup during create fuels routine #2149

Merged
merged 29 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d049507
feat: optionally auto-install `fuelup` during `create fuels` routine
Dhaiwat10 Apr 23, 2024
b3fea24
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 Apr 23, 2024
5e96de3
remove execa
Dhaiwat10 Apr 24, 2024
0508c61
reword string
Dhaiwat10 Apr 24, 2024
ca12b87
merge
Dhaiwat10 Apr 24, 2024
f0fe416
fix lockfile
Dhaiwat10 Apr 24, 2024
8399c0a
revert unnecessary change
Dhaiwat10 Apr 24, 2024
5be777f
add changeset
Dhaiwat10 Apr 24, 2024
e7169a9
add warning for manual installation
Dhaiwat10 Apr 24, 2024
4500048
update prompt message
Dhaiwat10 Apr 25, 2024
14b37d5
update message
Dhaiwat10 Apr 25, 2024
8e717b9
Merge remote-tracking branch 'origin' into dp/install-fuelup
Dhaiwat10 Apr 25, 2024
d89e4bb
add error msg if installation fails
Dhaiwat10 Apr 25, 2024
a813511
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 Apr 26, 2024
fe89b9e
add missing param
Dhaiwat10 Apr 27, 2024
0e8f0a1
refactor
Dhaiwat10 Apr 27, 2024
db06cdc
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 Apr 27, 2024
b22596c
better spacing
Dhaiwat10 Apr 27, 2024
1286013
Merge branch 'dp/install-fuelup' of https://github.com/FuelLabs/fuels…
Dhaiwat10 Apr 27, 2024
8757c11
prevent tests hanging
Dhaiwat10 Apr 27, 2024
e1f8c6c
disable pr release
Dhaiwat10 Apr 27, 2024
3de00d2
Merge branch 'master' into dp/install-fuelup
maschad Apr 29, 2024
64c5027
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 Apr 29, 2024
329f39c
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 Apr 30, 2024
c403f67
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 Apr 30, 2024
85f88fe
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 May 1, 2024
c62f8c1
Merge branch 'master' of github.com:FuelLabs/fuels-ts into dp/install…
petertonysmith94 May 6, 2024
8d52c3d
Merge branch 'master' of github.com:FuelLabs/fuels-ts into dp/install…
petertonysmith94 May 6, 2024
772b09e
Merge branch 'master' into dp/install-fuelup
Dhaiwat10 May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-points-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": minor
---

feat: optionally auto-install `fuelup` during `create fuels` routine
46 changes: 46 additions & 0 deletions packages/create-fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import prompts from 'prompts';

import packageJson from '../package.json';

import { checkIfFuelUpInstalled, installFuelUp } from './lib';

const log = (...data: unknown[]) => {
process.stdout.write(`${data.join(' ')}\n`);
};
Expand Down Expand Up @@ -113,6 +115,46 @@ function writeEnvFile(envFilePath: string, programsToInclude: ProgramsToInclude)
writeFileSync(envFilePath, newFileContents);
}

async function promptForFuelUpInstall() {
const shouldInstallFuelUp = await prompts(
{
type: 'confirm',
name: 'shouldInstallFuelUp',
message:
"It seems you don't have `fuelup` installed. `fuelup` is required to manage the Fuel toolchain and is a prerequisite for using this template app. Do you want to install it now?",
initial: true,
},
{ onCancel: () => process.exit(0) }
);
return shouldInstallFuelUp.shouldInstallFuelUp as boolean;
}

async function tryInstallFuelup(isVerbose: boolean = false) {
const fuelUpSpinner = ora({
text: 'Checking if fuelup is installed..',
color: 'green',
}).start();

if (checkIfFuelUpInstalled()) {
fuelUpSpinner.succeed('fuelup is already installed.');
return;
}

fuelUpSpinner.fail('fuelup not found.');

const shouldInstall = await promptForFuelUpInstall();

if (shouldInstall) {
installFuelUp(isVerbose);
} else {
log(
chalk.yellow(
'Warning: You will need to install fuelup manually. See https://docs.fuel.network/guides/installation/#running-fuelup-init'
)
);
}
}

export const setupProgram = () => {
const program = new Command(packageJson.name)
.version(packageJson.version)
Expand Down Expand Up @@ -144,6 +186,10 @@ export const runScaffoldCli = async ({
let projectPath = program.args[0] ?? (await promptForProjectPath());
const verboseEnabled = program.opts().verbose ?? false;

if (!process.env.VITEST) {
await tryInstallFuelup(verboseEnabled);
}

while (existsSync(projectPath)) {
log(
chalk.red(
Expand Down
32 changes: 32 additions & 0 deletions packages/create-fuels/src/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { execSync } from 'child_process';
import { log } from 'console';
import ora from 'ora';

export const checkIfFuelUpInstalled = () => {
try {
execSync('fuelup --version', { stdio: 'pipe' });
return true;
} catch (error) {
return false;
}
};

export const installFuelUp = (isVerbose: boolean = false) => {
const installFuelUpSpinner = ora({
text: 'Installing fuelup..',
color: 'green',
});
try {
execSync(`curl https://install.fuel.network | sh`, { stdio: 'inherit' });
installFuelUpSpinner.succeed('Successfully installed fuelup!');
} catch (error) {
if (isVerbose) {
log(error);
}
log(
installFuelUpSpinner.fail(
'An error occurred while installing `fuelup`. Please try again, or try installing it manually. See https://docs.fuel.network/guides/installation/#running-fuelup-init for more information.'
)
);
}
};