This guide is written for Glitch team members making changes to our shared-components project.
- Making changes to shared components
- Viewing shared components in app context
- Code Review
- Publishing and Deploying
- Additional Resources
This package renders its own documentation and development environment. You can edit this project by either creating a remix of shared-components (remix link) or working with it locally (Clone the repo, npm install
, npm start
). When running locally, you may wish to add a .env file so that the project consistently starts on the same port. See .sample.env for an example.
- Add the component you need in the appropriate
lib/type-of-thing.js
file. - Add some stories.
- A Story is a component exported from your
lib/
file whose name starts withStory
.- A Story with no underscore in the name will appear in the side navigation of the documentation page. (
StoryButton
) - A Story with an underscore in the name will not appear in the side navigation, but can still be deep-linked to. (`StoryTextInput_and_TextArea_variants)
- A Story with no underscore in the name will appear in the side navigation of the documentation page. (
- If you've added stories to a new
lib/
file, add an import for that file at the top oflib/stories.js
and add the variable you imported to themodules
array. - All stories that are exported from files included in
stories.js
will appear on the documentation site. (the root webpage of your running app, or shared-components.glitch.me)
- A Story is a component exported from your
- important! Export your new component from
lib/index.js
. This is how your component gets into the NPM shared-components package.
All emoji assets live directly in the shared-components app's .glitch-assets. To add a new emoji:
- Make sure that the changes has been approved by someone in #design
- Resize and scale the emoji bitmap. All emojis should be 64x64 pngs that have been compressed using Pngyu. Each image should be on the order of <~5kb in size.
- Upload the image directly to shared-component .glitch-assets (NOTE: the image is uploaded to shared-components, not your remix!)
- In your remix, add the emoji alphabetically to
icons
in icon.js. The name should match that on emojipedia and uses camelCase when needed. - Follow the rest of the steps below to finish submitting your PR.
While the components in shared-components should be the kind of components you can build in isolation of any particular consumer, you may wish to see it in the context of your application.
One way to do that is to use this package's helper createRemoteComponent
that loads a development version of the library from a URL. For example:
import { Icon, createRemoteComponent } from '@glitchdotcom/shared-components'
const DevIcon = createRemoteComponent('https://sour-environment.glitch.me/module.js', 'Icon');
In the above case, <Icon>
will render the Icon component as its defined in the version of shared-components on npm, but <DevIcon>
will render the Icon component as its currently defined in the sour-environment
remix of shared-components. If you change how Icon renders in this remix, it will be reflected in how DevIcon renders in your application.
Note that at this time, this only works for React components, not themes or other imports.
You can see a demo of this in /test/remote-component/index.js
.
Create a remix of shared-components (remix link) and make all your changes within the remix .
Note:
- this does not currently work with SSR in the community site. The current work around is to go in Glitch-Community/server/routes.js and change this line:
const renderPage = require('./render');
to
const renderPage = () => ({ html: null, helmet: null, styleTags: null });
Another note: if you plan on using this component in multiple places you'll have to add the createRemoteComponent every place the component is used. This might be tricky if you're editing a component that's used widely, so you may wish to try the following process below instead.
You may decide you'd rather work locally or you'd rather test an entire version of shared-components before publishing. There are a number of different ways to do this but here is one possible route that may work for you:
-
cd into shared-components
- run
npm link
- run
npm run rollup:watch
- run
-
in your editor, in the community site project:
- in aliases.js, add:
react: path.resolve('./node_modules/react'), 'styled-components': path.resolve('./node_modules/styled-components'),
We do this because otherwise shared-components will use its own version of react and styled-components, and you'll get an error message mentioning invalid hooks if you don't add the react alias. In theory any package shared-components uses that is also used by community will need a similar alias to ensure we're only using one dependency.
-
in a new terminal tab (
rollup:watch
should still be running in the shared-components tab), cd into community- run
npm uninstall @glitchdotcom/shared-components
- run
npm link @glitchdotcom/shared-components
- run
-
After making changes to a shared component that you'd like to see reflected in your community site build, restart the community server
- you don't have to do anything in the terminal to rebuild shared-components;
rollup:watch
is handling that for you - there are supposedly ways to make you not have to restart community, by
touch
ing an application file after the rollup new build is available, but Cassey couldn't get them working - Webpack would rebuild, but it seemed to cache the node_modules parts, so new changes from shared-components weren't picked up. - see NPM link troubleshooting guide for more tips
- you don't have to do anything in the terminal to rebuild shared-components;
Do this when you're done working with a local copy of shared-components inside a local version of community. Don't skip this step!
- in community, in your terminal:
- run
npm unlink @glitchdotcom/shared-components
- run
- in shared-components, in your terminal:
- stop the rollup watch process, if you haven't yet
- run
npm unlink
- back in community
- reinstall shared-components from NPM (
npm install @glitchdotcom/shared-components
)
- reinstall shared-components from NPM (
Note: this process that was just outlined is kind of a pain and not particularly sustainable. If you find a better alternative feel free to update this documentation!
Another alternative to this process would be to publish a prerelease version. This is particularly convenient if you need to share this in-progress version with other teammates.
While shared-components is a cross-team collaboration, any stylistic changes should be reviewed by design to ensure we're keeping a cohesive feel across the site. When making a pull request, do add a member of the design team for review.
If you've been working from a glitch remix of shared-components rather than locally you can use the following commands in your local terminal to setup a branch on github:
./sh/setup.sh my-remix
If you want to update an existing branch on github from work done on glitch.com, use the update.sh
script:
./sh/update.sh my-remix
If you wish to update a glitch remix with changes from github, use the glitch terminal:
git pull origin branch-name-on-github
- First ensure that your PR is tagged with either
patch
,minor
ormajor
, this will determine the version bump - Once your PR has been approved, merge it on github
- A github action will fire, creating a new version of the shared-components package and apply updates to CHANGELOG.md
skip-release
will skip the github action and not create a new release when the PR is merged