Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/create-termui-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { dirname, resolve, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
import { mkdirSync, writeFileSync, existsSync, readFileSync, readdirSync } from 'node:fs';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | πŸ”΄ Critical | ⚑ Quick win

Use the imported readdirSync binding.

Line 7 imports readdirSync, but Line 126 uses an undeclared fs namespace. This causes the TypeScript build to fail. Call readdirSync(projectDir), or import the namespace explicitly.

Proposed fix
-        const entries = fs.readdirSync(projectDir);
+        const entries = readdirSync(projectDir);

Also applies to: 126-126

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/create-termui-app/src/index.ts` at line 7, Replace the undeclared fs
namespace usage in the directory-reading logic with the imported readdirSync
binding, calling readdirSync(projectDir) while preserving the existing behavior.

import { getBuiltinThemeNames } from '@termuijs/tss';
import { textPrompt, selectPrompt, multiSelectPrompt } from './prompts.js';
import { generateProject, type ProjectConfig } from './templates.js';
Expand Down Expand Up @@ -122,6 +122,17 @@ async function runProjectScaffold(args: CliArgs): Promise<void> {
// ── Generate project ──
const projectDir = resolve(process.cwd(), projectName);
if (existsSync(projectDir)) {
try {
const entries = fs.readdirSync(projectDir);
const hasContent = entries.some(e => e !== '.git');
if (hasContent) {
console.log(`\n βœ– Directory "${projectName}" is not empty. Refusing to overwrite.\n`);
console.log(` Remove the directory or choose a different name.\n`);
Comment on lines +129 to +130

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ“ Maintainability & Code Quality | 🟠 Major | ⚑ Quick win

Use the approved output and Unicode capability handling.

The new branch calls console.log and hard-codes βœ–. Use the permitted CLI output mechanism and render the symbol with caps.unicode plus an ASCII fallback.

As per coding guidelines, packages/**/src/**/*.{ts,tsx} must not contain console.log, and packages/**/*.{ts,tsx} must use caps.unicode for non-ASCII characters with an ASCII fallback.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/create-termui-app/src/index.ts` around lines 129 - 130, Replace the
direct console.log calls in the non-empty-directory branch with the approved CLI
output mechanism, and render the error symbol through caps.unicode with an ASCII
fallback instead of hard-coding βœ–. Ensure the updated output remains equivalent
and complies with the package-wide console and Unicode handling conventions.

Source: Coding guidelines

return;
}
} catch {
// readdirSync failed β€” let the write calls fail naturally
}
Comment on lines +133 to +135

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ—„οΈ Data Integrity & Integration | 🟠 Major | πŸ—οΈ Heavy lift

Fail closed when directory inspection fails.

This catch block continues to generation after readdirSync fails. writeFileSync on Line 148 uses overwrite mode by default, so an existing directory that cannot be read can still have files overwritten. A check/write race has the same result. Abort on inspection failure and enforce exclusive or atomic file creation.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/create-termui-app/src/index.ts` around lines 133 - 135, Update the
directory inspection flow around readdirSync to abort generation when inspection
fails instead of continuing to write. Ensure the subsequent writeFileSync calls
cannot overwrite existing files, including check/write races, by using exclusive
or atomic file creation semantics.

console.log(`\n ⚠ Directory "${projectName}" already exists. Files may be overwritten.\n`);
}

Expand Down
Loading