platformatic 0.16.0 → 0.17.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/README.md CHANGED
@@ -1,21 +1,26 @@
1
- # Platformatic
1
+ ![The Platformatic logo](https://github.com/platformatic/platformatic/raw/HEAD/assets/banner-light.png 'The Platformatic logo')
2
2
 
3
- Platformatic is a set a Open Source tools that you can use to build your own
4
- _Internal Developer Platform_.
5
-
6
- The first of these tools is **Platformatic DB** — more will follow!
3
+ <p align="center">
4
+ <br/>
5
+ <a href="https://platformatic.dev/">Platformatic</a> open-source tools simplify
6
+ building and
7
+ <br/>
8
+ running Node.js applications, with best practices baked in.
9
+ <br/><br/>
10
+ </p>
7
11
 
8
12
  ## Install
9
13
 
10
14
  ```bash
11
- npm install platformatic
15
+ # Create a new application
16
+ npm create platformatic@latest
12
17
 
13
- # Start a new project
14
- npx platformatic db init
18
+ # Or install manually:
19
+ npm install platformatic
15
20
  ```
16
21
 
17
22
  Follow our [Quick Start Guide](https://oss.platformatic.dev/docs/getting-started/quick-start-guide)
18
- guide to get up and running with Platformatic DB.
23
+ guide to get up and running with Platformatic.
19
24
 
20
25
  ## Documentation
21
26
 
@@ -32,4 +37,4 @@ for help.
32
37
 
33
38
  ## License
34
39
 
35
- Apache 2.0
40
+ [Apache 2.0](LICENSE)
package/cli.js CHANGED
@@ -9,6 +9,7 @@ import { readFile } from 'fs/promises'
9
9
  import { join } from 'desm'
10
10
  import { isColorSupported } from 'colorette'
11
11
  import helpMe from 'help-me'
12
+ import { upgrade } from './lib/upgrade.js'
12
13
 
13
14
  import { logo } from './lib/ascii.js'
14
15
 
@@ -34,6 +35,7 @@ const ensureCommand = async ({ output, help }) => {
34
35
 
35
36
  program.register('db', async (args) => ensureCommand(await runDB(args)))
36
37
  program.register('service', async (args) => ensureCommand(await runService(args)))
38
+ program.register('upgrade', upgrade)
37
39
  program.register('help', help.toStdout)
38
40
  program.register('help db', async (args) => runDB(['help', ...args]))
39
41
  program.register('help service', async (args) => runService(['help', ...args]))
Binary file
package/help/help.txt CHANGED
@@ -4,3 +4,4 @@ Welcome to Platformatic. Available commands are:
4
4
  * help <command> - shows more information about a command.
5
5
  * db - start Platformatic DB; type `platformatic db help` to know more.
6
6
  * service - start Platformatic Service; type `platformatic service help` to know more.
7
+ * upgrade - upgrade the Platformatic configuration to the latest version.
@@ -0,0 +1,16 @@
1
+ Upgrade the Platformatic configuration to the latest version.
2
+
3
+ ``` bash
4
+ $ platformatic upgrade
5
+ ```
6
+
7
+ Options:
8
+
9
+ -c, --config FILE Specify a configuration file to use
10
+
11
+ If not specified, the configuration specified will be loaded from `platformatic.db.json`,
12
+ `platformatic.db.yml`, or `platformatic.db.tml`, `platformatic.service.json`,
13
+ `platformatic.service.yml`, or `platformatic.service.tml` in the current directory. You can find more details about
14
+ the configuration format at:
15
+ https://oss.platformatic.dev/docs/reference/db/configuration and
16
+ https://oss.platformatic.dev/docs/reference/service/configuration.
package/lib/upgrade.js ADDED
@@ -0,0 +1,62 @@
1
+ import { analyze, write } from '@platformatic/metaconfig'
2
+ import parseArgs from 'minimist'
3
+ import { access } from 'fs/promises'
4
+ import { resolve } from 'path'
5
+
6
+ const configFileNames = [
7
+ './platformatic.db.json',
8
+ './platformatic.db.json5',
9
+ './platformatic.db.yaml',
10
+ './platformatic.db.yml',
11
+ './platformatic.db.toml',
12
+ './platformatic.db.tml',
13
+ './platformatic.service.json',
14
+ './platformatic.service.json5',
15
+ './platformatic.service.yaml',
16
+ './platformatic.service.yml',
17
+ './platformatic.service.toml',
18
+ './platformatic.service.tml'
19
+ ]
20
+
21
+ async function isFileAccessible (filename) {
22
+ try {
23
+ await access(filename)
24
+ return true
25
+ } catch (err) {
26
+ return false
27
+ }
28
+ }
29
+
30
+ export async function upgrade (argv) {
31
+ const args = parseArgs(argv, {
32
+ alias: {
33
+ config: 'c'
34
+ }
35
+ })
36
+
37
+ let accessibleConfigFilename = args.config
38
+
39
+ if (!accessibleConfigFilename) {
40
+ const configFilesAccessibility = await Promise.all(configFileNames.map((fileName) => isFileAccessible(fileName)))
41
+ accessibleConfigFilename = configFileNames.find((value, index) => configFilesAccessibility[index])
42
+ }
43
+
44
+ if (!accessibleConfigFilename) {
45
+ console.error('No config file found')
46
+ process.exitCode = 1
47
+ return
48
+ }
49
+
50
+ accessibleConfigFilename = resolve(accessibleConfigFilename)
51
+
52
+ let meta = await analyze({ file: accessibleConfigFilename })
53
+
54
+ console.log(`Found ${meta.version} for Platformatic ${meta.kind} in ${meta.format} format`)
55
+
56
+ while (typeof meta.up === 'function') {
57
+ meta = meta.up()
58
+ }
59
+
60
+ await write(meta)
61
+ console.log('Upgraded to', meta.version)
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "platformatic",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
4
4
  "description": "Platformatic CLI",
5
5
  "main": "cli.js",
6
6
  "type": "module",
@@ -27,26 +27,29 @@
27
27
  "mercurius"
28
28
  ],
29
29
  "devDependencies": {
30
- "c8": "^7.12.0",
30
+ "c8": "^7.13.0",
31
31
  "execa": "^7.0.0",
32
+ "license-checker": "^25.0.1",
32
33
  "snazzy": "^9.0.0",
33
34
  "split2": "^4.1.0",
34
35
  "standard": "^17.0.0",
35
- "tap": "^16.3.2",
36
- "undici": "^5.14.0"
36
+ "tap": "^16.3.4",
37
+ "undici": "^5.20.0"
37
38
  },
38
39
  "dependencies": {
39
40
  "colorette": "^2.0.19",
40
41
  "commist": "^3.2.0",
41
42
  "desm": "^1.3.0",
42
43
  "help-me": "^4.2.0",
43
- "minimist": "^1.2.7",
44
- "@platformatic/db": "0.16.0",
45
- "@platformatic/service": "0.16.0",
46
- "@platformatic/authenticate": "0.16.0"
44
+ "minimist": "^1.2.8",
45
+ "@platformatic/db": "0.17.1",
46
+ "@platformatic/authenticate": "0.17.1",
47
+ "@platformatic/service": "0.17.1",
48
+ "@platformatic/metaconfig": "0.17.1"
47
49
  },
48
50
  "scripts": {
49
51
  "test": "standard | snazzy && c8 --100 tap --no-coverage test/*.test.js",
50
- "lint": "standard | snazzy"
52
+ "lint": "standard | snazzy",
53
+ "license": "license-checker --production --onlyAllow 'Apache-2.0;MIT;ISC;BSD-2-Clause'"
51
54
  }
52
55
  }
@@ -0,0 +1,41 @@
1
+ {
2
+ "$schema": "./platformatic.db.schema.json",
3
+ "server": {
4
+ "hostname": "{PLT_SERVER_HOSTNAME}",
5
+ "port": "{PORT}",
6
+ "logger": {
7
+ "level": "{PLT_SERVER_LOGGER_LEVEL}"
8
+ }
9
+ },
10
+ "core": {
11
+ "connectionString": "{DATABASE_URL}",
12
+ "graphql": true,
13
+ "openapi": true,
14
+ "events": false
15
+ },
16
+ "authorization": {
17
+ "adminSecret": "{PLT_ADMIN_SECRET}",
18
+ "rules": [{
19
+ "role": "anonymous",
20
+ "entity": "queue",
21
+ "find": false,
22
+ "save": false,
23
+ "delete": false
24
+ }, {
25
+ "role": "anonymous",
26
+ "entity": "message",
27
+ "find": false,
28
+ "save": false,
29
+ "delete": false
30
+ }]
31
+ },
32
+ "migrations": {
33
+ "dir": "migrations"
34
+ },
35
+ "plugin": {
36
+ "path": "plugin.js"
37
+ },
38
+ "types": {
39
+ "autogenerate": true
40
+ }
41
+ }
@@ -0,0 +1,45 @@
1
+ import { test } from 'tap'
2
+ import { tmpdir } from 'os'
3
+ import { execa } from 'execa'
4
+ import { cp, readFile } from 'fs/promises'
5
+ import { cliPath } from './helper.js'
6
+ import { fileURLToPath } from 'url'
7
+ import { dirname, join } from 'path'
8
+
9
+ const pkg = JSON.parse(await readFile(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8'))
10
+
11
+ let count = 0
12
+
13
+ test('writes a config file', async (t) => {
14
+ const dest = join(tmpdir(), `test-cli-${process.pid}-${count++}`)
15
+
16
+ await cp(
17
+ join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'v0.16.0.db.json'),
18
+ join(dest, 'platformatic.db.json'))
19
+
20
+ await execa('node', [cliPath, 'upgrade'], {
21
+ cwd: dest
22
+ })
23
+
24
+ const config = JSON.parse(await readFile(join(dest, 'platformatic.db.json'), 'utf8'))
25
+
26
+ t.equal(config.$schema, `https://platformatic.dev/schemas/v${pkg.version.replace('-dev', '')}/db`)
27
+ })
28
+
29
+ test('writes a config file with a config option', async (t) => {
30
+ const dest = join(tmpdir(), `test-cli-${process.pid}-${count++}`)
31
+
32
+ await cp(
33
+ join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'v0.16.0.db.json'),
34
+ join(dest, 'platformatic.db.json'))
35
+
36
+ await execa('node', [cliPath, 'upgrade', '-c', join(dest, 'platformatic.db.json')])
37
+
38
+ const config = JSON.parse(await readFile(join(dest, 'platformatic.db.json'), 'utf8'))
39
+
40
+ t.equal(config.$schema, `https://platformatic.dev/schemas/v${pkg.version.replace('-dev', '')}/db`)
41
+ })
42
+
43
+ test('no config file no party', async (t) => {
44
+ await t.rejects(execa('node', [cliPath, 'upgrade']))
45
+ })