-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add infra to support multiple
create fuels
templates (#2851)
* chore: add infra to support multiple `create fuels` templates * add docs * disable pr release * move template name validation to the top * add default value * refactor * pass template name in tests via args * mock `doesTemplateExist` * remove param * add missing testing groups * refactor * switch to named params for `generateArgs.ts` * use `spyOn` to mock * use `mockReturnValueOnce`
- Loading branch information
Showing
11 changed files
with
127 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-fuels": patch | ||
--- | ||
|
||
chore: add infra to support multiple `create fuels` templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { doesTemplateExist } from './doesTemplateExist'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
test('doesTemplateExist should return true if the template exists', () => { | ||
expect(doesTemplateExist('nextjs')).toBeTruthy(); | ||
}); | ||
|
||
test('doesTemplateExist should return false if the template does not exist', () => { | ||
// @ts-expect-error intentionally passing in a non-existent template | ||
expect(doesTemplateExist('non-existent-template')).toBeFalsy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { Template } from './setupProgram'; | ||
import { templates } from './setupProgram'; | ||
|
||
export const doesTemplateExist = (templateName: Template): boolean => templates.has(templateName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
export const generateArgs = (projectName?: string, packageManager: string = 'pnpm'): string[] => { | ||
export const generateArgs = ({ | ||
projectName, | ||
packageManager = 'pnpm', | ||
template, | ||
}: { | ||
projectName?: string; | ||
packageManager: string; | ||
template?: string; | ||
}): string[] => { | ||
const args = []; | ||
if (packageManager === 'npm') { | ||
args.push('--'); | ||
} | ||
if (projectName) { | ||
args.push(projectName); | ||
} | ||
if (template) { | ||
args.push(`--template`); | ||
args.push(template); | ||
} | ||
args.push(`--${packageManager}`); | ||
args.push(`--no-install`); | ||
return args; | ||
}; | ||
|
||
export const generateArgv = (projectName?: string, packageManager: string = 'pnpm'): string[] => [ | ||
'', | ||
'', | ||
...generateArgs(projectName, packageManager), | ||
]; | ||
export const generateArgv = ({ | ||
projectName, | ||
packageManager = 'pnpm', | ||
template, | ||
}: { | ||
projectName?: string; | ||
packageManager?: string; | ||
template?: string; | ||
}): string[] => ['', '', ...generateArgs({ projectName, packageManager, template })]; |