platformatic 2.0.0-alpha.4 → 2.0.0-alpha.6
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/cli.js +3 -1
- package/help/resolve.txt +57 -0
- package/lib/resolve.js +137 -0
- package/package.json +12 -12
package/cli.js
CHANGED
|
@@ -13,6 +13,7 @@ import { join } from 'desm'
|
|
|
13
13
|
import { isColorSupported } from 'colorette'
|
|
14
14
|
import helpMe from 'help-me'
|
|
15
15
|
import { upgrade } from './lib/upgrade.js'
|
|
16
|
+
import { resolve } from './lib/resolve.js'
|
|
16
17
|
import { logo } from './lib/ascii.js'
|
|
17
18
|
import {
|
|
18
19
|
runControl,
|
|
@@ -66,6 +67,7 @@ program.register('ps', async (args) => getRuntimesCommand(args))
|
|
|
66
67
|
program.register('inject', async (args) => injectRuntimeCommand(args))
|
|
67
68
|
program.register('logs', async (args) => streamRuntimeLogsCommand(args))
|
|
68
69
|
program.register('upgrade', upgrade)
|
|
70
|
+
program.register('resolve', resolve)
|
|
69
71
|
program.register('client', client)
|
|
70
72
|
program.register('compile', async (args) => await compile(args) ? null : process.exit(1))
|
|
71
73
|
program.register('help', help.toStdout)
|
|
@@ -89,7 +91,7 @@ const args = minimist(process.argv.slice(2), {
|
|
|
89
91
|
})
|
|
90
92
|
|
|
91
93
|
if (args.version && !args._.includes('inject')) {
|
|
92
|
-
const version = JSON.parse(await readFile(join(import.meta.url, 'package.json'))).version
|
|
94
|
+
const version = JSON.parse(await readFile(join(import.meta.url, 'package.json'), 'utf-8')).version
|
|
93
95
|
console.log('v' + version)
|
|
94
96
|
process.exit(0)
|
|
95
97
|
}
|
package/help/resolve.txt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Resolve Platformatic Runtime external services
|
|
2
|
+
|
|
3
|
+
``` bash
|
|
4
|
+
$ platformatic resolve
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
|
|
9
|
+
* `-c, --config FILE` - Path to the runtime configuration file.
|
|
10
|
+
* `-u, --username string` - Username for the service repository.
|
|
11
|
+
* `-p, --password string` - Password for the service repository.
|
|
12
|
+
|
|
13
|
+
Platformatic resolve command resolves runtime services that have the `url` in their configuration.
|
|
14
|
+
By default services are cloned with `git` to the `external` directory inside the runtime directory.
|
|
15
|
+
To change the directory where a service is cloned, you can set the `path` property in the service configuration.
|
|
16
|
+
|
|
17
|
+
After cloning the service, the resolve command will set the relative path to the service in the runtime configuration file.
|
|
18
|
+
|
|
19
|
+
Example of the runtime platformatic.json configuration file:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.0.0.json",
|
|
24
|
+
"entrypoint": "service-1",
|
|
25
|
+
"services": [
|
|
26
|
+
{
|
|
27
|
+
"id": "service-1",
|
|
28
|
+
"path": "./services/service-1",
|
|
29
|
+
"config": "platformatic.json"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "service-2",
|
|
33
|
+
"config": "platformatic.json",
|
|
34
|
+
"url": "https://github.com/test-owner/test-service.git"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "service-3",
|
|
38
|
+
"config": "platformatic.json",
|
|
39
|
+
"path": "./custom-external/service-3",
|
|
40
|
+
"url": "https://github.com/test-owner/test-service.git"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
47
|
+
|
|
48
|
+
* `platformatic.json`, or
|
|
49
|
+
* `platformatic.yml`, or
|
|
50
|
+
* `platformatic.tml`, or
|
|
51
|
+
* `platformatic.json`, or
|
|
52
|
+
* `platformatic.yml`, or
|
|
53
|
+
* `platformatic.tml`
|
|
54
|
+
|
|
55
|
+
You can find more details about the configuration format here:
|
|
56
|
+
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
|
57
|
+
* [Platformatic Service Configuration](https://docs.platformatic.dev/docs/service/configuration)
|
package/lib/resolve.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { join, relative } from 'node:path'
|
|
2
|
+
import { access, writeFile, mkdir, readdir } from 'node:fs/promises'
|
|
3
|
+
import { Store, getStringifier } from '@platformatic/config'
|
|
4
|
+
import { platformaticRuntime } from '@platformatic/runtime'
|
|
5
|
+
import parseArgs from 'minimist'
|
|
6
|
+
import pino from 'pino'
|
|
7
|
+
import pretty from 'pino-pretty'
|
|
8
|
+
import { execa } from 'execa'
|
|
9
|
+
import fjs from 'fast-json-stringify'
|
|
10
|
+
|
|
11
|
+
const RESOLVED_SERVICES_DIRNAME = 'external'
|
|
12
|
+
|
|
13
|
+
export async function resolve (argv) {
|
|
14
|
+
const args = parseArgs(argv, {
|
|
15
|
+
alias: {
|
|
16
|
+
config: 'c',
|
|
17
|
+
username: 'u',
|
|
18
|
+
password: 'p',
|
|
19
|
+
},
|
|
20
|
+
boolean: ['test'],
|
|
21
|
+
string: ['config', 'username', 'password'],
|
|
22
|
+
default: { test: false },
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const logger = pino(pretty({
|
|
26
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
27
|
+
ignore: 'hostname,pid',
|
|
28
|
+
}))
|
|
29
|
+
try {
|
|
30
|
+
await resolveServices(args.config, logger, {
|
|
31
|
+
test: args.test,
|
|
32
|
+
username: args.username,
|
|
33
|
+
password: args.password,
|
|
34
|
+
})
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(err)
|
|
37
|
+
process.exit(1)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function resolveServices (config, logger, options = {}) {
|
|
42
|
+
const store = new Store({
|
|
43
|
+
cwd: process.cwd(),
|
|
44
|
+
logger,
|
|
45
|
+
})
|
|
46
|
+
store.add(platformaticRuntime)
|
|
47
|
+
|
|
48
|
+
const { configManager } = await store.loadConfig({
|
|
49
|
+
config,
|
|
50
|
+
overrides: {
|
|
51
|
+
fixPaths: false,
|
|
52
|
+
onMissingEnv (key) {
|
|
53
|
+
return '{' + key + '}'
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
await configManager.parseAndValidate(true)
|
|
59
|
+
config = configManager.current
|
|
60
|
+
|
|
61
|
+
// If the schema is present, we use it to format the config
|
|
62
|
+
if (configManager.schema) {
|
|
63
|
+
const stringify = fjs(configManager.schema)
|
|
64
|
+
config = JSON.parse(stringify(config))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const projectDir = configManager.dirname
|
|
68
|
+
const externalDir = join(projectDir, RESOLVED_SERVICES_DIRNAME)
|
|
69
|
+
|
|
70
|
+
if (!config.services || config.services.length === 0) {
|
|
71
|
+
logger.info('No external services to resolve')
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const services = config.services || []
|
|
76
|
+
for (const service of services) {
|
|
77
|
+
if (service.url) {
|
|
78
|
+
let path = service.path
|
|
79
|
+
if (!path || (path.startsWith('{') && path.endsWith('}'))) {
|
|
80
|
+
await mkdir(externalDir, { recursive: true })
|
|
81
|
+
path = join(externalDir, service.id)
|
|
82
|
+
service.path = relative(projectDir, path)
|
|
83
|
+
} else {
|
|
84
|
+
path = join(projectDir, path)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const isNotEmpty = await isDirectoryNotEmpty(path)
|
|
88
|
+
if (isNotEmpty) {
|
|
89
|
+
logger.info(`Skipping ${service.id} as it is not empty`)
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const relativePath = relative(projectDir, path)
|
|
94
|
+
|
|
95
|
+
logger.info(`Cloning ${service.url} into ${relativePath}`)
|
|
96
|
+
if (!options.test) {
|
|
97
|
+
let url = service.url
|
|
98
|
+
if (options.username && options.password) {
|
|
99
|
+
const urlObj = new URL(service.url)
|
|
100
|
+
if (!urlObj.username && !urlObj.password) {
|
|
101
|
+
urlObj.username = options.username
|
|
102
|
+
urlObj.password = options.password
|
|
103
|
+
}
|
|
104
|
+
url = urlObj.href
|
|
105
|
+
}
|
|
106
|
+
await execa('git', ['clone', url, path])
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// TODO: replace it with a proper runtime build step
|
|
110
|
+
logger.info(`Resolving dependencies for service "${service.id}"`)
|
|
111
|
+
if (!options.test) {
|
|
112
|
+
await execa('npm', ['i'], { cwd: path })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!service.path) {
|
|
116
|
+
service.path = relativePath
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const stringify = getStringifier(configManager.fullPath)
|
|
122
|
+
const newConfig = stringify(config)
|
|
123
|
+
|
|
124
|
+
await writeFile(configManager.fullPath, newConfig, 'utf8')
|
|
125
|
+
|
|
126
|
+
logger.info('✅ All external services have been resolved')
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function isDirectoryNotEmpty (directoryPath) {
|
|
130
|
+
try {
|
|
131
|
+
await access(directoryPath)
|
|
132
|
+
const files = await readdir(directoryPath)
|
|
133
|
+
return files.length > 0
|
|
134
|
+
} catch (err) {
|
|
135
|
+
return false
|
|
136
|
+
}
|
|
137
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "platformatic",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.6",
|
|
4
4
|
"description": "Platformatic CLI",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"neostandard": "^0.11.1",
|
|
38
38
|
"split2": "^4.2.0",
|
|
39
39
|
"typescript": "^5.5.3",
|
|
40
|
-
"@platformatic/
|
|
41
|
-
"@platformatic/
|
|
42
|
-
"@platformatic/service": "2.0.0-alpha.
|
|
40
|
+
"@platformatic/db": "2.0.0-alpha.6",
|
|
41
|
+
"@platformatic/composer": "2.0.0-alpha.6",
|
|
42
|
+
"@platformatic/service": "2.0.0-alpha.6"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@fastify/error": "^3.4.1",
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
"pino": "^8.19.0",
|
|
57
57
|
"pino-pretty": "^11.0.0",
|
|
58
58
|
"undici": "^6.9.0",
|
|
59
|
-
"@platformatic/
|
|
60
|
-
"@platformatic/
|
|
61
|
-
"@platformatic/
|
|
62
|
-
"@platformatic/
|
|
63
|
-
"@platformatic/
|
|
64
|
-
"@platformatic/utils": "2.0.0-alpha.
|
|
65
|
-
"create-platformatic": "2.0.0-alpha.
|
|
66
|
-
"@platformatic/
|
|
59
|
+
"@platformatic/client-cli": "2.0.0-alpha.6",
|
|
60
|
+
"@platformatic/config": "2.0.0-alpha.6",
|
|
61
|
+
"@platformatic/control": "2.0.0-alpha.6",
|
|
62
|
+
"@platformatic/db": "2.0.0-alpha.6",
|
|
63
|
+
"@platformatic/frontend-template": "2.0.0-alpha.6",
|
|
64
|
+
"@platformatic/utils": "2.0.0-alpha.6",
|
|
65
|
+
"create-platformatic": "2.0.0-alpha.6",
|
|
66
|
+
"@platformatic/runtime": "2.0.0-alpha.6"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"test": "pnpm run lint && borp --timeout=180000 --concurrency 1",
|