platformatic 2.15.0 → 2.16.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/lib/resolve.js +24 -118
- package/package.json +17 -16
package/lib/resolve.js
CHANGED
|
@@ -1,141 +1,47 @@
|
|
|
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, {
|
|
14
10
|
alias: {
|
|
15
11
|
config: 'c',
|
|
16
12
|
username: 'u',
|
|
17
|
-
password: 'p'
|
|
13
|
+
password: 'p'
|
|
18
14
|
},
|
|
19
|
-
|
|
20
|
-
string: ['config', 'username', 'password'],
|
|
21
|
-
default: { test: false },
|
|
15
|
+
string: ['config', 'username', 'password']
|
|
22
16
|
})
|
|
23
17
|
|
|
24
|
-
const logger = pino(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
const logger = pino(
|
|
19
|
+
pretty({
|
|
20
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
21
|
+
ignore: 'hostname,pid'
|
|
22
|
+
})
|
|
23
|
+
)
|
|
28
24
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
password: args.password,
|
|
25
|
+
const store = new Store({
|
|
26
|
+
cwd: process.cwd(),
|
|
27
|
+
logger
|
|
33
28
|
})
|
|
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)
|
|
76
|
-
|
|
77
|
-
// Failed to resolve the path
|
|
78
|
-
if (path.startsWith('{') && path.endsWith('}')) {
|
|
79
|
-
path = null
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!path) {
|
|
84
|
-
await mkdir(externalDir, { recursive: true })
|
|
85
|
-
path = join(externalDir, service.id)
|
|
86
|
-
service.path = relative(projectDir, path)
|
|
87
|
-
} else {
|
|
88
|
-
path = resolvePath(projectDir, path)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const isNotEmpty = await isDirectoryNotEmpty(path)
|
|
92
|
-
if (isNotEmpty) {
|
|
93
|
-
logger.info(`Skipping ${service.id} as it is not empty`)
|
|
94
|
-
continue
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const relativePath = relative(projectDir, path)
|
|
29
|
+
store.add(platformaticRuntime)
|
|
98
30
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!urlObj.username && !urlObj.password) {
|
|
105
|
-
urlObj.username = options.username
|
|
106
|
-
urlObj.password = options.password
|
|
107
|
-
}
|
|
108
|
-
url = urlObj.href
|
|
31
|
+
const { configManager } = await store.loadConfig({
|
|
32
|
+
config: args.config,
|
|
33
|
+
overrides: {
|
|
34
|
+
onMissingEnv () {
|
|
35
|
+
return ''
|
|
109
36
|
}
|
|
110
|
-
await execa('git', ['clone', url, path])
|
|
111
37
|
}
|
|
38
|
+
})
|
|
112
39
|
|
|
113
|
-
|
|
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')
|
|
40
|
+
await resolveServices(logger, configManager.dirname, configManager.fullPath, args.username, args.password, false)
|
|
129
41
|
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async function isDirectoryNotEmpty (directoryPath) {
|
|
134
|
-
try {
|
|
135
|
-
await access(directoryPath)
|
|
136
|
-
const files = await readdir(directoryPath)
|
|
137
|
-
return files.length > 0
|
|
42
|
+
logger.info('✅ All external services have been resolved')
|
|
138
43
|
} catch (err) {
|
|
139
|
-
|
|
44
|
+
console.log(err)
|
|
45
|
+
process.exit(1)
|
|
140
46
|
}
|
|
141
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "platformatic",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.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/
|
|
42
|
-
"@platformatic/db": "2.
|
|
43
|
-
"@platformatic/
|
|
44
|
-
"@platformatic/
|
|
45
|
-
"@platformatic/remix": "2.
|
|
46
|
-
"@platformatic/
|
|
47
|
-
"@platformatic/
|
|
40
|
+
"@platformatic/composer": "2.16.0-alpha.1",
|
|
41
|
+
"@platformatic/astro": "2.16.0-alpha.1",
|
|
42
|
+
"@platformatic/db": "2.16.0-alpha.1",
|
|
43
|
+
"@platformatic/next": "2.16.0-alpha.1",
|
|
44
|
+
"@platformatic/node": "2.16.0-alpha.1",
|
|
45
|
+
"@platformatic/remix": "2.16.0-alpha.1",
|
|
46
|
+
"@platformatic/vite": "2.16.0-alpha.1",
|
|
47
|
+
"@platformatic/service": "2.16.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": "^6.9.0",
|
|
63
|
-
"@platformatic/basic": "2.
|
|
64
|
-
"@platformatic/
|
|
65
|
-
"@platformatic/config": "2.
|
|
66
|
-
"@platformatic/
|
|
67
|
-
"@platformatic/
|
|
68
|
-
"@platformatic/utils": "2.
|
|
69
|
-
"create-platformatic": "2.
|
|
63
|
+
"@platformatic/basic": "2.16.0-alpha.1",
|
|
64
|
+
"@platformatic/control": "2.16.0-alpha.1",
|
|
65
|
+
"@platformatic/config": "2.16.0-alpha.1",
|
|
66
|
+
"@platformatic/runtime": "2.16.0-alpha.1",
|
|
67
|
+
"@platformatic/client-cli": "2.16.0-alpha.1",
|
|
68
|
+
"@platformatic/utils": "2.16.0-alpha.1",
|
|
69
|
+
"create-platformatic": "2.16.0-alpha.1",
|
|
70
|
+
"wattpm": "2.16.0-alpha.1"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"test": "pnpm run lint && borp --no-timeout --concurrency 1",
|