pockethost 1.0.0 → 1.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # pockethost
2
+
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 72a6c6d: --version now displays version number
8
+ - ac10d1f: Display notification when new pockethost update is available.
9
+ - f9aea10: Debugging info removed from `plugin ls`
10
+
11
+ ### Patch Changes
12
+
13
+ - 76d57f6: CHANGELOG.md is now published with package.
14
+ - 3783447: plugin-console-logger and plugin-launcher-spawn are now automatically installed.
15
+
16
+ ## 1.1.0
17
+
18
+ ### Minor Changes
19
+
20
+ - 1695b59: New feature: list plugins (pockethost plugin ls)
21
+
22
+ ### Patch Changes
23
+
24
+ - 2514c09: Fix: make sure PH_PLUGINS contains only unique values.
25
+ - 1228840: Fixed extra newline when listing configs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pockethost",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "author": {
5
5
  "name": "Ben Allfree",
6
6
  "url": "https://github.com/benallfree"
@@ -37,7 +37,10 @@
37
37
  "tsx": "^4.15.7",
38
38
  "type-fest": "^4.6.0",
39
39
  "typescript": "^5.4.5",
40
- "url-pattern": "^1.0.3"
40
+ "update-notifier": "^7.0.0",
41
+ "url-pattern": "^1.0.3",
42
+ "@pockethost/plugin-console-logger": "^0.0.1",
43
+ "@pockethost/plugin-launcher-spawn": "^0.0.1"
41
44
  },
42
45
  "devDependencies": {
43
46
  "@types/express": "^4.17.21",
@@ -45,7 +48,10 @@
45
48
  "@types/json-stringify-safe": "^5.0.2",
46
49
  "@types/node": "^20.8.10",
47
50
  "@types/semver": "^7.5.4",
48
- "@types/tmp": "^0.2.5"
51
+ "@types/tmp": "^0.2.5",
52
+ "@types/update-notifier": "^6.0.8",
53
+ "@pockethost/plugin-launcher-spawn": "0.0.1",
54
+ "@pockethost/plugin-console-logger": "0.0.1"
49
55
  },
50
56
  "scripts": {
51
57
  "check-types": "tsc --noEmit ",
@@ -71,12 +71,12 @@ export const ConfigCommand = () => {
71
71
  const values = _parse()
72
72
 
73
73
  if (keys(values).length > 0) {
74
- info(`\n`)
74
+ info()
75
75
  info(`Config values from ${envFile()}:`)
76
76
  forEach(values, (v, k) => {
77
77
  info(`\t${k}=${v}`)
78
78
  })
79
- info(`\n`)
79
+ info()
80
80
  } else {
81
81
  info(`No config values found in ${envFile()}`)
82
82
  }
@@ -1,9 +1,10 @@
1
+ import { uniq } from '@s-libs/micro-dash'
1
2
  import { Command } from 'commander'
2
3
  import { parse } from 'dotenv'
3
4
  import { existsSync, readFileSync, writeFileSync } from 'fs'
4
- import { error, info } from '..'
5
- import { PH_HOME, PH_PLUGINS, PH_PROJECT_DIR } from '../../constants'
6
- import { getCompatibleVersions, removePackage } from './util'
5
+ import { error, info } from '../..'
6
+ import { PH_HOME, PH_PLUGINS, PH_PROJECT_DIR } from '../../../constants'
7
+ import { getCompatibleVersions, getPackageJson, removePackage } from './util'
7
8
 
8
9
  const envFile = () => {
9
10
  const envFile = PH_HOME(`.env`)
@@ -33,13 +34,13 @@ export const PluginCommand = () => {
33
34
  await getCompatibleVersions(`pockethost`, version, [name])
34
35
 
35
36
  const values = _parse()
36
- values[`PH_PLUGINS`] = [
37
+ values[`PH_PLUGINS`] = uniq([
37
38
  ...(values[`PH_PLUGINS`]
38
39
  ?.split(/,/)
39
40
  .map((v) => v.trim())
40
41
  .filter((v) => !!v) || []),
41
42
  name,
42
- ].join(`,`)
43
+ ]).join(`,`)
43
44
  writeFileSync(
44
45
  envFile(),
45
46
  Object.entries(values)
@@ -54,6 +55,22 @@ export const PluginCommand = () => {
54
55
  }),
55
56
  )
56
57
 
58
+ .addCommand(
59
+ new Command(`list`)
60
+ .alias(`ls`)
61
+ .description(`List plugins`)
62
+ .action(async (name: string) => {
63
+ try {
64
+ for (const plugin of PH_PLUGINS()) {
65
+ const pkg = await getPackageJson(plugin)
66
+ info(`${plugin}@${pkg.version} - ${pkg?.description}`)
67
+ }
68
+ } catch (e) {
69
+ error(`${e}`)
70
+ }
71
+ }),
72
+ )
73
+
57
74
  .addCommand(
58
75
  new Command(`remove`)
59
76
  .alias(`rm`)
@@ -65,12 +82,12 @@ export const PluginCommand = () => {
65
82
  try {
66
83
  await removePackage(name)
67
84
  const values = _parse()
68
- values[`PH_PLUGINS`] = [
85
+ values[`PH_PLUGINS`] = uniq([
69
86
  ...(values[`PH_PLUGINS`]
70
87
  ?.split(/,/)
71
88
  .map((v) => v.trim())
72
89
  .filter((v) => v !== name) || []),
73
- ].join(`,`)
90
+ ]).join(`,`)
74
91
  writeFileSync(
75
92
  envFile(),
76
93
  Object.entries(values)
@@ -84,6 +101,7 @@ export const PluginCommand = () => {
84
101
  }
85
102
  }),
86
103
  )
104
+
87
105
  .addCommand(
88
106
  new Command(`update`)
89
107
  .alias(`up`)
@@ -9,7 +9,7 @@ import util from 'util'
9
9
  const execPromise = util.promisify(exec)
10
10
  const require = createRequire(import.meta.url)
11
11
 
12
- async function getPackageJson(packageName: string): Promise<any | null> {
12
+ export async function getPackageJson(packageName: string): Promise<any | null> {
13
13
  try {
14
14
  const packageJsonPath = require.resolve(`${packageName}/package.json`)
15
15
  const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'))
@@ -19,7 +19,9 @@ async function getPackageJson(packageName: string): Promise<any | null> {
19
19
  }
20
20
  }
21
21
 
22
- async function fetchPackageData(packageName: string): Promise<any | null> {
22
+ export async function fetchPackageData(
23
+ packageName: string,
24
+ ): Promise<any | null> {
23
25
  const npmRegistryUrl = `https://registry.npmjs.org/${packageName}`
24
26
  try {
25
27
  const response = await fetch(npmRegistryUrl)
package/src/cli/index.ts CHANGED
@@ -1,17 +1,21 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
+ import { uniq } from '@s-libs/micro-dash'
3
4
  import { Command, program } from 'commander'
5
+ import { readFileSync } from 'fs'
6
+ import updateNotifier from 'update-notifier'
4
7
  import {
5
8
  DEBUG,
6
9
  LogLevelName,
7
10
  LoggerService,
8
11
  PH_PLUGINS,
12
+ PH_PROJECT_DIR,
9
13
  PocketHostFilter,
10
14
  filter,
11
15
  loadPlugins,
12
16
  } from '../../core'
13
- import { PluginCommand } from './PluginCommand'
14
17
  import { ConfigCommand } from './commands/ConfigCommand'
18
+ import { PluginCommand } from './commands/PluginCommand'
15
19
  import { ServeCommand } from './commands/ServeCommand'
16
20
 
17
21
  export const { dbg, info, error } = LoggerService({
@@ -19,9 +23,18 @@ export const { dbg, info, error } = LoggerService({
19
23
  })
20
24
 
21
25
  export const main = async () => {
22
- await loadPlugins(PH_PLUGINS())
26
+ await loadPlugins(uniq(PH_PLUGINS()))
27
+ const pkg = await JSON.parse(
28
+ readFileSync(PH_PROJECT_DIR(`package.json`), 'utf8').toString(),
29
+ )
30
+ updateNotifier({ pkg }).notify()
23
31
 
24
- program.name('pockethost').description('Multitenant PocketBase hosting')
32
+ const { version } = pkg
33
+
34
+ program
35
+ .name('pockethost')
36
+ .description('Multitenant PocketBase hosting')
37
+ .version(version)
25
38
 
26
39
  const commands = await filter<Command[]>(PocketHostFilter.Core_CliCommands, [
27
40
  ServeCommand(),