@pikku/cli 0.7.4 → 0.7.5

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,13 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.7.5
4
+
5
+ ### Patch Changes
6
+
7
+ - faa1369: refactor: moving function imports into pikku-fun.gen file
8
+ - Updated dependencies [faa1369]
9
+ - @pikku/inspector@0.7.6
10
+
3
11
  ## 0.7.4
4
12
 
5
13
  ### Patch Changes
package/bin/pikku-all.ts CHANGED
@@ -70,7 +70,6 @@ const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
70
70
  await pikkuRPC(cliConfig, visitState)
71
71
  await pikkuRPCMap(cliConfig, visitState)
72
72
  addImport(cliConfig.rpcMetaFile, 'meta')
73
- addImport(cliConfig.rpcFile, 'events')
74
73
 
75
74
  const routes = await pikkuHTTP(cliConfig, visitState)
76
75
  if (routes) {
@@ -1,9 +1,62 @@
1
1
  import { PikkuCLIConfig } from '../src/pikku-cli-config.js'
2
2
  import { InspectorState } from '@pikku/inspector'
3
- import { logCommandInfoAndTime, writeFileInDir } from '../src/utils/utils.js'
3
+ import {
4
+ getFileImportRelativePath,
5
+ logCommandInfoAndTime,
6
+ writeFileInDir,
7
+ } from '../src/utils/utils.js'
8
+
9
+ export const serializeFunctionImports = (
10
+ outputPath: string,
11
+ functionsMap: Map<string, { path: string; exportedName: string }>,
12
+ packageMappings: Record<string, string> = {}
13
+ ) => {
14
+ const serializedImports: string[] = [
15
+ `/* Import and register RPCs */`,
16
+ `import { addFunction } from '@pikku/core'`,
17
+ ]
18
+
19
+ const serializedRegistrations: string[] = []
20
+
21
+ // Sort by function name for consistent output
22
+ const sortedEntries = Array.from(functionsMap.entries()).sort((a, b) =>
23
+ a[0].localeCompare(b[0])
24
+ )
25
+
26
+ for (const [name, { path, exportedName }] of sortedEntries) {
27
+ const filePath = getFileImportRelativePath(
28
+ outputPath,
29
+ path,
30
+ packageMappings
31
+ )
32
+
33
+ // For directly exported functions, we can just import and register them
34
+ if (name === exportedName) {
35
+ serializedImports.push(`import { ${exportedName} } from '${filePath}'`)
36
+ serializedRegistrations.push(
37
+ `addFunction('${name}', { func: ${exportedName} })`
38
+ )
39
+ }
40
+ // For renamed functions, we need to import and alias them
41
+ else {
42
+ serializedImports.push(
43
+ `import { ${exportedName} as ${name} } from '${filePath}'`
44
+ )
45
+ serializedRegistrations.push(`addFunction('${name}', ${name})`)
46
+ }
47
+ }
48
+
49
+ // Add a blank line between imports and registrations
50
+ if (serializedImports.length > 0 && serializedRegistrations.length > 0) {
51
+ serializedImports.push('')
52
+ }
53
+
54
+ // Combine the imports and registrations
55
+ return [...serializedImports, ...serializedRegistrations].join('\n')
56
+ }
4
57
 
5
58
  export const pikkuFunctions = async (
6
- { functionsMetaFile }: PikkuCLIConfig,
59
+ { functionsMetaFile, functionsFile, packageMappings }: PikkuCLIConfig,
7
60
  { functions }: InspectorState
8
61
  ) => {
9
62
  return await logCommandInfoAndTime(
@@ -11,6 +64,14 @@ export const pikkuFunctions = async (
11
64
  'Serialized Pikku functions',
12
65
  [false],
13
66
  async () => {
67
+ await writeFileInDir(
68
+ functionsFile,
69
+ serializeFunctionImports(
70
+ functionsFile,
71
+ functions.files,
72
+ packageMappings
73
+ )
74
+ )
14
75
  await writeFileInDir(
15
76
  functionsMetaFile,
16
77
  `import { pikkuState } from '@pikku/core'\npikkuState('function', 'meta', ${JSON.stringify(functions.meta, null, 2)})`
@@ -10,7 +10,7 @@ export const pikkuRPCMap = async (
10
10
  return await logCommandInfoAndTime(
11
11
  'Creating RPC map',
12
12
  'Created RPC map',
13
- [rpc.files.size === 0],
13
+ [false],
14
14
  async () => {
15
15
  const content = serializeTypedRPCMap(
16
16
  rpcMapDeclarationFile,
package/bin/pikku-rpc.ts CHANGED
@@ -1,73 +1,16 @@
1
1
  import { PikkuCLIConfig } from '../src/pikku-cli-config.js'
2
2
  import { InspectorState } from '@pikku/inspector'
3
- import {
4
- getFileImportRelativePath,
5
- logCommandInfoAndTime,
6
- writeFileInDir,
7
- } from '../src/utils/utils.js'
8
-
9
- export const serializeRPCImports = (
10
- outputPath: string,
11
- functionsMap: Map<string, { path: string; exportedName: string }>,
12
- packageMappings: Record<string, string> = {}
13
- ) => {
14
- const serializedImports: string[] = [
15
- `/* Import and register RPCs */`,
16
- `import { addFunction } from '@pikku/core'`,
17
- ]
18
-
19
- const serializedRegistrations: string[] = []
20
-
21
- // Sort by function name for consistent output
22
- const sortedEntries = Array.from(functionsMap.entries()).sort((a, b) =>
23
- a[0].localeCompare(b[0])
24
- )
25
-
26
- for (const [name, { path, exportedName }] of sortedEntries) {
27
- const filePath = getFileImportRelativePath(
28
- outputPath,
29
- path,
30
- packageMappings
31
- )
32
-
33
- // For directly exported functions, we can just import and register them
34
- if (name === exportedName) {
35
- serializedImports.push(`import { ${exportedName} } from '${filePath}'`)
36
- serializedRegistrations.push(
37
- `addFunction('${name}', { func: ${exportedName} })`
38
- )
39
- }
40
- // For renamed functions, we need to import and alias them
41
- else {
42
- serializedImports.push(
43
- `import { ${exportedName} as ${name} } from '${filePath}'`
44
- )
45
- serializedRegistrations.push(`addFunction('${name}', ${name})`)
46
- }
47
- }
48
-
49
- // Add a blank line between imports and registrations
50
- if (serializedImports.length > 0 && serializedRegistrations.length > 0) {
51
- serializedImports.push('')
52
- }
53
-
54
- // Combine the imports and registrations
55
- return [...serializedImports, ...serializedRegistrations].join('\n')
56
- }
3
+ import { logCommandInfoAndTime, writeFileInDir } from '../src/utils/utils.js'
57
4
 
58
5
  export const pikkuRPC = async (
59
- { rpcFile, rpcMetaFile, packageMappings }: PikkuCLIConfig,
6
+ { rpcMetaFile }: PikkuCLIConfig,
60
7
  { rpc }: InspectorState
61
8
  ) => {
62
9
  return await logCommandInfoAndTime(
63
10
  'Finding RPCs tasks',
64
11
  'Found RPCs',
65
- [rpc.files.size === 0],
12
+ [false],
66
13
  async () => {
67
- await writeFileInDir(
68
- rpcFile,
69
- serializeRPCImports(rpcFile, rpc.files, packageMappings)
70
- )
71
14
  await writeFileInDir(
72
15
  rpcMetaFile,
73
16
  `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`
@@ -50,7 +50,6 @@ const runAll = async (cliConfig, options) => {
50
50
  await pikkuRPC(cliConfig, visitState);
51
51
  await pikkuRPCMap(cliConfig, visitState);
52
52
  addImport(cliConfig.rpcMetaFile, 'meta');
53
- addImport(cliConfig.rpcFile, 'events');
54
53
  const routes = await pikkuHTTP(cliConfig, visitState);
55
54
  if (routes) {
56
55
  await pikkuHTTPMap(cliConfig, visitState);
@@ -1,3 +1,7 @@
1
1
  import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
2
2
  import { InspectorState } from '@pikku/inspector';
3
- export declare const pikkuFunctions: ({ functionsMetaFile }: PikkuCLIConfig, { functions }: InspectorState) => Promise<boolean>;
3
+ export declare const serializeFunctionImports: (outputPath: string, functionsMap: Map<string, {
4
+ path: string;
5
+ exportedName: string;
6
+ }>, packageMappings?: Record<string, string>) => string;
7
+ export declare const pikkuFunctions: ({ functionsMetaFile, functionsFile, packageMappings }: PikkuCLIConfig, { functions }: InspectorState) => Promise<boolean>;
@@ -1,6 +1,35 @@
1
- import { logCommandInfoAndTime, writeFileInDir } from '../src/utils/utils.js';
2
- export const pikkuFunctions = async ({ functionsMetaFile }, { functions }) => {
1
+ import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../src/utils/utils.js';
2
+ export const serializeFunctionImports = (outputPath, functionsMap, packageMappings = {}) => {
3
+ const serializedImports = [
4
+ `/* Import and register RPCs */`,
5
+ `import { addFunction } from '@pikku/core'`,
6
+ ];
7
+ const serializedRegistrations = [];
8
+ // Sort by function name for consistent output
9
+ const sortedEntries = Array.from(functionsMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
10
+ for (const [name, { path, exportedName }] of sortedEntries) {
11
+ const filePath = getFileImportRelativePath(outputPath, path, packageMappings);
12
+ // For directly exported functions, we can just import and register them
13
+ if (name === exportedName) {
14
+ serializedImports.push(`import { ${exportedName} } from '${filePath}'`);
15
+ serializedRegistrations.push(`addFunction('${name}', { func: ${exportedName} })`);
16
+ }
17
+ // For renamed functions, we need to import and alias them
18
+ else {
19
+ serializedImports.push(`import { ${exportedName} as ${name} } from '${filePath}'`);
20
+ serializedRegistrations.push(`addFunction('${name}', ${name})`);
21
+ }
22
+ }
23
+ // Add a blank line between imports and registrations
24
+ if (serializedImports.length > 0 && serializedRegistrations.length > 0) {
25
+ serializedImports.push('');
26
+ }
27
+ // Combine the imports and registrations
28
+ return [...serializedImports, ...serializedRegistrations].join('\n');
29
+ };
30
+ export const pikkuFunctions = async ({ functionsMetaFile, functionsFile, packageMappings }, { functions }) => {
3
31
  return await logCommandInfoAndTime('Serializing Pikku functions', 'Serialized Pikku functions', [false], async () => {
32
+ await writeFileInDir(functionsFile, serializeFunctionImports(functionsFile, functions.files, packageMappings));
4
33
  await writeFileInDir(functionsMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('function', 'meta', ${JSON.stringify(functions.meta, null, 2)})`);
5
34
  });
6
35
  };
@@ -1,7 +1,7 @@
1
1
  import { logCommandInfoAndTime, writeFileInDir } from '../src/utils/utils.js';
2
2
  import { serializeTypedRPCMap } from '../src/serialize-typed-rpc-map.js';
3
3
  export const pikkuRPCMap = async ({ rpcMapDeclarationFile, packageMappings }, { functions, rpc }) => {
4
- return await logCommandInfoAndTime('Creating RPC map', 'Created RPC map', [rpc.files.size === 0], async () => {
4
+ return await logCommandInfoAndTime('Creating RPC map', 'Created RPC map', [false], async () => {
5
5
  const content = serializeTypedRPCMap(rpcMapDeclarationFile, packageMappings, functions.typesMap, functions.meta, rpc.meta);
6
6
  await writeFileInDir(rpcMapDeclarationFile, content);
7
7
  });
@@ -1,7 +1,3 @@
1
1
  import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
2
2
  import { InspectorState } from '@pikku/inspector';
3
- export declare const serializeRPCImports: (outputPath: string, functionsMap: Map<string, {
4
- path: string;
5
- exportedName: string;
6
- }>, packageMappings?: Record<string, string>) => string;
7
- export declare const pikkuRPC: ({ rpcFile, rpcMetaFile, packageMappings }: PikkuCLIConfig, { rpc }: InspectorState) => Promise<boolean>;
3
+ export declare const pikkuRPC: ({ rpcMetaFile }: PikkuCLIConfig, { rpc }: InspectorState) => Promise<boolean>;
@@ -1,35 +1,6 @@
1
- import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../src/utils/utils.js';
2
- export const serializeRPCImports = (outputPath, functionsMap, packageMappings = {}) => {
3
- const serializedImports = [
4
- `/* Import and register RPCs */`,
5
- `import { addFunction } from '@pikku/core'`,
6
- ];
7
- const serializedRegistrations = [];
8
- // Sort by function name for consistent output
9
- const sortedEntries = Array.from(functionsMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
10
- for (const [name, { path, exportedName }] of sortedEntries) {
11
- const filePath = getFileImportRelativePath(outputPath, path, packageMappings);
12
- // For directly exported functions, we can just import and register them
13
- if (name === exportedName) {
14
- serializedImports.push(`import { ${exportedName} } from '${filePath}'`);
15
- serializedRegistrations.push(`addFunction('${name}', { func: ${exportedName} })`);
16
- }
17
- // For renamed functions, we need to import and alias them
18
- else {
19
- serializedImports.push(`import { ${exportedName} as ${name} } from '${filePath}'`);
20
- serializedRegistrations.push(`addFunction('${name}', ${name})`);
21
- }
22
- }
23
- // Add a blank line between imports and registrations
24
- if (serializedImports.length > 0 && serializedRegistrations.length > 0) {
25
- serializedImports.push('');
26
- }
27
- // Combine the imports and registrations
28
- return [...serializedImports, ...serializedRegistrations].join('\n');
29
- };
30
- export const pikkuRPC = async ({ rpcFile, rpcMetaFile, packageMappings }, { rpc }) => {
31
- return await logCommandInfoAndTime('Finding RPCs tasks', 'Found RPCs', [rpc.files.size === 0], async () => {
32
- await writeFileInDir(rpcFile, serializeRPCImports(rpcFile, rpc.files, packageMappings));
1
+ import { logCommandInfoAndTime, writeFileInDir } from '../src/utils/utils.js';
2
+ export const pikkuRPC = async ({ rpcMetaFile }, { rpc }) => {
3
+ return await logCommandInfoAndTime('Finding RPCs tasks', 'Found RPCs', [false], async () => {
33
4
  await writeFileInDir(rpcMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`);
34
5
  });
35
6
  };
@@ -12,7 +12,6 @@ export interface PikkuCLICoreOutputFiles {
12
12
  channelsFile: string;
13
13
  channelsMetaFile: string;
14
14
  channelsMapDeclarationFile: string;
15
- rpcFile: string;
16
15
  rpcMetaFile: string;
17
16
  rpcMapDeclarationFile: string;
18
17
  schedulersFile: string;
@@ -62,9 +62,6 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags =
62
62
  if (!result.functionsMetaFile) {
63
63
  result.functionsMetaFile = join(result.outDir, 'pikku-functions-meta.gen.ts');
64
64
  }
65
- if (!result.rpcFile) {
66
- result.rpcFile = join(result.outDir, 'pikku-rpc.gen.ts');
67
- }
68
65
  if (!result.rpcMetaFile) {
69
66
  result.rpcMetaFile = join(result.outDir, 'pikku-rpc-meta.gen.ts');
70
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@openapi-contrib/json-schema-to-openapi-schema": "^3.0.2",
25
25
  "@pikku/core": "^0.7.7",
26
- "@pikku/inspector": "^0.7.4",
26
+ "@pikku/inspector": "^0.7.6",
27
27
  "@types/cookie": "^0.6.0",
28
28
  "@types/uuid": "^10.0.0",
29
29
  "chalk": "^5.4.1",
@@ -26,7 +26,6 @@ export interface PikkuCLICoreOutputFiles {
26
26
  channelsMapDeclarationFile: string
27
27
 
28
28
  // RPC
29
- rpcFile: string
30
29
  rpcMetaFile: string
31
30
  rpcMapDeclarationFile: string
32
31
 
@@ -153,9 +152,6 @@ const _getPikkuCLIConfig = async (
153
152
  'pikku-functions-meta.gen.ts'
154
153
  )
155
154
  }
156
- if (!result.rpcFile) {
157
- result.rpcFile = join(result.outDir, 'pikku-rpc.gen.ts')
158
- }
159
155
  if (!result.rpcMetaFile) {
160
156
  result.rpcMetaFile = join(result.outDir, 'pikku-rpc-meta.gen.ts')
161
157
  }