Skip to content

Commit 4fda047

Browse files
authored
docs(mobile): add documentation for utils (#314)
1 parent ba89e86 commit 4fda047

73 files changed

Lines changed: 1352 additions & 350 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.scripts/commands/generateDocs/index.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ export async function generateDocs(names: string[]) {
4040
ctx.docSource = docSource;
4141
},
4242
},
43+
{
44+
title: `Write English document`,
45+
task: async ctx => {
46+
const { docSource } = ctx;
47+
const dirname = path.dirname(sourceFilePath);
48+
49+
if (docSource != null) {
50+
await fs.writeFile(`${dirname}/${name}.md`, docSource);
51+
}
52+
},
53+
},
4354
{
4455
title: `Translate markdown to Korean`,
4556
task: async ctx => {
@@ -48,37 +59,45 @@ export async function generateDocs(names: string[]) {
4859

4960
let isFileExists = false;
5061
try {
51-
await fs.access(`${dirname}/${name}.md`);
5262
await fs.access(`${dirname}/ko/${name}.md`);
5363
isFileExists = true;
5464
} catch {
5565
isFileExists = false;
5666
}
5767

58-
if (isFileExists && (await fs.readFile(`${dirname}/${name}.md`)).toString() === docSource) {
59-
return;
68+
// Skip if Korean file already exists and English file hasn't changed
69+
if (isFileExists) {
70+
try {
71+
const existingEnglish = await fs.readFile(`${dirname}/${name}.md`, 'utf-8');
72+
if (existingEnglish === docSource) {
73+
return;
74+
}
75+
} catch {
76+
// Continue with translation if we can't read existing file
77+
}
6078
}
6179

6280
if (docSource == null) {
6381
throw new Error('docSource is not found');
6482
}
6583

66-
const translatedDoc = await translate(docSource);
67-
68-
ctx.translatedDoc = translatedDoc;
84+
try {
85+
const translatedDoc = await translate(docSource);
86+
ctx.translatedDoc = translatedDoc;
87+
} catch (error) {
88+
// Log the error but don't fail the task - English doc is already saved
89+
console.warn(`Translation failed for ${name}: ${error instanceof Error ? error.message : error}`);
90+
ctx.translatedDoc = null;
91+
}
6992
},
7093
},
7194
{
72-
title: `Write document files`,
95+
title: `Write Korean document`,
96+
skip: ctx => ctx.translatedDoc == null,
7397
task: async ctx => {
74-
const { docSource, translatedDoc } = ctx;
75-
98+
const { translatedDoc } = ctx;
7699
const dirname = path.dirname(sourceFilePath);
77100

78-
if (docSource != null) {
79-
await fs.writeFile(`${dirname}/${name}.md`, docSource);
80-
}
81-
82101
if (translatedDoc != null) {
83102
await fs.mkdir(`${dirname}/ko`).catch(e => {
84103
if (e.code === 'EEXIST') {
@@ -92,7 +111,7 @@ export async function generateDocs(names: string[]) {
92111
},
93112
},
94113
],
95-
{ concurrent: false, ctx: subCtx }
114+
{ concurrent: false, ctx: subCtx, exitOnError: false }
96115
),
97116
},
98117
]);
@@ -108,7 +127,8 @@ function parseJSDoc(source: string) {
108127

109128
const template = targetComment.tags.find(tag => tag.tag === 'template');
110129

111-
const description = targetComment.tags.find(tag => tag.tag === 'description')?.description ?? '';
130+
const description =
131+
targetComment.tags.find(tag => tag.tag === 'description')?.description ?? targetComment.description ?? '';
112132

113133
const params = targetComment.tags.filter(tag => tag.tag === 'param');
114134

.scripts/commands/generateDocs/translate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ ${origin}
284284
`;
285285

286286
const response = await client.chat.completions.create({
287-
model: 'gpt-4o',
287+
model: 'gpt-3.5-turbo',
288288
messages: [{ role: 'user', content: prompt }],
289289
response_format: { type: 'json_object' },
290290
});

.scripts/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import 'dotenv/config';
1+
import dotenv from 'dotenv';
2+
import path from 'path';
23

34
import { Command } from 'commander';
45

6+
import { getRootPath } from './utils/getRootPath.ts';
7+
8+
// Load .env from project root
9+
dotenv.config({ path: path.join(getRootPath(), '.env') });
10+
511
import { generateDocs } from './commands/generateDocs/index.ts';
612
import { scaffold } from './commands/scaffold/index.ts';
713

.vitepress/config.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default defineConfig({
5151
'packages/mobile/src/hooks/:hook/:hook.md': 'mobile/hooks/:hook.md',
5252
'packages/mobile/src/hooks/:hook/ko/:hook.md': 'ko/mobile/hooks/:hook.md',
5353

54+
// Mobile utils
55+
'packages/mobile/src/utils/:util/:util.md': 'mobile/utils/:util.md',
56+
'packages/mobile/src/utils/:util/ko/:util.md': 'ko/mobile/utils/:util.md',
57+
5458
// Mobile keyboardHeight (special case - folder name differs from hook name)
5559
'packages/mobile/src/hooks/keyboardHeight/useKeyboardHeight.md': 'mobile/hooks/useKeyboardHeight.md',
5660
'packages/mobile/src/hooks/keyboardHeight/ko/useKeyboardHeight.md': 'ko/mobile/hooks/useKeyboardHeight.md',

.vitepress/en.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ function mobileSidebar(): DefaultTheme.SidebarItem[] {
8989
collapsed: false,
9090
items: getSidebarItems(mobilePackageRoot, 'hooks', '/mobile'),
9191
},
92+
{
93+
text: 'Utils',
94+
collapsed: false,
95+
items: getSidebarItems(mobilePackageRoot, 'utils', '/mobile'),
96+
},
9297
],
9398
},
9499
];

.vitepress/ko.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ function mobileSidebar(): DefaultTheme.SidebarItem[] {
8989
collapsed: false,
9090
items: getSidebarItems(mobilePackageRoot, 'hooks', '/mobile', 'ko'),
9191
},
92+
{
93+
text: '유틸리티',
94+
collapsed: false,
95+
items: getSidebarItems(mobilePackageRoot, 'utils', '/mobile', 'ko'),
96+
},
9297
],
9398
},
9499
];

packages/mobile/src/hooks/keyboardHeight/useKeyboardHeight.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { act, renderHook } from '@testing-library/react';
22
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
33

4-
import { subscribeKeyboardHeight } from '../../utils/keyboard/subscribeKeyboardHeight.ts';
4+
import { subscribeKeyboardHeight } from '../../utils/subscribeKeyboardHeight/index.ts';
55

66
import { useKeyboardHeight } from './useKeyboardHeight.ts';
77

8-
vi.mock('../../utils/keyboard/subscribeKeyboardHeight.ts', () => ({
8+
vi.mock('../../utils/subscribeKeyboardHeight/index.ts', () => ({
99
subscribeKeyboardHeight: vi.fn(),
1010
}));
1111

packages/mobile/src/hooks/keyboardHeight/useKeyboardHeight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3-
import { subscribeKeyboardHeight } from '../../utils/keyboard/subscribeKeyboardHeight.ts';
3+
import { subscribeKeyboardHeight } from '../../utils/subscribeKeyboardHeight/index.ts';
44

55
type UseKeyboardHeightOptions = {
66
/**

packages/mobile/src/hooks/useBodyScrollLock/useBodyScrollLock.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect } from 'react';
22

3-
import { disableBodyScrollLock, enableBodyScrollLock } from '../../utils/bodyScrollLock.ts';
3+
import { disableBodyScrollLock } from '../../utils/disableBodyScrollLock/index.ts';
4+
import { enableBodyScrollLock } from '../../utils/enableBodyScrollLock/index.ts';
45

56
/**
67
* Hook to lock body scroll

packages/mobile/src/hooks/useNetworkStatus/useNetworkStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3-
import { isServer } from '../../utils/isServer.ts';
3+
import { isServer } from '../../utils/isServer/index.ts';
44

55
/**
66
* Effective connection type based on Network Information API

0 commit comments

Comments
 (0)