@poetora/cli 0.0.1 → 0.1.2

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.
Files changed (117) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/LICENSE +93 -0
  3. package/bin/accessibility.js +2 -2
  4. package/bin/cli-builder.d.ts +8 -0
  5. package/bin/cli-builder.js +178 -0
  6. package/bin/cli.d.ts +5 -11
  7. package/bin/cli.js +8 -200
  8. package/bin/commands/base.command.d.ts +13 -0
  9. package/bin/commands/base.command.js +40 -0
  10. package/bin/commands/check.command.d.ts +14 -0
  11. package/bin/commands/check.command.js +21 -0
  12. package/bin/commands/dev.command.d.ts +13 -0
  13. package/bin/commands/dev.command.js +40 -0
  14. package/bin/commands/index.d.ts +6 -0
  15. package/bin/commands/index.js +6 -0
  16. package/bin/commands/init.command.d.ts +16 -0
  17. package/bin/commands/init.command.js +88 -0
  18. package/bin/commands/link.command.d.ts +13 -0
  19. package/bin/commands/link.command.js +19 -0
  20. package/bin/commands/update.command.d.ts +10 -0
  21. package/bin/commands/update.command.js +13 -0
  22. package/bin/constants.js +1 -1
  23. package/bin/errors/cli-error.d.ts +26 -0
  24. package/bin/errors/cli-error.js +53 -0
  25. package/bin/errors/index.d.ts +1 -0
  26. package/bin/errors/index.js +1 -0
  27. package/bin/index.d.ts +1 -1
  28. package/bin/index.js +6 -6
  29. package/bin/mdxAccessibility.js +2 -2
  30. package/bin/services/accessibility-check.service.d.ts +10 -0
  31. package/bin/services/accessibility-check.service.js +144 -0
  32. package/bin/services/index.d.ts +7 -0
  33. package/bin/services/index.js +7 -0
  34. package/bin/services/link.service.d.ts +7 -0
  35. package/bin/services/link.service.js +40 -0
  36. package/bin/services/openapi-check.service.d.ts +7 -0
  37. package/bin/services/openapi-check.service.js +43 -0
  38. package/bin/services/port.service.d.ts +7 -0
  39. package/bin/services/port.service.js +26 -0
  40. package/bin/services/template.service.d.ts +22 -0
  41. package/bin/services/template.service.js +127 -0
  42. package/bin/services/update.service.d.ts +10 -0
  43. package/bin/services/update.service.js +57 -0
  44. package/bin/services/version.service.d.ts +16 -0
  45. package/bin/services/version.service.js +102 -0
  46. package/bin/types/common.d.ts +38 -0
  47. package/bin/types/common.js +21 -0
  48. package/bin/types/index.d.ts +2 -0
  49. package/bin/types/index.js +2 -0
  50. package/bin/types/options.d.ts +23 -0
  51. package/bin/types/options.js +1 -0
  52. package/bin/utils/console-logger.d.ts +16 -0
  53. package/bin/utils/console-logger.js +65 -0
  54. package/bin/utils/index.d.ts +2 -0
  55. package/bin/utils/index.js +2 -0
  56. package/bin/utils/logger.interface.d.ts +15 -0
  57. package/bin/utils/logger.interface.js +1 -0
  58. package/package.json +29 -29
  59. package/src/accessibility.ts +2 -2
  60. package/src/cli-builder.ts +267 -0
  61. package/src/cli.ts +15 -0
  62. package/src/commands/__tests__/base.command.test.ts +145 -0
  63. package/src/commands/__tests__/dev.command.test.ts +241 -0
  64. package/src/commands/__tests__/init.command.test.ts +281 -0
  65. package/{__test__ → src/commands/__tests__}/utils.ts +1 -1
  66. package/src/commands/base.command.ts +97 -0
  67. package/src/commands/check.command.ts +40 -0
  68. package/src/commands/dev.command.ts +63 -0
  69. package/src/commands/index.ts +6 -0
  70. package/src/commands/init.command.ts +125 -0
  71. package/src/commands/link.command.ts +39 -0
  72. package/src/commands/update.command.ts +23 -0
  73. package/src/constants.ts +1 -1
  74. package/src/errors/cli-error.ts +83 -0
  75. package/src/errors/index.ts +1 -0
  76. package/src/index.ts +6 -6
  77. package/src/mdxAccessibility.ts +3 -4
  78. package/src/services/__tests__/port.service.test.ts +83 -0
  79. package/src/services/__tests__/template.service.test.ts +234 -0
  80. package/src/services/__tests__/version.service.test.ts +165 -0
  81. package/src/services/accessibility-check.service.ts +226 -0
  82. package/src/services/index.ts +7 -0
  83. package/src/services/link.service.ts +65 -0
  84. package/src/services/openapi-check.service.ts +68 -0
  85. package/src/services/port.service.ts +47 -0
  86. package/src/services/template.service.ts +203 -0
  87. package/src/services/update.service.ts +76 -0
  88. package/src/services/version.service.ts +161 -0
  89. package/src/types/common.ts +53 -0
  90. package/src/types/index.ts +2 -0
  91. package/src/types/options.ts +42 -0
  92. package/src/utils/console-logger.ts +114 -0
  93. package/src/utils/index.ts +2 -0
  94. package/src/utils/logger.interface.ts +70 -0
  95. package/tsconfig.build.json +2 -1
  96. package/tsconfig.json +1 -1
  97. package/.prettierignore +0 -2
  98. package/__test__/brokenLinks.test.ts +0 -93
  99. package/__test__/checkPort.test.ts +0 -92
  100. package/__test__/openApiCheck.test.ts +0 -127
  101. package/__test__/update.test.ts +0 -108
  102. package/bin/accessibilityCheck.d.ts +0 -2
  103. package/bin/accessibilityCheck.js +0 -70
  104. package/bin/helpers.d.ts +0 -17
  105. package/bin/helpers.js +0 -104
  106. package/bin/init.d.ts +0 -1
  107. package/bin/init.js +0 -73
  108. package/bin/mdxLinter.d.ts +0 -2
  109. package/bin/mdxLinter.js +0 -45
  110. package/bin/update.d.ts +0 -3
  111. package/bin/update.js +0 -32
  112. package/src/accessibilityCheck.tsx +0 -145
  113. package/src/cli.tsx +0 -302
  114. package/src/helpers.tsx +0 -131
  115. package/src/init.tsx +0 -93
  116. package/src/mdxLinter.tsx +0 -88
  117. package/src/update.tsx +0 -37
@@ -1,127 +0,0 @@
1
- import * as previewing from '@poetora/previewing';
2
- import { getOpenApiDocumentFromUrl, isAllowedLocalSchemaUrl, validate } from '@poetora/shared';
3
- import { mockProcessExit } from 'vitest-mock-process';
4
-
5
- import { readLocalOpenApiFile } from '../src/helpers';
6
- import { mockValidOpenApiDocument, runCommand } from './utils';
7
-
8
- vi.mock('@poetora/shared', () => ({
9
- getOpenApiDocumentFromUrl: vi.fn(),
10
- isAllowedLocalSchemaUrl: vi.fn(),
11
- validate: vi.fn(),
12
- }));
13
-
14
- vi.mock('../src/helpers', async () => {
15
- const originalModule = await import('../src/helpers');
16
- return {
17
- ...originalModule,
18
- readLocalOpenApiFile: vi.fn(),
19
- };
20
- });
21
-
22
- const addLogSpy = vi.spyOn(previewing, 'addLog');
23
- const processExitMock = mockProcessExit();
24
-
25
- describe('openApiCheck', () => {
26
- beforeEach(() => {
27
- vi.clearAllMocks();
28
- });
29
-
30
- afterEach(() => {
31
- vi.clearAllMocks();
32
- });
33
-
34
- it('valid openApi file from url', async () => {
35
- vi.mocked(isAllowedLocalSchemaUrl).mockReturnValueOnce(true);
36
- vi.mocked(getOpenApiDocumentFromUrl).mockResolvedValueOnce(mockValidOpenApiDocument);
37
-
38
- await runCommand('openapi-check', 'https://petstore3.swagger.io/api/v3/openapi.json');
39
-
40
- expect(addLogSpy).toHaveBeenCalledWith(
41
- expect.objectContaining({
42
- props: { message: 'OpenAPI definition is valid.' },
43
- })
44
- );
45
- expect(processExitMock).toHaveBeenCalledWith(0);
46
- });
47
-
48
- it('invalid openApi file from url', async () => {
49
- vi.mocked(isAllowedLocalSchemaUrl).mockReturnValueOnce(true);
50
- vi.mocked(getOpenApiDocumentFromUrl).mockRejectedValueOnce(
51
- new Error('Could not parse OpenAPI document.')
52
- );
53
-
54
- await runCommand('openapi-check', 'https://petstore3.swagger.io/api/v3/openapi.json');
55
-
56
- expect(addLogSpy).toHaveBeenCalledWith(
57
- expect.objectContaining({
58
- props: { message: 'Could not parse OpenAPI document.' },
59
- })
60
- );
61
- expect(processExitMock).toHaveBeenCalledWith(1);
62
- });
63
-
64
- it('valid openApi file from localhost', async () => {
65
- vi.mocked(isAllowedLocalSchemaUrl).mockReturnValueOnce(true);
66
- vi.mocked(getOpenApiDocumentFromUrl).mockResolvedValueOnce(mockValidOpenApiDocument);
67
-
68
- await runCommand('openapi-check', 'http://localhost:3000/openapi.json');
69
-
70
- expect(addLogSpy).toHaveBeenCalledWith(
71
- expect.objectContaining({
72
- props: { message: 'OpenAPI definition is valid.' },
73
- })
74
- );
75
- expect(processExitMock).toHaveBeenCalledWith(0);
76
- });
77
-
78
- it('invalid openApi file from localhost', async () => {
79
- vi.mocked(isAllowedLocalSchemaUrl).mockReturnValueOnce(false);
80
- vi.mocked(readLocalOpenApiFile).mockResolvedValueOnce(undefined);
81
-
82
- await runCommand('openapi-check', 'http://localhost:3000/openapi.json');
83
-
84
- expect(addLogSpy).toHaveBeenCalledWith(
85
- expect.objectContaining({
86
- props: {
87
- message:
88
- 'failed to parse OpenAPI spec: could not parse file correctly, please check for any syntax errors.',
89
- },
90
- })
91
- );
92
- expect(processExitMock).toHaveBeenCalledWith(1);
93
- });
94
-
95
- it('valid openApi file from local file', async () => {
96
- vi.mocked(isAllowedLocalSchemaUrl).mockReturnValueOnce(false);
97
- vi.mocked(readLocalOpenApiFile).mockResolvedValueOnce(mockValidOpenApiDocument);
98
- vi.mocked(validate).mockResolvedValueOnce({
99
- valid: true,
100
- errors: [],
101
- });
102
-
103
- await runCommand('openapi-check', 'test/openapi.yaml');
104
-
105
- expect(addLogSpy).toHaveBeenCalledWith(
106
- expect.objectContaining({
107
- props: { message: 'OpenAPI definition is valid.' },
108
- })
109
- );
110
- expect(processExitMock).toHaveBeenCalledWith(0);
111
- });
112
-
113
- it('invalid openApi file from local file', async () => {
114
- vi.mocked(isAllowedLocalSchemaUrl).mockReturnValueOnce(false);
115
- vi.mocked(readLocalOpenApiFile).mockResolvedValueOnce(mockValidOpenApiDocument);
116
- vi.mocked(validate).mockRejectedValueOnce(new Error('some schema parsing error'));
117
-
118
- await runCommand('openapi-check', 'test/openapi.yaml');
119
-
120
- expect(addLogSpy).toHaveBeenCalledWith(
121
- expect.objectContaining({
122
- props: { message: 'some schema parsing error' },
123
- })
124
- );
125
- expect(processExitMock).toHaveBeenCalledWith(1);
126
- });
127
- });
@@ -1,108 +0,0 @@
1
- import * as previewing from '@poetora/previewing';
2
-
3
- import { getLatestCliVersion, getVersions, execAsync } from '../src/helpers';
4
- import { update } from '../src/update';
5
-
6
- vi.mock('@poetora/previewing', async () => {
7
- const originalModule =
8
- await vi.importActual<typeof import('@poetora/previewing')>('@poetora/previewing');
9
- return {
10
- ...originalModule,
11
- getClientVersion: vi.fn(),
12
- downloadTargetPoet: vi.fn(),
13
- };
14
- });
15
-
16
- vi.mock('../src/helpers', async () => {
17
- const originalModule = await vi.importActual<typeof import('../src/helpers')>('../src/helpers');
18
- return {
19
- ...originalModule,
20
- execAsync: vi.fn(),
21
- getLatestCliVersion: vi.fn(),
22
- getVersions: vi.fn().mockReturnValue({
23
- cli: '1.0.0',
24
- client: '1.0.0',
25
- }),
26
- detectPackageManager: vi.fn().mockResolvedValue('pnpm'),
27
- };
28
- });
29
-
30
- const addLogSpy = vi.spyOn(previewing, 'addLog');
31
-
32
- describe('update', () => {
33
- beforeEach(() => {
34
- vi.clearAllMocks();
35
- });
36
-
37
- afterEach(() => {
38
- vi.resetAllMocks();
39
- });
40
-
41
- it('should update the cli successfully', async () => {
42
- vi.mocked(getVersions).mockReturnValue({
43
- cli: '1.0.0',
44
- client: '1.0.0',
45
- });
46
- vi.mocked(getLatestCliVersion).mockReturnValue('2.0.0');
47
- vi.mocked(execAsync).mockResolvedValue({ stdout: '', stderr: '' });
48
- vi.mocked(previewing.downloadTargetPoet).mockResolvedValue();
49
-
50
- await update({ packageName: 'poetora' });
51
-
52
- expect(addLogSpy).toHaveBeenCalledTimes(3);
53
- expect(addLogSpy).toHaveBeenCalledWith(
54
- expect.objectContaining({ props: { message: 'updating...' } })
55
- );
56
- expect(addLogSpy).toHaveBeenCalledWith(
57
- expect.objectContaining({ props: { message: 'updating poetora package...' } })
58
- );
59
- expect(addLogSpy).toHaveBeenCalledWith(
60
- expect.objectContaining({
61
- props: { message: 'updated poetora to the latest version: 2.0.0' },
62
- })
63
- );
64
- expect(execAsync).toHaveBeenCalledWith('pnpm install -g poetora@latest --silent');
65
- });
66
-
67
- it('should return when already up to date', async () => {
68
- vi.mocked(getVersions).mockReturnValue({
69
- cli: '1.0.0',
70
- client: '1.0.0',
71
- });
72
- vi.mocked(getLatestCliVersion).mockReturnValue('1.0.0');
73
- vi.mocked(execAsync).mockResolvedValue({ stdout: '', stderr: '' });
74
-
75
- await update({ packageName: 'poetora' });
76
-
77
- expect(addLogSpy).toHaveBeenCalledTimes(2);
78
- expect(addLogSpy).toHaveBeenCalledWith(
79
- expect.objectContaining({ props: { message: 'updating...' } })
80
- );
81
- expect(addLogSpy).toHaveBeenCalledWith(
82
- expect.objectContaining({ props: { message: 'already up to date' } })
83
- );
84
- expect(execAsync).not.toHaveBeenCalled();
85
- });
86
-
87
- it('should handle cli update failure', async () => {
88
- vi.mocked(getVersions).mockReturnValue({
89
- cli: '1.0.0',
90
- client: '1.0.0',
91
- });
92
- vi.mocked(getLatestCliVersion).mockReturnValue('2.0.0');
93
- vi.mocked(execAsync).mockRejectedValue(new Error('Update failed'));
94
-
95
- await update({ packageName: 'poetora' });
96
-
97
- expect(addLogSpy).toHaveBeenCalledTimes(3);
98
- expect(addLogSpy).toHaveBeenCalledWith(
99
- expect.objectContaining({ props: { message: 'updating...' } })
100
- );
101
- expect(addLogSpy).toHaveBeenCalledWith(
102
- expect.objectContaining({ props: { message: 'updating poetora package...' } })
103
- );
104
- expect(addLogSpy).toHaveBeenCalledWith(
105
- expect.objectContaining({ props: { message: 'failed to update poetora@latest' } })
106
- );
107
- });
108
- });
@@ -1,2 +0,0 @@
1
- export type TerminateCode = 0 | 1;
2
- export declare const accessibilityCheck: () => Promise<TerminateCode>;
@@ -1,70 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { getConfigObj, getConfigPath } from '@poetora/prebuild';
3
- import { addLog, ErrorLog, WarningLog } from '@poetora/previewing';
4
- import { getBackgroundColors } from '@poetora/shared';
5
- import { Text } from 'ink';
6
- import { checkDocsColors } from './accessibility.js';
7
- import { CMD_EXEC_PATH } from './constants.js';
8
- export const accessibilityCheck = async () => {
9
- try {
10
- const docsConfigPath = await getConfigPath(CMD_EXEC_PATH);
11
- if (!docsConfigPath) {
12
- addLog(_jsx(ErrorLog, { message: "No configuration file found. Please run this command from a directory with a docs.json file." }));
13
- return 1;
14
- }
15
- const config = await getConfigObj(CMD_EXEC_PATH);
16
- if (!config.colors) {
17
- addLog(_jsx(WarningLog, { message: "No colors section found in configuration file" }));
18
- return 0;
19
- }
20
- const { colors, navigation } = config;
21
- const { lightHex, darkHex } = getBackgroundColors(config);
22
- const results = checkDocsColors(colors, { lightHex, darkHex }, navigation);
23
- const displayContrastResult = (result, label, prefix = '') => {
24
- if (!result)
25
- return;
26
- const { recommendation, message } = result;
27
- const icon = recommendation === 'pass' ? 'PASS' : recommendation === 'warning' ? 'WARN' : 'FAIL';
28
- const color = recommendation === 'pass' ? 'green' : recommendation === 'warning' ? 'yellow' : 'red';
29
- addLog(_jsxs(Text, { children: [_jsxs(Text, { bold: prefix === '', children: [prefix, label, ":", ' '] }), _jsxs(Text, { color: color, children: [icon, " ", message] })] }));
30
- };
31
- addLog(_jsx(Text, { bold: true, color: "cyan", children: "Checking color accessibility..." }));
32
- addLog(_jsx(Text, {}));
33
- displayContrastResult(results.primaryContrast, `Primary Color (${colors.primary}) vs Light Background`);
34
- displayContrastResult(results.lightContrast, `Light Color (${colors.light}) vs Dark Background`);
35
- displayContrastResult(results.darkContrast, `Dark Color (${colors.dark}) vs Dark Background`);
36
- displayContrastResult(results.darkOnLightContrast, `Dark Color (${colors.dark}) vs Light Background`);
37
- const anchorsWithResults = results.anchorResults.filter((anchor) => anchor.lightContrast || anchor.darkContrast);
38
- if (anchorsWithResults.length > 0) {
39
- addLog(_jsx(Text, {}));
40
- addLog(_jsx(Text, { bold: true, color: "cyan", children: "Navigation Anchors:" }));
41
- for (const anchor of anchorsWithResults) {
42
- addLog(_jsxs(Text, { bold: true, children: [" ", anchor.name, ":"] }));
43
- displayContrastResult(anchor.lightContrast, 'Light variant vs Light Background', ' ');
44
- displayContrastResult(anchor.darkContrast, 'Dark variant vs Dark Background', ' ');
45
- }
46
- }
47
- addLog(_jsx(Text, {}));
48
- const overallIcon = results.overallScore === 'pass'
49
- ? 'PASS'
50
- : results.overallScore === 'warning'
51
- ? 'WARN'
52
- : 'FAIL';
53
- const overallColor = results.overallScore === 'pass'
54
- ? 'green'
55
- : results.overallScore === 'warning'
56
- ? 'yellow'
57
- : 'red';
58
- const overallMessage = results.overallScore === 'pass'
59
- ? 'All colors meet accessibility standards!'
60
- : results.overallScore === 'warning'
61
- ? 'Some colors could be improved for better accessibility'
62
- : 'Some colors fail accessibility standards and should be updated';
63
- addLog(_jsx(Text, { children: _jsxs(Text, { bold: true, color: overallColor, children: ["Overall Assessment: ", overallIcon, " ", overallMessage] }) }));
64
- return results.overallScore === 'fail' ? 1 : 0;
65
- }
66
- catch (error) {
67
- addLog(_jsx(ErrorLog, { message: `Accessibility check failed: ${error instanceof Error ? error.message : 'Unknown error'}` }));
68
- return 1;
69
- }
70
- };
package/bin/helpers.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { exec } from 'node:child_process';
2
- import type { ArgumentsCamelCase } from 'yargs';
3
- export declare const checkPort: (argv: ArgumentsCamelCase) => Promise<number | undefined>;
4
- export declare const checkNodeVersion: () => Promise<void>;
5
- export declare const getCliVersion: () => string | undefined;
6
- export declare const getVersions: () => {
7
- cli: string | undefined;
8
- client: string | undefined;
9
- };
10
- export declare const getLatestCliVersion: (packageName: string) => string;
11
- export declare const suppressConsoleWarnings: () => void;
12
- export declare const readLocalOpenApiFile: (filename: string) => Promise<Record<string, unknown> | undefined>;
13
- export declare const terminate: (code: number) => Promise<never>;
14
- export declare const execAsync: typeof exec.__promisify__;
15
- export declare const detectPackageManager: ({ packageName }: {
16
- packageName: string;
17
- }) => Promise<"pnpm" | "npm">;
package/bin/helpers.js DELETED
@@ -1,104 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { addLog, ErrorLog, getClientVersion, InfoLog, LOCAL_LINKED_CLI_VERSION, } from '@poetora/previewing';
3
- import detect from 'detect-port';
4
- import fs from 'fs/promises';
5
- import yaml from 'js-yaml';
6
- import { exec, execSync } from 'node:child_process';
7
- import { promisify } from 'node:util';
8
- import path from 'path';
9
- import yargs from 'yargs';
10
- export const checkPort = async (argv) => {
11
- const initialPort = typeof argv.port === 'number' ? argv.port : 3000;
12
- if (initialPort === (await detect(initialPort)))
13
- return initialPort;
14
- for (let port = initialPort + 1; port < initialPort + 10; port++) {
15
- addLog(_jsx(InfoLog, { message: `port ${port - 1} is already in use. trying ${port} instead` }));
16
- if (port === (await detect(port)))
17
- return port;
18
- }
19
- };
20
- export const checkNodeVersion = async () => {
21
- let nodeVersionString = process.version;
22
- if (nodeVersionString.charAt(0) === 'v') {
23
- nodeVersionString = nodeVersionString.slice(1);
24
- }
25
- const versionArr = nodeVersionString.split('.');
26
- const majorVersion = parseInt(versionArr[0], 10);
27
- if (majorVersion < 18) {
28
- addLog(_jsx(ErrorLog, { message: `poetora requires a node version >= 18.0.0 (current version ${nodeVersionString}). try removing the poetora package, upgrading node, reinstalling poetora, and running again.` }));
29
- }
30
- };
31
- export const getCliVersion = () => {
32
- const y = yargs();
33
- let version = undefined;
34
- y.showVersion((s) => {
35
- version = s;
36
- return false;
37
- });
38
- if (process.env.CLI_TEST_MODE === 'true') {
39
- return 'test-cli';
40
- }
41
- if (version === 'unknown') {
42
- version = LOCAL_LINKED_CLI_VERSION;
43
- }
44
- return version;
45
- };
46
- export const getVersions = () => {
47
- const cli = getCliVersion();
48
- const client = getClientVersion().trim();
49
- return { cli, client };
50
- };
51
- export const getLatestCliVersion = (packageName) => {
52
- return execSync(`npm view ${packageName} version --silent`, {
53
- encoding: 'utf-8',
54
- stdio: ['pipe', 'pipe', 'pipe'],
55
- }).trim();
56
- };
57
- export const suppressConsoleWarnings = () => {
58
- const ignoredMessages = [
59
- 'No utility classes were detected',
60
- 'https://tailwindcss.com/docs/content-configuration',
61
- 'DeprecationWarning',
62
- ];
63
- const originalConsoleError = console.error;
64
- console.error = (...args) => {
65
- const message = args.join(' ');
66
- if (ignoredMessages.some((ignoredMessage) => message.includes(ignoredMessage))) {
67
- return;
68
- }
69
- originalConsoleError.apply(console, args);
70
- };
71
- const originalConsoleWarn = console.warn;
72
- console.warn = (...args) => {
73
- const message = args.join(' ');
74
- if (ignoredMessages.some((ignoredMessage) => message.includes(ignoredMessage))) {
75
- return;
76
- }
77
- originalConsoleWarn.apply(console, args);
78
- };
79
- };
80
- export const readLocalOpenApiFile = async (filename) => {
81
- const pathname = path.resolve(process.cwd(), filename);
82
- const file = await fs.readFile(pathname, 'utf-8');
83
- const document = yaml.load(file);
84
- return document;
85
- };
86
- export const terminate = async (code) => {
87
- await new Promise((resolve) => setTimeout(resolve, 50));
88
- process.exit(code);
89
- };
90
- export const execAsync = promisify(exec);
91
- export const detectPackageManager = async ({ packageName }) => {
92
- try {
93
- const { stdout: packagePath } = await execAsync(`which ${packageName}`);
94
- if (packagePath.includes('pnpm')) {
95
- return 'pnpm';
96
- }
97
- else {
98
- return 'npm';
99
- }
100
- }
101
- catch (error) {
102
- return 'npm';
103
- }
104
- };
package/bin/init.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function init(installDir: string): Promise<void>;
package/bin/init.js DELETED
@@ -1,73 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { select, input } from '@inquirer/prompts';
3
- import { addLogs, addLog, SpinnerLog, removeLastLog } from '@poetora/previewing';
4
- import { docsConfigSchema } from '@poetora/validation';
5
- import AdmZip from 'adm-zip';
6
- import fse from 'fs-extra';
7
- import { Box, Text } from 'ink';
8
- const sendOnboardingMessage = (installDir) => {
9
- addLogs(_jsx(Text, { bold: true, children: "Documentation Setup!" }), _jsx(Text, { children: "To see your docs run" }), _jsxs(Box, { children: [_jsx(Text, { color: "blue", children: "cd" }), _jsxs(Text, { children: [" ", installDir] })] }), _jsx(Text, { color: "blue", children: "poet dev" }));
10
- };
11
- export async function init(installDir) {
12
- await fse.ensureDir(installDir);
13
- const dirContents = await fse.readdir(installDir).catch(() => []);
14
- if (dirContents.length > 0) {
15
- const choice = await select({
16
- message: `Directory ${installDir} is not empty. What would you like to do?`,
17
- choices: [
18
- { name: 'Create in a subdirectory', value: 'subdir' },
19
- { name: 'Overwrite current directory (may lose contents)', value: 'overwrite' },
20
- { name: 'Cancel', value: 'cancel' },
21
- ],
22
- });
23
- if (choice === 'cancel') {
24
- return;
25
- }
26
- if (choice === 'subdir') {
27
- const subdir = await input({
28
- message: 'Subdirectory name:',
29
- default: 'docs',
30
- });
31
- if (!subdir || subdir.trim() === '') {
32
- throw new Error('Subdirectory name cannot be empty');
33
- }
34
- installDir = installDir === '.' ? subdir : `${installDir}/${subdir}`;
35
- await fse.ensureDir(installDir);
36
- }
37
- }
38
- const defaultProject = installDir == '.' ? 'Poetora' : installDir;
39
- const projectName = await input({
40
- message: 'Project Name',
41
- default: defaultProject,
42
- });
43
- const themes = docsConfigSchema.options.map((option) => {
44
- return option.shape.theme._def.value;
45
- });
46
- const theme = await select({
47
- message: 'Theme',
48
- choices: themes.map((t) => ({
49
- name: t,
50
- value: t,
51
- })),
52
- });
53
- addLog(_jsx(SpinnerLog, { message: "downloading starter template..." }));
54
- const response = await fetch('https://github.com/poetora/starter/archive/refs/heads/main.zip');
55
- const buffer = await response.arrayBuffer();
56
- await fse.writeFile(installDir + '/starter.zip', Buffer.from(buffer));
57
- removeLastLog();
58
- addLog(_jsx(SpinnerLog, { message: "extracting..." }));
59
- new AdmZip(installDir + '/starter.zip').extractAllTo(installDir, true);
60
- removeLastLog();
61
- await fse.copy(installDir + '/starter-main', installDir, {
62
- overwrite: true,
63
- filter: (src) => !src.includes('starter-main/starter-main'),
64
- });
65
- await fse.remove(installDir + '/starter.zip');
66
- await fse.remove(installDir + '/starter-main');
67
- const docsJsonPath = installDir + '/docs.json';
68
- const docsConfig = await fse.readJson(docsJsonPath);
69
- docsConfig.theme = theme;
70
- docsConfig.name = projectName;
71
- await fse.writeJson(docsJsonPath, docsConfig, { spaces: 2 });
72
- sendOnboardingMessage(installDir);
73
- }
@@ -1,2 +0,0 @@
1
- import { TerminateCode } from './accessibilityCheck.js';
2
- export declare const mdxLinter: () => Promise<TerminateCode>;
package/bin/mdxLinter.js DELETED
@@ -1,45 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { addLog, ErrorLog, SuccessLog } from '@poetora/previewing';
3
- import { Text } from 'ink';
4
- import path from 'path';
5
- import { checkMdxAccessibility } from './mdxAccessibility.js';
6
- export const mdxLinter = async () => {
7
- try {
8
- addLog(_jsx(Text, { bold: true, color: "cyan", children: "Checking mdx files for accessibility issues..." }));
9
- const results = await checkMdxAccessibility();
10
- if (results.missingAltAttributes.length === 0) {
11
- addLog(_jsx(SuccessLog, { message: "no accessibility issues found" }));
12
- addLog(_jsxs(Text, { children: ["Checked ", results.totalFiles, " MDX files - all images and videos have alt attributes."] }));
13
- return 0;
14
- }
15
- const issuesByFile = {};
16
- results.missingAltAttributes.forEach((issue) => {
17
- if (!issuesByFile[issue.filePath]) {
18
- issuesByFile[issue.filePath] = [];
19
- }
20
- issuesByFile[issue.filePath]?.push(issue);
21
- });
22
- addLog(_jsxs(Text, { bold: true, color: "red", children: ["Found ", results.missingAltAttributes.length, " accessibility issues in", ' ', results.filesWithIssues, " files:"] }));
23
- addLog(_jsx(Text, {}));
24
- for (const [filePath, issues] of Object.entries(issuesByFile)) {
25
- const relativePath = path.relative(process.cwd(), filePath);
26
- addLog(_jsxs(Text, { bold: true, children: [relativePath, ":"] }));
27
- for (const issue of issues) {
28
- const location = issue.line && issue.column ? ` (line ${issue.line}, col ${issue.column})` : '';
29
- if (issue.element === 'a') {
30
- addLog(_jsxs(Text, { children: [_jsx(Text, { color: "red", children: " \u2717" }), " Missing text attribute ", _jsx(Text, { bold: true, children: issue.tagName }), ' ', "element", location] }));
31
- }
32
- else {
33
- addLog(_jsxs(Text, { children: [_jsx(Text, { color: "red", children: " \u2717" }), " Missing alt attribute on ", _jsx(Text, { bold: true, children: issue.tagName }), ' ', "element", location] }));
34
- }
35
- }
36
- addLog(_jsx(Text, {}));
37
- }
38
- addLog(_jsxs(Text, { color: "yellow", children: [_jsx(Text, { bold: true, children: "Recommendation:" }), " Add alt attributes to all images and videos for better accessibility."] }));
39
- return 1;
40
- }
41
- catch (error) {
42
- addLog(_jsx(ErrorLog, { message: `MDX accessibility check failed: ${error instanceof Error ? error.message : 'Unknown error'}` }));
43
- return 1;
44
- }
45
- };
package/bin/update.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const update: ({ packageName }: {
2
- packageName: string;
3
- }) => Promise<void>;
package/bin/update.js DELETED
@@ -1,32 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { SpinnerLog, SuccessLog, ErrorLog, addLog, clearLogs } from '@poetora/previewing';
3
- import { execAsync, getLatestCliVersion, getVersions, detectPackageManager } from './helpers.js';
4
- export const update = async ({ packageName }) => {
5
- addLog(_jsx(SpinnerLog, { message: "updating..." }));
6
- const { cli: existingCliVersion } = getVersions();
7
- const latestCliVersion = getLatestCliVersion(packageName);
8
- const isUpToDate = existingCliVersion && latestCliVersion && latestCliVersion.trim() === existingCliVersion.trim();
9
- if (isUpToDate) {
10
- addLog(_jsx(SuccessLog, { message: "already up to date" }));
11
- return;
12
- }
13
- if (existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
14
- try {
15
- clearLogs();
16
- addLog(_jsx(SpinnerLog, { message: `updating ${packageName} package...` }));
17
- const packageManager = await detectPackageManager({ packageName });
18
- if (packageManager === 'pnpm') {
19
- await execAsync(`pnpm install -g ${packageName}@latest --silent`);
20
- }
21
- else {
22
- await execAsync(`npm install -g ${packageName}@latest --silent`);
23
- }
24
- }
25
- catch (err) {
26
- addLog(_jsx(ErrorLog, { message: `failed to update ${packageName}@latest` }));
27
- return;
28
- }
29
- }
30
- clearLogs();
31
- addLog(_jsx(SuccessLog, { message: `updated ${packageName} to the latest version: ${latestCliVersion}` }));
32
- };