Skip to content

Commit 5b3f864

Browse files
committed
resolve comments
1 parent 2aa0bb2 commit 5b3f864

File tree

7 files changed

+13
-213
lines changed

7 files changed

+13
-213
lines changed

packages/create-onchain/rules/onchainkit.cursor.txt

Lines changed: 0 additions & 65 deletions
This file was deleted.

packages/create-onchain/rules/onchainkit.windsurf.txt

Lines changed: 0 additions & 79 deletions
This file was deleted.

packages/create-onchain/src/onchainkit.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ vi.mock('./utils.js', () => ({
1919
createClickableLink: vi.fn(),
2020
isValidPackageName: vi.fn().mockReturnValue(true),
2121
toValidPackageName: vi.fn().mockImplementation((name) => name),
22-
ensureDir: vi.fn().mockResolvedValue(undefined),
2322
addToGitignore: vi.fn().mockResolvedValue(undefined),
2423
}));
2524
vi.mock('ora', () => ({

packages/create-onchain/src/onchainkit.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
toValidPackageName,
99
createClickableLink,
1010
copyDir,
11-
ensureDir,
1211
addToGitignore,
1312
} from './utils.js';
1413
import { fileURLToPath } from 'url';
@@ -154,60 +153,45 @@ export async function createOnchainKitTemplate() {
154153

155154
if (aiTool !== 'none') {
156155
console.log(`${pc.greenBright('\u2713')} ${pc.blueBright(`${aiTool}`)}`);
156+
const onchainkitRulesTemplate = await fs.promises.readFile(
157+
path.resolve(
158+
fileURLToPath(import.meta.url),
159+
'../../../rules/onchainkit.txt',
160+
),
161+
'utf-8',
162+
);
157163

158164
if (aiTool === 'cursor') {
159-
const cursorRulesTemplate = await fs.promises.readFile(
160-
path.resolve(
161-
fileURLToPath(import.meta.url),
162-
'../../../rules/onchainkit.cursor.txt',
163-
),
164-
'utf-8',
165-
);
166-
167165
const rulesDir = path.join(root, '.cursor/rules');
168166

169167
const fileContent = `---
170168
description: OnchainKit Cursor Rules
171169
globs:
172170
alwaysApply: false
173171
---
174-
${cursorRulesTemplate.trim()}`;
175-
await ensureDir(rulesDir);
172+
${onchainkitRulesTemplate.trim()}`;
173+
await fs.promises.mkdir(rulesDir, { recursive: true });
176174
// Write the file
177175
await fs.promises.writeFile(path.join(rulesDir, 'onchainkit.mdc'), fileContent);
178176
await addToGitignore({
179177
gitignorePath: path.join(root, '.gitignore'),
180178
additionalPath: '.cursor/rules/onchainkit.mdc',
181179
});
182180
} else if (aiTool === 'windsurf') {
183-
const windsurfRulesTemplate = await fs.promises.readFile(
184-
path.resolve(
185-
fileURLToPath(import.meta.url),
186-
'../../../rules/onchainkit.windsurf.txt',
187-
),
188-
'utf-8',
189-
);
190181
await fs.promises.writeFile(
191182
path.join(root, '.windsurfrules'),
192-
windsurfRulesTemplate,
183+
onchainkitRulesTemplate,
193184
);
194185
await addToGitignore({
195186
gitignorePath: path.join(root, '.gitignore'),
196187
additionalPath: '.windsurfrules',
197188
});
198189
} else if (aiTool === 'copilot') {
199-
await ensureDir(path.join(root, '.github'));
200-
201-
const copilotRulesTemplate = await fs.promises.readFile(
202-
path.resolve(
203-
fileURLToPath(import.meta.url),
204-
'../../../rules/onchainkit.copilot.txt',
205-
),
206-
'utf-8',
207-
);
190+
await fs.promises.mkdir(path.join(root, '.github'), { recursive: true });
191+
208192
await fs.promises.writeFile(
209193
path.join(root, '.github/copilot-instructions.md'),
210-
copilotRulesTemplate,
194+
onchainkitRulesTemplate,
211195
);
212196
await addToGitignore({
213197
gitignorePath: path.join(root, '.gitignore'),

packages/create-onchain/src/utils.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
toValidPackageName,
88
detectPackageManager,
99
getVersion,
10-
ensureDir,
1110
addToGitignore,
1211
} from './utils';
1312
import { Stats } from 'node:fs';
@@ -109,29 +108,6 @@ describe('utils', () => {
109108
});
110109
});
111110

112-
describe('ensureDir', () => {
113-
beforeEach(() => {
114-
vi.resetAllMocks();
115-
});
116-
117-
it('should create a directory if it does not exist', async () => {
118-
const error = new Error('ENOENT');
119-
(error as NodeJS.ErrnoException).code = 'ENOENT';
120-
vi.mocked(fs.stat).mockRejectedValue(error);
121-
122-
await ensureDir('test/foobar/directory');
123-
124-
expect(fs.mkdir).toHaveBeenCalledWith('test/foobar/directory', { recursive: true });
125-
});
126-
127-
it('should not create a directory if it already exists', async () => {
128-
vi.mocked(fs.stat).mockResolvedValue({ isDirectory: () => true } as unknown as Stats);
129-
130-
await ensureDir('test/foobar/directory');
131-
expect(fs.mkdir).not.toHaveBeenCalled();
132-
});
133-
});
134-
135111
describe('addToGitignore', () => {
136112
it('should add a path to the gitignore file', async () => {
137113
vi.mocked(fs.readFile).mockResolvedValue('existing content');

packages/create-onchain/src/utils.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,6 @@ export function detectPackageManager(): string {
109109
return 'npm'; // default to npm if unable to detect
110110
}
111111

112-
export async function ensureDir(dirPath: string) {
113-
try {
114-
const stats = await fs.stat(dirPath);
115-
if (!stats.isDirectory()) {
116-
throw new Error(`Path exists but is not a directory: ${dirPath}`);
117-
}
118-
} catch (error) {
119-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
120-
await fs.mkdir(dirPath, { recursive: true });
121-
} else {
122-
throw error;
123-
}
124-
}
125-
}
126-
127112
export async function addToGitignore({
128113
gitignorePath,
129114
additionalPath,

0 commit comments

Comments
 (0)