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:
parent
b1165cdc85
commit
848436bca5
@ -25,14 +25,13 @@ export const flavorList: {
|
|||||||
export class DocumentsApi {
|
export class DocumentsApi {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly options: {
|
private readonly options: {
|
||||||
previewRoot: string;
|
publicDocsRoot: string;
|
||||||
archiveRoot: string;
|
|
||||||
versions: VersionMetadata[];
|
versions: VersionMetadata[];
|
||||||
documentsMap: Map<string, DocumentMetadata[]>;
|
documentsMap: Map<string, DocumentMetadata[]>;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (!options.archiveRoot || !options.previewRoot) {
|
if (!options.publicDocsRoot) {
|
||||||
throw new Error('archive and preview roots cannot be undefined');
|
throw new Error('public docs root cannot be undefined');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,14 +58,8 @@ export class DocumentsApi {
|
|||||||
if (!file.data.title) {
|
if (!file.data.title) {
|
||||||
file.data.title = extractTitle(originalContent) ?? path[path.length - 1];
|
file.data.title = extractTitle(originalContent) ?? path[path.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filePath: relative(
|
filePath: join(this.options.publicDocsRoot, docPath),
|
||||||
versionId === 'preview'
|
|
||||||
? this.options.previewRoot
|
|
||||||
: this.options.archiveRoot,
|
|
||||||
docPath
|
|
||||||
),
|
|
||||||
data: file.data,
|
data: file.data,
|
||||||
content: file.content,
|
content: file.content,
|
||||||
excerpt: file.excerpt,
|
excerpt: file.excerpt,
|
||||||
@ -117,16 +110,12 @@ export class DocumentsApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDocumentsRoot(version: string): string {
|
getDocumentsRoot(version: string): string {
|
||||||
if (version === 'preview') {
|
|
||||||
return this.options.previewRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionPath = this.options.versions.find(
|
const versionPath = this.options.versions.find(
|
||||||
(x) => x.id === version
|
(x) => x.id === version
|
||||||
)?.path;
|
)?.path;
|
||||||
|
|
||||||
if (versionPath) {
|
if (versionPath) {
|
||||||
return join(this.options.archiveRoot, versionPath);
|
return join(this.options.publicDocsRoot, versionPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Cannot find root for ${version}`);
|
throw new Error(`Cannot find root for ${version}`);
|
||||||
|
|||||||
@ -36,7 +36,6 @@ export function createDocumentApiOptions() {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
]),
|
]),
|
||||||
previewRoot: join(__dirname, '../../../../docs'),
|
publicDocsRoot: join(__dirname, '../../../nx-dev/public/documentation'),
|
||||||
archiveRoot: join(__dirname, '../../../nx-dev/public/documentation'),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { join } from 'path';
|
|
||||||
import {
|
import {
|
||||||
DocumentMetadata,
|
DocumentMetadata,
|
||||||
DocumentsApi,
|
DocumentsApi,
|
||||||
@ -8,42 +7,23 @@ import {
|
|||||||
|
|
||||||
// Imports JSON directly so they can be bundled into the app and functions.
|
// Imports JSON directly so they can be bundled into the app and functions.
|
||||||
// Also provides some test safety.
|
// Also provides some test safety.
|
||||||
import previewDocuments from '../../../docs/map.json';
|
|
||||||
import previousDocuments from '../public/documentation/previous/map.json';
|
import previousDocuments from '../public/documentation/previous/map.json';
|
||||||
import latestDocuments from '../public/documentation/latest/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[]> {
|
export function loadDocumentsData(): Map<string, DocumentMetadata[]> {
|
||||||
const map = new Map<string, DocumentMetadata[]>();
|
const map = new Map<string, DocumentMetadata[]>();
|
||||||
map.set('latest', latestDocuments);
|
map.set('latest', latestDocuments);
|
||||||
map.set('previous', previousDocuments);
|
map.set('previous', previousDocuments);
|
||||||
if (process.env.VERCEL_ENV !== 'production') {
|
|
||||||
map.set('preview', previewDocuments);
|
|
||||||
}
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadVersionsData(): VersionMetadata[] {
|
export function loadVersionsData(): VersionMetadata[] {
|
||||||
const versions: VersionMetadata[] = archiveVersionsData;
|
return versionsData;
|
||||||
if (process.env.VERCEL_ENV !== 'production') {
|
|
||||||
versions.push({
|
|
||||||
name: 'Preview',
|
|
||||||
id: 'preview',
|
|
||||||
release: 'preview',
|
|
||||||
path: 'preview',
|
|
||||||
default: false,
|
|
||||||
hidden: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return versions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const documentsApi = new DocumentsApi({
|
export const documentsApi = new DocumentsApi({
|
||||||
previewRoot: join(process.env.NX_WORKSPACE_ROOT, 'docs'),
|
publicDocsRoot: 'nx-dev/nx-dev/public/documentation',
|
||||||
archiveRoot: join(
|
|
||||||
process.env.NX_WORKSPACE_ROOT,
|
|
||||||
'nx-dev/nx-dev/public/documentation'
|
|
||||||
),
|
|
||||||
documentsMap: loadDocumentsData(),
|
documentsMap: loadDocumentsData(),
|
||||||
versions: loadVersionsData(),
|
versions: loadVersionsData(),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -8,56 +8,33 @@
|
|||||||
{
|
{
|
||||||
"target": "build-base",
|
"target": "build-base",
|
||||||
"projects": "self"
|
"projects": "self"
|
||||||
},
|
|
||||||
{
|
|
||||||
"target": "copy-preview",
|
|
||||||
"projects": "self"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"target": "sitemap",
|
|
||||||
"projects": "self"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"executor": "@nrwl/workspace:run-commands",
|
"executor": "@nrwl/workspace:run-commands",
|
||||||
"options": {
|
"options": {
|
||||||
"root": "nx-dev/nx-dev",
|
|
||||||
"outputPath": "dist/nx-dev/nx-dev",
|
"outputPath": "dist/nx-dev/nx-dev",
|
||||||
"command": "echo Build complete!"
|
"command": "nx run nx-dev:sitemap"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sitemap": {
|
"sitemap": {
|
||||||
"dependsOn": [
|
|
||||||
{
|
|
||||||
"target": "copy-preview",
|
|
||||||
"projects": "self"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"executor": "@nrwl/workspace:run-commands",
|
"executor": "@nrwl/workspace:run-commands",
|
||||||
"outputs": ["dist/nx-dev/nx-dev/public"],
|
"outputs": [],
|
||||||
"options": {
|
"options": {
|
||||||
"command": "npx next-sitemap --config ./nx-dev/nx-dev/next-sitemap.js"
|
"command": "npx next-sitemap --config ./nx-dev/nx-dev/next-sitemap.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"copy-preview": {
|
"serve": {
|
||||||
"dependsOn": [
|
|
||||||
{
|
|
||||||
"target": "build-base",
|
|
||||||
"projects": "self"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"executor": "@nrwl/workspace:run-commands",
|
"executor": "@nrwl/workspace:run-commands",
|
||||||
"outputs": ["dist/nx-dev/nx-dev/public"],
|
"outputs": [],
|
||||||
"options": {
|
"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": {
|
"build-base": {
|
||||||
"dependsOn": [
|
|
||||||
{
|
|
||||||
"target": "build",
|
|
||||||
"projects": "dependencies"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"executor": "@nrwl/next:build",
|
"executor": "@nrwl/next:build",
|
||||||
"outputs": ["{options.outputPath}"],
|
"outputs": ["{options.outputPath}"],
|
||||||
"options": {
|
"options": {
|
||||||
@ -68,10 +45,10 @@
|
|||||||
"production": {}
|
"production": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"serve": {
|
"serve-nextjs": {
|
||||||
"executor": "@nrwl/next:server",
|
"executor": "@nrwl/next:server",
|
||||||
"options": {
|
"options": {
|
||||||
"buildTarget": "nx-dev:build",
|
"buildTarget": "nx-dev:build-base",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
|
|||||||
@ -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
|
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
|
nx g @nrwl/react:storybook-migrate-defaults-5-to-6
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
Just `cd` into your Create-React-App (CRA) project and run the following command:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
npx cra-to-nx
|
npx cra-to-nx
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -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).
|
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
|
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.
|
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
|
nx g @nrwl/react:lib mylib --buildable
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
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".
|
A project tagged with "scope:admin" can only depend on projects tagged with "scoped:shared" or "scope:admin".
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "Latest (v12.9.0)",
|
"name": "Latest",
|
||||||
"id": "latest",
|
"id": "latest",
|
||||||
"release": "12.9.0",
|
"release": "12.9.0",
|
||||||
"path": "latest",
|
"path": "latest",
|
||||||
|
|||||||
1
nx.json
1
nx.json
@ -20,7 +20,6 @@
|
|||||||
"test",
|
"test",
|
||||||
"lint",
|
"lint",
|
||||||
"e2e",
|
"e2e",
|
||||||
"copy-preview",
|
|
||||||
"sitemap"
|
"sitemap"
|
||||||
],
|
],
|
||||||
"canTrackAnalytics": false,
|
"canTrackAnalytics": false,
|
||||||
|
|||||||
76
scripts/documentation/nx-dev-docs-latest-sync.ts
Normal file
76
scripts/documentation/nx-dev-docs-latest-sync.ts
Normal 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);
|
||||||
@ -12,7 +12,6 @@ import {
|
|||||||
readJsonFile,
|
readJsonFile,
|
||||||
writeJsonFile,
|
writeJsonFile,
|
||||||
} from '../../packages/tao/src/utils/fileutils';
|
} from '../../packages/tao/src/utils/fileutils';
|
||||||
import { execSync } from 'child_process';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Available colours
|
* Available colours
|
||||||
@ -32,6 +31,10 @@ const argv = yargs
|
|||||||
'$0',
|
'$0',
|
||||||
'Will update the nx.dev content with Nx releases for the current releases in the `nx-dev/nx-dev/public/documentation/versions.json`'
|
'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', {
|
.option('previousRelease', {
|
||||||
alias: 'p',
|
alias: 'p',
|
||||||
demandOption: false,
|
demandOption: false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user