phio 0.2.0 → 0.2.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phio",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A CLI tool to manage your PocketHost instances",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"types": "src/index.ts",
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@changesets/cli": "^2.27.10",
|
|
25
26
|
"@types/bun": "latest",
|
|
26
27
|
"@types/fs-extra": "^11.0.4",
|
|
27
28
|
"@types/node": "^22.5.5",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { debounce } from '@s-libs/micro-dash'
|
|
2
2
|
import { deploy, excludeDefaults } from '@samkirkland/ftp-deploy'
|
|
3
|
+
import { IFtpDeployArguments } from '@samkirkland/ftp-deploy/src/types'
|
|
3
4
|
import Bottleneck from 'bottleneck'
|
|
4
5
|
import { watch } from 'chokidar'
|
|
5
6
|
import { Command } from 'commander'
|
|
@@ -96,7 +97,7 @@ export async function deployMyCode(
|
|
|
96
97
|
ensureDirSync(cachePath)
|
|
97
98
|
|
|
98
99
|
console.log('🚚 Deploy started')
|
|
99
|
-
|
|
100
|
+
const args: IFtpDeployArguments = {
|
|
100
101
|
server: 'ftp.pockethost.io',
|
|
101
102
|
username: `__auth__`,
|
|
102
103
|
password: config(`auth`)!.token,
|
|
@@ -104,7 +105,9 @@ export async function deployMyCode(
|
|
|
104
105
|
include,
|
|
105
106
|
exclude: [...excludeDefaults, ...exclude],
|
|
106
107
|
'log-level': verbose ? 'verbose' : 'standard',
|
|
107
|
-
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await deploy(args)
|
|
108
111
|
console.log('🚀 Deploy done!')
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { select } from '@inquirer/prompts'
|
|
2
2
|
import { Command } from 'commander'
|
|
3
3
|
import { config } from '../lib/config'
|
|
4
|
+
import { saveInstanceId } from '../lib/defaultInstanceId'
|
|
4
5
|
import { InstanceFields } from '../lib/InstanceFields'
|
|
5
6
|
import { getClient, getInstanceBySubdomainCnameOrId } from './../lib/getClient'
|
|
6
7
|
|
|
7
8
|
export const isLinked = () => !!config('instanceId')
|
|
8
9
|
|
|
9
10
|
export const link = async (instanceNameOrId: string) => {
|
|
11
|
+
saveInstanceId(instanceNameOrId, 'package.json')
|
|
10
12
|
const instance = await getInstanceBySubdomainCnameOrId(instanceNameOrId)
|
|
11
13
|
if (!instance) {
|
|
12
14
|
return
|
|
@@ -2,6 +2,7 @@ import { fetchEventSource } from '@sentool/fetch-event-source'
|
|
|
2
2
|
import { Command } from 'commander'
|
|
3
3
|
import { config } from '../lib/config'
|
|
4
4
|
import { savedInstanceId } from '../lib/defaultInstanceId'
|
|
5
|
+
import { ensureLoggedIn } from './ensureLoggedIn'
|
|
5
6
|
|
|
6
7
|
export enum StreamNames {
|
|
7
8
|
StdOut = 'stdout',
|
|
@@ -13,13 +14,19 @@ export type InstanceLogFields = {
|
|
|
13
14
|
time: string
|
|
14
15
|
stream: StreamNames
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
type Unsubscribe = () => void
|
|
19
|
+
|
|
20
|
+
const watchInstanceLog = async (
|
|
17
21
|
instanceId: string,
|
|
18
22
|
update: (log: InstanceLogFields) => void,
|
|
19
23
|
nInitial = 100
|
|
20
|
-
):
|
|
24
|
+
): Promise<Unsubscribe> => {
|
|
21
25
|
const controller = new AbortController()
|
|
22
26
|
const signal = controller.signal
|
|
27
|
+
|
|
28
|
+
await ensureLoggedIn()
|
|
29
|
+
|
|
23
30
|
const continuallyFetchFromEventSource = () => {
|
|
24
31
|
const url = `https://${instanceId}.pockethost.io/logs`
|
|
25
32
|
const body = {
|
|
@@ -37,14 +44,13 @@ const watchInstanceLog = (
|
|
|
37
44
|
body: JSON.stringify(body),
|
|
38
45
|
onmessage: (event: any) => {
|
|
39
46
|
const { data } = event
|
|
40
|
-
|
|
47
|
+
if (!data) return
|
|
41
48
|
update(data)
|
|
42
49
|
},
|
|
43
50
|
onopen: async (response: Response) => {
|
|
44
51
|
// console.log(response)
|
|
45
52
|
},
|
|
46
53
|
onerror: (e: Error) => {
|
|
47
|
-
console.error(`got an error`, e)
|
|
48
54
|
setTimeout(continuallyFetchFromEventSource, 100)
|
|
49
55
|
},
|
|
50
56
|
onclose: () => {
|
|
@@ -73,6 +79,8 @@ export const LogsCommand = () => {
|
|
|
73
79
|
} else {
|
|
74
80
|
console.log(`[${time}] ${message}`)
|
|
75
81
|
}
|
|
82
|
+
}).catch((e) => {
|
|
83
|
+
console.error(`Error fetching logs`, e)
|
|
76
84
|
})
|
|
77
85
|
})
|
|
78
86
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'fs'
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|
2
2
|
|
|
3
3
|
export const savedInstanceId = () => {
|
|
4
4
|
if (existsSync('package.json')) {
|
|
@@ -15,3 +15,28 @@ export const savedInstanceId = () => {
|
|
|
15
15
|
}
|
|
16
16
|
return null
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
export const saveInstanceId = (
|
|
20
|
+
instanceId: string,
|
|
21
|
+
file: 'package.json' | 'pockethost.json'
|
|
22
|
+
) => {
|
|
23
|
+
if (!existsSync(file)) {
|
|
24
|
+
// Create new file if it doesn't exist
|
|
25
|
+
const newContent =
|
|
26
|
+
file === 'package.json' ? { pockethost: { instanceId } } : { instanceId }
|
|
27
|
+
writeFileSync(file, JSON.stringify(newContent, null, 2))
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Update existing file
|
|
32
|
+
const content = JSON.parse(readFileSync(file).toString())
|
|
33
|
+
|
|
34
|
+
if (file === 'package.json') {
|
|
35
|
+
content.pockethost = content.pockethost || {}
|
|
36
|
+
content.pockethost.instanceId = instanceId
|
|
37
|
+
} else {
|
|
38
|
+
content.instanceId = instanceId
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
writeFileSync(file, JSON.stringify(content, null, 2))
|
|
42
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { config } from '../lib/config'
|
|
2
|
+
import { getClient } from '../lib/getClient'
|
|
3
|
+
|
|
4
|
+
export const ensureLoggedIn = async () => {
|
|
5
|
+
try {
|
|
6
|
+
const token = config(`auth`)!.token
|
|
7
|
+
const client = getClient()
|
|
8
|
+
client.authStore.loadFromCookie(token)
|
|
9
|
+
await client.collection(`users`).authRefresh()
|
|
10
|
+
config(`auth`, {
|
|
11
|
+
token: client.authStore.exportToCookie(),
|
|
12
|
+
record: client.authStore.model,
|
|
13
|
+
})
|
|
14
|
+
} catch (e) {
|
|
15
|
+
console.error(`You must be logged in first. Use 'phio login'`)
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/lib/getClient.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const getClient = () => {
|
|
|
10
10
|
client.authStore.loadFromCookie(token)
|
|
11
11
|
// console.log({ valid: client.authStore.isValid })
|
|
12
12
|
client.authStore.onChange((token, record) => {
|
|
13
|
-
config('auth', { token, record })
|
|
13
|
+
config('auth', { token: client.authStore.exportToCookie(), record })
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
return client
|