platformatic 2.0.0-alpha.3 → 2.0.0-alpha.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/cli.js +3 -1
- package/help/download.txt +55 -0
- package/lib/download.js +121 -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 { download } from './lib/download.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('download', download)
|
|
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
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Download Platformatic Runtime external services
|
|
2
|
+
|
|
3
|
+
``` bash
|
|
4
|
+
$ platformatic download
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
|
|
9
|
+
* `-c, --config FILE` - Path to the runtime configuration file.
|
|
10
|
+
|
|
11
|
+
Platformatic download command downloads runtime services that have the `url` in their configuration.
|
|
12
|
+
By default services are cloned with `git` to the `external` directory inside the runtime directory.
|
|
13
|
+
To change the directory where a service is cloned, you can set the `path` property in the service configuration.
|
|
14
|
+
|
|
15
|
+
After cloning the service, the download command will set the relative path to the service in the runtime configuration file.
|
|
16
|
+
|
|
17
|
+
Example of the runtime platformatic.json configuration file:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.0.0.json",
|
|
22
|
+
"entrypoint": "service-1",
|
|
23
|
+
"services": [
|
|
24
|
+
{
|
|
25
|
+
"id": "service-1",
|
|
26
|
+
"path": "./services/service-1",
|
|
27
|
+
"config": "platformatic.json"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "service-2",
|
|
31
|
+
"config": "platformatic.json",
|
|
32
|
+
"url": "https://github.com/test-owner/test-service.git"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "service-3",
|
|
36
|
+
"config": "platformatic.json",
|
|
37
|
+
"path": "./custom-external/service-3",
|
|
38
|
+
"url": "https://github.com/test-owner/test-service.git"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
45
|
+
|
|
46
|
+
* `platformatic.json`, or
|
|
47
|
+
* `platformatic.yml`, or
|
|
48
|
+
* `platformatic.tml`, or
|
|
49
|
+
* `platformatic.json`, or
|
|
50
|
+
* `platformatic.yml`, or
|
|
51
|
+
* `platformatic.tml`
|
|
52
|
+
|
|
53
|
+
You can find more details about the configuration format here:
|
|
54
|
+
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
|
55
|
+
* [Platformatic Service Configuration](https://docs.platformatic.dev/docs/service/configuration)
|
package/lib/download.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
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 DOWNLOAD_SERVICES_DIRNAME = 'external'
|
|
12
|
+
|
|
13
|
+
export async function download (argv) {
|
|
14
|
+
const args = parseArgs(argv, {
|
|
15
|
+
alias: {
|
|
16
|
+
config: 'c',
|
|
17
|
+
},
|
|
18
|
+
boolean: ['test'],
|
|
19
|
+
default: { test: false },
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const logger = pino(pretty({
|
|
23
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
24
|
+
ignore: 'hostname,pid',
|
|
25
|
+
}))
|
|
26
|
+
try {
|
|
27
|
+
await downloadServices(args.config, logger, args.test)
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.log(err)
|
|
30
|
+
process.exit(1)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function downloadServices (config, logger, isTest = false) {
|
|
35
|
+
const store = new Store({
|
|
36
|
+
cwd: process.cwd(),
|
|
37
|
+
logger,
|
|
38
|
+
})
|
|
39
|
+
store.add(platformaticRuntime)
|
|
40
|
+
|
|
41
|
+
const { configManager } = await store.loadConfig({
|
|
42
|
+
config,
|
|
43
|
+
overrides: {
|
|
44
|
+
fixPaths: false,
|
|
45
|
+
onMissingEnv (key) {
|
|
46
|
+
return '{' + key + '}'
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
await configManager.parseAndValidate(true)
|
|
52
|
+
config = configManager.current
|
|
53
|
+
|
|
54
|
+
// If the schema is present, we use it to format the config
|
|
55
|
+
if (configManager.schema) {
|
|
56
|
+
const stringify = fjs(configManager.schema)
|
|
57
|
+
config = JSON.parse(stringify(config))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const projectDir = configManager.dirname
|
|
61
|
+
const externalDir = join(projectDir, DOWNLOAD_SERVICES_DIRNAME)
|
|
62
|
+
|
|
63
|
+
if (!config.services || config.services.length === 0) {
|
|
64
|
+
logger.info('No external services to download')
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const services = config.services || []
|
|
69
|
+
for (const service of services) {
|
|
70
|
+
if (service.url) {
|
|
71
|
+
let path = service.path
|
|
72
|
+
if (!path || (path.startsWith('{') && path.endsWith('}'))) {
|
|
73
|
+
await mkdir(externalDir, { recursive: true })
|
|
74
|
+
path = join(externalDir, service.id)
|
|
75
|
+
service.path = relative(projectDir, path)
|
|
76
|
+
} else {
|
|
77
|
+
path = join(projectDir, path)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const isNotEmpty = await isDirectoryNotEmpty(path)
|
|
81
|
+
if (isNotEmpty) {
|
|
82
|
+
logger.info(`Skipping ${service.id} as it is not empty`)
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const relativePath = relative(projectDir, path)
|
|
87
|
+
|
|
88
|
+
logger.info(`Cloning ${service.url} into ${relativePath}`)
|
|
89
|
+
if (!isTest) {
|
|
90
|
+
await execa('git', ['clone', service.url, path])
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// TODO: replace it with a proper runtime build step
|
|
94
|
+
logger.info(`Downloading dependencies for service "${service.id}"`)
|
|
95
|
+
if (!isTest) {
|
|
96
|
+
await execa('npm', ['i'], { cwd: path })
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!service.path) {
|
|
100
|
+
service.path = relativePath
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const stringify = getStringifier(configManager.fullPath)
|
|
106
|
+
const newConfig = stringify(config)
|
|
107
|
+
|
|
108
|
+
await writeFile(configManager.fullPath, newConfig, 'utf8')
|
|
109
|
+
|
|
110
|
+
logger.info('✅ All external services have been downloaded')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function isDirectoryNotEmpty (directoryPath) {
|
|
114
|
+
try {
|
|
115
|
+
await access(directoryPath)
|
|
116
|
+
const files = await readdir(directoryPath)
|
|
117
|
+
return files.length > 0
|
|
118
|
+
} catch (err) {
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
}
|
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.5",
|
|
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/composer": "2.0.0-alpha.
|
|
41
|
-
"@platformatic/
|
|
42
|
-
"@platformatic/
|
|
40
|
+
"@platformatic/composer": "2.0.0-alpha.5",
|
|
41
|
+
"@platformatic/service": "2.0.0-alpha.5",
|
|
42
|
+
"@platformatic/db": "2.0.0-alpha.5"
|
|
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/client-cli": "2.0.0-alpha.
|
|
60
|
-
"@platformatic/
|
|
61
|
-
"@platformatic/
|
|
62
|
-
"@platformatic/
|
|
63
|
-
"@platformatic/
|
|
64
|
-
"
|
|
65
|
-
"@platformatic/utils": "2.0.0-alpha.
|
|
66
|
-
"
|
|
59
|
+
"@platformatic/client-cli": "2.0.0-alpha.5",
|
|
60
|
+
"@platformatic/control": "2.0.0-alpha.5",
|
|
61
|
+
"@platformatic/db": "2.0.0-alpha.5",
|
|
62
|
+
"@platformatic/frontend-template": "2.0.0-alpha.5",
|
|
63
|
+
"@platformatic/runtime": "2.0.0-alpha.5",
|
|
64
|
+
"create-platformatic": "2.0.0-alpha.5",
|
|
65
|
+
"@platformatic/utils": "2.0.0-alpha.5",
|
|
66
|
+
"@platformatic/config": "2.0.0-alpha.5"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"test": "pnpm run lint && borp --timeout=180000 --concurrency 1",
|