Skip to content

Commit

Permalink
fix: passing arguments with NPM (FuelLabs#2563)
Browse files Browse the repository at this point in the history
* docs: added correct NPM option format

* chore: added npm to e2e test

* chore: changeset

* chore: made opts `no-install`

* chore: fix merge
  • Loading branch information
petertonysmith94 authored Jun 20, 2024
1 parent de4e16f commit 95d351b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
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
2 changes: 1 addition & 1 deletion 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 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
15 changes: 6 additions & 9 deletions packages/create-fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ function writeEnvFile(envFilePath: string) {
export const runScaffoldCli = async ({
program,
args = process.argv,
shouldInstallDeps = false,
}: {
program: Command;
args: string[];
shouldInstallDeps?: boolean;
}) => {
program.parse(args);

Expand Down Expand Up @@ -120,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
2 changes: 2 additions & 0 deletions packages/create-fuels/src/lib/setupProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ProgramOptions {
npm?: boolean;
bun?: boolean;
verbose?: boolean;
'no-install'?: boolean;
}

export const setupProgram = () => {
Expand All @@ -20,6 +21,7 @@ export const setupProgram = () => {
.option('--npm', 'Use npm to install dependencies')
.option('--bun', 'Use bun to install dependencies')
.option('--verbose', 'Enable verbose logging')
.option('--no-install', `Do not install dependencies after scaffolding`, false)
.addHelpCommand()
.showHelpAfterError(true);
return program;
Expand Down
3 changes: 0 additions & 3 deletions packages/create-fuels/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('CLI', () => {
await runScaffoldCli({
program: setupProgram(),
args,
shouldInstallDeps: false,
});

let originalTemplateFiles = await getAllFiles(paths.template);
Expand All @@ -59,7 +58,6 @@ describe('CLI', () => {
await runScaffoldCli({
program: setupProgram(),
args,
shouldInstallDeps: false,
});

const packageJsonPath = join(paths.root, 'package.json');
Expand All @@ -82,7 +80,6 @@ describe('CLI', () => {
await runScaffoldCli({
program: setupProgram(),
args,
shouldInstallDeps: false,
}).catch((e) => {
expect(e).toBeInstanceOf(Error);
});
Expand Down
13 changes: 7 additions & 6 deletions packages/create-fuels/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {

const { log } = console;

const PUBLISHED_NPM_VERSION = process.env.PUBLISHED_NPM_VERSION;
const packageManagerCreateCommands: [PackageManager, string, string[]][] = [
['pnpm', 'pnpm --ignore-workspace create fuels', []],
['bun', 'bunx --bun create-fuels', ['/bun.lockb']],
const PUBLISHED_NPM_VERSION = process.env.PUBLISHED_NPM_VERSION ?? 'next';
const packageManagerCreateCommands: [PackageManager, string][] = [
['pnpm', 'pnpm --ignore-workspace create fuels'],
['bun', 'bunx --bun create-fuels'],
['npm', 'npm create fuels'],
];

/**
Expand All @@ -45,14 +46,14 @@ describe('`create fuels` package integrity', () => {

it.each(packageManagerCreateCommands)(
`should perform 'create fuels' using '%s'`,
async (packageManager, createCommand, additionalFiles) => {
async (packageManager, createCommand) => {
if (shouldSkip) {
return;
}

const args = generateArgs(paths.root, packageManager).join(' ');
const expectedTemplateFiles = await getAllFiles(paths.sourceTemplate).then((files) =>
filterOriginalTemplateFiles(files).filter(filterForcBuildFiles).concat(additionalFiles)
filterOriginalTemplateFiles(files).filter(filterForcBuildFiles)
);

const { error: createFuelsError } = await safeExec(() =>
Expand Down
4 changes: 4 additions & 0 deletions packages/create-fuels/test/utils/generateArgs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
export const generateArgs = (projectName?: string, packageManager: string = 'pnpm'): string[] => {
const args = [];
if (packageManager === 'npm') {
args.push('--');
}
if (projectName) {
args.push(projectName);
}
args.push(`--${packageManager}`);
args.push(`--no-install`);
return args;
};

Expand Down

0 comments on commit 95d351b

Please sign in to comment.