-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
8,475 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
templates/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
// Use only this configuration | ||
root: true, | ||
// Environment global objects | ||
env: { | ||
es6: true, | ||
jest: true, | ||
}, | ||
extends: [ | ||
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style | ||
'standard', | ||
], | ||
rules: { | ||
'comma-dangle': ['error', 'always-multiline'], | ||
'semi': ['error', 'always'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
|
||
.tmp* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
.eslintignore | ||
.eslintrc.js | ||
yarn.lock | ||
logo.psd | ||
src/**/.tmp* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./src/generator'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// eslint-disable-next-line no-global-assign | ||
require = require('esm')(module); | ||
|
||
module.exports = require('./src/servicePlugin'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./src/prompts'); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const serverDir = './srv'; | ||
|
||
export const commandOptionsDefaults = { | ||
delay: false, | ||
host: '0.0.0.0', | ||
port: 3000, | ||
https: false, | ||
}; | ||
|
||
export const commandOptionsDoc = { | ||
'--delay': `delays run by a small duration (default: ${commandOptionsDefaults.delay})`, | ||
'--host': `specify host (default: ${commandOptionsDefaults.host})`, | ||
'--port': `specify port (default: ${commandOptionsDefaults.port})`, | ||
'--https': `use https (default: ${commandOptionsDefaults.https})`, | ||
}; | ||
|
||
export const shouldServeApp = true; | ||
|
||
export default { | ||
serverDir, | ||
commandOptionsDefaults, | ||
commandOptionsDoc, | ||
shouldServeApp, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = (api, options, rootOptions) => { | ||
api.extendPackage({ | ||
scripts: { | ||
'express': 'vue-cli-service express:watch', | ||
'express:run': 'vue-cli-service express:run', | ||
}, | ||
vue: { | ||
pluginOptions: { | ||
express: { | ||
shouldServeApp: options.shouldServeApp, | ||
serverDir: options.serverDir, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
api.render('./templates/srv'); | ||
|
||
if (options.addExamples) { | ||
// TODO | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import express from 'express'; | ||
|
||
export default app => { | ||
app.use(express.json()); | ||
|
||
app.get('/foo', (req, res) => { | ||
res.json({msg: 'foo'}); | ||
}); | ||
|
||
app.post('/bar', (req, res) => { | ||
res.json(req.body); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { serverDir, shouldServeApp } = require('../config'); | ||
|
||
module.exports = [ | ||
{ | ||
type: 'confirm', | ||
name: 'shouldServeApp', | ||
message: `Should serve vue app? (default: ${shouldServeApp})`, | ||
description: 'This will allow you to serve the vue app via the express server. So only one server for the app and the api.', | ||
default: shouldServeApp, | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'serverDir', | ||
message: `Where will be located your server? (default: "${serverDir}")`, | ||
description: 'The location of your server code, relative to the root of your project.', | ||
default: serverDir, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import express from 'express'; | ||
import { load } from './utils/misc'; | ||
import listEndpoints from 'express-list-endpoints'; | ||
|
||
import history from 'connect-history-api-fallback'; | ||
|
||
export default ({ | ||
port, | ||
srvPath, | ||
distPath, | ||
hasTypescript, | ||
shouldServeApp, | ||
isInProduction, | ||
}) => { | ||
return new Promise((resolve, reject) => { | ||
const app = express(); | ||
|
||
if (hasTypescript) { | ||
require('ts-node/register/transpile-only'); | ||
} | ||
|
||
load(srvPath)(app); | ||
|
||
if (isInProduction && shouldServeApp) { | ||
app.use(history()); | ||
app.use(express.static(distPath)); | ||
} | ||
|
||
app.listen(port, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(listEndpoints(app)); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import config from '../config'; | ||
import serveCommand from './serveCommand'; | ||
import runCommand from './runCommand'; | ||
import webpackConfig from './webpackConfig'; | ||
|
||
module.exports = (api, options) => { | ||
const expressOptions = (options.pluginOptions && options.pluginOptions.express) || {}; | ||
const shouldServeApp = expressOptions.shouldServeApp || config.shouldServeApp; | ||
const isInProduction = process.env.NODE_ENV === 'production'; | ||
const srvPath = api.resolve(expressOptions.serverDir || config.serverDir); | ||
const distPath = api.resolve(options.outputDir); | ||
const hasTypescript = api.hasPlugin('typescript') || expressOptions.hasTypescript; | ||
|
||
if (shouldServeApp && !isInProduction) { | ||
addServerUrlToWebpackProxy(api); | ||
} | ||
|
||
registerServeCommand(api, { srvPath }); | ||
|
||
registerRunCommand(api, { | ||
defaultOptions: config.commandOptionsDefaults, | ||
srvPath, | ||
shouldServeApp, | ||
isInProduction, | ||
distPath, | ||
hasTypescript, | ||
}); | ||
}; | ||
|
||
module.exports.defaultModes = { | ||
'express:watch': 'development', | ||
'express:run': 'production', | ||
}; | ||
|
||
function registerServeCommand (api, options) { | ||
api.registerCommand( | ||
'express:watch', | ||
{ | ||
description: 'Run the Express server and watch the sources to restart automatically', | ||
usage: 'vue-cli-service express:watch [options]', | ||
options: config.commandOptionsDoc, | ||
details: 'For more info, see https://github.com/mathieutu/vue-cli-plugin-express', | ||
}, | ||
serveCommand(options), | ||
); | ||
} | ||
|
||
function registerRunCommand (api, options) { | ||
api.registerCommand( | ||
'express:run', | ||
{ | ||
description: 'Run the Express server', | ||
usage: 'vue-cli-service express:run [options]', | ||
options: config.commandOptionsDoc, | ||
details: 'For more info, see https://github.com/mathieutu/vue-cli-plugin-express', | ||
}, | ||
runCommand(options), | ||
); | ||
} | ||
|
||
function addServerUrlToWebpackProxy (api) { | ||
api.chainWebpack(webpackConfig); | ||
} |
Oops, something went wrong.