@pikku/cli 0.8.0 → 0.8.2
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 +37 -0
- package/bin/pikku-all.ts +122 -64
- package/bin/pikku-fetch.ts +5 -1
- package/bin/pikku-nextjs.ts +6 -2
- package/bin/pikku-openapi.ts +3 -1
- package/bin/pikku-queue-service.ts +5 -1
- package/bin/pikku-websocket.ts +5 -1
- package/cli.schema.json +131 -10
- package/dist/bin/pikku-all.js +51 -50
- package/dist/bin/pikku-fetch.js +5 -1
- package/dist/bin/pikku-nextjs.js +6 -2
- package/dist/bin/pikku-openapi.js +3 -1
- package/dist/bin/pikku-queue-service.js +5 -1
- package/dist/bin/pikku-websocket.js +5 -1
- package/dist/src/events/functions/pikku-command-services.d.ts +3 -0
- package/dist/src/events/functions/pikku-command-services.js +73 -0
- package/dist/src/events/http/serialize-typed-http-map.d.ts +0 -1
- package/dist/src/events/http/serialize-typed-http-map.js +1 -14
- package/dist/src/events/rpc/pikku-command-rpc-client.d.ts +2 -0
- package/dist/src/events/rpc/pikku-command-rpc-client.js +12 -0
- package/dist/src/events/rpc/serialize-rpc-wrapper.d.ts +1 -0
- package/dist/src/events/rpc/serialize-rpc-wrapper.js +29 -0
- package/dist/src/events/rpc/serialize-typed-rpc-map.js +1 -1
- package/dist/src/inspector-glob.js +1 -1
- package/dist/src/pikku-cli-config.d.ts +4 -1
- package/dist/src/pikku-cli-config.js +26 -14
- package/dist/src/schema-generator.js +2 -2
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.js +25 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/events/functions/pikku-command-services.ts +125 -0
- package/src/events/http/serialize-typed-http-map.ts +1 -18
- package/src/events/rpc/pikku-command-rpc-client.ts +33 -0
- package/src/events/rpc/serialize-rpc-wrapper.ts +29 -0
- package/src/events/rpc/serialize-typed-rpc-map.ts +1 -1
- package/src/inspector-glob.ts +1 -1
- package/src/pikku-cli-config.ts +33 -17
- package/src/schema-generator.ts +2 -2
- package/src/utils.test.ts +137 -0
- package/src/utils.ts +31 -6
- package/dist/src/events/http/pikku-command-nextjs.d.ts +0 -2
- package/dist/src/events/http/pikku-command-nextjs.js +0 -36
- package/src/events/http/pikku-command-nextjs.ts +0 -111
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relative, dirname } from 'path'
|
|
1
|
+
import { relative, dirname, resolve } from 'path'
|
|
2
2
|
import { PathToNameAndType, InspectorState, TypesMap } from '@pikku/inspector'
|
|
3
3
|
import { mkdir, writeFile } from 'fs/promises'
|
|
4
4
|
import chalk from 'chalk'
|
|
@@ -38,6 +38,11 @@ export class CLILogger {
|
|
|
38
38
|
warn(message: string) {
|
|
39
39
|
console.error(chalk.yellow(message))
|
|
40
40
|
}
|
|
41
|
+
debug(message: string) {
|
|
42
|
+
if (process.env.DEBUG) {
|
|
43
|
+
console.log(chalk.gray(message))
|
|
44
|
+
}
|
|
45
|
+
}
|
|
41
46
|
|
|
42
47
|
private logPikkuLogo() {
|
|
43
48
|
this.primary(logo)
|
|
@@ -57,14 +62,32 @@ export const getFileImportRelativePath = (
|
|
|
57
62
|
if (!/^\.+\//.test(filePath)) {
|
|
58
63
|
filePath = `./${filePath}`
|
|
59
64
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
|
|
66
|
+
const absolutePath = resolve(dirname(from), to)
|
|
67
|
+
const fromAbsolutePath = resolve(dirname(from))
|
|
68
|
+
|
|
69
|
+
// Check if both files are in the same package directory
|
|
70
|
+
// If so, skip packageMappings to use relative paths
|
|
71
|
+
let inSamePackage = false
|
|
72
|
+
for (const [path] of Object.entries(packageMappings)) {
|
|
73
|
+
if (absolutePath.includes(path) && fromAbsolutePath.includes(path)) {
|
|
74
|
+
inSamePackage = true
|
|
65
75
|
break
|
|
66
76
|
}
|
|
67
77
|
}
|
|
78
|
+
|
|
79
|
+
// Only apply packageMappings if files are not in the same package
|
|
80
|
+
if (!inSamePackage) {
|
|
81
|
+
// let usesPackageName = false
|
|
82
|
+
for (const [path, packageName] of Object.entries(packageMappings)) {
|
|
83
|
+
if (absolutePath.includes(path)) {
|
|
84
|
+
// usesPackageName = true
|
|
85
|
+
filePath = absolutePath.replace(new RegExp(`.*${path}`), packageName)
|
|
86
|
+
break
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
68
91
|
// if (usesPackageName) {
|
|
69
92
|
// return filePath.replace('.ts', '')
|
|
70
93
|
// }
|
|
@@ -95,6 +118,8 @@ export interface PikkuCLIOptions {
|
|
|
95
118
|
singletonServicesFactoryType?: string
|
|
96
119
|
sessionServicesFactoryType?: string
|
|
97
120
|
tags?: string[]
|
|
121
|
+
types?: string[]
|
|
122
|
+
directories?: string[]
|
|
98
123
|
}
|
|
99
124
|
|
|
100
125
|
const getMetaTypes = (
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from '../../runtimes/nextjs/serialize-nextjs-backend-wrapper.js';
|
|
2
|
-
import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../../runtimes/nextjs/serialize-nextjs-http-wrapper.js';
|
|
3
|
-
import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
4
|
-
export const pikkuNext = async (logger, { nextBackendFile, nextHTTPFile, httpRoutesMapDeclarationFile, packageMappings, fetchFile, bootstrapFiles, }, visitState, options = {}) => {
|
|
5
|
-
return await logCommandInfoAndTime(logger, 'Generating nextjs wrapper', 'Generated nextjs wrapper', [
|
|
6
|
-
nextBackendFile === undefined && nextHTTPFile === undefined,
|
|
7
|
-
'nextjs outfile is not defined',
|
|
8
|
-
], async () => {
|
|
9
|
-
if (!nextBackendFile && !nextHTTPFile) {
|
|
10
|
-
throw new Error('nextBackendFile or nextHTTPFile is required in pikku config for nextJS');
|
|
11
|
-
}
|
|
12
|
-
if (nextHTTPFile && !fetchFile) {
|
|
13
|
-
throw new Error('fetchFile is required in pikku config in order for nextJS http wrapper to work');
|
|
14
|
-
}
|
|
15
|
-
if (nextBackendFile) {
|
|
16
|
-
const { pikkuConfigFactory, singletonServicesFactory, sessionServicesFactory, } = await getPikkuFilesAndMethods(logger, visitState, packageMappings, nextBackendFile, options, {
|
|
17
|
-
config: true,
|
|
18
|
-
singletonServicesFactory: true,
|
|
19
|
-
sessionServicesFactory: true,
|
|
20
|
-
});
|
|
21
|
-
const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`;
|
|
22
|
-
const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`;
|
|
23
|
-
const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`;
|
|
24
|
-
const httpBootstrapPath = getFileImportRelativePath(nextBackendFile, bootstrapFiles.http, packageMappings);
|
|
25
|
-
const routesMapDeclarationPath = getFileImportRelativePath(nextBackendFile, httpRoutesMapDeclarationFile, packageMappings);
|
|
26
|
-
const content = serializeNextBackendWrapper(httpBootstrapPath, routesMapDeclarationPath, pikkuConfigImport, singletonServicesImport, sessionServicesImport);
|
|
27
|
-
await writeFileInDir(logger, nextBackendFile, content);
|
|
28
|
-
}
|
|
29
|
-
if (nextHTTPFile && fetchFile) {
|
|
30
|
-
const routesMapDeclarationPath = getFileImportRelativePath(nextHTTPFile, httpRoutesMapDeclarationFile, packageMappings);
|
|
31
|
-
const fetchPath = getFileImportRelativePath(nextHTTPFile, fetchFile, packageMappings);
|
|
32
|
-
const content = serializeNextHTTPWrapper(routesMapDeclarationPath, fetchPath);
|
|
33
|
-
await writeFileInDir(logger, nextHTTPFile, content);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { PikkuCLIConfig } from '../../pikku-cli-config.js'
|
|
2
|
-
import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from '../../runtimes/nextjs/serialize-nextjs-backend-wrapper.js'
|
|
3
|
-
import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../../runtimes/nextjs/serialize-nextjs-http-wrapper.js'
|
|
4
|
-
import {
|
|
5
|
-
getFileImportRelativePath,
|
|
6
|
-
getPikkuFilesAndMethods,
|
|
7
|
-
logCommandInfoAndTime,
|
|
8
|
-
writeFileInDir,
|
|
9
|
-
} from '../../utils.js'
|
|
10
|
-
import { PikkuCommand } from '../../types.js'
|
|
11
|
-
|
|
12
|
-
export const pikkuNext: PikkuCommand = async (
|
|
13
|
-
logger,
|
|
14
|
-
{
|
|
15
|
-
nextBackendFile,
|
|
16
|
-
nextHTTPFile,
|
|
17
|
-
httpRoutesMapDeclarationFile,
|
|
18
|
-
packageMappings,
|
|
19
|
-
fetchFile,
|
|
20
|
-
bootstrapFiles,
|
|
21
|
-
}: PikkuCLIConfig,
|
|
22
|
-
visitState,
|
|
23
|
-
options = {}
|
|
24
|
-
) => {
|
|
25
|
-
return await logCommandInfoAndTime(
|
|
26
|
-
logger,
|
|
27
|
-
'Generating nextjs wrapper',
|
|
28
|
-
'Generated nextjs wrapper',
|
|
29
|
-
[
|
|
30
|
-
nextBackendFile === undefined && nextHTTPFile === undefined,
|
|
31
|
-
'nextjs outfile is not defined',
|
|
32
|
-
],
|
|
33
|
-
async () => {
|
|
34
|
-
if (!nextBackendFile && !nextHTTPFile) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
'nextBackendFile or nextHTTPFile is required in pikku config for nextJS'
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (nextHTTPFile && !fetchFile) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
'fetchFile is required in pikku config in order for nextJS http wrapper to work'
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (nextBackendFile) {
|
|
47
|
-
const {
|
|
48
|
-
pikkuConfigFactory,
|
|
49
|
-
singletonServicesFactory,
|
|
50
|
-
sessionServicesFactory,
|
|
51
|
-
} = await getPikkuFilesAndMethods(
|
|
52
|
-
logger,
|
|
53
|
-
visitState,
|
|
54
|
-
packageMappings,
|
|
55
|
-
nextBackendFile,
|
|
56
|
-
options,
|
|
57
|
-
{
|
|
58
|
-
config: true,
|
|
59
|
-
singletonServicesFactory: true,
|
|
60
|
-
sessionServicesFactory: true,
|
|
61
|
-
}
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`
|
|
65
|
-
const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`
|
|
66
|
-
const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`
|
|
67
|
-
|
|
68
|
-
const httpBootstrapPath = getFileImportRelativePath(
|
|
69
|
-
nextBackendFile,
|
|
70
|
-
bootstrapFiles.http,
|
|
71
|
-
packageMappings
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
75
|
-
nextBackendFile,
|
|
76
|
-
httpRoutesMapDeclarationFile,
|
|
77
|
-
packageMappings
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
const content = serializeNextBackendWrapper(
|
|
81
|
-
httpBootstrapPath,
|
|
82
|
-
routesMapDeclarationPath,
|
|
83
|
-
pikkuConfigImport,
|
|
84
|
-
singletonServicesImport,
|
|
85
|
-
sessionServicesImport
|
|
86
|
-
)
|
|
87
|
-
await writeFileInDir(logger, nextBackendFile, content)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (nextHTTPFile && fetchFile) {
|
|
91
|
-
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
92
|
-
nextHTTPFile,
|
|
93
|
-
httpRoutesMapDeclarationFile,
|
|
94
|
-
packageMappings
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
const fetchPath = getFileImportRelativePath(
|
|
98
|
-
nextHTTPFile,
|
|
99
|
-
fetchFile,
|
|
100
|
-
packageMappings
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
const content = serializeNextHTTPWrapper(
|
|
104
|
-
routesMapDeclarationPath,
|
|
105
|
-
fetchPath
|
|
106
|
-
)
|
|
107
|
-
await writeFileInDir(logger, nextHTTPFile, content)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
)
|
|
111
|
-
}
|