Skip to content

Commit

Permalink
Improvements v2 (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs authored Jun 17, 2024
2 parents 564181c + fb15dde commit dc73d89
Show file tree
Hide file tree
Showing 76 changed files with 8,615 additions and 323 deletions.
5 changes: 5 additions & 0 deletions e2e/docusaurus-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
displayName: 'docusaurus-e2e',
preset: '../../jest.preset.js',
coverageDirectory: '../../coverage/apps/docusaurus-e2e',
};
19 changes: 19 additions & 0 deletions e2e/docusaurus-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "docusaurus-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "e2e/docusaurus-e2e/src",
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "e2e/docusaurus-e2e/jest.config.ts",
"runInBand": true,
"passWithNoTests": false
},
"dependsOn": ["docusaurus:build"]
}
},
"tags": [],
"implicitDependencies": ["docusaurus"]
}
31 changes: 31 additions & 0 deletions e2e/docusaurus-e2e/tests/docusaurus.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ensureNxProject, installDeps } from '../../utils/workspace'
import { runNxCommandAsync } from '../../utils/run-nx-command-async'
import { checkFilesExist, rmDist } from '@nx/plugin/testing'

describe('(e2e) docusaurus', () => {
beforeAll(() => ensureNxProject([
'@nx-extend/core:dist/packages/core',
'@nx-extend/docusaurus:dist/packages/docusaurus'
]))

const appName = 'test-docusaurus'

it('should be able to generate', async () => {
await runNxCommandAsync(`generate @nx-extend/docusaurus:app ${appName}`)
installDeps()

expect(() => checkFilesExist(
`${appName}/docusaurus.config.ts`
)).not.toThrow()
})

it('should be able to build', async () => {
rmDist()
await runNxCommandAsync(`build ${appName}`)

expect(() => checkFilesExist(
`dist/${appName}/index.html`,
`dist/${appName}/sitemap.xml`
)).not.toThrow()
})
})
13 changes: 13 additions & 0 deletions e2e/docusaurus-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions e2e/docusaurus-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
1 change: 1 addition & 0 deletions e2e/strapi-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "../../tsconfig.base.json",

"files": [],
"include": [],
"references": [
Expand Down
10 changes: 8 additions & 2 deletions e2e/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ export function ensureNxProject(patchPlugins: string[] = []): void {
env: process.env
})

execSync('yarn install --immutable', {
installDeps()

execSync('echo "enableHardenedMode: false" >> .yarnrc.yml', {
cwd: tmpProjectPath,
stdio: 'inherit',
env: process.env
})
}

execSync('echo "enableHardenedMode: false" >> .yarnrc.yml', {
export function installDeps() {
const tmpProjectPath = tmpProjPath()

execSync('yarn install --immutable', {
cwd: tmpProjectPath,
stdio: 'inherit',
env: process.env
Expand Down
3 changes: 2 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"inputs": ["production"],
"options": {
"trackDeps": true,
"tagPrefix": "${target}@"
"tagPrefix": "${target}@",
"changelogHeader": " "
}
},
"@nx/jest:jest": {
Expand Down
37 changes: 37 additions & 0 deletions packages/docusaurus/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": "../../.eslintrc.json",
"ignorePatterns": [
"!**/*"
],
"rules": {},
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"parserOptions": {
"project": [
"packages/docusaurus/tsconfig.*?.json"
]
},
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
3 changes: 3 additions & 0 deletions packages/docusaurus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
114 changes: 114 additions & 0 deletions packages/docusaurus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# @nx-extend/docusaurus

<a href="https://www.npmjs.com/package/@nx-extend/docusaurus" rel="nofollow">
<img src="https://badgen.net/npm/v/@nx-extend/docusaurus" alt="@nx-extend/docusaurus NPM package">
</a>

**Nx plugin for working with [docusaurus](https://docusaurus.io/)**.

## This was originally build by [nx-plus](https://github.com/ZachJW34/nx-plus)

## Contents

- [Prerequisite](#prerequisite)
- [Getting Started](#getting-started)
- [Schematics (i.e. code generation)](#schematics-ie-code-generation)
- [Builders (i.e. task runners)](#builders-ie-task-runners)
- [Troubleshooting](#troubleshooting)

## Getting Started

### Install Plugin

```
# npm
npm install @extend/docusaurus --save-dev
# yarn
yarn add @extend/docusaurus --dev
```

### Generate Your App

```
nx g @nx-extend/docusaurus:app my-app
```

### Serve Your App

```
nx serve my-app
```

## Schematics (i.e. code generation)

### Application

`nx g @nx-extend/docusaurus:app <name> [options]`

| Arguments | Description |
| --------- | --------------------- |
| `<name>` | The name of your app. |

| Options | Default | Description |
| -------------- | ------- | ------------------------------------------ |
| `--tags` | - | Tags to use for linting (comma-delimited). |
| `--directory` | `apps` | A directory where the project is placed. |
| `--skipFormat` | `false` | Skip formatting files. |

## Builders (i.e. task runners)

### Dev Server

`nx serve <name> [options]`

| Arguments | Description |
| --------- | --------------------- |
| `<name>` | The name of your app. |

| Options | Default | Description |
| ----------- | ----------- | ---------------------------------------------------- |
| `--port` | `3000` | Use specified port. |
| `--host` | `localhost` | Use specified host. |
| `--hotOnly` | `false` | Do not fallback to page refresh if hot reload fails. |
| `--open` | `false` | Open page in the browser. |

### Browser

`nx build <name> [options]`

| Arguments | Description |
| --------- | --------------------- |
| `<name>` | The name of your app. |

| Options | Default | Description |
| ------------------ | ------- | ------------------------------------------------------------------------------ |
| `--bundleAnalyzer` | `false` | Visualize size of webpack output files with an interactive zoomable treemap. |
| `--outputPath` | - | The full path for the new output directory, relative to the current workspace. |
| `--minify` | `true` | Build website minimizing JS bundles. |

## Troubleshooting

If you encounter this error while building a Docusaurus app, then you may need to add a `terser` resolution to your `package.json`. Note: this only works with Yarn and not npm.

**Error:**

```
Docusaurus user: you probably have this known error due to using a monorepo/workspace.
We have a workaround for you, check https://github.com/facebook/docusaurus/issues/3515
```

**package.json:**

```
{
// ...
"resolutions": {
"terser": "^4.0.0"
}
// ...
}
```

Once this has been updated, you should be able to run `yarn install` and then build your Docusaurus application.

27 changes: 27 additions & 0 deletions packages/docusaurus/executors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/schema",
"executors": {
"browser": {
"implementation": "./src/executors/browser/executor",
"schema": "./src/executors/browser/schema.json",
"description": "browser executor"
},
"dev-server": {
"implementation": "./src/executors/dev-server/executor",
"schema": "./src/executors/dev-server/schema.json",
"description": "serve executor"
}
},
"builders": {
"build": {
"implementation": "./src/executors/browser/compat",
"schema": "./src/executors/browser/schema.json",
"description": "browser builder"
},
"dev-server": {
"implementation": "./src/executors/dev-server/compat",
"schema": "./src/executors/dev-server/schema.json",
"description": "dev-server builder"
}
}
}
21 changes: 21 additions & 0 deletions packages/docusaurus/generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://json-schema.org/schema",
"name": "docusaurus",
"version": "0.0.1",
"generators": {
"application": {
"factory": "./src/generators/application/generator#applicationGenerator",
"schema": "./src/generators/application/schema.json",
"description": "application generator",
"aliases": ["app"]
}
},
"schematics": {
"application": {
"factory": "./src/generators/application/generator#applicationSchematic",
"schema": "./src/generators/application/schema.json",
"description": "application schematic",
"aliases": ["app"]
}
}
}
12 changes: 12 additions & 0 deletions packages/docusaurus/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
export default {
displayName: 'docusaurus',
preset: '../../jest.preset.js',
globals: {},
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/docusaurus',
testEnvironment: 'node'
}
35 changes: 35 additions & 0 deletions packages/docusaurus/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@nx-extend/docusaurus",
"version": "0.0.1",
"keywords": [
"nx",
"docusaurus"
],
"homepage": "https://github.com/TriPSs/nx-extend/blob/master/packages/docusaurus/README.md",
"bugs": {
"url": "https://github.com/tripss/nx-extend/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tripss/nx-extend"
},
"license": "MIT",
"main": "src/index.js",
"builders": "./executors.json",
"generators": "./generators.json",
"dependencies": {
"@docusaurus/core": "3.4.0",
"@docusaurus/preset-classic": "3.4.0",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.4.0",
"@docusaurus/tsconfig": "3.4.0",
"@docusaurus/types": "3.4.0",
"typescript": "~5.2.2"
}
}
Loading

0 comments on commit dc73d89

Please sign in to comment.