platformatic 2.19.0 → 2.20.0-alpha.1
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 +2 -0
- package/help/help.txt +1 -0
- package/help/install.txt +10 -0
- package/help/resolve.txt +1 -0
- package/lib/install.js +54 -0
- package/lib/resolve.js +33 -118
- package/package.json +17 -16
package/cli.js
CHANGED
|
@@ -20,6 +20,7 @@ import path from 'node:path'
|
|
|
20
20
|
import { pathToFileURL } from 'node:url'
|
|
21
21
|
import { logo } from './lib/ascii.js'
|
|
22
22
|
import { build } from './lib/build.js'
|
|
23
|
+
import { install } from './lib/install.js'
|
|
23
24
|
import { resolve } from './lib/resolve.js'
|
|
24
25
|
import { upgrade } from './lib/upgrade.js'
|
|
25
26
|
|
|
@@ -73,6 +74,7 @@ program.register('upgrade', upgrade)
|
|
|
73
74
|
program.register('resolve', resolve)
|
|
74
75
|
program.register('client', client)
|
|
75
76
|
program.register('build', build)
|
|
77
|
+
program.register('install', install)
|
|
76
78
|
program.register('compile', async args => ((await compile(args)) ? null : process.exit(1)))
|
|
77
79
|
program.register('help', help.toStdout)
|
|
78
80
|
program.register('help db', async args => {
|
package/help/help.txt
CHANGED
|
@@ -13,6 +13,7 @@ Welcome to Platformatic. Available commands are:
|
|
|
13
13
|
* `resolve` - resolve Platformatic Runtime external services
|
|
14
14
|
* `client` - generate a Platformatic client.
|
|
15
15
|
* `build` - builds all services.
|
|
16
|
+
* `install` - install all dependencies of an application and its services.
|
|
16
17
|
* `compile` - compile all typescript plugins.
|
|
17
18
|
* `help` - display this message.
|
|
18
19
|
* `help <command>` - show more information about a command.
|
package/help/install.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Install all dependencies of an application and its services.
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
platformatic install
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
|
|
9
|
+
* `-p, --production`: Only install production dependencies.
|
|
10
|
+
* `-P, --package-manager EXECUTABLE`: Use an alternative package manager (the default is to autodetect it).
|
package/help/resolve.txt
CHANGED
|
@@ -9,6 +9,7 @@ Options:
|
|
|
9
9
|
* `-c, --config FILE` - Path to the runtime configuration file.
|
|
10
10
|
* `-u, --username string` - Username for the service repository.
|
|
11
11
|
* `-p, --password string` - Password for the service repository.
|
|
12
|
+
* `-P, --package-manager EXECUTABLE`: Use an alternative package manager to install dependencies (the default is to autodetect it).
|
|
12
13
|
|
|
13
14
|
Platformatic resolve command resolves runtime services that have the `url` in their configuration.
|
|
14
15
|
By default services are cloned with `git` to the `external` directory inside the runtime directory.
|
package/lib/install.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Store } from '@platformatic/config'
|
|
2
|
+
import { platformaticRuntime } from '@platformatic/runtime'
|
|
3
|
+
import parseArgs from 'minimist'
|
|
4
|
+
import pino from 'pino'
|
|
5
|
+
import pretty from 'pino-pretty'
|
|
6
|
+
import { installDependencies } from 'wattpm/lib/commands/build.js'
|
|
7
|
+
|
|
8
|
+
export async function install (argv) {
|
|
9
|
+
const args = parseArgs(argv, {
|
|
10
|
+
alias: {
|
|
11
|
+
production: 'p',
|
|
12
|
+
'package-manager': 'P'
|
|
13
|
+
},
|
|
14
|
+
boolean: ['production'],
|
|
15
|
+
string: ['package-manager']
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const logger = pino(
|
|
19
|
+
pretty({
|
|
20
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
21
|
+
ignore: 'hostname,pid'
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const store = new Store({
|
|
27
|
+
cwd: process.cwd(),
|
|
28
|
+
logger
|
|
29
|
+
})
|
|
30
|
+
store.add(platformaticRuntime)
|
|
31
|
+
|
|
32
|
+
const { configManager } = await store.loadConfig({
|
|
33
|
+
config: args.config,
|
|
34
|
+
overrides: {
|
|
35
|
+
onMissingEnv () {
|
|
36
|
+
return ''
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
await installDependencies(
|
|
42
|
+
logger,
|
|
43
|
+
configManager.dirname,
|
|
44
|
+
configManager.fullPath,
|
|
45
|
+
args.production,
|
|
46
|
+
args['package-manager']
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
logger.info('✅ All dependencies have been installed')
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.log(err)
|
|
52
|
+
process.exit(1)
|
|
53
|
+
}
|
|
54
|
+
}
|
package/lib/resolve.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { access, writeFile, readFile, mkdir, readdir } from 'node:fs/promises'
|
|
3
|
-
import { Store, getParser, getStringifier } from '@platformatic/config'
|
|
1
|
+
import { Store } from '@platformatic/config'
|
|
4
2
|
import { platformaticRuntime } from '@platformatic/runtime'
|
|
5
3
|
import parseArgs from 'minimist'
|
|
6
4
|
import pino from 'pino'
|
|
7
5
|
import pretty from 'pino-pretty'
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const RESOLVED_SERVICES_DIRNAME = 'external'
|
|
6
|
+
import { resolveServices } from 'wattpm'
|
|
11
7
|
|
|
12
8
|
export async function resolve (argv) {
|
|
13
9
|
const args = parseArgs(argv, {
|
|
@@ -15,127 +11,46 @@ export async function resolve (argv) {
|
|
|
15
11
|
config: 'c',
|
|
16
12
|
username: 'u',
|
|
17
13
|
password: 'p',
|
|
14
|
+
'package-manager': 'P'
|
|
18
15
|
},
|
|
19
|
-
|
|
20
|
-
string: ['config', 'username', 'password'],
|
|
21
|
-
default: { test: false },
|
|
16
|
+
string: ['config', 'username', 'password', 'package-manager']
|
|
22
17
|
})
|
|
23
18
|
|
|
24
|
-
const logger = pino(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
const logger = pino(
|
|
20
|
+
pretty({
|
|
21
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
22
|
+
ignore: 'hostname,pid'
|
|
23
|
+
})
|
|
24
|
+
)
|
|
28
25
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
password: args.password,
|
|
26
|
+
const store = new Store({
|
|
27
|
+
cwd: process.cwd(),
|
|
28
|
+
logger
|
|
33
29
|
})
|
|
34
|
-
|
|
35
|
-
console.log(err)
|
|
36
|
-
process.exit(1)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function resolveServices (configPath, logger, options = {}) {
|
|
41
|
-
const store = new Store({
|
|
42
|
-
cwd: process.cwd(),
|
|
43
|
-
logger,
|
|
44
|
-
})
|
|
45
|
-
store.add(platformaticRuntime)
|
|
46
|
-
|
|
47
|
-
const { configManager } = await store.loadConfig({
|
|
48
|
-
config: configPath,
|
|
49
|
-
overrides: {
|
|
50
|
-
onMissingEnv (key) {
|
|
51
|
-
return '{' + key + '}'
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
configPath = configManager.fullPath
|
|
57
|
-
|
|
58
|
-
const parseConfig = getParser(configPath)
|
|
59
|
-
const configFile = await readFile(configPath, 'utf8')
|
|
60
|
-
const config = await parseConfig(configFile)
|
|
61
|
-
|
|
62
|
-
if (!config.services || config.services.length === 0) {
|
|
63
|
-
logger.info('No external services to resolve')
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const projectDir = configManager.dirname
|
|
68
|
-
const externalDir = join(projectDir, RESOLVED_SERVICES_DIRNAME)
|
|
69
|
-
|
|
70
|
-
const services = config.services || []
|
|
71
|
-
for (const service of services) {
|
|
72
|
-
if (service.url) {
|
|
73
|
-
let path = service.path
|
|
74
|
-
if (path && path.startsWith('{') && path.endsWith('}')) {
|
|
75
|
-
path = await configManager.replaceEnv(path)
|
|
30
|
+
store.add(platformaticRuntime)
|
|
76
31
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
32
|
+
const { configManager } = await store.loadConfig({
|
|
33
|
+
config: args.config,
|
|
34
|
+
overrides: {
|
|
35
|
+
onMissingEnv () {
|
|
36
|
+
return ''
|
|
80
37
|
}
|
|
81
38
|
}
|
|
39
|
+
})
|
|
82
40
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
continue
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const relativePath = relative(projectDir, path)
|
|
98
|
-
|
|
99
|
-
logger.info(`Cloning ${service.url} into ${relativePath}`)
|
|
100
|
-
if (!options.test) {
|
|
101
|
-
let url = service.url
|
|
102
|
-
if (options.username && options.password) {
|
|
103
|
-
const urlObj = new URL(service.url)
|
|
104
|
-
if (!urlObj.username && !urlObj.password) {
|
|
105
|
-
urlObj.username = options.username
|
|
106
|
-
urlObj.password = options.password
|
|
107
|
-
}
|
|
108
|
-
url = urlObj.href
|
|
109
|
-
}
|
|
110
|
-
await execa('git', ['clone', url, path])
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// TODO: replace it with a proper runtime build step
|
|
114
|
-
logger.info(`Resolving dependencies for service "${service.id}"`)
|
|
115
|
-
if (!options.test) {
|
|
116
|
-
await execa('npm', ['i'], { cwd: path })
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!service.path) {
|
|
120
|
-
service.path = relativePath
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const stringifyConfig = getStringifier(configPath)
|
|
126
|
-
const newConfig = stringifyConfig(config)
|
|
127
|
-
|
|
128
|
-
await writeFile(configManager.fullPath, newConfig, 'utf8')
|
|
129
|
-
|
|
130
|
-
logger.info('✅ All external services have been resolved')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async function isDirectoryNotEmpty (directoryPath) {
|
|
134
|
-
try {
|
|
135
|
-
await access(directoryPath)
|
|
136
|
-
const files = await readdir(directoryPath)
|
|
137
|
-
return files.length > 0
|
|
41
|
+
await resolveServices(
|
|
42
|
+
logger,
|
|
43
|
+
configManager.dirname,
|
|
44
|
+
configManager.fullPath,
|
|
45
|
+
args.username,
|
|
46
|
+
args.password,
|
|
47
|
+
false,
|
|
48
|
+
args.packageManager
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
logger.info('✅ All external services have been resolved')
|
|
138
52
|
} catch (err) {
|
|
139
|
-
|
|
53
|
+
console.log(err)
|
|
54
|
+
process.exit(1)
|
|
140
55
|
}
|
|
141
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "platformatic",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0-alpha.1",
|
|
4
4
|
"description": "Platformatic CLI",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"mkdirp": "^2.1.6",
|
|
38
38
|
"neostandard": "^0.11.1",
|
|
39
39
|
"typescript": "^5.5.3",
|
|
40
|
-
"@platformatic/
|
|
41
|
-
"@platformatic/composer": "2.
|
|
42
|
-
"@platformatic/
|
|
43
|
-
"@platformatic/
|
|
44
|
-
"@platformatic/node": "2.
|
|
45
|
-
"@platformatic/service": "2.
|
|
46
|
-
"@platformatic/
|
|
47
|
-
"@platformatic/
|
|
40
|
+
"@platformatic/db": "2.20.0-alpha.1",
|
|
41
|
+
"@platformatic/composer": "2.20.0-alpha.1",
|
|
42
|
+
"@platformatic/astro": "2.20.0-alpha.1",
|
|
43
|
+
"@platformatic/next": "2.20.0-alpha.1",
|
|
44
|
+
"@platformatic/node": "2.20.0-alpha.1",
|
|
45
|
+
"@platformatic/service": "2.20.0-alpha.1",
|
|
46
|
+
"@platformatic/remix": "2.20.0-alpha.1",
|
|
47
|
+
"@platformatic/vite": "2.20.0-alpha.1"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@fastify/error": "^4.0.0",
|
|
@@ -60,13 +60,14 @@
|
|
|
60
60
|
"pino-pretty": "^13.0.0",
|
|
61
61
|
"split2": "^4.2.0",
|
|
62
62
|
"undici": "^7.0.0",
|
|
63
|
-
"@platformatic/basic": "2.
|
|
64
|
-
"@platformatic/
|
|
65
|
-
"@platformatic/
|
|
66
|
-
"@platformatic/
|
|
67
|
-
"@platformatic/
|
|
68
|
-
"@platformatic/utils": "2.
|
|
69
|
-
"create-platformatic": "2.
|
|
63
|
+
"@platformatic/basic": "2.20.0-alpha.1",
|
|
64
|
+
"@platformatic/client-cli": "2.20.0-alpha.1",
|
|
65
|
+
"@platformatic/config": "2.20.0-alpha.1",
|
|
66
|
+
"@platformatic/control": "2.20.0-alpha.1",
|
|
67
|
+
"@platformatic/runtime": "2.20.0-alpha.1",
|
|
68
|
+
"@platformatic/utils": "2.20.0-alpha.1",
|
|
69
|
+
"create-platformatic": "2.20.0-alpha.1",
|
|
70
|
+
"wattpm": "2.20.0-alpha.1"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"test": "pnpm run lint && borp --no-timeout --concurrency 1",
|