pockethost 1.6.1 → 3.0.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 +123 -84
- package/README.md +96 -0
- package/dist/cli.js +21542 -0
- package/package.json +55 -53
- package/changesetx.ts +0 -110
- package/common.ts +0 -1
- package/core.ts +0 -1
- package/readme.md +0 -129
- package/src/cli/commands/ConfigCommand/index.ts +0 -28
- package/src/cli/commands/PluginCommand/index.ts +0 -81
- package/src/cli/commands/PluginCommand/util.ts +0 -140
- package/src/cli/commands/ServeCommand/index.ts +0 -36
- package/src/cli/index.ts +0 -70
- package/src/common/CleanupManager.ts +0 -65
- package/src/common/Logger.ts +0 -174
- package/src/common/ResourceAllocator.ts +0 -49
- package/src/common/TimerManager.ts +0 -64
- package/src/common/assert.ts +0 -26
- package/src/common/debug.ts +0 -8
- package/src/common/error.ts +0 -16
- package/src/common/events.ts +0 -53
- package/src/common/index.ts +0 -12
- package/src/common/mergeConfig.ts +0 -27
- package/src/common/mkSingleton.ts +0 -28
- package/src/common/plugin/action.ts +0 -164
- package/src/common/plugin/filter.ts +0 -197
- package/src/common/plugin/index.ts +0 -21
- package/src/common/promiseSerializer.ts +0 -22
- package/src/common/schema/BaseFields.ts +0 -10
- package/src/common/schema/Instance.ts +0 -46
- package/src/common/schema/InstanceLog.ts +0 -12
- package/src/common/schema/index.ts +0 -3
- package/src/common/schema/util.ts +0 -7
- package/src/constants.ts +0 -70
- package/src/core/Settings.ts +0 -119
- package/src/core/asyncExecutionGuard.ts +0 -49
- package/src/core/config.ts +0 -108
- package/src/core/exit.ts +0 -11
- package/src/core/index.ts +0 -8
- package/src/core/internal.ts +0 -3
- package/src/core/smartFetch.ts +0 -32
- package/src/core/tryFetch.ts +0 -69
- package/src/plugin.ts +0 -54
- package/src/server.ts +0 -129
package/package.json
CHANGED
|
@@ -1,67 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pockethost",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "The PocketHost CLI: deploy, sync, and tail logs for your PocketHost instances",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/pockethost/pockethost.git",
|
|
8
|
+
"directory": "packages/cli"
|
|
7
9
|
},
|
|
10
|
+
"homepage": "https://pockethost.io",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"cli",
|
|
13
|
+
"pocketbase",
|
|
14
|
+
"pockethost"
|
|
15
|
+
],
|
|
16
|
+
"author": "Ben Allfree",
|
|
8
17
|
"license": "MIT",
|
|
9
|
-
"
|
|
10
|
-
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/pockethost/pockethost/issues"
|
|
20
|
+
},
|
|
11
21
|
"type": "module",
|
|
12
22
|
"bin": {
|
|
13
|
-
"pockethost": "
|
|
23
|
+
"pockethost": "dist/cli.js"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20"
|
|
14
27
|
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"CHANGELOG.md",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
15
33
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"ajv": "^8.12.0",
|
|
18
|
-
"boolean": "^3.2.0",
|
|
19
|
-
"bottleneck": "^2.19.5",
|
|
20
|
-
"chalk": "^5.3.0",
|
|
21
|
-
"commander": "^11.1.0",
|
|
22
|
-
"dotenv": "^16.3.1",
|
|
23
|
-
"env-paths": "^3.0.0",
|
|
24
|
-
"exit-hook": "^4.0.0",
|
|
25
|
-
"express": "^4.18.2",
|
|
26
|
-
"express-async-errors": "^3.1.1",
|
|
27
|
-
"get-port": "^6.1.2",
|
|
28
|
-
"http-proxy": "^1.18.1",
|
|
29
|
-
"immer": "^10.1.1",
|
|
30
|
-
"json-stringify-safe": "^5.0.1",
|
|
31
|
-
"listr2": "^8.2.3",
|
|
32
|
-
"minimist": "^1.2.8",
|
|
33
|
-
"nanoid": "^5.0.2",
|
|
34
|
-
"node-fetch": "^3.3.2",
|
|
35
|
-
"pocketbase": "^0.21.3",
|
|
36
|
-
"rimraf": "^5.0.5",
|
|
37
|
-
"semver": "^7.6.2",
|
|
38
|
-
"tmp": "^0.2.1",
|
|
39
|
-
"tsx": "^4.15.7",
|
|
40
|
-
"type-fest": "^4.6.0",
|
|
41
|
-
"typescript": "^5.4.5",
|
|
42
|
-
"update-notifier": "^7.0.0",
|
|
43
|
-
"url-pattern": "^1.0.3",
|
|
44
|
-
"@pockethost/plugin-auto-admin": "^0.2.0",
|
|
45
|
-
"@pockethost/plugin-console-logger": "^0.3.0",
|
|
46
|
-
"@pockethost/plugin-launcher-spawn": "^0.4.0"
|
|
34
|
+
"ssh2-sftp-client": "^12.1.1"
|
|
47
35
|
},
|
|
48
36
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@types/
|
|
52
|
-
"@types/
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
37
|
+
"@inquirer/prompts": "^8.5.2",
|
|
38
|
+
"@microsoft/fetch-event-source": "github:pockethost/fetch-event-source#ebe3b7122647b48b93fd11effbbfb915d98956b0",
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"@types/ssh2-sftp-client": "^9.0.6",
|
|
41
|
+
"bottleneck": "^2.19.5",
|
|
42
|
+
"chokidar": "^5.0.0",
|
|
43
|
+
"commander": "^15.0.0",
|
|
44
|
+
"env-paths": "^4.0.0",
|
|
45
|
+
"env-var": "^7.5.0",
|
|
46
|
+
"esbuild": "^0.28.1",
|
|
47
|
+
"glob": "^13.0.6",
|
|
48
|
+
"multimatch": "^8.0.0",
|
|
49
|
+
"ora": "^9.4.0",
|
|
50
|
+
"pocketbase": "^0.27.0",
|
|
51
|
+
"pretty-bytes": "^7.1.0",
|
|
52
|
+
"pretty-ms": "^9.3.0",
|
|
53
|
+
"tsx": "^4.22.4",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"vitest": "^4.1.8"
|
|
56
|
+
},
|
|
57
|
+
"prettier": {
|
|
58
|
+
"semi": false,
|
|
59
|
+
"singleQuote": true,
|
|
60
|
+
"trailingComma": "es5"
|
|
60
61
|
},
|
|
61
62
|
"scripts": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"dev": "
|
|
65
|
-
"start": "tsx ./src/cli
|
|
63
|
+
"build": "node scripts/build.mjs",
|
|
64
|
+
"check:types": "tsc --noEmit",
|
|
65
|
+
"dev": "node --import tsx ./src/cli.ts",
|
|
66
|
+
"start": "node --import tsx ./src/cli.ts",
|
|
67
|
+
"test": "vitest run"
|
|
66
68
|
}
|
|
67
69
|
}
|
package/changesetx.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env tsx
|
|
2
|
-
import { execSync } from 'child_process'
|
|
3
|
-
import { sync } from 'conventional-commits-parser'
|
|
4
|
-
import fs, { readFileSync } from 'fs'
|
|
5
|
-
import minimist from 'minimist'
|
|
6
|
-
import { dirname, join } from 'path'
|
|
7
|
-
import { fileURLToPath } from 'url'
|
|
8
|
-
|
|
9
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
10
|
-
const repoRootDir = join(__dirname, `../..`)
|
|
11
|
-
|
|
12
|
-
const argv = minimist(process.argv.slice(2))
|
|
13
|
-
const commitMessage = argv._[0]!
|
|
14
|
-
const { type, subject } = sync(commitMessage)
|
|
15
|
-
if (!type) {
|
|
16
|
-
console.log('Invalid commit message type')
|
|
17
|
-
process.exit(1)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getStagedPackageNames(filePaths: string[]): string[] {
|
|
21
|
-
const packageNames = new Set<string>()
|
|
22
|
-
|
|
23
|
-
filePaths.forEach((filePath) => {
|
|
24
|
-
const packageName = getPackageName(filePath)
|
|
25
|
-
if (packageName) {
|
|
26
|
-
packageNames.add(packageName)
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return Array.from(packageNames)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function getPackageName(filePath: string): string | null {
|
|
34
|
-
const packagePath = filePath.split('/').slice(0, 2).join('/')
|
|
35
|
-
const packageJsonPath = join(repoRootDir, `${packagePath}/package.json`)
|
|
36
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
|
37
|
-
try {
|
|
38
|
-
return packageJson.name
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return null
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getStagedFileNames(): string[] {
|
|
45
|
-
const output = execSync('git diff --name-only --cached').toString()
|
|
46
|
-
const fileNames = output
|
|
47
|
-
.trim()
|
|
48
|
-
.split('\n')
|
|
49
|
-
.filter((fileName) => fileName.startsWith(`packages/`))
|
|
50
|
-
return fileNames
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function createChangesetFile() {
|
|
54
|
-
const fileNames = getStagedFileNames()
|
|
55
|
-
const packageNames = getStagedPackageNames(fileNames)
|
|
56
|
-
|
|
57
|
-
if (packageNames.length === 0) {
|
|
58
|
-
console.log('No packages staged for commit')
|
|
59
|
-
process.exit(0)
|
|
60
|
-
}
|
|
61
|
-
console.log('Staged packages:', packageNames)
|
|
62
|
-
|
|
63
|
-
const prefixMap = {
|
|
64
|
-
feat: 'minor',
|
|
65
|
-
enh: 'minor',
|
|
66
|
-
fix: 'patch',
|
|
67
|
-
docs: 'patch',
|
|
68
|
-
chore: 'patch',
|
|
69
|
-
} as const
|
|
70
|
-
|
|
71
|
-
if (!(type! in prefixMap)) {
|
|
72
|
-
console.log('Invalid prefix found in commit message')
|
|
73
|
-
process.exit(1)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const versionType = prefixMap[type as keyof typeof prefixMap]
|
|
77
|
-
|
|
78
|
-
const changesetFile = [
|
|
79
|
-
`---`,
|
|
80
|
-
...packageNames.map((packageName) => `'${packageName}': ${versionType}`),
|
|
81
|
-
`---`,
|
|
82
|
-
``,
|
|
83
|
-
subject,
|
|
84
|
-
].join('\n')
|
|
85
|
-
return changesetFile
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function writeChangesetFile(changesetFile: string) {
|
|
89
|
-
const filePath = join(repoRootDir, `.changeset`, `${+new Date()}.md`)
|
|
90
|
-
try {
|
|
91
|
-
fs.writeFileSync(filePath, changesetFile)
|
|
92
|
-
console.log(`Changeset file written successfully at ${filePath}`)
|
|
93
|
-
execSync(`git add ${filePath}`)
|
|
94
|
-
console.log(`Changeset file added to git`)
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error(`Error writing changeset file: ${error}`)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function commit() {
|
|
101
|
-
execSync(`git commit -m "${commitMessage}"`)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function main() {
|
|
105
|
-
const changesetFile = await createChangesetFile()
|
|
106
|
-
await writeChangesetFile(changesetFile)
|
|
107
|
-
commit()
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
main()
|
package/common.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src/common'
|
package/core.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src/core'
|
package/readme.md
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# PocketHost
|
|
2
|
-
|
|
3
|
-
PocketHost is the open source multi-tenant PocketBase server. PocketHost can run dozens, hundreds, even thousands of PocketBase instances on a single server or across a global cloud.
|
|
4
|
-
|
|
5
|
-
Extend PocketHost with its Plugin ecosystem. Start with the bare-bones dev server and add plugins to grow your enterprise into a global cloud.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
### Sponsored by https://pockethost.io. Instantly host your PocketBase projects.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
<!-- @import "[TOC]" {cmd="toc" depthFrom=2 depthTo=2 orderedList=false} -->
|
|
14
|
-
|
|
15
|
-
<!-- code_chunk_output -->
|
|
16
|
-
|
|
17
|
-
- [Quickstart](#quickstart)
|
|
18
|
-
- [Introduction](#introduction)
|
|
19
|
-
- [The magic `serve` command](#the-magic-serve-command)
|
|
20
|
-
- [Configuration](#configuration)
|
|
21
|
-
- [Plugins Directory](#plugins-directory)
|
|
22
|
-
- [Writing Plugins](#writing-plugins)
|
|
23
|
-
- [Support](#support)
|
|
24
|
-
|
|
25
|
-
<!-- /code_chunk_output -->
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## Quickstart
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
npx pockethost serve
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Introduction
|
|
36
|
-
|
|
37
|
-
PocketHost is a multitenant PocketBase hosting system. With it, you can run multiple instances of PocketBase on different subdomains, all on the same server.
|
|
38
|
-
|
|
39
|
-
Use PocketHost for development or production purposes.
|
|
40
|
-
|
|
41
|
-
PocketHost can be easily extended using its thoughtful plugin architecture. By choosing additional plugins, PocketHost's features can be extended according to your exact needs. You can even write your own plugins.
|
|
42
|
-
|
|
43
|
-
## The magic `serve` command
|
|
44
|
-
|
|
45
|
-
`pockethost serve` is a special command that can be decorated with plugins. Plugins can respond to the `serve` command by running their own services.
|
|
46
|
-
|
|
47
|
-
By convention, plugins that have some kind of `serve` functionality such as running a server, will make it available in two ways.
|
|
48
|
-
|
|
49
|
-
The first way runs ONLY the plugin's `serve` functionality:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
pockethost <plugin-name> serve
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The second way runs ALL `serve` functionality from ALL plugins:
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
pockethost serve
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
The exact plugins can also be narrowed:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
pockethost serve --only=plugin1,plugin2,plugin3
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
See the plugin authoring guide for more information on how to make a plugin that responds to both methods.
|
|
68
|
-
|
|
69
|
-
## Configuration
|
|
70
|
-
|
|
71
|
-
PocketHost supports configuration by environment variable, `.env` file, and also built-in settings via `pockethost config`.
|
|
72
|
-
|
|
73
|
-
All PocketHost variables begin with `PH_`.
|
|
74
|
-
|
|
75
|
-
PocketHost will search the current directory for an `.env` when it loads. Anything in `.env` will be merged with and override any `<PH_HOME>/.env` that may exist.
|
|
76
|
-
|
|
77
|
-
Use `pockethost config` to list and set global defaults.
|
|
78
|
-
|
|
79
|
-
### Core Variables
|
|
80
|
-
|
|
81
|
-
See `pockethost config ls` for a full list of variables. Plugin variables will also be listed for loaded plugins.
|
|
82
|
-
|
|
83
|
-
| Name | Default | Discussion |
|
|
84
|
-
| -------------- | -------------------------- | ----------------------------------------------------------------------------- |
|
|
85
|
-
| PH_HOME | `~/.pockethost` | PocketHost's home directory where it holds all data. |
|
|
86
|
-
| PH_APEX_DOMAIN | `pockethost.lvh.me` | The apex domain used for routing and determining instance names. |
|
|
87
|
-
| PH_PORT | `3000` | The port PocketHost listens on |
|
|
88
|
-
| PH_DEBUG | `NODE_ENV==='development'` | Debug mode |
|
|
89
|
-
| PH_PLUGINS | (see below) | A comma-separated list of Plugins to load |
|
|
90
|
-
| PH_DATA_DIR | `~/.pockethost/data` | The root directory for storing PocketHost data, including instance databases. |
|
|
91
|
-
| PH_DEV | `NODE_ENV==='development'` | Whether PocketHost is running in development mode. |
|
|
92
|
-
|
|
93
|
-
### Default Plugins
|
|
94
|
-
|
|
95
|
-
- `@pockethost/plugin-console-logger`
|
|
96
|
-
- `@pockethost/plugin-launcher-spawn`
|
|
97
|
-
- `@pockethost/plugin-auto-admin`
|
|
98
|
-
|
|
99
|
-
## Plugins Directory
|
|
100
|
-
|
|
101
|
-
PocketHost uses an action/filter architecture to support a growing list plugins. Some plugins have a CLI component, whereas others add purely programmatic support to alter how PocketHost works.
|
|
102
|
-
|
|
103
|
-
### Core plugins
|
|
104
|
-
|
|
105
|
-
These plugins are maintained by the PocketHost project.
|
|
106
|
-
|
|
107
|
-
| Name | Description |
|
|
108
|
-
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
109
|
-
| `@pockethost/plugin-console-logger` | Routes log messages to the console |
|
|
110
|
-
| `@pockethost/plugin-auto-admin` | Auto-creates a default admin account on instance launch |
|
|
111
|
-
| `@pockethost/plugin-launcher-spawn` | Launches PocketBase instances via `spawn()` on the local machine. PocketHost uses this by default |
|
|
112
|
-
| `@pockethost/plugin-cloudflare-request-logger` | Log additional data when running behind Cloudflare |
|
|
113
|
-
| `@pockethost/plugin-ftp-server` | Used to provide secure FTPS access to PocketBase instance data. This FTP server can run along-side a PocketHost server. |
|
|
114
|
-
| `@pockethost/plugin-local-auth` | A light-weight username/password auth provider for associating instances with users. |
|
|
115
|
-
|
|
116
|
-
Coming soon:
|
|
117
|
-
| name | description |
|
|
118
|
-
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
119
|
-
| plugin-launcher-docker | Launches PocketBase instances via Docker. This is useful for running untrusted PocketBase code and instances. pockethost.io uses this. |
|
|
120
|
-
| plugin-waf | A Web Application Firewall |
|
|
121
|
-
| plugin-waf-enforce-ssl | Enforce SSL at the WAF
|
|
122
|
-
|
|
123
|
-
## Writing Plugins
|
|
124
|
-
|
|
125
|
-
See the [Plugin Authoring Guide](https://github.com/pockethost/pockethost/blob/master/packages/pockethost/plugin-guide.md) for details about how to write your own plugins.
|
|
126
|
-
|
|
127
|
-
## Support
|
|
128
|
-
|
|
129
|
-
PocketHost has a thriving [Discord community](https://discord.gg/nVTxCMEcGT).
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander'
|
|
2
|
-
import { listConfig, setConfig, unsetConfig } from '../../../core'
|
|
3
|
-
|
|
4
|
-
export const ConfigCommand = () => {
|
|
5
|
-
const cmd = new Command(`config`)
|
|
6
|
-
.description(`Set global config defaults`)
|
|
7
|
-
.addCommand(
|
|
8
|
-
new Command(`set`)
|
|
9
|
-
.argument(`<name>`, `Config name`)
|
|
10
|
-
.argument(`<value>`, `Config value`)
|
|
11
|
-
.description(`Set a config value`)
|
|
12
|
-
.action(setConfig),
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
.addCommand(
|
|
16
|
-
new Command(`unset`)
|
|
17
|
-
.argument(`<name>`, `Config name`)
|
|
18
|
-
.description(`Unset a config value`)
|
|
19
|
-
.action(unsetConfig),
|
|
20
|
-
)
|
|
21
|
-
.addCommand(
|
|
22
|
-
new Command(`list`)
|
|
23
|
-
.description(`List all config values`)
|
|
24
|
-
.alias(`ls`)
|
|
25
|
-
.action(listConfig),
|
|
26
|
-
)
|
|
27
|
-
return cmd
|
|
28
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander'
|
|
2
|
-
import { readFileSync } from 'fs'
|
|
3
|
-
import { error, info } from '../..'
|
|
4
|
-
import { PH_PLUGINS, PH_PROJECT_DIR } from '../../../constants'
|
|
5
|
-
import { appendConfig, filterConfig } from '../../../core'
|
|
6
|
-
import { getCompatibleVersions, getPackageJson, removePackage } from './util'
|
|
7
|
-
|
|
8
|
-
export const PluginCommand = () => {
|
|
9
|
-
const cmd = new Command(`plugin`)
|
|
10
|
-
.description(`Manage PocketHost plugins`)
|
|
11
|
-
.addCommand(
|
|
12
|
-
new Command(`install`)
|
|
13
|
-
.alias(`i`)
|
|
14
|
-
.argument(`<name>`, `NPM registry plugin name`)
|
|
15
|
-
.description(`Install a plugin`)
|
|
16
|
-
.action(async (name: string) => {
|
|
17
|
-
try {
|
|
18
|
-
const pkg = JSON.parse(
|
|
19
|
-
readFileSync(PH_PROJECT_DIR(`package.json`), 'utf8').toString(),
|
|
20
|
-
)
|
|
21
|
-
const { version } = pkg
|
|
22
|
-
await getCompatibleVersions(`pockethost`, version, [name])
|
|
23
|
-
|
|
24
|
-
appendConfig(`PH_PLUGINS`, name)
|
|
25
|
-
} catch (e) {
|
|
26
|
-
error(`${e}`)
|
|
27
|
-
}
|
|
28
|
-
}),
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
.addCommand(
|
|
32
|
-
new Command(`list`)
|
|
33
|
-
.alias(`ls`)
|
|
34
|
-
.description(`List plugins`)
|
|
35
|
-
.action(async (name: string) => {
|
|
36
|
-
try {
|
|
37
|
-
for (const plugin of PH_PLUGINS()) {
|
|
38
|
-
const pkg = await getPackageJson(plugin)
|
|
39
|
-
info(`${plugin}@${pkg.version} - ${pkg?.description}`)
|
|
40
|
-
}
|
|
41
|
-
} catch (e) {
|
|
42
|
-
error(`${e}`)
|
|
43
|
-
}
|
|
44
|
-
}),
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
.addCommand(
|
|
48
|
-
new Command(`remove`)
|
|
49
|
-
.alias(`rm`)
|
|
50
|
-
.alias(`uninstall`)
|
|
51
|
-
.alias(`delete`)
|
|
52
|
-
.argument(`<name>`, `Plugin name`)
|
|
53
|
-
.description(`Remove a plugin`)
|
|
54
|
-
.action(async (name) => {
|
|
55
|
-
try {
|
|
56
|
-
await removePackage(name)
|
|
57
|
-
filterConfig(`PH_PLUGINS`, name)
|
|
58
|
-
} catch (e) {
|
|
59
|
-
error(`${e}`)
|
|
60
|
-
}
|
|
61
|
-
}),
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
.addCommand(
|
|
65
|
-
new Command(`update`)
|
|
66
|
-
.alias(`up`)
|
|
67
|
-
.description(`Update all plugins`)
|
|
68
|
-
.action(async () => {
|
|
69
|
-
try {
|
|
70
|
-
const pkg = JSON.parse(
|
|
71
|
-
readFileSync(PH_PROJECT_DIR(`package.json`), 'utf8').toString(),
|
|
72
|
-
)
|
|
73
|
-
const { version } = pkg
|
|
74
|
-
await getCompatibleVersions(`pockethost`, version, PH_PLUGINS())
|
|
75
|
-
} catch (e) {
|
|
76
|
-
error(`${e}`)
|
|
77
|
-
}
|
|
78
|
-
}),
|
|
79
|
-
)
|
|
80
|
-
return cmd
|
|
81
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { exec } from 'child_process'
|
|
2
|
-
import fs from 'fs/promises'
|
|
3
|
-
import { Listr, ListrTask } from 'listr2'
|
|
4
|
-
import { createRequire } from 'module'
|
|
5
|
-
import fetch from 'node-fetch'
|
|
6
|
-
import semver from 'semver'
|
|
7
|
-
import util from 'util'
|
|
8
|
-
|
|
9
|
-
const execPromise = util.promisify(exec)
|
|
10
|
-
const require = createRequire(import.meta.url)
|
|
11
|
-
|
|
12
|
-
export async function getPackageJson(packageName: string): Promise<any | null> {
|
|
13
|
-
try {
|
|
14
|
-
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
15
|
-
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'))
|
|
16
|
-
return packageJson
|
|
17
|
-
} catch (error) {
|
|
18
|
-
return null
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function fetchPackageData(
|
|
23
|
-
packageName: string,
|
|
24
|
-
): Promise<any | null> {
|
|
25
|
-
const npmRegistryUrl = `https://registry.npmjs.org/${packageName}`
|
|
26
|
-
try {
|
|
27
|
-
const response = await fetch(npmRegistryUrl)
|
|
28
|
-
return await response.json()
|
|
29
|
-
} catch (error) {
|
|
30
|
-
return null
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function installPackage(
|
|
35
|
-
packageName: string,
|
|
36
|
-
version: string,
|
|
37
|
-
): Promise<void> {
|
|
38
|
-
try {
|
|
39
|
-
await execPromise(`npm install -g ${packageName}@${version}`)
|
|
40
|
-
} catch (e) {
|
|
41
|
-
throw new Error(`Error installing ${packageName}@${version}: ${e}`)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function removePackage(packageName: string): Promise<void> {
|
|
46
|
-
try {
|
|
47
|
-
await execPromise(`npm remove -g ${packageName}`)
|
|
48
|
-
} catch (e) {
|
|
49
|
-
throw new Error(`Error removing ${packageName}: ${e}`)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function checkPackageCompatibility(
|
|
54
|
-
packageA: string,
|
|
55
|
-
versionA: string,
|
|
56
|
-
packageB: string,
|
|
57
|
-
): Promise<string> {
|
|
58
|
-
const localPackageJson = await getPackageJson(packageB)
|
|
59
|
-
|
|
60
|
-
if (localPackageJson) {
|
|
61
|
-
const { version: localPackageBVersion, dependencies } = localPackageJson
|
|
62
|
-
|
|
63
|
-
if (dependencies && semver.satisfies(versionA, dependencies[packageA])) {
|
|
64
|
-
return `Local ${packageB}@${localPackageBVersion} is already compatible with ${packageA}@${versionA}`
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const packageBData = await fetchPackageData(packageB)
|
|
69
|
-
if (!packageBData) {
|
|
70
|
-
throw new Error(`Error fetching data for ${packageB}`)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const versions = packageBData.versions
|
|
74
|
-
let latestCompatibleVersion: string | null = null
|
|
75
|
-
|
|
76
|
-
for (const version in versions) {
|
|
77
|
-
const dependencies = versions[version].dependencies
|
|
78
|
-
if (
|
|
79
|
-
dependencies &&
|
|
80
|
-
packageA in dependencies &&
|
|
81
|
-
semver.satisfies(versionA, dependencies[packageA])
|
|
82
|
-
) {
|
|
83
|
-
if (
|
|
84
|
-
!latestCompatibleVersion ||
|
|
85
|
-
semver.gt(version, latestCompatibleVersion)
|
|
86
|
-
) {
|
|
87
|
-
latestCompatibleVersion = version
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (latestCompatibleVersion) {
|
|
93
|
-
await installPackage(packageB, latestCompatibleVersion)
|
|
94
|
-
return `${packageB}@${latestCompatibleVersion} installed successfully`
|
|
95
|
-
} else {
|
|
96
|
-
throw new Error(
|
|
97
|
-
`No compatible version of ${packageB} found for ${packageA}@${versionA}`,
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export async function getCompatibleVersions(
|
|
103
|
-
packageA: string,
|
|
104
|
-
versionA: string,
|
|
105
|
-
packagesB: string[],
|
|
106
|
-
): Promise<void> {
|
|
107
|
-
const tasks = packagesB.map(
|
|
108
|
-
(packageB) =>
|
|
109
|
-
({
|
|
110
|
-
title: `Checking ${packageB}...`,
|
|
111
|
-
task: async (_, task) => {
|
|
112
|
-
try {
|
|
113
|
-
const result = await checkPackageCompatibility(
|
|
114
|
-
packageA,
|
|
115
|
-
versionA,
|
|
116
|
-
packageB,
|
|
117
|
-
)
|
|
118
|
-
task.output = result
|
|
119
|
-
} catch (error) {
|
|
120
|
-
task.output = `${error}`
|
|
121
|
-
throw error
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
}) as ListrTask,
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
const listr = new Listr(tasks, {
|
|
128
|
-
concurrent: true,
|
|
129
|
-
rendererOptions: { collapseSubtasks: false },
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
await listr.run()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Example usage
|
|
136
|
-
// const packageA = 'express'
|
|
137
|
-
// const versionA = '4.17.1'
|
|
138
|
-
// const packagesB = ['some-package', 'another-package', 'yet-another-package']
|
|
139
|
-
|
|
140
|
-
// getCompatibleVersions(packageA, versionA, packagesB)
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander'
|
|
2
|
-
import {
|
|
3
|
-
LoggerService,
|
|
4
|
-
doServeAction,
|
|
5
|
-
doServeSlugsFilter,
|
|
6
|
-
} from '../../../common'
|
|
7
|
-
|
|
8
|
-
type Options = {
|
|
9
|
-
only: string[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const ServeCommand = async () => {
|
|
13
|
-
const serveSlugs = await doServeSlugsFilter([])
|
|
14
|
-
|
|
15
|
-
const cmd = new Command(`serve`)
|
|
16
|
-
.description(`Run PocketHost`)
|
|
17
|
-
.option(
|
|
18
|
-
`-o, --only <only>`,
|
|
19
|
-
`Only run the specified services`,
|
|
20
|
-
(s) =>
|
|
21
|
-
s
|
|
22
|
-
.split(/,/)
|
|
23
|
-
.map((s) => s.trim())
|
|
24
|
-
.filter((s) => serveSlugs.includes(s)),
|
|
25
|
-
serveSlugs,
|
|
26
|
-
)
|
|
27
|
-
.action(async (options: Options, cmd: Command) => {
|
|
28
|
-
const logger = LoggerService().create(`ServeCommand`)
|
|
29
|
-
const { dbg, error, info, warn } = logger
|
|
30
|
-
info(`Starting`)
|
|
31
|
-
|
|
32
|
-
const { only } = options
|
|
33
|
-
await doServeAction({ only })
|
|
34
|
-
})
|
|
35
|
-
return cmd
|
|
36
|
-
}
|