platformatic 1.0.0 → 1.1.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.
Files changed (2) hide show
  1. package/lib/upgrade.js +65 -3
  2. package/package.json +21 -21
package/lib/upgrade.js CHANGED
@@ -3,7 +3,8 @@ import { analyze, write, upgrade as upgradeConfig } from '@platformatic/metaconf
3
3
  import parseArgs from 'minimist'
4
4
  import { access } from 'fs/promises'
5
5
  import { resolve } from 'path'
6
-
6
+ import { request } from 'undici'
7
+ import { execa } from 'execa'
7
8
  const configFileNames = ConfigManager.listConfigFiles()
8
9
 
9
10
  async function isFileAccessible (filename) {
@@ -21,8 +22,16 @@ export async function upgrade (argv) {
21
22
  config: 'c'
22
23
  }
23
24
  })
25
+ try {
26
+ await upgradeApp(args.config)
27
+ await upgradeSystem()
28
+ } catch (err) {
29
+ // silently ignore errors
30
+ }
31
+ }
24
32
 
25
- let accessibleConfigFilename = args.config
33
+ async function upgradeApp (config) {
34
+ let accessibleConfigFilename = config
26
35
 
27
36
  if (!accessibleConfigFilename) {
28
37
  const configFilesAccessibility = await Promise.all(configFileNames.map((fileName) => isFileAccessible(fileName)))
@@ -44,5 +53,58 @@ export async function upgrade (argv) {
44
53
  meta = upgradeConfig(meta)
45
54
 
46
55
  await write(meta)
47
- console.log('Upgraded to', meta.version)
56
+ console.log('App Upgraded to', meta.version)
57
+ }
58
+
59
+ async function upgradeSystem () {
60
+ console.log('Checking latest platformatic version on npm registry...')
61
+ const currentRunningVersion = await checkSystemPlatformaticVersion()
62
+ const latestNpmVersion = await checkNpmVersion()
63
+ if (latestNpmVersion) {
64
+ const compareResult = compareVersions(currentRunningVersion, latestNpmVersion)
65
+ switch (compareResult) {
66
+ case 0:
67
+ console.log(`✅ You are running the latest Platformatic version v${latestNpmVersion}!`)
68
+ break
69
+ case -1:
70
+ console.log(`✨ Version ${latestNpmVersion} of Platformatic has been released, please update with "npm update -g platformatic"`)
71
+ break
72
+ }
73
+ }
74
+ }
75
+
76
+ async function checkNpmVersion () {
77
+ const res = await request('https://registry.npmjs.org/platformatic')
78
+
79
+ if (res.statusCode === 200) {
80
+ const json = await res.body.json()
81
+ return json['dist-tags'].latest
82
+ }
83
+ return null
84
+ }
85
+
86
+ export function compareVersions (first, second) {
87
+ const [firstMajor, firstMinor, firstPatch] = first.split('.')
88
+ const [secondMajor, secondMinor, secondPatch] = second.split('.')
89
+
90
+ if (firstMajor < secondMajor) return -1
91
+ if (firstMajor > secondMajor) return 1
92
+
93
+ // firstMajor === secondMajor
94
+ if (firstMinor < secondMinor) return -1
95
+ if (firstMinor > secondMinor) return 1
96
+
97
+ // firstMinor === secondMinor
98
+ if (firstPatch < secondPatch) return -1
99
+ if (firstPatch > secondPatch) return 1
100
+
101
+ return 0
102
+ }
103
+
104
+ async function checkSystemPlatformaticVersion () {
105
+ const { stdout } = await execa('platformatic', ['--version'])
106
+ if (stdout.match(/v\d+\.\d+\.\d+/)) {
107
+ return stdout.substring(1)
108
+ }
109
+ return '0.0.0'
48
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "platformatic",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Platformatic CLI",
5
5
  "main": "cli.js",
6
6
  "type": "module",
@@ -27,38 +27,38 @@
27
27
  "mercurius"
28
28
  ],
29
29
  "devDependencies": {
30
- "execa": "^8.0.0",
31
- "fastify": "^4.18.0",
30
+ "fastify": "^4.23.2",
32
31
  "license-checker": "^25.0.1",
33
32
  "mkdirp": "^2.1.6",
34
33
  "snazzy": "^9.0.0",
35
34
  "split2": "^4.2.0",
36
35
  "standard": "^17.1.0",
37
- "tap": "^16.3.6",
38
- "undici": "^5.22.1"
36
+ "tap": "^16.3.9"
39
37
  },
40
38
  "dependencies": {
41
- "@fastify/error": "^3.2.1",
39
+ "@fastify/error": "^3.3.0",
42
40
  "colorette": "^2.0.20",
43
41
  "commist": "^3.2.0",
44
42
  "desm": "^1.3.0",
45
- "dotenv": "^16.1.4",
43
+ "dotenv": "^16.3.1",
44
+ "execa": "^8.0.1",
46
45
  "help-me": "^4.2.0",
47
- "inquirer": "^9.2.7",
46
+ "inquirer": "^9.2.11",
48
47
  "minimist": "^1.2.8",
49
- "pino": "^8.14.1",
50
- "pino-pretty": "^10.0.0",
51
- "@platformatic/authenticate": "1.0.0",
52
- "@platformatic/client-cli": "1.0.0",
53
- "@platformatic/composer": "1.0.0",
54
- "@platformatic/frontend-template": "1.0.0",
55
- "@platformatic/db": "1.0.0",
56
- "@platformatic/config": "1.0.0",
57
- "@platformatic/metaconfig": "1.0.0",
58
- "@platformatic/runtime": "1.0.0",
59
- "@platformatic/deploy-client": "1.0.0",
60
- "create-platformatic": "1.0.0",
61
- "@platformatic/service": "1.0.0"
48
+ "pino": "^8.15.3",
49
+ "pino-pretty": "^10.2.0",
50
+ "undici": "^5.25.3",
51
+ "@platformatic/client-cli": "1.1.0",
52
+ "@platformatic/config": "1.1.0",
53
+ "@platformatic/authenticate": "1.1.0",
54
+ "@platformatic/frontend-template": "1.1.0",
55
+ "@platformatic/deploy-client": "1.1.0",
56
+ "@platformatic/service": "1.1.0",
57
+ "create-platformatic": "1.1.0",
58
+ "@platformatic/composer": "1.1.0",
59
+ "@platformatic/runtime": "1.1.0",
60
+ "@platformatic/db": "1.1.0",
61
+ "@platformatic/metaconfig": "1.1.0"
62
62
  },
63
63
  "scripts": {
64
64
  "test": "standard | snazzy && tap --no-coverage test/*.test.js",