@pikku/cli 0.9.11 → 0.9.13

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.9.13
4
+
5
+ ### Patch Changes
6
+
7
+ - ccd2a45: fix: adding functions should always be using func config and not pure functions
8
+
9
+ ## 0.9.12
10
+
11
+ ### Patch Changes
12
+
13
+ - eb8ed09: feat: only write files if the content changed / file doesn't exist, this stops triggering restarts for development
14
+
3
15
  ## 0.9.11
4
16
 
5
17
  ### Patch Changes
@@ -204,7 +204,7 @@ export const pikkuFunc = <In, Out = unknown>(
204
204
  | PikkuFunction<In, Out>
205
205
  | CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In>>
206
206
  ) => {
207
- return typeof func === 'function' ? func : func.func
207
+ return typeof func === 'function' ? { func } : func
208
208
  }
209
209
 
210
210
  /**
@@ -232,7 +232,7 @@ export const pikkuSessionlessFunc = <In, Out = unknown>(
232
232
  | PikkuFunctionSessionless<In, Out>
233
233
  | CorePikkuFunctionConfig<PikkuFunctionSessionless<In, Out>, PikkuPermission<In>, PikkuMiddleware>
234
234
  ) => {
235
- return typeof func === 'function' ? func : func.func
235
+ return typeof func === 'function' ? { func } : func
236
236
  }
237
237
 
238
238
  /**
@@ -263,7 +263,7 @@ export const pikkuChannelConnectionFunc = <Out = unknown, ChannelData = unknown>
263
263
  name?: string
264
264
  }
265
265
  ) => {
266
- return typeof func === 'function' ? func : func.func
266
+ return typeof func === 'function' ? { func } : func
267
267
  }
268
268
 
269
269
  /**
@@ -292,7 +292,7 @@ export const pikkuChannelDisconnectionFunc = <ChannelData = unknown>(
292
292
  name?: string
293
293
  }
294
294
  ) => {
295
- return typeof func === 'function' ? func : func.func
295
+ return typeof func === 'function' ? { func } : func
296
296
  }
297
297
 
298
298
  /**
@@ -319,7 +319,7 @@ export const pikkuChannelFunc = <In = unknown, Out = unknown, ChannelData = unkn
319
319
  | PikkuFunctionSessionless<In, Out, ChannelData>
320
320
  | CorePikkuFunctionConfig<PikkuFunction<In, Out, ChannelData>, PikkuPermission<In>>
321
321
  ) => {
322
- return typeof func === 'function' ? func : func.func
322
+ return typeof func === 'function' ? { func } : func
323
323
  }
324
324
 
325
325
  /**
@@ -343,7 +343,7 @@ export const pikkuVoidFunc = (
343
343
  | PikkuFunctionSessionless<void, void>
344
344
  | CorePikkuFunctionConfig<PikkuFunctionSessionless<void, void>, PikkuPermission<void>>
345
345
  ) => {
346
- return typeof func === 'function' ? func : func.func
346
+ return typeof func === 'function' ? { func } : func
347
347
  }
348
348
 
349
349
  /**
@@ -534,7 +534,7 @@ export const pikkuMCPPromptFunc = <In>(
534
534
  name?: string
535
535
  }
536
536
  ) => {
537
- return typeof func === 'function' ? func : func.func
537
+ return typeof func === 'function' ? { func } : func
538
538
  }
539
539
 
540
540
  /**
@@ -566,7 +566,7 @@ export const pikkuMCPToolFunc = <In>(
566
566
  name?: string
567
567
  }
568
568
  ) => {
569
- return typeof func === 'function' ? func : func.func
569
+ return typeof func === 'function' ? { func } : func
570
570
  }
571
571
 
572
572
  /**
@@ -599,7 +599,7 @@ export const pikkuMCPResourceFunc = <In>(
599
599
  name?: string
600
600
  }
601
601
  ) => {
602
- return typeof func === 'function' ? func : func.func
602
+ return typeof func === 'function' ? { func } : func
603
603
  }
604
604
  `;
605
605
  };
package/dist/src/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { relative, dirname, resolve } from 'path';
2
- import { mkdir, writeFile } from 'fs/promises';
2
+ import { mkdir, readFile, writeFile } from 'fs/promises';
3
3
  import chalk from 'chalk';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { readFileSync } from 'fs';
@@ -165,10 +165,21 @@ export const writeFileInDir = async (logger, path, content, { ignoreModifyCommen
165
165
  else {
166
166
  content = `${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}${content}`;
167
167
  }
168
- await mkdir(dirname(path), { recursive: true });
169
- await writeFile(path, content, 'utf-8');
170
- if (logWrite) {
171
- logger.success(`✓ File written to ${path}`);
168
+ // Try to read existing file content
169
+ let existingContent;
170
+ try {
171
+ existingContent = await readFile(path, 'utf-8');
172
+ }
173
+ catch (error) {
174
+ // File doesn't exist, so we need to write it
175
+ }
176
+ // Only write if content has changed or file doesn't exist
177
+ if (existingContent !== content) {
178
+ await mkdir(dirname(path), { recursive: true });
179
+ await writeFile(path, content, 'utf-8');
180
+ if (logWrite) {
181
+ logger.success(`✓ File written to ${path}`);
182
+ }
172
183
  }
173
184
  };
174
185
  export const logCommandInfoAndTime = async (logger, commandStart, commandEnd, [skipCondition, skipMessage = 'none found'], callback) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -212,7 +212,7 @@ export const pikkuFunc = <In, Out = unknown>(
212
212
  | PikkuFunction<In, Out>
213
213
  | CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In>>
214
214
  ) => {
215
- return typeof func === 'function' ? func : func.func
215
+ return typeof func === 'function' ? { func } : func
216
216
  }
217
217
 
218
218
  /**
@@ -240,7 +240,7 @@ export const pikkuSessionlessFunc = <In, Out = unknown>(
240
240
  | PikkuFunctionSessionless<In, Out>
241
241
  | CorePikkuFunctionConfig<PikkuFunctionSessionless<In, Out>, PikkuPermission<In>, PikkuMiddleware>
242
242
  ) => {
243
- return typeof func === 'function' ? func : func.func
243
+ return typeof func === 'function' ? { func } : func
244
244
  }
245
245
 
246
246
  /**
@@ -271,7 +271,7 @@ export const pikkuChannelConnectionFunc = <Out = unknown, ChannelData = unknown>
271
271
  name?: string
272
272
  }
273
273
  ) => {
274
- return typeof func === 'function' ? func : func.func
274
+ return typeof func === 'function' ? { func } : func
275
275
  }
276
276
 
277
277
  /**
@@ -300,7 +300,7 @@ export const pikkuChannelDisconnectionFunc = <ChannelData = unknown>(
300
300
  name?: string
301
301
  }
302
302
  ) => {
303
- return typeof func === 'function' ? func : func.func
303
+ return typeof func === 'function' ? { func } : func
304
304
  }
305
305
 
306
306
  /**
@@ -327,7 +327,7 @@ export const pikkuChannelFunc = <In = unknown, Out = unknown, ChannelData = unkn
327
327
  | PikkuFunctionSessionless<In, Out, ChannelData>
328
328
  | CorePikkuFunctionConfig<PikkuFunction<In, Out, ChannelData>, PikkuPermission<In>>
329
329
  ) => {
330
- return typeof func === 'function' ? func : func.func
330
+ return typeof func === 'function' ? { func } : func
331
331
  }
332
332
 
333
333
  /**
@@ -351,7 +351,7 @@ export const pikkuVoidFunc = (
351
351
  | PikkuFunctionSessionless<void, void>
352
352
  | CorePikkuFunctionConfig<PikkuFunctionSessionless<void, void>, PikkuPermission<void>>
353
353
  ) => {
354
- return typeof func === 'function' ? func : func.func
354
+ return typeof func === 'function' ? { func } : func
355
355
  }
356
356
 
357
357
  /**
@@ -542,7 +542,7 @@ export const pikkuMCPPromptFunc = <In>(
542
542
  name?: string
543
543
  }
544
544
  ) => {
545
- return typeof func === 'function' ? func : func.func
545
+ return typeof func === 'function' ? { func } : func
546
546
  }
547
547
 
548
548
  /**
@@ -574,7 +574,7 @@ export const pikkuMCPToolFunc = <In>(
574
574
  name?: string
575
575
  }
576
576
  ) => {
577
- return typeof func === 'function' ? func : func.func
577
+ return typeof func === 'function' ? { func } : func
578
578
  }
579
579
 
580
580
  /**
@@ -607,7 +607,7 @@ export const pikkuMCPResourceFunc = <In>(
607
607
  name?: string
608
608
  }
609
609
  ) => {
610
- return typeof func === 'function' ? func : func.func
610
+ return typeof func === 'function' ? { func } : func
611
611
  }
612
612
  `
613
613
  }
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { relative, dirname, resolve } from 'path'
2
2
  import { PathToNameAndType, InspectorState, TypesMap } from '@pikku/inspector'
3
- import { mkdir, writeFile } from 'fs/promises'
3
+ import { mkdir, readFile, writeFile } from 'fs/promises'
4
4
  import chalk from 'chalk'
5
5
  import { fileURLToPath } from 'url'
6
6
  import { readFileSync } from 'fs'
@@ -301,11 +301,22 @@ export const writeFileInDir = async (
301
301
  content = `${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}${content}`
302
302
  }
303
303
 
304
- await mkdir(dirname(path), { recursive: true })
305
- await writeFile(path, content, 'utf-8')
304
+ // Try to read existing file content
305
+ let existingContent: string | undefined
306
+ try {
307
+ existingContent = await readFile(path, 'utf-8')
308
+ } catch (error) {
309
+ // File doesn't exist, so we need to write it
310
+ }
311
+
312
+ // Only write if content has changed or file doesn't exist
313
+ if (existingContent !== content) {
314
+ await mkdir(dirname(path), { recursive: true })
315
+ await writeFile(path, content, 'utf-8')
306
316
 
307
- if (logWrite) {
308
- logger.success(`✓ File written to ${path}`)
317
+ if (logWrite) {
318
+ logger.success(`✓ File written to ${path}`)
319
+ }
309
320
  }
310
321
  }
311
322