docs(nxdev): master docs is latest (#6975)

* docs(nxdev): master docs is latest

* docs(nxdev): update latest documentation

* docs(nxdev): removing NX ROOT
This commit is contained in:
Benjamin Cabanes 2021-09-13 09:55:18 -04:00 committed by GitHub
parent b1165cdc85
commit 848436bca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 106 additions and 122 deletions

View File

@ -25,14 +25,13 @@ export const flavorList: {
export class DocumentsApi {
constructor(
private readonly options: {
previewRoot: string;
archiveRoot: string;
publicDocsRoot: string;
versions: VersionMetadata[];
documentsMap: Map<string, DocumentMetadata[]>;
}
) {
if (!options.archiveRoot || !options.previewRoot) {
throw new Error('archive and preview roots cannot be undefined');
if (!options.publicDocsRoot) {
throw new Error('public docs root cannot be undefined');
}
}
@ -59,14 +58,8 @@ export class DocumentsApi {
if (!file.data.title) {
file.data.title = extractTitle(originalContent) ?? path[path.length - 1];
}
return {
filePath: relative(
versionId === 'preview'
? this.options.previewRoot
: this.options.archiveRoot,
docPath
),
filePath: join(this.options.publicDocsRoot, docPath),
data: file.data,
content: file.content,
excerpt: file.excerpt,
@ -117,16 +110,12 @@ export class DocumentsApi {
}
getDocumentsRoot(version: string): string {
if (version === 'preview') {
return this.options.previewRoot;
}
const versionPath = this.options.versions.find(
(x) => x.id === version
)?.path;
if (versionPath) {
return join(this.options.archiveRoot, versionPath);
return join(this.options.publicDocsRoot, versionPath);
}
throw new Error(`Cannot find root for ${version}`);

View File

@ -36,7 +36,6 @@ export function createDocumentApiOptions() {
),
],
]),
previewRoot: join(__dirname, '../../../../docs'),
archiveRoot: join(__dirname, '../../../nx-dev/public/documentation'),
publicDocsRoot: join(__dirname, '../../../nx-dev/public/documentation'),
};
}

View File

@ -1,4 +1,3 @@
import { join } from 'path';
import {
DocumentMetadata,
DocumentsApi,
@ -8,42 +7,23 @@ import {
// Imports JSON directly so they can be bundled into the app and functions.
// Also provides some test safety.
import previewDocuments from '../../../docs/map.json';
import previousDocuments from '../public/documentation/previous/map.json';
import latestDocuments from '../public/documentation/latest/map.json';
import archiveVersionsData from '../public/documentation/versions.json';
import versionsData from '../public/documentation/versions.json';
export function loadDocumentsData(): Map<string, DocumentMetadata[]> {
const map = new Map<string, DocumentMetadata[]>();
map.set('latest', latestDocuments);
map.set('previous', previousDocuments);
if (process.env.VERCEL_ENV !== 'production') {
map.set('preview', previewDocuments);
}
return map;
}
export function loadVersionsData(): VersionMetadata[] {
const versions: VersionMetadata[] = archiveVersionsData;
if (process.env.VERCEL_ENV !== 'production') {
versions.push({
name: 'Preview',
id: 'preview',
release: 'preview',
path: 'preview',
default: false,
hidden: true,
});
}
return versions;
return versionsData;
}
export const documentsApi = new DocumentsApi({
previewRoot: join(process.env.NX_WORKSPACE_ROOT, 'docs'),
archiveRoot: join(
process.env.NX_WORKSPACE_ROOT,
'nx-dev/nx-dev/public/documentation'
),
publicDocsRoot: 'nx-dev/nx-dev/public/documentation',
documentsMap: loadDocumentsData(),
versions: loadVersionsData(),
});

View File

@ -1,39 +0,0 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { join } from 'path';
import * as send from 'send';
// nx-ignore-next-line
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
// This is only guaranteed during local dev since Vercel will not contain the entire workspace during runtime
const previewRootPath = join(appRootPath, 'docs');
export default function (req: NextApiRequest, res: NextApiResponse) {
return new Promise<void>((resolve) => {
if (Array.isArray(req.query.uri) || Array.isArray(req.query.document)) {
res.writeHead(422, { 'Content-Type': 'text/plain' });
res.end('Invalid URI');
} else {
const uri = decodeURIComponent(req.query.uri);
const document = decodeURIComponent(req.query.document);
const src = uri.startsWith('.') ? join(document, '..', uri) : uri;
const stream = send(req, src, {
// Files outside of the root are forbidden and will result in 404.
root: previewRootPath,
});
stream.on('end', () => {
resolve();
});
stream.on('error', (err) => {
res.status(404);
res.write(`Not Found ${err.message}`);
res.end();
resolve();
});
stream.pipe(res);
}
});
}

View File

@ -8,56 +8,33 @@
{
"target": "build-base",
"projects": "self"
},
{
"target": "copy-preview",
"projects": "self"
},
{
"target": "sitemap",
"projects": "self"
}
],
"executor": "@nrwl/workspace:run-commands",
"options": {
"root": "nx-dev/nx-dev",
"outputPath": "dist/nx-dev/nx-dev",
"command": "echo Build complete!"
"command": "nx run nx-dev:sitemap"
}
},
"sitemap": {
"dependsOn": [
{
"target": "copy-preview",
"projects": "self"
}
],
"executor": "@nrwl/workspace:run-commands",
"outputs": ["dist/nx-dev/nx-dev/public"],
"outputs": [],
"options": {
"command": "npx next-sitemap --config ./nx-dev/nx-dev/next-sitemap.js"
}
},
"copy-preview": {
"dependsOn": [
{
"target": "build-base",
"projects": "self"
}
],
"serve": {
"executor": "@nrwl/workspace:run-commands",
"outputs": ["dist/nx-dev/nx-dev/public"],
"outputs": [],
"options": {
"command": "rm -rf dist/nx-dev/nx-dev/public/documentation/preview && cp -r docs dist/nx-dev/nx-dev/public/documentation/preview"
"commands": [
"ts-node -P ./scripts/tsconfig.scripts.json ./scripts/documentation/nx-dev-docs-latest-sync.ts --watch",
"nx run nx-dev:serve-nextjs"
],
"parallel": true
}
},
"build-base": {
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"executor": "@nrwl/next:build",
"outputs": ["{options.outputPath}"],
"options": {
@ -68,10 +45,10 @@
"production": {}
}
},
"serve": {
"serve-nextjs": {
"executor": "@nrwl/next:server",
"options": {
"buildTarget": "nx-dev:build",
"buildTarget": "nx-dev:build-base",
"dev": true
},
"configurations": {

View File

@ -38,7 +38,7 @@ The `@nrwl/react:storybook-migrate-defaults-5-to-6` generator will not exactly d
That way, you can have working Storybook instances for all your projects just by running
```
```bash
nx g @nrwl/react:storybook-migrate-defaults-5-to-6
```

View File

@ -10,7 +10,7 @@ You can use the [`cra-to-nx`](https://www.npmjs.com/package/cra-to-nx) tool, tha
Just `cd` into your Create-React-App (CRA) project and run the following command:
```
```bash
npx cra-to-nx
```

View File

@ -17,13 +17,13 @@ This provides the best dev experience for small and medium-size applications, be
Nx has **publishable libraries**. As the name suggests, such libraries are meant to be built and published to some package registry s.t. they can be consumed also from outside the Nx workspace. The executor for building a publishable library does more than just building. It makes sure the output is properly compressed and might even produce more bundles s.t. the package can be consumed in a variety of ways (e.g. also produces UMD bundles).
```
```bash
nx g @nrwl/react:lib mylib --publishable --importPath=@myorg/mylib
```
On the other hand, the executor of a **buildable library**, performs a subset of the operations compared to the publishable library's executor. That's because buildable libraries are not intended to be published and thus only produce the minimum necessary output for the incremental build scenario to work. For example, no UMD bundles or minification is being done. The main goal of the executor is to perform the build as fast as possible.
```
```bash
nx g @nrwl/react:lib mylib --buildable
```

View File

@ -132,7 +132,7 @@ Projects without any tags cannot depend on any other projects. If you add the fo
If you try to violate the constrains, you will get an error:
```
```bash
A project tagged with "scope:admin" can only depend on projects tagged with "scoped:shared" or "scope:admin".
```

View File

@ -1,6 +1,6 @@
[
{
"name": "Latest (v12.9.0)",
"name": "Latest",
"id": "latest",
"release": "12.9.0",
"path": "latest",

View File

@ -20,7 +20,6 @@
"test",
"lint",
"e2e",
"copy-preview",
"sitemap"
],
"canTrackAnalytics": false,

View File

@ -0,0 +1,76 @@
import * as chalk from 'chalk';
import * as yargs from 'yargs';
import { watch } from 'chokidar';
import * as shell from 'shelljs';
import { BehaviorSubject } from 'rxjs';
import { debounceTime, filter, switchMapTo, tap } from 'rxjs/operators';
/**
* Available colours
*/
const { bgGreen, white } = chalk;
const argv = yargs
.command(
'Usage: $0',
'Sync the public latest folder with the /docs folder one time'
)
.example(
'$0 --watch',
'Sync the public latest folder with the /docs folder whenever changes are done'
)
.option('watch', {
alias: 'w',
demandOption: false,
type: 'boolean',
description: 'Enable the watch mode',
}).argv;
function sync(): void {
return shell.exec(
'rsync -avrR --delete ./docs/./ ./nx-dev/nx-dev/public/documentation/latest',
{ sync: true }
);
}
function main(isWatched: boolean) {
if (isWatched) {
const isReady$ = new BehaviorSubject(false);
const syncR$ = new BehaviorSubject(null);
/**
* If we do not debounce, the sync will happen for every file detect by the watcher
*/
isReady$
.pipe(
filter((isReady) => isReady),
tap(() =>
console.log(
bgGreen(
white(
' => DOCS SYNC ENABLED & READY: You can modify `/docs`, changes will be synced '
)
)
)
),
switchMapTo(syncR$),
debounceTime(1000)
)
.subscribe(() => sync());
return watch('./docs', {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true,
awaitWriteFinish: true,
})
.on('ready', () => isReady$.next(true))
.on('add', (path) => syncR$.next(path))
.on('addDir', (path) => syncR$.next(path))
.on('change', (path) => syncR$.next(path))
.on('unlink', (path) => syncR$.next(path));
}
return sync();
}
main(argv.watch as boolean);

View File

@ -12,7 +12,6 @@ import {
readJsonFile,
writeJsonFile,
} from '../../packages/tao/src/utils/fileutils';
import { execSync } from 'child_process';
/**
* Available colours
@ -32,6 +31,10 @@ const argv = yargs
'$0',
'Will update the nx.dev content with Nx releases for the current releases in the `nx-dev/nx-dev/public/documentation/versions.json`'
)
.example(
'$0 --latestRelease master',
'Will update the nx.dev content with the latest master as "latest" version'
)
.option('previousRelease', {
alias: 'p',
demandOption: false,