Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
simplify admin command
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Mar 13, 2019
1 parent 60edaaf commit c71159a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 52 deletions.
1 change: 0 additions & 1 deletion cli/packages/prisma-cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
"node-forge": "^0.7.1",
"npm-run": "4.1.2",
"opn": "^5.1.0",
"prisma-admin-html": "^0.0.6",
"prisma-client-lib": "1.23.0-test.3",
"prisma-datamodel": "1.23.0-alpha.1",
"prisma-db-introspection": "0.0.7",
Expand Down
51 changes: 9 additions & 42 deletions cli/packages/prisma-cli-core/src/commands/admin/admin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Command, flags, Flags } from 'prisma-cli-engine'
import * as express from 'express'
import chalk from 'chalk'
import * as opn from 'opn'
import { renderAdminPage } from 'prisma-admin-html'
import { satisfiesVersion } from '../../utils/satisfiesVersion'

export default class Admin extends Command {
Expand All @@ -14,19 +12,9 @@ export default class Admin extends Command {
description: 'Path to .env file to inject env vars',
char: 'e',
}),
port: flags.number({
char: 'p',
description: 'Port to serve the Prisma Admin',
}),
}

async run() {
let { port } = this.flags

if (!port) {
port = 3000
}

const envFile = this.flags['env-file']
await this.definition.load(this.flags, envFile)

Expand All @@ -37,21 +25,20 @@ export default class Admin extends Command {
const cluster = await this.definition.getCluster(false)
const clusterVersion = await cluster!.getVersion()

if (satisfiesVersion(clusterVersion!, '1.25.0')) {
const link = await this.startServer({
endpoint: this.definition.endpoint,
token,
port,
})

opn(link).catch(() => {})
if (satisfiesVersion(clusterVersion!, '1.29.0')) {
let adminUrl = this.definition.endpoint + '/_admin'
if (token && token.length > 0) {
adminUrl += `?token=${token}`
}
this.out.log(`Opening Prisma Admin ${adminUrl} in the browser`)
opn(adminUrl).catch(() => {})
} else {
this.out.log(`Your Prisma server at ${chalk.bold(
`${this.definition.endpoint}`,
)} doesn't support Prisma Admin yet. Prisma Admin is supported from Prisma ${chalk.green(
`v1.25`,
`1.29`,
)} and higher. Your Prisma server currently uses Prisma ${chalk.red(
`v${clusterVersion}`,
`${clusterVersion}`,
)}.\n\n
Please upgrade your Prisma server to use Prisma Admin.`)
this.out.exit(1)
Expand All @@ -67,24 +54,4 @@ Please upgrade your Prisma server to use Prisma Admin.`)
}
return version
}

startServer = ({ endpoint, token, port = 3000 }) =>
new Promise((resolve, reject) => {
const app = express()

app.use('/admin', (req, res) => {
res.send(renderAdminPage({ endpoint, token, singleProject: true }))
})

const listener = app.listen(port, () => {
let host = listener.address().address
if (host === '::') {
host = 'localhost'
}
const link = `http://${host}:${port}/admin`
console.log('Serving admin at %s', chalk.blue(link))

resolve(link)
})
})
}
5 changes: 1 addition & 4 deletions cli/packages/prisma-cli-engine/src/CLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ export class CLI {
})
}

if (
!this.config.argv.includes('playground') &&
!this.config.argv.includes('admin')
) {
if (!this.config.argv.includes('playground')) {
const { timeout } = require('./util')
await timeout(this.flush(), 1000)

Expand Down
5 changes: 0 additions & 5 deletions cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7681,11 +7681,6 @@ pretty-ms@^3.0.0:
dependencies:
parse-ms "^1.0.0"

prisma-admin-html@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/prisma-admin-html/-/prisma-admin-html-0.0.6.tgz#08c66289f149cdcc7844f26ba69b518fe9ad2b69"
integrity sha512-k0tjrxt5nZb61T9qKtOADxc7GycGuRASe72K+khAtsd8OFYf3wt8fwqsR0tYI5S2LE8cvda5OiDVyp5EurKx6A==

prisma-json-schema@0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/prisma-json-schema/-/prisma-json-schema-0.1.3.tgz#6c302db8f464f8b92e8694d3f7dd3f41ac9afcbe"
Expand Down

0 comments on commit c71159a

Please sign in to comment.