Skip to content

Commit

Permalink
docs: Add Node.js handbook. (#630)
Browse files Browse the repository at this point in the history
* Copy files.

* Add section.

* Update sveltekit.
  • Loading branch information
milesj authored Feb 19, 2023
1 parent 9c2d79b commit 5ee1f3b
Show file tree
Hide file tree
Showing 6 changed files with 660 additions and 81 deletions.
66 changes: 66 additions & 0 deletions website/docs/__partials__/node/package-workspaces.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
groupId="package-manager"
defaultValue="yarn"
values={[
{ label: 'npm', value: 'npm' },
{ label: 'pnpm', value: 'pnpm' },
{ label: 'Yarn', value: 'yarn' },
{ label: 'Yarn (classic)', value: 'yarn1' },
]}
>
<TabItem value="yarn">

```json title="package.json"
{
// ...
"workspaces": ["apps/*", "packages/*"]
}
```

```yaml title=".yarnrc.yml"
# ...
nodeLinker: 'node-modules'
```
- [Documentation](https://yarnpkg.com/features/workspaces)
</TabItem>
<TabItem value="yarn1">
```json title="package.json"
{
// ...
"workspaces": ["apps/*", "packages/*"]
}
```

- [Documentation](https://classic.yarnpkg.com/en/docs/workspaces)

</TabItem>
<TabItem value="npm">

```json title="package.json"
{
// ...
"workspaces": ["apps/*", "packages/*"]
}
```

- [Documentation](https://docs.npmjs.com/cli/v8/using-npm/workspaces)

</TabItem>
<TabItem value="pnpm">

```yaml title="pnpm-workspace.yaml"
packages:
- 'apps/*'
- 'packages/*'
```

- [Documentation](https://pnpm.io/workspaces)

</TabItem>
</Tabs>
66 changes: 47 additions & 19 deletions website/docs/guides/examples/sveltekit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ sidebar_label: SvelteKit

import AddDepsTabs from '@site/src/components/AddDepsTabs';
import CreateDepTabs from '@site/src/components/CreateDepTabs';
import HeadingApiLink from '@site/src/components/Docs/HeadingApiLink';

<HeadingApiLink to="https://github.com/moonrepo/examples/tree/master/apps/sveltekit" />

[SvelteKit](https://kit.svelte.dev) is built on [Svelte](https://svelte.dev), a UI framework that
uses a compiler to let you write breathtakingly concise components that do minimal work in the
Expand Down Expand Up @@ -43,14 +46,8 @@ tasks:
command: 'vite dev'
local: true

lint:
command: 'eslint .'

# Production build (SSR)
build:
command: 'vite build'
deps:
- '~:lint'
inputs:
- '@group(svelte)'
outputs:
Expand All @@ -64,11 +61,8 @@ tasks:

test:
command: 'vitest'

playwright:
command: 'playwright test'
inputs:
- '@globs(tests)'
- '@group(svelte)'
```
To run the SvelteKit dev server:
Expand All @@ -80,12 +74,31 @@ moon run <project>:dev
### ESLint integration

SvelteKit provides an option to setup ESLint along with your project, with moon you can use a
[global `lint` task](./eslint).
[global `lint` task](./eslint). We encourage using the global `lint` task for consistency across all
projects within the repository. With this approach, the `eslint` command itself will be ran and the
`svelte3` rules will still be used.

We encourage using the global `lint` task for consistency across all projects within the repository.
With this approach, the `eslint` command itself will be ran and the `svelte3` rules will still be
used. Additionally, we suggest disabling the linter during the build process, but is not a
requirement. As a potential alternative, add the `lint` task as a dependency for the `build` task.
```yaml title="<project>/moon.yml"
tasks:
# Extends the top-level lint
lint:
args:
- '--ext'
- '.ts,.svelte'
```
Be sure to enable the Svelte parser and plugin in a project local ESLint configuration file.
```js title=".eslintrc.cjs"
module.exports = {
plugins: ['svelte3'],
ignorePatterns: ['*.cjs'],
settings: {
'svelte3/typescript': () => require('typescript'),
},
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
};
```

### TypeScript integration

Expand All @@ -96,11 +109,26 @@ continuing.

At this point we'll assume that a `tsconfig.json` has been created in the application, and
typechecking works. From here we suggest utilizing a [global `typecheck` task](./typescript) for
consistency across all projects within the repository.
consistency across all projects within the repository. However, because Svelte isn't standard
JavaScript, it requires the use of the `svelte-check` command for type-checking.

Additionally, we suggest disabling the typechecker during the build process, but is not a
requirement. As a potential alternative, add the `typecheck` task as a dependency for the `build`
task.
```yaml title="<project>/moon.yml"
workspace:
inheritedTasks:
exclude: ['typecheck']

tasks:
typecheck-sync:
command: 'svelte-kit sync'

typecheck:
command: 'svelte-check --tsconfig ./tsconfig.json'
deps:
- 'typecheck-sync'
inputs:
- '@group(svelte)'
- 'tsconfig.json'
```
In case Svelte doesn't automatically create a `tsconfig.json`, you can use the following:

Expand Down
154 changes: 154 additions & 0 deletions website/docs/guides/javascript/__partials__/workspace-commands.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
groupId="package-manager"
defaultValue="yarn"
values={[
{ label: 'npm', value: 'npm' },
{ label: 'pnpm', value: 'pnpm' },
{ label: 'Yarn', value: 'yarn' },
{ label: 'Yarn (classic)', value: 'yarn1' },
]}
>
<TabItem value="npm">

Install dependencies:

```shell
npm install
```

Add a package:

```shell
# At the root
npm install <dependency>

# In a project
npm install <dependency> --workspace <project>
```

Remove a package:

```shell
# At the root
npm install <dependency>

# In a project
npm install <dependency> --workspace <project>
```

Update packages:

```shell
npx npm-check-updates --interactive
```

</TabItem>
<TabItem value="pnpm">

Install dependencies:

```shell
pnpm install
```

Add a package:

```shell
# At the root
pnpm add <dependency>

# In a project
pnpm add <dependency> --filter <project>
```

Remove a package:

```shell
# At the root
pnpm remove <dependency>

# In a project
pnpm remove <dependency> --filter <project>
```

Update packages:

```shell
pnpm update -i -r --latest
```

</TabItem>
<TabItem value="yarn">

Install dependencies:

```shell
yarn install
```

Add a package:

```shell
# At the root
yarn add <dependency>

# In a project
yarn workspace <project> add <dependency>
```

Remove a package:

```shell
# At the root
yarn remove <dependency>

# In a project
yarn workspace <project> remove <dependency>
```

Update packages:

```shell
yarn upgrade-interactive
```

</TabItem>
<TabItem value="yarn1">

Install dependencies:

```shell
yarn install
```

Add a package:

```shell
# At the root
yarn add <dependency> -w

# In a project
yarn workspace <project> add <dependency>
```

Remove a package:

```shell
# At the root
yarn remove <dependency> -w

# In a project
yarn workspace <project> remove <dependency>
```

Update packages:

```shell
yarn upgrade-interactive --latest
```

</TabItem>
</Tabs>
Loading

0 comments on commit 5ee1f3b

Please sign in to comment.