phio 0.2.0 → 0.2.1

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.0",
3
+ "version": "0.2.1",
4
4
  "description": "A CLI tool to manage your PocketHost instances",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
@@ -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
+ }