Skip to content

Commit

Permalink
docs(nxdev): display specific nx package name exception (#10139)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcabanes committed May 4, 2022
1 parent 664df0e commit aa36064
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Simple utility to get the public name of a package handling arbitrary use cases
* @param packageName
* @param prefix
*/
export function getPublicPackageName(
packageName: string,
prefix: string = '@nrwl/'
): string {
/**
* Core Nx package is not prefixed by "@nrwl/" on NPM
*/
const isNxCorePackage = packageName === 'nx';
return isNxCorePackage ? packageName : prefix + packageName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@nrwl/nx-dev/models-package';
import { ParsedUrlQuery } from 'querystring';
import { Errors, Example, generateJsonExampleFor } from './examples';
import { getPublicPackageName } from './get-public-package-name';
import { SchemaRequest } from './schema-request.models';

function getReferenceFromQuery(query: string): string {
Expand Down Expand Up @@ -40,7 +41,7 @@ export function getSchemaViewModel(

return {
schemaMetadata,
packageName: `@nrwl/${schemaRequest.pkg.name}`,
packageName: getPublicPackageName(schemaRequest.pkg.name),
packageUrl: `/packages/${schemaRequest.pkg.name}`,
schemaGithubUrl: schemaRequest.pkg.githubRoot + schemaMetadata.path,
rootReference: '#',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NextSeo } from 'next-seo';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { ReactComponentElement } from 'react';
import { getPublicPackageName } from './get-public-package-name';
import { Heading1, Heading2 } from './ui/headings';
import { Markdown } from './ui/markdown/markdown';

Expand All @@ -30,12 +31,12 @@ export function PackageSchemaList({
seo: { title: string; description: string; url: string; imageUrl: string };
} = {
pkg: {
name: `@nrwl/${pkg.name}`,
name: getPublicPackageName(pkg.name),
description: pkg.description,
githubUrl: pkg.githubRoot + pkg.root,
},
seo: {
title: `@nrwl/${pkg.name} | Nx`,
title: `${getPublicPackageName(pkg.name)} | Nx`,
description: pkg.description,
imageUrl: `https://nx.dev/images/open-graph/${router.asPath
.replace('/', '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextSeo } from 'next-seo';
import { useRouter } from 'next/router';
import { ReactComponentElement } from 'react';
import Content from './content';
import { getPublicPackageName } from './get-public-package-name';
import { getSchemaViewModel, SchemaViewModel } from './get-schema-view-model';
import { SchemaRequest } from './schema-request.models';

Expand All @@ -26,7 +27,9 @@ export function PackageSchemaViewer({
// Process the request and make available the needed schema information
schema: getSchemaViewModel(router.query, schemaRequest),
seo: {
title: `@nrwl/${schemaRequest.pkg.name}:${schemaRequest.schemaName} | Nx`,
title: `${getPublicPackageName(schemaRequest.pkg.name)}:${
schemaRequest.schemaName
} | Nx`,
description:
'Next generation build system with first class monorepo support and powerful integrations.',
imageUrl: `https://nx.dev/images/open-graph/${router.asPath
Expand Down
17 changes: 14 additions & 3 deletions scripts/documentation/open-graph/generate-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ documents.map((category) => {
packages.map((pkg) => {
data.push({
title: 'Package details',
content: `@nrwl/${pkg.name}`,
content: getPublicPackageName(pkg.name),
filename: ['packages', pkg.name].join('-'),
});
pkg.schemas.executors.map((schema) => {
data.push({
title: 'Executor details',
content: `@nrwl/${pkg.name}:${schema}`,
content: `${getPublicPackageName(pkg.name)}:${schema}`,
filename: ['packages', pkg.name, 'executors', schema].join('-'),
});
});
pkg.schemas.generators.map((schema) => {
data.push({
title: 'Generator details',
content: `@nrwl/${pkg.name}:${schema}`,
content: `${getPublicPackageName(pkg.name)}:${schema}`,
filename: ['packages', pkg.name, 'generators', schema].join('-'),
});
});
Expand Down Expand Up @@ -131,3 +131,14 @@ ensureDir(targetFolder).then(() =>
)
)
);

export function getPublicPackageName(
packageName: string,
prefix: string = '@nrwl/'
): string {
/**
* Core Nx package is not prefixed by "@nrwl/" on NPM
*/
const isNxCorePackage = packageName === 'nx';
return isNxCorePackage ? packageName : prefix + packageName;
}

1 comment on commit aa36064

@vercel
Copy link

@vercel vercel bot commented on aa36064 May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.