Skip to content

Commit

Permalink
feat: custom ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Nauxscript committed Dec 10, 2022
1 parent 1088f91 commit e37fe46
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ dist

# TernJS port file
.tern-port

# stupid mac .DS_Store
.DS_Store
18 changes: 18 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import type { Selection } from './types'
const app = Application.currentApplication()
app.includeStandardAdditions = true

export const getenv = (name: string) => {
if (typeof $ === 'undefined')
return process.env[name]

ObjC.import('stdlib')
try {
return $.getenv(name)
}
catch (e) {
return null
}
}

const getIntranetIP = () => (app.systemInfo() as any).ipv4Address

export const parsePort = (port: string): Selection => {
Expand All @@ -23,3 +36,8 @@ export const parsePort = (port: string): Selection => {
},
}
}

export const parseEnvPort = (ports: string) => {
const portArr = ports.split(',')
return portArr.filter(item => item).map(item => parsePort(item))
}
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { parsePort } from './core'
import { getenv, parseEnvPort, parsePort } from './core'
import type { Selection } from './types'

export default function run(argv: [string, boolean]) {
const query = argv[0]
const items = []
const envPortsStr = getenv('myPort') as string
envPortsStr && items.push(...parseEnvPort(envPortsStr))
items.push(parsePort('8080'))
const currPort = parsePort(query)
query && items.push(currPort)
Expand Down

0 comments on commit e37fe46

Please sign in to comment.