This commit is contained in:
Shotaro Nakamura
2026-06-24 21:29:37 +09:00
parent fed3ac1b61
commit e08920bc47
12 changed files with 109 additions and 30 deletions
+1
View File
@@ -15,6 +15,7 @@
"db:push": "vp run server:db:push", "db:push": "vp run server:db:push",
"env:check": "vp run env:doctor", "env:check": "vp run env:doctor",
"fmt": "vp check --fix", "fmt": "vp check --fix",
"sdk:build": "vp run sdk-build",
"typecheck": "vp run typecheck:all" "typecheck": "vp run typecheck:all"
}, },
"devDependencies": { "devDependencies": {
+3 -2
View File
@@ -2,15 +2,16 @@
"name": "@repo/client-sbi", "name": "@repo/client-sbi",
"private": true, "private": true,
"type": "module", "type": "module",
"module": "index.ts", "module": "./dist/index.mjs",
"types": "./src/index.ts", "types": "./src/index.ts",
"exports": { "exports": {
".": { ".": {
"types": "./src/index.ts", "types": "./src/index.ts",
"import": "./src/index.ts" "import": "./dist/index.mjs"
} }
}, },
"scripts": { "scripts": {
"build": "cd ../.. && vp run @repo/mnie-types#build && cd packages/client-sbi && vp pack",
"clean": "rm -rf dist", "clean": "rm -rf dist",
"typecheck": "tsc" "typecheck": "tsc"
}, },
+1
View File
@@ -1 +1,2 @@
export type * from '@repo/mnie-types' export type * from '@repo/mnie-types'
export type { SbiClientMethods } from '@repo/mnie-types'
+14
View File
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite-plus'
export default defineConfig({
pack: {
entry: ['src/index.ts'],
deps: {
alwaysBundle: [/^@repo\//, 'iconv-lite', 'safer-buffer'],
onlyBundle: false,
},
dts: { eager: true },
format: ['esm'],
platform: 'node',
},
})
+4 -1
View File
@@ -2,10 +2,13 @@
"name": "@repo/mnie-cli", "name": "@repo/mnie-cli",
"private": true, "private": true,
"bin": { "bin": {
"mnie": "./src/index.ts" "mnie": "./dist/index.mjs"
}, },
"type": "module", "type": "module",
"module": "./dist/index.mjs",
"types": "./dist/index.d.mts",
"scripts": { "scripts": {
"build": "cd ../.. && vp run @repo/mnie-sdk#build && cd packages/mnie-cli && vp pack",
"clean": "rm -rf dist", "clean": "rm -rf dist",
"typecheck": "tsc" "typecheck": "tsc"
}, },
+32 -23
View File
@@ -1,6 +1,8 @@
#!/usr/bin/env bun #!/usr/bin/env node
import { spawn } from 'node:child_process'
import { createHash, randomBytes } from 'node:crypto' import { createHash, randomBytes } from 'node:crypto'
import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises' import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises'
import { createServer } from 'node:http'
import { homedir } from 'node:os' import { homedir } from 'node:os'
import { dirname, join } from 'node:path' import { dirname, join } from 'node:path'
import { createMnieClient } from '@repo/mnie-sdk' import { createMnieClient } from '@repo/mnie-sdk'
@@ -191,27 +193,34 @@ const listenForOAuthCallback = async () => {
resolveCode = resolve resolveCode = resolve
rejectCode = reject rejectCode = reject
}) })
const server = Bun.serve({ const server = createServer((request, response) => {
hostname: '127.0.0.1', const url = new URL(request.url ?? '/', 'http://127.0.0.1')
port: 0, const error = url.searchParams.get('error')
fetch(request) { const value = url.searchParams.get('code')
const url = new URL(request.url) queueMicrotask(() => server.close())
const error = url.searchParams.get('error') if (error) {
const value = url.searchParams.get('code') rejectCode(new Error(error))
queueMicrotask(() => server.stop(true)) response.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' })
if (error) { response.end('Mnie login failed. You can close this tab.')
rejectCode(new Error(error)) return
return new Response('Mnie login failed. You can close this tab.', { status: 400 }) }
} if (!value) {
if (!value) { rejectCode(new Error('oauth callback did not include a code'))
rejectCode(new Error('oauth callback did not include a code')) response.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' })
return new Response('Mnie login failed. You can close this tab.', { status: 400 }) response.end('Mnie login failed. You can close this tab.')
} return
resolveCode(value) }
return new Response('Mnie login complete. You can close this tab.') resolveCode(value)
}, response.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' })
response.end('Mnie login complete. You can close this tab.')
}) })
return { port: server.port, code } await new Promise<void>((resolve, reject) => {
server.once('error', reject)
server.listen(0, '127.0.0.1', () => resolve())
})
const address = server.address()
if (!address || typeof address === 'string') throw new Error('failed to bind oauth callback')
return { port: address.port, code }
} }
const registerOAuthClient = async (origin: string, redirectUri: string) => { const registerOAuthClient = async (origin: string, redirectUri: string) => {
@@ -254,7 +263,7 @@ const openBrowser = (url: string) => {
const command = const command =
process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open' process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open'
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url] const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]
Bun.spawn({ cmd: [command, ...args], stdout: 'ignore', stderr: 'ignore' }) spawn(command, args, { detached: true, stdio: 'ignore' }).unref()
} }
const rpc = async (args: string[]) => { const rpc = async (args: string[]) => {
@@ -285,7 +294,7 @@ const rpc = async (args: string[]) => {
} }
const main = async () => { const main = async () => {
const [command, subcommand, ...rest] = Bun.argv.slice(2) const [command, subcommand, ...rest] = process.argv.slice(2)
if (!command || command === '--help' || command === '-h') { if (!command || command === '--help' || command === '-h') {
console.log(help) console.log(help)
return return
+14
View File
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite-plus'
export default defineConfig({
pack: {
entry: ['src/index.ts'],
deps: {
alwaysBundle: [/^@repo\//, /^@napi-rs\/keyring/],
onlyBundle: false,
},
dts: true,
format: ['esm'],
platform: 'node',
},
})
+3 -2
View File
@@ -2,15 +2,16 @@
"name": "@repo/mnie-sdk", "name": "@repo/mnie-sdk",
"private": true, "private": true,
"type": "module", "type": "module",
"module": "./src/index.ts", "module": "./dist/index.mjs",
"types": "./src/index.ts", "types": "./src/index.ts",
"exports": { "exports": {
".": { ".": {
"types": "./src/index.ts", "types": "./src/index.ts",
"import": "./src/index.ts" "import": "./dist/index.mjs"
} }
}, },
"scripts": { "scripts": {
"build": "cd ../.. && vp run @repo/mnie-types#build && cd packages/mnie-sdk && vp pack",
"clean": "rm -rf dist", "clean": "rm -rf dist",
"typecheck": "tsc" "typecheck": "tsc"
}, },
+14
View File
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite-plus'
export default defineConfig({
pack: {
entry: ['src/index.ts'],
deps: {
alwaysBundle: [/^@repo\//],
onlyBundle: false,
},
dts: { eager: true },
format: ['esm'],
platform: 'node',
},
})
+3 -1
View File
@@ -2,14 +2,16 @@
"name": "@repo/mnie-types", "name": "@repo/mnie-types",
"private": true, "private": true,
"type": "module", "type": "module",
"module": "./dist/index.mjs",
"types": "./src/index.ts", "types": "./src/index.ts",
"exports": { "exports": {
".": { ".": {
"types": "./src/index.ts", "types": "./src/index.ts",
"import": "./src/index.ts" "import": "./dist/index.mjs"
} }
}, },
"scripts": { "scripts": {
"build": "vp pack",
"clean": "rm -rf dist", "clean": "rm -rf dist",
"typecheck": "tsc" "typecheck": "tsc"
}, },
+11
View File
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite-plus'
export default defineConfig({
pack: {
entry: ['src/index.ts'],
dts: { eager: true },
format: ['esm'],
platform: 'neutral',
fixedExtension: true,
},
})
+9 -1
View File
@@ -15,7 +15,15 @@ export default defineConfig({
}, },
'app:build': { 'app:build': {
command: 'vp run @repo/mnie-app#build', command: 'vp run @repo/mnie-app#build',
dependsOn: ['typecheck:all'], dependsOn: ['typecheck:all', 'sdk-build'],
},
'sdk-build': {
command: [
'vp run @repo/mnie-types#build',
'vp run @repo/client-sbi#build',
'vp run @repo/mnie-sdk#build',
'vp run @repo/mnie-cli#build',
],
}, },
'app:start': { 'app:start': {
command: 'vp run @repo/mnie-app#start', command: 'vp run @repo/mnie-app#start',