Giter Site home page Giter Site logo

moishinetzer / pbandj Goto Github PK

View Code? Open in Web Editor NEW
107.0 2.0 6.0 1.57 MB

Zero-Config Reusable Component Framework for React ๐Ÿฅœ๐Ÿ’œ

License: MIT License

HTML 2.31% CSS 18.21% TypeScript 26.40% JavaScript 22.48% MDX 30.60%
library npm package react reactjs storybook typescript design-system styleguide zero-config

pbandj's Introduction

The Zero-Config Reusable Component Framework For React


Introduction

PBandJ is an all-in-one tool to quickly create and publish a high-quality component library, taking care of tedious setup and ensuring best practices. Publish your library to be reused across projects or shared with others!

PBandJ works just as well for publishing vanilla TypeScript libraries too!

What's Inside

  • โš›๏ธ React, with TypeScript by default

  • ๐Ÿ“ฆ Tsup for building and bundling

  • ๐Ÿค– GitHub Actions for publishing to npm and testing

  • ๐Ÿ“• Storybook v7 running on Vite for instant HMR

  • โšก Vite playground dev server

  • ๐Ÿฆ‹ Changesets for versioning

  • ๐Ÿงช Vitest for testing

  • ๐Ÿ•ต๏ธโ€โ™‚๏ธ Eslint for linting

  • ๐Ÿ’… Prettier for formatting

Getting Started

To get started run the following:

npx pbandj@latest

This will run you through the CLI to get your project set up with all the tools you need to get started!


๐Ÿš€ Publishing

To publish your library to npm, you need to follow the steps below.

1. Generate a Personal Access Token

To publish your library to npm, you need to generate a personal access token. This is a token that is used to authenticate you when publishing to npm. You can generate one here.

If your account requires 2FA, you will need to generate an Automation token, otherwise, a Publish token will suffice.

2. Add the Token to GitHub Secrets

Once you have generated your token, you need to add it to your GitHub repository as a secret. This is so that the GitHub Action can use it to publish your library to npm. You can find out how to do this here.

Set the name of the secret to NPM_TOKEN and the value to your token.

3. Change the GitHub Workflow Permissions

This can be done by going to the Settings tab of your repository, then going to Actions and then General and changing the Workflow Permissions to allow "Read and Write permissions", and make sure the box that says "Allow GitHub Actions to create and approve pull requests" is checked.

4. Commit a Changeset

Once you have added your token to GitHub secrets, you need to commit a changeset. Generate your first changeset by running:

npx changeset

Then commit the changeset log to trigger the GitHub Action.

See below for more information on how to use changesets.

Note: PBandJ has been configured assuming projects use the main branch as the default branch. If you use a different branch, you will need to change the publish.yml file in the .github/workflows folder to use your default branch. You will also need to change the config.json file in the .changeset folder to use your default branch.

5. Merge the Release PR

Once the GitHub Action has been triggered, it will create a PR that will publish your library to npm. Once the PR has been merged, your library will be published to npm!

Note: Sometimes the GitHub Action can fail, this can be due to a number of reasons most likely it is to do with the name of your package. If this happens, change the name of your package in package.json, and either rerun the action or try again from step 4.

๐Ÿ“ฆ Bundling

This project uses tsup for bundling.

Everything that PBandJ uses is hot-swappable. Meaning, if you don't want to use tsup as a bundler for whatever reason you can easily change it to your favourite bundler. Change the build scripts in package.json to whatever you want.

You can edit the tsup.config.ts file to your liking.

For example, if you wanted to enable code-splitting and minify the code your config would look like this:

// tsup.config.ts

export default defineConfig({
  // ...
  splitting: true,
  minify: true,
});

CSS Caveat

Most bundlers don't bundle CSS by default at all. When they do, it usually requires injecting the styles directly into the head tag, which means that any classes you define could potentially clash with any other project that uses your library.

For this reason, we highly recommend only using CSS Modules (which is what the css-check script checks for) and PostCSS plugins for other transformations.

๐Ÿ“• Storybook

Storybook has been preconfigured to run on Vite, which means that you get instant HMR when developing your components. This is a huge productivity boost when developing components.

To start storybook run:

npm run storybook

PBandJ utilises version 7 of Storybook, which means that you can use the new Component Story Format (CSF) to write your stories.

Check out the official documentation for more information on how to make the most out of the awesome features that Storybook provides.

โšก Vite Dev Server

Each project is preconfigured with a Vite dev server that can be started by running:

npm run dev

This has been provided for those that like to create components in a playground rather than a storybook-first approach.

๐Ÿฆ‹ Changesets

Changesets are used to version your library, and publish it to npm.

To create a changesets run:

npx changeset

Commit the generated changelog to trigger the GitHub Action mentioned below.

The files that you commit alongside the generated changeset log are the changes that will be referenced in the release notes. This means you can commit the changeset log by itself to just trigger the publish without referencing the exact files.

๐Ÿค– GitHub Actions

There are two actions provided out of the box located in the .github/workflows folder.

main.yml:

  • This action is run on all branches.
  • It runs linting, tests, and typechecking.
  • It runs typechecking, and performs a build to make sure it can be built safely.

publish.yml

  • This action is run on the main branch
  • If there is a changeset that was committed, a PR is created that when merged will automatically publish that version to npm.
  • If a publishing PR already exists, the changes are added to that release PR.

๐Ÿงช Testing

There are several approaches to testing components that have been provided out of the box.

Vitest

Vitest is a testing framework that is built on top of Vite. It is a great choice for testing components, as it provides a fast and easy way to test components. It's mainly used to test the functionality of components, rather than the visual aspects, however it can be used for both.

To run the tests, run:

npm run test

Storybook Tests

The recommended way to run storybook tests is to use the Chromatic integration. This is a service that allows you to run visual regression tests on your components.

The setup steps can be found here.

Once that has been set up, you can use the Storybook play function to run integration tests on your components. See the official documentation for more information.

Future Features

There is a planned configuration to be added to the CLI, that will allow simple setup of popular styling frameworks.

These are an example of some that could be added to help users get set up automatically.

Made With PBandJ

Get us started by sharing your component library!

Open up an issue here.

Contributors

Thanks goes to these wonderful people (emoji key):

Moishi Netzer
Moishi Netzer

๐Ÿ’ป ๐Ÿ“–
Alex Maldonado
Alex Maldonado

๐Ÿ’ฌ
Paschal
Paschal

๐Ÿ’ฌ
MartinPlayon
MartinPlayon

๐Ÿ’ป ๐Ÿ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is licensed under the terms of the MIT license.

pbandj's People

Contributors

allcontributors[bot] avatar github-actions[bot] avatar martinplayon avatar moishinetzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pbandj's Issues

Rebuilding on file changes

Is it possible to rebuild the lib on file changes?

I'm coming from tsdx (which sadly looks like it's been abandoned), which has tsdx watch command along with onSuccess and other options.

This is particularly useful when using yalc to be able to automatically re-build the lib and run yalc push whenever a file is changed.

CLI doesn't work properly on Windows

node:child_process:826
    err = new Error(msg);
          ^

Error: Command failed: rm -rf .git
    at checkExecSyncError (node:child_process:826:11)
    at execSync (node:child_process:900:15)
    at C:\User\AppData\Local\npm-cache\_npx\2198dfff2919e4a1\node_modules\pbandj\dist\cli.cjs:36029:37
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 11288,
  stdout: null,
  stderr: null
}

I'm guessing this should be a quick fix

yarn link support?

As much as Storybook is great, sometimes I want to test a library in another repo, and id like to be able to do this before publishing. Can this be done with PRandJ?

Ive done this previously with "yarn link". When I run the command it looks promising:

success Registered "PROJECT-NAME".
info You can now run `yarn link "PROJECT-NAME"` in the projects where you want to use this package and it will be used instead.
โœจ  Done in 0.02s.

But when I try and use it in another repo I get an error:

Module not found: Can't resolve 'PROJECT-NAME'

These steps have worked for me before when my component library was just a .tsx file, so im not sure if my set up is wrong or if this wont work with PRandJ?

Update Node Version on Github Actions

The current GitHub actions are using

 - uses: actions/setup-node@v3
        with:
          node-version: 16.x

This version is out of support. The point of discussion is whether to move to 20 or 18.

20 is about to become LTS, but I don't think that most images are there yet. I know that lambdas are only at 18.

Question; can Vue and Angular be built as well?

Hi,

Forgive what is probably an ignorant question. Can't find the QA site.

I am completely new to this.. I'd love to know if this can also be used to build Vue & Angular components or if it is exclusive to react.

CLI base project has type error

I came across your project (and found it promising). I tried the starter command and notice type syntaxe error highlighting in vsCode. Not sure if this is knowns but here is a screenshot (stories/Button.stories):
Screen Shot 2023-02-19 at 8 46 31 PM
EDIT: nevermind, it was my editor that needed to be restarted

[Documentation] Using other CI pipelines

This is more of a documentation question/issue. If using bitbucket pipelines or Circle CI instead of GitHub actions, how would the deployment configuration need to change?

Tailwindcss Integration

Hi Moishi, First off great job with this package! I'm really interested in integrating tailwindcss. How can we go about that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.