Skip to content

Commit

Permalink
refactor(ui): vue ui command
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed May 4, 2018
1 parent adce5f0 commit cec571e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 50 deletions.
2 changes: 2 additions & 0 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ program
.command('ui')
.option('-p, --port <port>', 'Port used for the UI server (by default search for awailable port)')
.option('-D, --dev', 'Run in dev mode')
.option('--quiet', `Don't output starting messages`)
.option('--headless', `Don't open browser on start and output port`)
.description('start and open the vue-cli ui')
.action((cmd) => {
require('../lib/ui')(cleanArgs(cmd))
Expand Down
71 changes: 30 additions & 41 deletions packages/@vue/cli/lib/ui.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,48 @@
const { log, error, openBrowser } = require('@vue/cli-shared-utils')
const portfinder = require('portfinder')
const execa = require('execa')

async function ui (options = {}, context = process.cwd()) {
let port = options.port
if (!port) {
port = await portfinder.getPortPromise()
}

const configOk = process.env.VUE_UI_CONFIGURED === 'OK'
if (!configOk) {
process.env.VUE_UI_CONFIGURED = 'OK'
// Config
process.env.VUE_APP_GRAPHQL_PORT = port
process.env.VUE_APP_GRAPHQL_ENDPOINT = ''
process.env.VUE_APP_GRAPHQL_PLAYGROUND_PATH = '/graphql-playground'
// Config
process.env.VUE_APP_GRAPHQL_PORT = port
process.env.VUE_APP_GRAPHQL_ENDPOINT = ''
process.env.VUE_APP_GRAPHQL_PLAYGROUND_PATH = '/graphql-playground'

if (!options.dev) {
process.env.NODE_ENV = 'production'
}

if (!options.dev && !configOk) {
// Re-run in production mode
const command = require.resolve('@vue/cli/bin/vue')
execa('cross-env', [
'NODE_ENV=production',
'node',
command,
'ui'
], {
cwd: context,
stdio: ['inherit', 'inherit', 'inherit']
})
} else {
log(`🚀 Starting GUI...`)
let server = require('vue-cli-plugin-apollo/graphql-server')
server = server.default || server
if (!options.quiet) log(`🚀 Starting GUI...`)
let server = require('vue-cli-plugin-apollo/graphql-server')
server = server.default || server

const opts = {
mock: false,
apolloEngine: false,
timeout: 999999999,
quiet: true,
paths: {
typeDefs: require.resolve('@vue/cli-ui/src/graphql-api/type-defs.js'),
resolvers: require.resolve('@vue/cli-ui/src/graphql-api/resolvers.js'),
context: require.resolve('@vue/cli-ui/src/graphql-api/context.js'),
pubsub: require.resolve('@vue/cli-ui/src/graphql-api/pubsub.js'),
server: require.resolve('@vue/cli-ui/src/graphql-api/server.js')
}
const opts = {
mock: false,
apolloEngine: false,
timeout: 999999999,
quiet: true,
paths: {
typeDefs: require.resolve('@vue/cli-ui/src/graphql-api/type-defs.js'),
resolvers: require.resolve('@vue/cli-ui/src/graphql-api/resolvers.js'),
context: require.resolve('@vue/cli-ui/src/graphql-api/context.js'),
pubsub: require.resolve('@vue/cli-ui/src/graphql-api/pubsub.js'),
server: require.resolve('@vue/cli-ui/src/graphql-api/server.js')
}
}

server(opts, () => {
const url = `http://localhost:${process.env.VUE_APP_GRAPHQL_PORT}`
console.log(`🌠 Ready on ${url}`)
server(opts, () => {
const url = `http://localhost:${process.env.VUE_APP_GRAPHQL_PORT}`
if (!options.quiet) log(`🌠 Ready on ${url}`)
if (options.headless) {
console.log(port)
} else {
openBrowser(url)
})
}
}
})
}

module.exports = (...args) => {
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@vue/cli-ui-addon-webpack": "^3.0.0-beta.9",
"chalk": "^2.3.0",
"commander": "^2.12.2",
"cross-env": "^5.1.4",
"debug": "^3.1.0",
"deepmerge": "^2.0.1",
"download-git-repo": "^1.0.2",
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3043,13 +3043,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

cross-env@^5.1.4:
version "5.1.4"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.1.4.tgz#f61c14291f7cc653bb86457002ea80a04699d022"
dependencies:
cross-spawn "^5.1.0"
is-windows "^1.0.0"

cross-fetch@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.0.0.tgz#a17475449561e0f325146cea636a8619efb9b382"
Expand Down Expand Up @@ -6063,7 +6056,7 @@ is-windows@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-0.2.0.tgz#de1aa6d63ea29dd248737b69f1ff8b8002d2108c"

is-windows@^1.0.0, is-windows@^1.0.2:
is-windows@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"

Expand Down

0 comments on commit cec571e

Please sign in to comment.