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

chore: add play script #1327

Merged
merged 25 commits into from
Apr 4, 2024
Merged

chore: add play script #1327

merged 25 commits into from
Apr 4, 2024

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Mar 29, 2024

Context

We often need a running Slice Machine instance complete with a Prismic repository. We have projects in the e2e-projects directory to serve that purpose, but they have the following limitations:

  • Tied to a specific Prismic repository.
  • Require access to the Prismic repository.
  • Are version controlled.
  • Are stateful since they are paired to a real Prismic repository.

The Solution

We can use a script to quickly generate new projects with their own Prismic repositories. Projects are generated using Prismic's minimal starters, just like customers would use.

These projects are called "playgrounds" since they allow us to play with Slice Machine while developing.

This PR introduces a new yarn play command. The CLI looks like this:

# Start the most recent playground or create one if none exist.
yarn play

# Start an existing playground or create one if it doesn't exist.
yarn play my-playground-name

# Force create a new playground
yarn play --new
yarn play --new my-playground-name

# Specify a framework (default: next)
yarn play -f sveltekit
yarn play --framework sveltekit

# If `-f` is passed with a playground name and the playground
# already exists, halt. If the playground does not exist, create
# a new one with that framework.
yarn play -f sveltekit my-playground-name

# Don't start the project
yarn play --no-start

# Dry run
yarn play -n
yarn play --dry-run

Both Slice Machine and the playground project are started automatically (unless disabled via --no-start).

Impact / Dependencies

This should make it easier to develop features. It could also streamline how we run end-to-end tests with Playwright.

Checklist before requesting a review

  • I hereby declare my code ready for review.
  • If it is a critical feature, I have added tests.
  • The CI is successful.
  • If there could backward compatibility issues, it has been discussed and planned.

Copy link

vercel bot commented Mar 29, 2024

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

Name Status Preview Updated (UTC)
slice-machine ✅ Ready (Inspect) Visit Preview Apr 4, 2024 1:22am

scripts/play.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@bapmrl bapmrl left a comment

Choose a reason for hiding this comment

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

Quick incomplete review as this is still a draft ^^ Thanks for starting this highly useful work!

scripts/utils/commandUtils.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
playgrounds/package.json Show resolved Hide resolved
playgrounds/package.json Show resolved Hide resolved
@angeloashmore angeloashmore marked this pull request as ready for review March 30, 2024 00:52
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@bapmrl bapmrl left a comment

Choose a reason for hiding this comment

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

This is a really nice advancement to easily work on Slice Machine! Thank you Angelo 😊

⚠️ I just had the following error when trying to access localhost:9999 in Chrome:

play-tall-semla-02707b3 [slicemachine] 
play-tall-semla-02707b3 [slicemachine] > [email protected] slicemachine
play-tall-semla-02707b3 [slicemachine] > ../../packages/start-slicemachine/bin/start-slicemachine.js
play-tall-semla-02707b3 [slicemachine] 
play-tall-semla-02707b3 [next] 
play-tall-semla-02707b3 [next] > [email protected] next:dev
play-tall-semla-02707b3 [next] > next dev --port=8001
play-tall-semla-02707b3 [next] 
play-tall-semla-02707b3 [next]    ▲ Next.js 14.1.4
play-tall-semla-02707b3 [next]    - Local:        http://localhost:8001
play-tall-semla-02707b3 [next] 
play-tall-semla-02707b3 [slicemachine] [HPM] Proxy created: /  -> http://localhost:3000
play-tall-semla-02707b3 [slicemachine] 
play-tall-semla-02707b3 [slicemachine]  Slice Machine v1.26.0  → Running at http://localhost:9999
play-tall-semla-02707b3 [slicemachine] 
play-tall-semla-02707b3 [next]  ✓ Ready in 1431ms
play-tall-semla-02707b3 [slicemachine] [HPM] Error occurred while proxying request localhost:9999/ to http://localhost:3000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
play-tall-semla-02707b3 [slicemachine] [HPM] Error occurred while proxying request localhost:9999/favicon.ico to http://localhost:3000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
play-tall-semla-02707b3 [next]  ○ Compiling / ...
play-tall-semla-02707b3 [next]  ✓ Compiled / in 1237ms (854 modules)
play-tall-semla-02707b3 [next]  ○ Compiling /icon.png ...
play-tall-semla-02707b3 [next]  ✓ Compiled /icon.png in 509ms (541 modules)
play-tall-semla-02707b3 [slicemachine] [HPM] Error occurred while proxying request localhost:9999/ to http://localhost:3000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
play-tall-semla-02707b3 [slicemachine] [HPM] Error occurred while proxying request localhost:9999/favicon.ico to http://localhost:3000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

scripts/play.ts Outdated Show resolved Hide resolved
playgrounds/package.json Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
scripts/play.ts Show resolved Hide resolved
scripts/play.ts Outdated Show resolved Hide resolved
package.json Outdated
Copy link
Collaborator

@bapmrl bapmrl Apr 2, 2024

Choose a reason for hiding this comment

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

⚠️ Is there a way to add the generated playgrounds to the clean script?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but I wonder if we should ask for confirmation before deleting all playgrounds. It's possible a playground could contain a lot of work or a specific set up, and I wouldn't want someone to accidentally lose it all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we could create a simple custom scripts/clean.ts with a prompt?

Copy link
Collaborator

@bapmrl bapmrl Apr 3, 2024

Choose a reason for hiding this comment

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

Oh, you're right. We'll probably have changes we don't want to lose.

Consequently, I think we can either:

  1. Keep it simple and not change anything.
  2. Update the clean script so that it only deletes well known build/cache directories in the playgrounds. For example, it could delete the nested .next directories. Of course, it shouldn't accidentally delete content in the playgrounds/node_modules directory or other configuration files.

Copy link
Member Author

Choose a reason for hiding this comment

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

To expedite merging this PR, let's not change the clean script for now. We can revisit it in a future PR. I like the second idea, perhaps in addition to the ability to delete playgrounds.

@angeloashmore
Copy link
Member Author

angeloashmore commented Apr 2, 2024

@bapmrl: ⚠️ I just had the following error when trying to access localhost:9999 in Chrome…

You may not have had the Slice Machine development server running. You need to run yarn dev in a separate terminal in order to run the playground.

I considered running yarn dev into the yarn play script, but I wasn't sure if that added complexity was worth it. What do you think?

@bapmrl
Copy link
Collaborator

bapmrl commented Apr 3, 2024

@bapmrl: ⚠️ I just had the following error when trying to access localhost:9999 in Chrome…

You may not have had the Slice Machine development server running. You need to run yarn dev in a separate terminal in order to run the playground.

I considered running yarn dev into the yarn play script, but I wasn't sure if that added complexity was worth it. What do you think?

You're right. I forgot to run yarn dev and doing it automatically in the play script would make it too complex. Let's keep it this way. It's perfect!

Copy link
Collaborator

@bapmrl bapmrl left a comment

Choose a reason for hiding this comment

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

❤️ This is truly excellent and will greatly help us!

I'm approving as there are just 4 comments remaining. Don't forget the little suggestion for the exec function ^^

scripts/play.ts Outdated Show resolved Hide resolved
@angeloashmore angeloashmore merged commit 91b4fb5 into main Apr 4, 2024
33 checks passed
@angeloashmore angeloashmore deleted the aa/playground-script branch April 4, 2024 01:32
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