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(cli): CATALYST-246 create-catalyst login, create env, scaffold project #474

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

matthewvolk
Copy link
Contributor

@matthewvolk matthewvolk commented Feb 1, 2024

What/Why?

  • Adds initial commands for the create-catalyst CLI: create and init.
  • create is the default command, and invoked by running [npm|pnpm|yarn] create @bigcommerce/catalyst@latest. The command accepts a number of configurable options that can be passed as flags the CLI command (this is mostly useful for running the CLI in a CI environment). A number of the configurable options have some default values if they are left empty. If no options are passed as flags, the user is prompted to enter values for each option via terminal input. The end result is a Catalyst project, created in a local directory, with an (optionally) configured environment variable file, with dependencies installed, and if the environment variable file is configured, the create command also runs GraphQL codegen for GraphQL types + lints the project to ensure the project can build without errors.
  • init is a utility command that can be used to swap the store that the Catalyst project is connected to. Running [npx|pnpx|yarn dlx] @bigcommerce/create-catalyst init prompts the user for authentication credentials to a BigCommerce store, and when successfully authenticated, overwrites the current local .env.local file with new environment variables that belong to the newly authenticated store.

Testing

Includes Unit and Integration tests

@matthewvolk matthewvolk requested a review from a team February 1, 2024 15:47
Copy link

vercel bot commented Feb 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-2000ms-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 13, 2024 8:56pm
catalyst-core-kynz ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 13, 2024 8:56pm
catalyst-latest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 13, 2024 8:56pm
catalyst-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 13, 2024 8:56pm
catalyst-uk 🔄 Building (Inspect) Visit Preview 💬 Add feedback Feb 13, 2024 8:56pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
catalyst ⬜️ Ignored (Inspect) Visit Preview Feb 13, 2024 8:56pm
catalyst-1millionproducts-store ⬜️ Ignored (Inspect) Visit Preview Feb 13, 2024 8:56pm
catalyst-500ms-api ⬜️ Ignored (Inspect) Visit Preview Feb 13, 2024 8:56pm
catalyst-ppr ⬜️ Ignored (Inspect) Visit Preview Feb 13, 2024 8:56pm

package.json Outdated Show resolved Hide resolved
@matthewvolk matthewvolk force-pushed the create-catalyst branch 3 times, most recently from c069937 to a78022a Compare February 1, 2024 16:00
@vercel vercel bot temporarily deployed to Preview – catalyst-core-kynz February 1, 2024 16:07 Inactive
@vercel vercel bot temporarily deployed to Preview – catalyst-core-kynz February 1, 2024 16:32 Inactive
@vercel vercel bot temporarily deployed to Preview – catalyst-core-kynz February 1, 2024 16:49 Inactive
@vercel vercel bot temporarily deployed to Preview – catalyst-core-kynz February 1, 2024 16:54 Inactive
@matthewvolk
Copy link
Contributor Author

@bigcommerce/team-catalyst PR description updated + branch rebased. This one is ready for a final review 👍

Copy link
Contributor

⚡️🏠 Lighthouse report

We ran Lighthouse against the changes and produced this report. Here's the summary:

Category Score
🟢 Performance 98
🟢 Accessibility 95
🟠 Best practices 78
🟢 SEO 92

Lighthouse ran against https://catalyst-latest-4qcnzug32-bigcommerce-platform.vercel.app/

@vercel vercel bot temporarily deployed to Preview – catalyst-core-kynz February 13, 2024 20:56 Inactive
Copy link
Contributor

@jorgemoya jorgemoya left a comment

Choose a reason for hiding this comment

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

A lot to unpack but looks good to me!

@matthewvolk matthewvolk added this pull request to the merge queue Feb 14, 2024
Merged via the queue into main with commit 57996e8 Feb 14, 2024
18 checks passed
@matthewvolk matthewvolk deleted the create-catalyst branch February 14, 2024 01:44
Copy link
Contributor

@chanceaclark chanceaclark left a comment

Choose a reason for hiding this comment

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

I know you already merged this but left a few comments for cleanup whenever you get around to it!

Comment on lines +1 to +12
module.exports = {
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.(t|j)s?$': '@swc/jest',
},
transformIgnorePatterns: [],
// moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testEnvironment: 'node',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

All you need is this (see tsconfig.json comments):

Suggested change
module.exports = {
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.(t|j)s?$': '@swc/jest',
},
transformIgnorePatterns: [],
// moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testEnvironment: 'node',
};
module.exports = {
transform: {
'^.+\\.(t|j)s?$': '@swc/jest',
},
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of this looks good! However, I do need to keep the moduleNameMapper because this is a "type": "module" package, and the .js extensions on imports are not found if the mapper is not present

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops 🤦‍♂️ Had to restart ESLint, and now the changes are working. Removing moduleNameMapper! Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

Try changing the tsconfig to this along with the jest config changes.

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Node 18",
  "compilerOptions": {
    "strict": true,
    "target": "es6",
    "module": "ESNext",
    "esModuleInterop": true,
    "moduleResolution": "Bundler",
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
  }
}

Additionally, let's remove disable the dts option and enable sourcemap in tsup.config.ts. We don't need types exported with the CLI and sourcemaps will be helpful for debugging.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be okay to remove with the jest + tsconfig changes.

`BIGCOMMERCE_STORE_HASH=${storeHash}`,
`BIGCOMMERCE_CHANNEL_ID=${channelId}`,
`BIGCOMMERCE_ACCESS_TOKEN=${accessToken}`,
`BIGCOMMERCE_CUSTOMER_IMPERSONATION_TOKEN=${customerImpersonationToken}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add this?

CLIENT_LOGGER="false"

@@ -0,0 +1,29 @@
import { oraPromise } from 'ora';

import { spinner } from './spinner.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

With the tsconfig changes, you can remove the .js extension.

Comment on lines +7 to +12
let projectName = kebabCase(opts.projectName);
let projectDir = opts.projectDir && projectName ? join(opts.projectDir, projectName) : undefined;

if (projectDir && projectName) {
return { projectDir, projectName };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 Instead of using let's, we can just do something like this just to clean these files up.

Suggested change
let projectName = kebabCase(opts.projectName);
let projectDir = opts.projectDir && projectName ? join(opts.projectDir, projectName) : undefined;
if (projectDir && projectName) {
return { projectDir, projectName };
}
if (opts.projectName && opts.projectDir) {
return {
projectDir: join(opts.projectDir, projectName),
projectName: kebabCase(opts.projectName),
};
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is a little tricky, and the more I think about it, I think there's a lot of refactoring that I'm gonna need to do around each option. In this case:

  • projectDir and projectName can be passed as CLI flags
  • projectName is optional, and if not passed as a flag it would be equal to undefined in this function.
  • If projectName is undefined, we need to not return, because we need to prompt the user to enter a project name
  • If projectName is defined but invalid (such as entering weird characters like *), I need to throw an error (just noticed this isn't currently accounted for)
  • It's possible for projectName to be a space character, in which case I need to throw an error (this isn't accounted for either)
  • projectDir always defaults to process.cwd(), but if the user enters a path that does not exist, I need to throw

I think I can reuse the validate method lower down in this file to help with a lot of this. I'll rework it in a separate PR 👍

Comment on lines +17 to +48
constructor({
bigCommerceApiUrl,
storeHash,
accessToken,
}: {
bigCommerceApiUrl: string;
storeHash: string;
accessToken: string;
});
constructor({
sampleDataApiUrl,
storeHash,
accessToken,
}: {
sampleDataApiUrl: string;
storeHash: string;
accessToken: string;
});
constructor({ bigCommerceAuthUrl }: { bigCommerceAuthUrl: string });
constructor({
bigCommerceApiUrl,
bigCommerceAuthUrl,
sampleDataApiUrl,
storeHash,
accessToken,
}: {
bigCommerceApiUrl?: string;
bigCommerceAuthUrl?: string;
sampleDataApiUrl?: string;
storeHash?: string;
accessToken?: string;
}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 Would love some descriptive interfaces for these overloaded args.

message: 'Which channel would you like to use?',
choices: activeChannels
.sort((a, b) => channelSortOrder.indexOf(a.platform) - channelSortOrder.indexOf(b.platform))
.map((ch) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 :nit:

Suggested change
.map((ch) => ({
.map((channel) => ({

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants