platformatic 3.4.1 → 3.5.0

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![The Platformatic logo](https://github.com/platformatic/platformatic/raw/HEAD/assets/banner-light.png 'The Platformatic logo')
1
+ ![The Platformatic logo](https://github.com/platformatic/platformatic/raw/HEAD/assets/banner-light.png)
2
2
 
3
3
  <p align="center">
4
4
  <br/>
@@ -19,20 +19,20 @@ npm create platformatic@latest
19
19
  npm install platformatic
20
20
  ```
21
21
 
22
- Follow our [Quick Start Guide](https://docs.platformatic.dev/docs/getting-started/quick-start-guide)
22
+ Follow our [Quick Start Guide](https://docs.platformatic.dev/docs/getting-started/quick-start)
23
23
  guide to get up and running with Platformatic.
24
24
 
25
25
  ## Documentation
26
26
 
27
27
  - [Getting Started](https://docs.platformatic.dev/docs/getting-started/quick-start-guide)
28
- - [CLI](https://docs.platformatic.dev/docs/cli)
29
- - [Guides](https://docs.platformatic.dev/docs/guides/movie-quotes-app-tutorial)
28
+ - [CLI](https://docs.platformatic.dev/docs/reference/wattpm/cli-commands)
29
+ - [Guides](https://docs.platformatic.dev/docs/guides/build-modular-monolith)
30
30
 
31
31
  Check out our full documentation at [docs.platformatic.dev](https://docs.platformatic.dev).
32
32
 
33
33
  ## Support
34
34
 
35
- If you run into a bug, issues or have a suggestion for improvement, please raise an
35
+ If you run into a bug, issues or have a suggestion for improvement, please raise an
36
36
  [issue on GitHub](https://github.com/platformatic/platformatic/issues/new) or join our [Discord feedback](https://discord.gg/platformatic) channel.
37
37
 
38
38
  ## License
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { checkNodeVersionForApplications, setExecutableId, setExecutableName } from '@platformatic/foundation'
4
+ import { main } from 'wattpm'
5
+
6
+ setExecutableId('platformatic')
7
+ setExecutableName('Platformatic')
8
+ checkNodeVersionForApplications()
9
+ await main()
package/bin/plt.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { checkNodeVersionForApplications, setExecutableId, setExecutableName } from '@platformatic/foundation'
4
+ import { main } from 'wattpm'
5
+
6
+ setExecutableId('plt')
7
+ setExecutableName('Platformatic')
8
+ checkNodeVersionForApplications()
9
+ await main()
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "platformatic",
3
- "version": "3.4.1",
3
+ "version": "3.5.0",
4
4
  "description": "Platformatic CLI",
5
- "main": "cli.js",
6
5
  "type": "module",
7
6
  "bin": {
8
- "platformatic": "cli.js",
9
- "plt": "cli.js"
7
+ "platformatic": "bin/platformatic.js",
8
+ "plt": "bin/plt.js"
10
9
  },
11
10
  "homepage": "https://docs.platformatic.dev/",
12
- "author": "Matteo Collina <hello@matteocollina.com>",
11
+ "author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
13
12
  "repository": {
14
13
  "type": "git",
15
14
  "url": "git+https://github.com/platformatic/platformatic.git"
@@ -27,54 +26,23 @@
27
26
  "mercurius"
28
27
  ],
29
28
  "devDependencies": {
30
- "add": "^2.0.6",
31
- "borp": "^0.17.0",
32
29
  "c8": "^10.0.0",
30
+ "cleaner-spec-reporter": "^0.5.0",
33
31
  "eslint": "9",
34
- "fastify": "^5.0.0",
35
32
  "license-checker": "^25.0.1",
36
- "minimatch": "^10.0.1",
37
- "mkdirp": "^2.1.6",
38
- "neostandard": "^0.11.1",
39
- "typescript": "^5.5.3",
40
- "@platformatic/composer": "3.4.1",
41
- "@platformatic/astro": "3.4.1",
42
- "@platformatic/db": "3.4.1",
43
- "@platformatic/next": "3.4.1",
44
- "@platformatic/node": "3.4.1",
45
- "@platformatic/remix": "3.4.1",
46
- "@platformatic/service": "3.4.1",
47
- "@platformatic/vite": "3.4.1"
33
+ "neostandard": "^0.12.0",
34
+ "typescript": "^5.5.3"
48
35
  },
49
36
  "dependencies": {
50
- "@fastify/error": "^4.0.0",
51
- "colorette": "^2.0.20",
52
- "commist": "^3.2.0",
53
- "desm": "^1.3.1",
54
- "dotenv": "^16.4.5",
55
- "execa": "^9.3.1",
56
- "fast-json-stringify": "^5.14.1",
57
- "graphql": "^16.8.1",
58
- "help-me": "^5.0.0",
59
- "inquirer": "^9.2.16",
60
- "minimist": "^1.2.8",
61
- "pino": "^9.4.0",
62
- "pino-pretty": "^11.2.2",
63
- "split2": "^4.2.0",
64
- "undici": "^6.9.0",
65
- "@platformatic/basic": "3.4.1",
66
- "@platformatic/client-cli": "3.4.1",
67
- "@platformatic/control": "3.4.1",
68
- "@platformatic/db": "3.4.1",
69
- "@platformatic/frontend-template": "3.4.1",
70
- "@platformatic/config": "3.4.1",
71
- "@platformatic/runtime": "3.4.1",
72
- "@platformatic/utils": "3.4.1",
73
- "create-platformatic": "3.4.1"
37
+ "@platformatic/foundation": "3.5.0",
38
+ "wattpm": "3.5.0"
39
+ },
40
+ "engines": {
41
+ "node": ">=22.19.0"
74
42
  },
75
43
  "scripts": {
76
- "test": "pnpm run lint && borp --no-timeout --concurrency 1",
44
+ "test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
77
45
  "lint": "eslint",
78
- "license": "license-checker --production --onlyAllow 'Apache-2.0;MIT;ISC;BSD-2-Clause;BSD-3-Clause;CC-BY-4.0'"
46
+ "license": "license-checker --production --onlyAllow 'Apache-2.0;MIT;ISC;BSD-2-Clause;BSD-3-Clause;CC-BY-4.0;BlueOak-1.0.0'"
79
47
  }
80
48
  }
package/cli.js DELETED
@@ -1,115 +0,0 @@
1
- #! /usr/bin/env node
2
- import { command as client } from '@platformatic/client-cli'
3
- import {
4
- getRuntimesCommand,
5
- injectRuntimeCommand,
6
- runControl,
7
- streamRuntimeLogsCommand
8
- } from '@platformatic/control/control.js'
9
- import { startCommand } from '@platformatic/runtime'
10
- import { compile, run as runRuntime } from '@platformatic/runtime/runtime.mjs'
11
- import { checkNodeVersionForServices } from '@platformatic/utils'
12
- import { isColorSupported } from 'colorette'
13
- import commist from 'commist'
14
- import { join } from 'desm'
15
- import helpMe from 'help-me'
16
- import minimist from 'minimist'
17
- import { readFile } from 'node:fs/promises'
18
- import { createRequire } from 'node:module'
19
- import path from 'node:path'
20
- import { pathToFileURL } from 'node:url'
21
- import { logo } from './lib/ascii.js'
22
- import { build } from './lib/build.js'
23
- import { resolve } from './lib/resolve.js'
24
- import { upgrade } from './lib/upgrade.js'
25
-
26
- checkNodeVersionForServices()
27
-
28
- const program = commist({ maxDistance: 2 })
29
- const help = helpMe({
30
- dir: join(import.meta.url, 'help'),
31
- // the default
32
- ext: '.txt'
33
- })
34
-
35
- async function load (moduleName) {
36
- const require = createRequire(path.join(process.cwd(), 'package.json'))
37
- const file = require.resolve(moduleName)
38
- return import(pathToFileURL(file))
39
- }
40
-
41
- const ensureCommand = async ({ output, help }) => {
42
- if (!output) {
43
- return
44
- }
45
-
46
- if (output.length) {
47
- console.log('Command not found:', output.join(' '), '\n')
48
- }
49
-
50
- await help.toStdout()
51
- process.exit(1)
52
- }
53
-
54
- program.register('db', async args => {
55
- const { runDB } = await load('@platformatic/db/db.mjs')
56
- return ensureCommand(await runDB(args))
57
- })
58
- program.register('runtime', async args => ensureCommand(await runRuntime(args)))
59
- program.register('service', async args => {
60
- const { runService } = await load('@platformatic/service/service.mjs')
61
- return ensureCommand(await runService(args))
62
- })
63
- program.register('composer', async args => {
64
- const { runComposer } = await load('@platformatic/composer/composer.mjs')
65
- return ensureCommand(await runComposer(args))
66
- })
67
- program.register('start', async args => ensureCommand(await startCommand(args)))
68
- program.register('ctl', async args => ensureCommand(await runControl(args)))
69
- program.register('ps', async args => getRuntimesCommand(args))
70
- program.register('inject', async args => injectRuntimeCommand(args))
71
- program.register('logs', async args => streamRuntimeLogsCommand(args))
72
- program.register('upgrade', upgrade)
73
- program.register('resolve', resolve)
74
- program.register('client', client)
75
- program.register('build', build)
76
- program.register('compile', async args => ((await compile(args)) ? null : process.exit(1)))
77
- program.register('help', help.toStdout)
78
- program.register('help db', async args => {
79
- const { runDB } = await load('@platformatic/db/db.mjs')
80
- return runDB(['help', ...args])
81
- })
82
- program.register('help client', () => client([]))
83
- program.register('help runtime', async args => runRuntime(['help', ...args]))
84
- program.register('help service', async args => {
85
- const { runService } = await load('@platformatic/service/service.mjs')
86
- return runService(['help', ...args])
87
- })
88
-
89
- const args = minimist(process.argv.slice(2), {
90
- boolean: ['help', 'version'],
91
- alias: {
92
- help: 'h',
93
- version: 'v'
94
- }
95
- })
96
-
97
- if (args.version && !args._.includes('inject')) {
98
- const version = JSON.parse(await readFile(join(import.meta.url, 'package.json'), 'utf-8')).version
99
- console.log('v' + version)
100
- process.exit(0)
101
- }
102
-
103
- if (args.help) {
104
- await help.toStdout(['help'])
105
- } else if (process.argv.length > 2) {
106
- const output = await program.parseAsync(process.argv.slice(2))
107
- await ensureCommand({ output, help })
108
- /* c8 ignore start */
109
- } else {
110
- if (isColorSupported && process.stdout.isTTY) {
111
- console.log(logo)
112
- }
113
- await help.toStdout(['help'])
114
- }
115
- /* c8 ignore stop */
package/help/compile.txt DELETED
@@ -1,7 +0,0 @@
1
- Compile all typescript plugins.
2
-
3
- ``` bash
4
- $ platformatic compile
5
- ```
6
-
7
- This command will compile the TypeScript plugins for each platformatic application.
package/help/help.txt DELETED
@@ -1,18 +0,0 @@
1
- Welcome to Platformatic. Available commands are:
2
-
3
- * `db` - start Platformatic DB; type `platformatic db help` to know more.
4
- * `runtime` - start Platformatic Runtime; type `platformatic runtime help` to know more.
5
- * `service` - start Platformatic Service; type `platformatic service help` to know more.
6
- * `composer` - start Platformatic Composer; type `platformatic composer help` to know more.
7
- * `start` - start a Platformatic application.
8
- * `ctl` - Platformatic Control commands; `platformatic ctl help` to know more.
9
- * `ps` - list all Platformatic runtime applications.
10
- * `inject` - inject a request into a Platformatic runtime application.
11
- * `logs` - stream logs for a Platformatic runtime application.
12
- * `upgrade` - upgrade the Platformatic configuration to the latest version.
13
- * `resolve` - resolve Platformatic Runtime external services
14
- * `client` - generate a Platformatic client.
15
- * `build` - builds all services.
16
- * `compile` - compile all typescript plugins.
17
- * `help` - display this message.
18
- * `help <command>` - show more information about a command.
package/help/inject.txt DELETED
@@ -1,30 +0,0 @@
1
- Injects a request to the Platformatic runtime service.
2
-
3
- ``` bash
4
- $ platformatic inject -n runtime-name /hello
5
- -X POST
6
- -H "Content-Type: application/json"
7
- -d '{"key": "value"}'
8
- ```
9
-
10
- Options:
11
-
12
- * `-p, --pid <number>` - The process `id` of the runtime.
13
- * `-n, --name <string>` - The name of the runtime.
14
- * `-s, --service <string>` - The name of the runtime service.
15
- * `-X, --request <string>` - The request HTTP method. Default is `GET`.
16
- * `-H, --header <string>` - The request header. Can be used multiple times.
17
- * `-d, --data <string>` - The request data.
18
- * `-i, --include <boolean>` - Include the response headers in the output. Default is `false`.
19
- * `-v, --verbose <boolean>` - Make the operation more talkative. Default is `false`.
20
- * `-o, --output <file>` - Write the response to the specified file.
21
-
22
- The `inject` command sends a request to the runtime service and prints the
23
- response to the standard output. If the `--service` option is not specified the
24
- request is sent to the runtime entry point.
25
-
26
- The `inject` command uses the Platformatic Runtime Management API. To enable it
27
- set the `managementApi` option to `true` in the runtime configuration file.
28
-
29
- To get the list of runtimes with enabled management API use the
30
- `platformatic ctl ps` command.
package/help/logs.txt DELETED
@@ -1,21 +0,0 @@
1
- Streams logs from the platformatic runtime application.
2
-
3
- ``` bash
4
- $ platformatic logs -n runtime-name
5
- ```
6
-
7
- Options:
8
-
9
- * `-p, --pid <number>` - The process id of the runtime.
10
- * `-n, --name <string>` - The name of the runtime.
11
- * `-l, --level <string>` - The pino log level to stream. Default is `info`.
12
- * `-s, --service <string>` - The name of the service to stream logs from.
13
- * `--pretty <boolean>` - Pretty print the logs. Default is `true`.
14
-
15
- If `--service` is not specified, the command will stream logs from all services.
16
-
17
- The `logs` command uses the Platformatic Runtime Management API. To enable it
18
- set the `managementApi` option to `true` in the runtime configuration file.
19
-
20
- To get the list of runtimes with enabled management API use the
21
- `platformatic ctl ps` command.
package/help/ps.txt DELETED
@@ -1,10 +0,0 @@
1
- Lists all running platformatic runtime applications.
2
-
3
- ``` bash
4
- $ platformatic ps
5
- ```
6
-
7
- To see the list of all available control commands, run `platformatic ctl help`.
8
-
9
- The `ps` command uses the Platformatic Runtime Management API. To enable it
10
- set the `managementApi` option to `true` in the runtime configuration file.
package/help/resolve.txt DELETED
@@ -1,57 +0,0 @@
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/help/start.txt DELETED
@@ -1,11 +0,0 @@
1
- Start a Platformatic application with the following command:
2
-
3
- ```bash
4
- $ platformatic start
5
- ```
6
-
7
- Options:
8
-
9
- * `-c, --config <path>` - Path to the configuration file.
10
- * `--inspect[=[host:]port]` - Start the Node.js debugger. `host` defaults to `'127.0.0.1'`. `port` defaults to 9229. Use caution when binding to a public host:port combination.
11
- * `--inspect-brk[=[host:]port]` - Start the Node.js debugger and block until a client has attached. `host` defaults to `'127.0.0.1'`. `port` defaults to 9229. Use caution when binding to a public host:port combination.
package/help/upgrade.txt DELETED
@@ -1,22 +0,0 @@
1
- Upgrade the Platformatic schema configuration to the latest version.
2
-
3
- ``` bash
4
- $ platformatic upgrade
5
- ```
6
-
7
- Options:
8
-
9
- * `-c, --config FILE` - Specify a schema configuration file to use.
10
-
11
- If not specified, the configuration will be loaded from any of the following, in the current directory.
12
-
13
- * `platformatic.json`, or
14
- * `platformatic.yml`, or
15
- * `platformatic.tml`, or
16
- * `platformatic.json`, or
17
- * `platformatic.yml`, or
18
- * `platformatic.tml`
19
-
20
- You can find more details about the configuration format here:
21
- * [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
22
- * [Platformatic Service Configuration](https://docs.platformatic.dev/docs/service/configuration)
package/lib/ascii.js DELETED
@@ -1,37 +0,0 @@
1
- import { green } from 'colorette'
2
-
3
- const str = `
4
-
5
- //////
6
- /////////////
7
- /////// ///////
8
- /////// ///////
9
- /////// ///////
10
- //// ////
11
- &&&& //// //// &&&&
12
- &&&&&&& //// //// &&&&&&&
13
- &&&&&&& //// //// &&&&&&&
14
- &&&& //// //// &&&&&&&
15
- &&&& //// //// &&&& &&
16
- &&&& //// //// &&& &&&&&&
17
- &&&& //// //// &&& &&&&&&
18
- &&&& ///// ///// &&& &&&&
19
- &&&& /////// /////// &&& &&&&
20
- &&&& ////// /////// &&& &&&&&&&
21
- &&&& //// ///////// //////// &&& &&&&&&
22
- &&&& //// /// //////////// &&&& &&& &&&
23
- &&&&&&& //// /// ///// &&&& &&&&
24
- &&&&&&& //// &&& &&&&& &&&&&&&
25
- &&& //// &&&& &&&&&&& &&&&&&&
26
- //// &&& &&&& &&&&&&&&&&
27
- //// &&& &&&& &&&&
28
- // &&&&& &&&&
29
- &&&&&&& &&&&&&
30
- &&&&&&&&&&&&&
31
- &&&&&&
32
-
33
- `
34
-
35
- export const logo = str.replace(/\//g, function (str) {
36
- return green(str)
37
- })
package/lib/build.js DELETED
@@ -1,37 +0,0 @@
1
- import { Store, loadConfig as pltConfigLoadConfig } from '@platformatic/config'
2
- import { buildRuntime, platformaticRuntime } from '@platformatic/runtime'
3
- import { ensureLoggableError } from '@platformatic/utils'
4
-
5
- export async function build (args) {
6
- const store = new Store()
7
- store.add(platformaticRuntime)
8
-
9
- const config = await pltConfigLoadConfig({}, args, store)
10
- config.configManager.args = config.args
11
-
12
- const runtimeConfig = config.configManager
13
- const runtime = await buildRuntime(runtimeConfig)
14
- const logger = runtime.logger
15
-
16
- // Gather informations for all services before starting
17
- const { services } = await runtime.getServices()
18
-
19
- for (const { id } of services) {
20
- logger.info(`Building service ${id}" ...`)
21
-
22
- try {
23
- await runtime.buildService(id)
24
- } catch (error) {
25
- if (error.code === 'PLT_BASIC_NON_ZERO_EXIT_CODE') {
26
- logger.error(`Building service "${id}" has failed with exit code ${error.exitCode}.`)
27
- } else {
28
- logger.error({ err: ensureLoggableError(error) }, `Building service "${id}" has throw an exception.`)
29
- }
30
-
31
- process.exit(1)
32
- }
33
- }
34
-
35
- logger.info('✅ All services have been built.')
36
- await runtime.close(false, true)
37
- }
package/lib/errors.js DELETED
@@ -1,19 +0,0 @@
1
- 'use strict'
2
-
3
- import createError from '@fastify/error'
4
-
5
- const ERROR_PREFIX = 'PLT_CLI'
6
-
7
- const errors = {
8
- InvalidWorkspaceTypeError: createError(`${ERROR_PREFIX}_INVALID_WORKSPACE_TYPE`, 'Invalid workspace type provided: "%s". Type must be one of: %s'),
9
- InvalidWorkspaceIdError: createError(`${ERROR_PREFIX}_INVALID_WORKSPACE_ID`, 'Invalid workspace id provided. Workspace id must be a valid uuid.'),
10
- CouldNotFindWorkspaceKeysError: createError(`${ERROR_PREFIX}_COULD_NOT_FIND_WORKSPACE_KEYS`, 'Could not find workspace keys in provided file.'),
11
- CouldNotFetchUserApplicationsError: createError(`${ERROR_PREFIX}_COULD_NOT_FETCH_USER_APPLICATIONS`, 'Could not fetch user applications'),
12
- CouldNotFetchDeployLabelsError: createError(`${ERROR_PREFIX}_COULD_NOT_FETCH_DEPLOY_LABELS`, 'Could not fetch deploy labels'),
13
- CouldNotCreateWorkspaceError: createError(`${ERROR_PREFIX}_COULD_NOT_CREATE_WORKSPACE`, 'Could not create workspace'),
14
- CouldNotCreateApplicationError: createError(`${ERROR_PREFIX}_COULD_NOT_CREATE_APPLICATION`, 'Could not create application'),
15
- CouldNotFetchUserOrgsError: createError(`${ERROR_PREFIX}_COULD_NOT_FETCH_USER_ORGS`, 'Could not fetch user ogranisations'),
16
- NoUserOrgsError: createError(`${ERROR_PREFIX}_NO_USER_ORGS`, 'User does not have any organisations.'),
17
- }
18
-
19
- export default errors
package/lib/resolve.js DELETED
@@ -1,141 +0,0 @@
1
- import { join, relative, resolve as resolvePath } from 'node:path'
2
- import { access, writeFile, readFile, mkdir, readdir } from 'node:fs/promises'
3
- import { Store, getParser, 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
-
10
- const RESOLVED_SERVICES_DIRNAME = 'external'
11
-
12
- export async function resolve (argv) {
13
- const args = parseArgs(argv, {
14
- alias: {
15
- config: 'c',
16
- username: 'u',
17
- password: 'p',
18
- },
19
- boolean: ['test'],
20
- string: ['config', 'username', 'password'],
21
- default: { test: false },
22
- })
23
-
24
- const logger = pino(pretty({
25
- translateTime: 'SYS:HH:MM:ss',
26
- ignore: 'hostname,pid',
27
- }))
28
- try {
29
- await resolveServices(args.config, logger, {
30
- test: args.test,
31
- username: args.username,
32
- password: args.password,
33
- })
34
- } catch (err) {
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)
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
138
- } catch (err) {
139
- return false
140
- }
141
- }
package/lib/upgrade.js DELETED
@@ -1,63 +0,0 @@
1
- import { Store, getStringifier } from '@platformatic/config'
2
- import parseArgs from 'minimist'
3
- import { writeFile } from 'fs/promises'
4
- import { platformaticRuntime } from '@platformatic/runtime'
5
- import pino from 'pino'
6
- import pretty from 'pino-pretty'
7
- import fjs from 'fast-json-stringify'
8
-
9
- export async function upgrade (argv) {
10
- const args = parseArgs(argv, {
11
- alias: {
12
- config: 'c',
13
- },
14
- })
15
-
16
- const logger = pino(pretty({
17
- translateTime: 'SYS:HH:MM:ss',
18
- ignore: 'hostname,pid',
19
- }))
20
- try {
21
- await upgradeApp(args.config, logger)
22
- } catch (err) {
23
- console.log(err)
24
- process.exit(1)
25
- }
26
- }
27
-
28
- async function upgradeApp (config, logger) {
29
- const store = new Store({
30
- cwd: process.cwd(),
31
- logger,
32
- })
33
- store.add(platformaticRuntime)
34
-
35
- const { configManager } = await store.loadConfig({
36
- config,
37
- overrides: {
38
- fixPaths: false,
39
- onMissingEnv (key) {
40
- return '{' + key + '}'
41
- },
42
- },
43
- })
44
-
45
- configManager.schemaOptions.useDefaults = false
46
-
47
- await configManager.parse(false, [], { validation: false, transform: false })
48
- config = configManager.current
49
-
50
- // If the schema is present, we use it to format the config
51
- if (configManager.schema) {
52
- const stringify = fjs(configManager.schema)
53
- config = JSON.parse(stringify(config))
54
- }
55
-
56
- const stringify = getStringifier(configManager.fullPath)
57
-
58
- const newConfig = stringify(config)
59
-
60
- await writeFile(configManager.fullPath, newConfig, 'utf8')
61
-
62
- logger.info(`✅ Updated ${configManager.fullPath}`)
63
- }