@travetto/doc 7.1.3 → 7.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/__index__.ts CHANGED
@@ -2,4 +2,5 @@ export { type JSXElement as DocJSXElement, isJSXElement as isDocJSXElement } fro
2
2
  export { c, d, JSXElementByFn as DocJSXElementByFn } from './src/jsx.ts';
3
3
  export { MODULES as module } from './src/mapping/module.ts';
4
4
  export { DocFileUtil } from './src/util/file.ts';
5
- export { DocRunUtil, COMMON_DATE } from './src/util/run.ts';
5
+ export { DocRunUtil, COMMON_DATE } from './src/util/run.ts';
6
+ export { PackageDocUtil } from './src/util/package.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/doc",
3
- "version": "7.1.3",
3
+ "version": "7.1.4",
4
4
  "description": "Documentation support for the Travetto framework",
5
5
  "keywords": [
6
6
  "docs",
@@ -24,12 +24,12 @@
24
24
  "directory": "module/doc"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/runtime": "^7.1.3",
27
+ "@travetto/runtime": "^7.1.4",
28
28
  "@types/prismjs": "^1.26.5",
29
29
  "prismjs": "^1.30.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@travetto/cli": "^7.1.3"
32
+ "@travetto/cli": "^7.1.4"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@travetto/cli": {
package/src/jsx.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { castTo, Runtime, TypedObject } from '@travetto/runtime';
2
- import { PackageUtil } from '@travetto/manifest';
1
+ import { castTo, TypedObject } from '@travetto/runtime';
3
2
 
4
3
  import type { LIBRARIES } from './mapping/library.ts';
5
4
  import type { MODULES } from './mapping/module.ts';
6
5
  import type { CodeProps, RunConfig } from './util/types.ts';
7
6
 
8
7
  import { createElement, type JSXElement, type JSXComponentFunction as CompFn } from '../support/jsx-runtime.ts';
8
+ import { PackageDocUtil } from './util/package.ts';
9
9
 
10
10
  type InstallProps = { title: string, pkg: string };
11
11
  type ExecProps = { title: string, cmd: string, args?: string[], config?: RunConfig & { formatCommand?(cmd: string, args: string[]): string } };
@@ -106,7 +106,5 @@ export const d = {
106
106
  field: (name: string) => createElement(c.Field, { name }),
107
107
  library: (name: keyof typeof LIBRARIES) => createElement(c.Library, { name }),
108
108
  module: (name: keyof typeof MODULES) => createElement(c.Module, { name }),
109
- installCommand: (pkg: string, production?: boolean) => PackageUtil.getInstallCommand(Runtime, pkg, production),
110
- workspaceInitCommand: () => PackageUtil.getWorkspaceInitCommand(Runtime),
111
- get trv() { return PackageUtil.getPackageCommand(Runtime, 'trv'); },
109
+ get trv() { return PackageDocUtil.getPackageCommand('trv'); },
112
110
  };
@@ -5,7 +5,8 @@ export const LIBRARIES = {
5
5
  Node: { title: 'Node', href: 'https://nodejs.org' },
6
6
  TravettoPlugin: { title: 'VSCode plugin', href: 'https://marketplace.visualstudio.com/items?itemName=arcsine.travetto-plugin' },
7
7
  Npm: { title: 'Npm', href: 'https://docs.npmjs.com/downloading-and-installing-node-js-and-npm' },
8
- Yarn: { title: 'Yarn', href: 'https://yarnpg.com' },
8
+ Yarn: { title: 'Yarn', href: 'https://yarnpkg.com' },
9
+ Pnpm: { title: 'Pnpm', href: 'https://pnpm.io/' },
9
10
  Eslint: { title: 'ESLint', href: 'https://eslint.org/' },
10
11
  Rollup: { title: 'Rollup', href: 'https://rollupjs.org/' },
11
12
  TSConfig: { title: 'TS Config', href: 'https://www.typescriptlang.org/docs/handbook/tsconfig-json.html' },
@@ -11,6 +11,7 @@ import { LIBRARIES } from '../mapping/library.ts';
11
11
  import type { RenderContext } from './context.ts';
12
12
  import { DocResolveUtil } from '../util/resolve.ts';
13
13
  import type { JSXElement } from '../../support/jsx-runtime.ts';
14
+ import { PackageDocUtil } from '../util/package.ts';
14
15
 
15
16
  const ESCAPE_ENTITIES: Record<string, string> = { '<': '&lt;', '>': '&gt;', '&': '&amp;', '{': "{{'{'}}", '}': "{{'}'}}" };
16
17
  const ENTITY_REGEX = new RegExp(`[${Object.keys(ESCAPE_ENTITIES).join('')}]`, 'gm');
@@ -52,7 +53,7 @@ export const Html: RenderProvider<RenderContext> = {
52
53
  },
53
54
  Install: async ({ context, node }) => {
54
55
  const highlighted = highlight(`
55
- ${PackageUtil.getInstallInstructions(node.props.pkg, true)}
56
+ ${PackageDocUtil.getInstallInstructions(node.props.pkg, true)}
56
57
  `, 'bash');
57
58
 
58
59
  return `\n
@@ -9,6 +9,7 @@ import { MODULES } from '../mapping/module.ts';
9
9
  import { LIBRARIES } from '../mapping/library.ts';
10
10
  import type { RenderContext } from './context.ts';
11
11
  import { DocResolveUtil } from '../util/resolve.ts';
12
+ import { PackageDocUtil } from '../util/package.ts';
12
13
 
13
14
  export const Markdown: RenderProvider<RenderContext> = {
14
15
  ext: 'md',
@@ -55,7 +56,7 @@ export const Markdown: RenderProvider<RenderContext> = {
55
56
  Install: async ({ context, node }) =>
56
57
  `\n\n**Install: ${node.props.title}**
57
58
  \`\`\`bash
58
- ${PackageUtil.getInstallInstructions(node.props.pkg, true)}
59
+ ${PackageDocUtil.getInstallInstructions(node.props.pkg, true)}
59
60
  \`\`\`
60
61
  `,
61
62
  Code: async ({ context, node, props }) => {
@@ -0,0 +1,46 @@
1
+ import { PACKAGE_MANAGERS, type NodePackageManager } from '@travetto/manifest';
2
+ import { Runtime } from '@travetto/runtime';
3
+
4
+ export class PackageDocUtil {
5
+ /**
6
+ * Get an the command for executing a package level binary
7
+ */
8
+ static getPackageCommand(pkg: string, args: string[] = [], manager?: NodePackageManager): string {
9
+ switch (manager ?? Runtime.workspace.manager) {
10
+ case 'npm':
11
+ case 'yarn': return `npx ${pkg} ${args.join(' ')}`.trim();
12
+ case 'pnpm': return `pnpm ${pkg} ${args.join(' ')}`.trim();
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Get an the command for executing a package level binary
18
+ */
19
+ static getWorkspaceInitCommand(manager?: NodePackageManager): string {
20
+ switch (manager ?? Runtime.workspace.manager) {
21
+ case 'npm': return 'npm init -f';
22
+ case 'yarn': return 'yarn init -y';
23
+ case 'pnpm': return 'pnpm init -y';
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Get an install command for a given npm module
29
+ */
30
+ static getInstallCommand(pkg: string, production = false, manager?: NodePackageManager): string {
31
+ switch (manager ?? Runtime.workspace.manager) {
32
+ case 'npm': return `npm install ${production ? '' : '--save-dev '}${pkg}`;
33
+ case 'yarn': return `yarn add ${production ? '' : '--dev '}${pkg}`;
34
+ case 'pnpm': return `pnpm add ${production ? '' : '--dev '}${pkg}`;
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Get install example for a given package
40
+ */
41
+ static getInstallInstructions(pkg: string, production = false): string {
42
+ return PACKAGE_MANAGERS
43
+ .map(manager => this.getInstallCommand(pkg, production, manager.type))
44
+ .join('\n\n# or\n\n');
45
+ }
46
+ }