platformatic 2.0.0-alpha.2 → 2.0.0-alpha.21

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 CHANGED
@@ -1,25 +1,27 @@
1
1
  #! /usr/bin/env node
2
2
 
3
- import { createRequire } from 'node:module'
4
- import path from 'node:path'
5
- import { pathToFileURL } from 'node:url'
6
- import { readFile } from 'node:fs/promises'
7
- import commist from 'commist'
8
- import minimist from 'minimist'
9
- import { run as runRuntime, compile } from '@platformatic/runtime/runtime.mjs'
10
- import { startCommand } from '@platformatic/runtime'
11
3
  import { command as client } from '@platformatic/client-cli'
12
- import { join } from 'desm'
13
- import { isColorSupported } from 'colorette'
14
- import helpMe from 'help-me'
15
- import { upgrade } from './lib/upgrade.js'
16
- import { logo } from './lib/ascii.js'
17
4
  import {
18
- runControl,
19
5
  getRuntimesCommand,
20
6
  injectRuntimeCommand,
7
+ runControl,
21
8
  streamRuntimeLogsCommand
22
9
  } from '@platformatic/control/control.js'
10
+ import { startCommand } from '@platformatic/runtime'
11
+ import { compile, run as runRuntime } from '@platformatic/runtime/runtime.mjs'
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'
23
25
 
24
26
  const program = commist({ maxDistance: 2 })
25
27
  const help = helpMe({
@@ -47,35 +49,37 @@ const ensureCommand = async ({ output, help }) => {
47
49
  process.exit(1)
48
50
  }
49
51
 
50
- program.register('db', async (args) => {
52
+ program.register('db', async args => {
51
53
  const { runDB } = await load('@platformatic/db/db.mjs')
52
54
  return ensureCommand(await runDB(args))
53
55
  })
54
- program.register('runtime', async (args) => ensureCommand(await runRuntime(args)))
55
- program.register('service', async (args) => {
56
+ program.register('runtime', async args => ensureCommand(await runRuntime(args)))
57
+ program.register('service', async args => {
56
58
  const { runService } = await load('@platformatic/service/service.mjs')
57
59
  return ensureCommand(await runService(args))
58
60
  })
59
- program.register('composer', async (args) => {
61
+ program.register('composer', async args => {
60
62
  const { runComposer } = await load('@platformatic/composer/composer.mjs')
61
63
  return ensureCommand(await runComposer(args))
62
64
  })
63
- program.register('start', async (args) => ensureCommand(await startCommand(args)))
64
- program.register('ctl', async (args) => ensureCommand(await runControl(args)))
65
- program.register('ps', async (args) => getRuntimesCommand(args))
66
- program.register('inject', async (args) => injectRuntimeCommand(args))
67
- program.register('logs', async (args) => streamRuntimeLogsCommand(args))
65
+ program.register('start', async args => ensureCommand(await startCommand(args)))
66
+ program.register('ctl', async args => ensureCommand(await runControl(args)))
67
+ program.register('ps', async args => getRuntimesCommand(args))
68
+ program.register('inject', async args => injectRuntimeCommand(args))
69
+ program.register('logs', async args => streamRuntimeLogsCommand(args))
68
70
  program.register('upgrade', upgrade)
71
+ program.register('resolve', resolve)
69
72
  program.register('client', client)
70
- program.register('compile', async (args) => await compile(args) ? null : process.exit(1))
73
+ program.register('build', build)
74
+ program.register('compile', async args => ((await compile(args)) ? null : process.exit(1)))
71
75
  program.register('help', help.toStdout)
72
- program.register('help db', async (args) => {
76
+ program.register('help db', async args => {
73
77
  const { runDB } = await load('@platformatic/db/db.mjs')
74
78
  return runDB(['help', ...args])
75
79
  })
76
80
  program.register('help client', () => client([]))
77
- program.register('help runtime', async (args) => runRuntime(['help', ...args]))
78
- program.register('help service', async (args) => {
81
+ program.register('help runtime', async args => runRuntime(['help', ...args]))
82
+ program.register('help service', async args => {
79
83
  const { runService } = await load('@platformatic/service/service.mjs')
80
84
  return runService(['help', ...args])
81
85
  })
@@ -89,7 +93,7 @@ const args = minimist(process.argv.slice(2), {
89
93
  })
90
94
 
91
95
  if (args.version && !args._.includes('inject')) {
92
- const version = JSON.parse(await readFile(join(import.meta.url, 'package.json'))).version
96
+ const version = JSON.parse(await readFile(join(import.meta.url, 'package.json'), 'utf-8')).version
93
97
  console.log('v' + version)
94
98
  process.exit(0)
95
99
  }
@@ -99,7 +103,7 @@ if (args.help) {
99
103
  } else if (process.argv.length > 2) {
100
104
  const output = await program.parseAsync(process.argv.slice(2))
101
105
  await ensureCommand({ output, help })
102
- /* c8 ignore start */
106
+ /* c8 ignore start */
103
107
  } else {
104
108
  if (isColorSupported && process.stdout.isTTY) {
105
109
  console.log(logo)
@@ -0,0 +1,3 @@
1
+ import neostandard from 'neostandard'
2
+
3
+ export default neostandard({ ignores: ['**/.astro', '**/.next', '**/.vite', '**/dist'] })
package/help/help.txt CHANGED
@@ -1,15 +1,18 @@
1
1
  Welcome to Platformatic. Available commands are:
2
2
 
3
- * `help` - display this message.
4
- * `help <command>` - show more information about a command.
5
3
  * `db` - start Platformatic DB; type `platformatic db help` to know more.
6
- * `service` - start Platformatic Service; type `platformatic service help` to know more.
7
- * `upgrade` - upgrade the Platformatic configuration to the latest version.
8
- * `gh` - create a new gh action for Platformatic deployments.
9
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.
10
7
  * `start` - start a Platformatic application.
11
- * `client` - generate a Platformatic client.
8
+ * `ctl` - Platformatic Control commands; `platformatic ctl help` to know more.
12
9
  * `ps` - list all Platformatic runtime applications.
13
- * `logs` - stream logs for a Platformatic runtime application.
14
10
  * `inject` - inject a request into a Platformatic runtime application.
15
- * `ctl` - Platformatic Control commands; `platformatic ctl help` to know more.
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.
@@ -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/build.js ADDED
@@ -0,0 +1,37 @@
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 CHANGED
@@ -13,7 +13,7 @@ const errors = {
13
13
  CouldNotCreateWorkspaceError: createError(`${ERROR_PREFIX}_COULD_NOT_CREATE_WORKSPACE`, 'Could not create workspace'),
14
14
  CouldNotCreateApplicationError: createError(`${ERROR_PREFIX}_COULD_NOT_CREATE_APPLICATION`, 'Could not create application'),
15
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.')
16
+ NoUserOrgsError: createError(`${ERROR_PREFIX}_NO_USER_ORGS`, 'User does not have any organisations.'),
17
17
  }
18
18
 
19
19
  export default errors
package/lib/resolve.js ADDED
@@ -0,0 +1,141 @@
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 CHANGED
@@ -9,13 +9,13 @@ import fjs from 'fast-json-stringify'
9
9
  export async function upgrade (argv) {
10
10
  const args = parseArgs(argv, {
11
11
  alias: {
12
- config: 'c'
13
- }
12
+ config: 'c',
13
+ },
14
14
  })
15
15
 
16
16
  const logger = pino(pretty({
17
17
  translateTime: 'SYS:HH:MM:ss',
18
- ignore: 'hostname,pid'
18
+ ignore: 'hostname,pid',
19
19
  }))
20
20
  try {
21
21
  await upgradeApp(args.config, logger)
@@ -28,7 +28,7 @@ export async function upgrade (argv) {
28
28
  async function upgradeApp (config, logger) {
29
29
  const store = new Store({
30
30
  cwd: process.cwd(),
31
- logger
31
+ logger,
32
32
  })
33
33
  store.add(platformaticRuntime)
34
34
 
@@ -38,8 +38,8 @@ async function upgradeApp (config, logger) {
38
38
  fixPaths: false,
39
39
  onMissingEnv (key) {
40
40
  return '{' + key + '}'
41
- }
42
- }
41
+ },
42
+ },
43
43
  })
44
44
 
45
45
  await configManager.parseAndValidate(false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "platformatic",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.21",
4
4
  "description": "Platformatic CLI",
5
5
  "main": "cli.js",
6
6
  "type": "module",
@@ -27,46 +27,54 @@
27
27
  "mercurius"
28
28
  ],
29
29
  "devDependencies": {
30
- "borp": "^0.16.0",
30
+ "add": "^2.0.6",
31
+ "borp": "^0.17.0",
31
32
  "c8": "^10.0.0",
32
- "fastify": "^4.26.2",
33
+ "eslint": "9",
34
+ "fastify": "^5.0.0",
33
35
  "license-checker": "^25.0.1",
36
+ "minimatch": "^10.0.1",
34
37
  "mkdirp": "^2.1.6",
35
- "snazzy": "^9.0.0",
36
- "split2": "^4.2.0",
37
- "standard": "^17.1.0",
38
+ "neostandard": "^0.11.1",
38
39
  "typescript": "^5.5.3",
39
- "@platformatic/db": "2.0.0-alpha.2",
40
- "@platformatic/composer": "2.0.0-alpha.2",
41
- "@platformatic/service": "2.0.0-alpha.2"
40
+ "@platformatic/astro": "2.0.0-alpha.21",
41
+ "@platformatic/composer": "2.0.0-alpha.21",
42
+ "@platformatic/db": "2.0.0-alpha.21",
43
+ "@platformatic/next": "2.0.0-alpha.21",
44
+ "@platformatic/node": "2.0.0-alpha.21",
45
+ "@platformatic/remix": "2.0.0-alpha.21",
46
+ "@platformatic/vite": "2.0.0-alpha.21",
47
+ "@platformatic/service": "2.0.0-alpha.21"
42
48
  },
43
49
  "dependencies": {
44
- "@fastify/error": "^3.4.1",
50
+ "@fastify/error": "^4.0.0",
45
51
  "colorette": "^2.0.20",
46
52
  "commist": "^3.2.0",
47
53
  "desm": "^1.3.1",
48
54
  "dotenv": "^16.4.5",
49
- "execa": "^8.0.1",
55
+ "execa": "^9.3.1",
50
56
  "fast-json-stringify": "^5.14.1",
51
57
  "graphql": "^16.8.1",
52
58
  "help-me": "^5.0.0",
53
59
  "inquirer": "^9.2.16",
54
60
  "minimist": "^1.2.8",
55
- "pino": "^8.19.0",
56
- "pino-pretty": "^11.0.0",
61
+ "pino": "^9.4.0",
62
+ "pino-pretty": "^11.2.2",
63
+ "split2": "^4.2.0",
57
64
  "undici": "^6.9.0",
58
- "@platformatic/config": "2.0.0-alpha.2",
59
- "@platformatic/control": "2.0.0-alpha.2",
60
- "@platformatic/db": "2.0.0-alpha.2",
61
- "@platformatic/frontend-template": "2.0.0-alpha.2",
62
- "@platformatic/client-cli": "2.0.0-alpha.2",
63
- "create-platformatic": "2.0.0-alpha.2",
64
- "@platformatic/utils": "2.0.0-alpha.2",
65
- "@platformatic/runtime": "2.0.0-alpha.2"
65
+ "@platformatic/basic": "2.0.0-alpha.21",
66
+ "@platformatic/config": "2.0.0-alpha.21",
67
+ "@platformatic/control": "2.0.0-alpha.21",
68
+ "@platformatic/db": "2.0.0-alpha.21",
69
+ "@platformatic/runtime": "2.0.0-alpha.21",
70
+ "@platformatic/frontend-template": "2.0.0-alpha.21",
71
+ "@platformatic/client-cli": "2.0.0-alpha.21",
72
+ "create-platformatic": "2.0.0-alpha.21",
73
+ "@platformatic/utils": "2.0.0-alpha.21"
66
74
  },
67
75
  "scripts": {
68
- "test": "pnpm run lint && borp --timeout 120000 --concurrency 1",
69
- "lint": "standard | snazzy",
76
+ "test": "pnpm run lint && borp --no-timeout --concurrency 1",
77
+ "lint": "eslint",
70
78
  "license": "license-checker --production --onlyAllow 'Apache-2.0;MIT;ISC;BSD-2-Clause;BSD-3-Clause;CC-BY-4.0'"
71
79
  }
72
80
  }