Skip to content
Open
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
2 changes: 1 addition & 1 deletion .eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export default [
github.getFlatConfigs().react,
{
// This lets your .eslintrc.js handle most configuration
ignores: ['.cache/**', 'public/**'],
ignores: ['public/**'],
},
]
104 changes: 28 additions & 76 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
module.exports = {
root: true,
ignorePatterns: ['.cache/', 'public/'],
plugins: ['primer-react'], // github plugin now comes from flat config
extends: ['@npmcli', 'react-app', 'eslint:recommended', 'plugin:react/recommended', 'prettier'],
ignorePatterns: ['public/'],
extends: [
'@npmcli',
'react-app',
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'prettier',
],
rules: {
'max-len': 'off',
'react/prop-types': 'off',
'primer-react/direct-slot-children': 'error',
'primer-react/no-system-props': ['error', {includeUtilityComponents: true}],
'primer-react/a11y-tooltip-interactive-trigger': 'error',
'primer-react/new-color-css-vars': 'error',
'primer-react/a11y-explicit-heading': 'error',
'primer-react/no-deprecated-props': 'warn',
'primer-react/a11y-remove-disable-tooltip': 'error',
'primer-react/a11y-use-accessible-tooltip': 'error',
// Preact components may use `class` and `for` too, but the site uses the
// React names throughout.
'react/no-unknown-property': ['error', {ignore: ['frameBorder', 'allowFullScreen']}],
},
settings: {
react: {
version: '18.0',
},
'import/resolver': {
typescript: {},
},
// Modules the site's build supplies (see doc-kit.config.mjs).
'import/core-modules': ['#theme/site', '#theme/nav', '#theme/header-nav', '#theme/config'],
},
overrides: [
{
files: ['*.js'],
extends: ['plugin:import/recommended'],
},
{
files: ['src/shared.js'],
files: ['src/theme/**/*.{js,jsx}'],
env: {browser: true},
rules: {
'import/no-unresolved': ['error', {ignore: ['^#theme/']}],
},
},
{
files: ['src/theme/mdx/shared.jsx'],
rules: {
'react/no-unescaped-entities': 'off',
},
Expand All @@ -41,28 +54,20 @@ module.exports = {
globals: {
Index: 'readonly',
Note: 'readonly',
Prompt: 'readonly',
Screenshot: 'readonly',
Link: 'readonly',
YouTube: 'readonly',
DataTable: 'readonly',
InlineCode: 'readonly',
Strikethrough: 'readonly',
CliLink: 'readonly',
Shared: 'readonly',
TrustedPublisherSwitcher: 'readonly',
TrustedPublisherOption: 'readonly',
},
settings: {
'import/resolver': 'webpack',
},
rules: {
'no-irregular-whitespace': 'off',
'react/no-unescaped-entities': 'off',
'react/jsx-key': 'off',
},
},
{
files: ['*.mdx', 'src/shared.js', 'src/**/*.js'],
files: ['*.mdx', 'src/theme/mdx/shared.jsx', 'src/theme/**/*.{js,jsx}'],
rules: {
'react/forbid-elements': [
'error',
Expand All @@ -85,85 +90,47 @@ module.exports = {
'big',
'blink',
'br',
'button',
'canvas',
'caption',
'center',
'cite',
'code',
'col',
'colgroup',
'content',
'data',
'datalist',
'dd',
'del',
'details',
'dfn',
'dialog',
'dir',
// ok because Box is deprecated and styles are provided via CSS modules
// 'div',
'dl',
'dt',
'element',
'em',
'embed',
'fieldset',
'figcaption',
'figure',
'footer',
'form',
'font',
'frame',
'frameset',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'head',
// ok because Box is deprecated and styles are provided via CSS modules
// 'header',
'hgroup',
'hr',
// used in head
// 'html',
'i',
// ok because Box is deprecated and styles are provided via CSS modules
// 'iframe',
'input',
'ins',
'isindex',
'kbd',
'keygen',
'label',
'legend',
// ok because there is no mdx replacement and styles are provided via parent ul/ol
// 'li',
'listing',
// ok because Box is deprecated and styles are provided via CSS modules
// 'main',
'map',
'mark',
'menu',
'menuitem',
'meter',
// ok because Box is deprecated and styles are provided via CSS modules
// 'nav',
'noembed',
'noscript',
'object',
'ol',
'optgroup',
'option',
'output',
// ok because Box is deprecated and styles are provided via CSS modules
// 'p',
'param',
'plaintext',
// ok because Box is deprecated and styles are provided via CSS modules
// 'pre',
'progress',
'q',
'rp',
Expand All @@ -174,35 +141,20 @@ module.exports = {
'samp',
'script',
'section',
'select',
'shadow',
'small',
'source',
'spacer',
'span',
'strike',
// ok since there is no mdx replacement
// 'strong'
'style',
'sub',
'summary',
'sup',
'table',
'tbody',
'td',
'template',
'tfoot',
'th',
'thead',
'time',
// used in head
// 'title',
'tr',
'track',
'tt',
'u',
// ok because Box is deprecated and styles are provided via CSS modules
// 'ul',
'var',
'video',
'wbr',
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,15 @@ jobs:
cache: npm
- name: Install Dependencies
run: npm i --no-audit --no-fund
- name: Rebuild deps
run: npm rebuild

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Restore cache
id: cache-gatsby
uses: actions/cache/restore@v4
with:
key: ${{ runner.os }}-gatsby-${{ github.ref_name }}
path: |
public
.cache

- name: Build documentation
run: npm run build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save cache
uses: actions/cache/save@v4
with:
key: ${{ steps.cache-gatsby.outputs.cache-primary-key }}
path: |
public
.cache

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
!/CONTENT-MODEL.md
!/content/
!/CONTRIBUTING.md
!/doc-kit.config.mjs
!/docs/
!/gatsby-*
!/jest*.js
!/lib/
!/LICENSE*
!/map.js
Expand All @@ -40,7 +39,6 @@
!/tap-snapshots/
!/test/
!/tsconfig.json
!/webpack.config.js
!cli-cache.json
tap-testdir*/
!/cli/
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
/content/cli/
.nyc_output/
coverage/
cli-cache.json
cli-cache.json
# A JavaScript template literal, not HTML
src/theme/template.html
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Files: content/* static/*
Copyright: 2020 GitHub
License: CC-BY-4.0

Files: scripts/* cli/* theme/* src/* .github/* *.md *.js *.mjs *.json .*
Files: scripts/* cli/* src/* .github/* *.md *.js *.mjs *.json .*
Copyright: 2020 GitHub
License: MIT
41 changes: 16 additions & 25 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,35 @@ This is the documentation for [https://docs.npmjs.com/](https://docs.npmjs.com/)

## Quick start

1. `npm install` to download Gatsby and all the dependencies
2. `npm run develop`: starts the test server at `http://localhost:8000`.
1. `npm install` to download [doc-kit](https://github.com/nodejs/doc-kit) and all the dependencies
2. `npm run develop`: builds the site and starts the test server at `http://localhost:8000`.
3. Update the content - it's MDX, which is like Markdown - in the `content` directory.
4. Review your content at `http://localhost:8000`. (Gatsby watches the filesystem and will reload your content changes immediately.)
4. Review your content at `http://localhost:8000`. (The site is rebuilt whenever the content changes; reload the page to see your changes.)
5. Once you're happy, commit it and open a pull request at https://github.com/npm/documentation.
6. A CI workflow run will publish your PR to a GitHub Preview Page.
7. Once the content is reviewed, merge the pull request. That will [deploy the site](https://github.com/npm/documentation/actions/workflows/publish.yml).

## Running locally

First, `npm install` the dependencies. This will install Gatsby, et al.
First, `npm install` the dependencies. This will install [doc-kit](https://github.com/nodejs/doc-kit), the documentation toolchain of the Node.js project, which generates the site, et al.

Next, `npm run develop` to start the test server to view your changes. The Gatsby server will be started on port 8000. You can navigate to `http://localhost:8000` to view the site live. This npm script doesn't work on Windows terminals, run it manually using appropriate syntax for your terminal. The syntax for command prompt is `set PARCEL_WORKERS=0 & npm run gatsby develop`.
Next, `npm run develop` to build the site and start the test server to view your changes. The server will be started on port 8000. You can navigate to `http://localhost:8000` to view the site. The site is rebuilt whenever anything in `content`, `src`, or `static` changes; reload the page to see your changes.

In order to cut down on the time it takes `npm run develop` to complete, you can use the environment variables `GATSBY_CONTENT_ALLOW` and `GATSBY_CONTENT_IGNORE` to only build some pages.
To build the site once, run `npm run build`. The site is written to the `public` directory, and `npm run serve` serves it the way GitHub Pages does.

For example, if the only pages you need to test locally are in `/cli/v10/commands`, then you can run the the following to build the `cli/v10/commands` pages:
In order to cut down on the time it takes to build the site, you can use the environment variable `CONTENT_IGNORE` to leave out some directories of content. The `content/cli` directory has the most pages so it tends to be most helpful to ignore older CLI versions unless you need to explicitly test those pages:

```sh
GATSBY_CONTENT_ALLOW=cli/v10/commands npm run develop
CONTENT_IGNORE=cli/v6,cli/v7,cli/v8,cli/v9 npm run develop
```

The `content/cli` directory has the most pages so it tends to be most helpful to ignore older CLI versions unless you need to explicitly test those pages:
**For best results use The latest versions of Node.js and npm**

```sh
GATSBY_CONTENT_IGNORE=cli/v6,cli/v7,cli/v8,cli/v9 npm run develop
```
The "Edit this page on GitHub" links and the contributors shown at the bottom of each page are fetched from GitHub when the site is built. Set the `GITHUB_TOKEN` environment variable to a GitHub token to fetch them locally; without one, placeholder data is used instead.

**For best results use The latest versions of Node.js and npm**
### How the site is built

**Gatsby will watch your filesystem looking for updates.** Any content changes you make should be reflected in the site immediately.
The site is generated by [doc-kit](https://github.com/nodejs/doc-kit), configured in `doc-kit.config.mjs`. Two generators in `src/generators` adapt it to this site: `npm-ast` maps the content files to the URLs they are published at, and `npm` builds each page's table of contents, edit link and contributors, writes the redirect pages, and writes the search index. The look and feel of the site, including the components content can use, lives in `src/theme`.

## Updating content

Expand Down Expand Up @@ -74,7 +72,7 @@ Static content lives in the `static` directory. Since most of the static content

### "Shared" content

There are various places where we want to share content between pages, to prevent copy-pasta. For example, we display a screenshot of the user login dialog repeatedly. Therefore this shared content is defined in `src/shared.js`, and includes a literal MDX snippet.
There are various places where we want to share content between pages, to prevent copy-pasta. For example, we display a screenshot of the user login dialog repeatedly. Therefore this shared content is defined in `src/theme/mdx/shared.jsx`, and includes a literal MDX snippet.

For example, `user-login` is defined with `text` and `image` properties:

Expand All @@ -87,19 +85,12 @@ m login dialog" />)
},
```

Since MDX is reactive, you can import the shared data at the top of the file, just beneath your frontmatter. It uses the special path `~/shared.js` so it can be imported the same way from any nested file without needing to figure out the appropriate relative path:
Reference the shared content with the `Shared` component, which renders the `text` of a snippet, or its `image` when asked to:

```
---
title: Using shared content
---
import shared form '~/shared.js'
```

And then reference the shared content within `<>`:
To login, <Shared id="user-login" />

```
To login, <>{shared['user-login'].text}</>
<Shared id="user-login" image />
```

### URLs
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ This is the documentation for [https://docs.npmjs.com/](https://docs.npmjs.com/)

## Quick start

1. `npm install` to download gatsby, our theme, and the dependencies
2. `npm run develop`: starts the test server at `http://localhost:8000`.
3. Update the content - it's Mdx, which is like markdown - in the `content` directory.
4. Review your content at `http://localhost:8000`. (Gatsby watches the filesystem and will reload your content changes immediately.)
1. `npm install` to download [doc-kit](https://github.com/nodejs/doc-kit), our theme, and the dependencies
2. `npm run develop`: builds the site and starts the test server at `http://localhost:8000`.
3. Update the content - it's MDX, which is like markdown - in the `content` directory.
4. Review your content at `http://localhost:8000`. (The site is rebuilt whenever the content changes; reload the page to see your changes.)
5. Once you're happy, commit it and open a pull request at https://github.com/npm/documentation.
6. A CI workflow run will publish your PR to a GitHub Preview Page.
7. Once the content is reviewed, merge the pull request. That will [deploy the site](https://github.com/npm/documentation/actions/workflows/publish.yml).
Expand Down
Loading