Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/lovely-camels-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/create-catalyst": minor
---

Adds an option to include the functional test suite as part of the create command. Defaults to false.
6 changes: 3 additions & 3 deletions packages/create-catalyst/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { writeEnv } from '../utils/write-env';
const exec = promisify(execCallback);

export const create = async (options: CreateCommandOptions) => {
const { packageManager, codeEditor } = options;
const { packageManager, codeEditor, includeFunctionalTests } = options;

const URLSchema = z.string().url();
const sampleDataApiUrl = parse(options.sampleDataApiUrl, URLSchema);
Expand Down Expand Up @@ -97,7 +97,7 @@ export const create = async (options: CreateCommandOptions) => {
if (!storeHash || !accessToken) {
console.log(`\nCreating '${projectName}' at '${projectDir}'\n`);

await cloneCatalyst({ projectDir, projectName, ghRef, codeEditor });
await cloneCatalyst({ projectDir, projectName, ghRef, codeEditor, includeFunctionalTests });

console.log(`\nUsing ${chalk.bold(packageManager)}\n`);

Expand Down Expand Up @@ -193,7 +193,7 @@ export const create = async (options: CreateCommandOptions) => {

console.log(`\nCreating '${projectName}' at '${projectDir}'\n`);

await cloneCatalyst({ projectDir, projectName, ghRef, codeEditor });
await cloneCatalyst({ projectDir, projectName, ghRef, codeEditor, includeFunctionalTests });

writeEnv(projectDir, {
channelId: channelId.toString(),
Expand Down
5 changes: 5 additions & 0 deletions packages/create-catalyst/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ const createCommand = program
.default('vscode')
.hideHelp(),
)
.addOption(
new Option('--include-functional-tests', 'Include the functional test suite')
.default(false)
.hideHelp(),
)
.action((opts) => create(opts));

export type CreateCommandOptions = Options<typeof createCommand>[0];
Expand Down
26 changes: 26 additions & 0 deletions packages/create-catalyst/src/utils/clone-catalyst.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from 'chalk';
import { readFile, writeFile } from 'fs/promises';
import { copySync, ensureDir, readJsonSync, removeSync, writeJsonSync } from 'fs-extra/esm';
import { downloadTemplate } from 'giget';
import merge from 'lodash.merge';
Expand All @@ -9,11 +10,13 @@ import { spinner } from './spinner';

export const cloneCatalyst = async ({
codeEditor,
includeFunctionalTests,
projectDir,
projectName,
ghRef = 'main',
}: {
codeEditor: string;
includeFunctionalTests: boolean;
projectDir: string;
projectName: string;
ghRef?: string;
Expand Down Expand Up @@ -93,6 +96,11 @@ export const cloneCatalyst = async ({
delete packageJson.devDependencies['react-dom']; // will go away
delete packageJson.devDependencies['@bigcommerce/eslint-config-catalyst'];

if (!includeFunctionalTests) {
delete packageJson.devDependencies['@faker-js/faker'];
delete packageJson.devDependencies['@playwright/test'];
}

writeJsonSync(join(projectDir, 'package.json'), packageJson, { spaces: 2 });

const tsConfigJson = z
Expand All @@ -108,6 +116,7 @@ export const cloneCatalyst = async ({
.passthrough(),
})
.passthrough(),
include: z.array(z.string()).optional(),
})
.passthrough()
.parse(
Expand All @@ -123,7 +132,24 @@ export const cloneCatalyst = async ({

tsConfigJson.compilerOptions.paths['@bigcommerce/components/*'] = ['./components/ui/*'];

if (!includeFunctionalTests) {
tsConfigJson.include = tsConfigJson.include?.filter(
(include) => !['tests/**/*', 'playwright.config.ts'].includes(include),
Comment thread
chanceaclark marked this conversation as resolved.
Outdated
);
}

writeJsonSync(join(projectDir, 'tsconfig.json'), tsConfigJson, { spaces: 2 });

if (!includeFunctionalTests) {
const eslint = (await readFile(join(projectDir, '.eslintrc.cjs'), { encoding: 'utf-8' }))
.replace(/['"]\/playwright-report\/\*\*['"],?/, '')
.replace(/['"]\/test-results\/\*\*['"],?/, '');
Comment on lines 145 to 146
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using regex instead as it could be multi-lined. Pretty sure eslint --fix will take care of the formatting. If not we can always revisit it and do some cleanup here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here were the regex test cases I used:
Screenshot 2024-04-23 at 11 28 52


await writeFile(join(projectDir, '.eslintrc.cjs'), eslint);

removeSync(join(projectDir, 'tests'));
removeSync(join(projectDir, 'playwright.config.ts'));
}

removeSync(join(projectDir, 'tmp'));
};