phio 0.2.1 → 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.1",
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
- await deploy({
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
 
@@ -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
- const watchInstanceLog = (
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
- ): (() => void) => {
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
  }
@@ -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
+ }
@@ -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