first commit

This commit is contained in:
hofee 2024-09-13 09:46:25 -05:00
commit e6cf99e8ae
42 changed files with 19527 additions and 0 deletions

18
.babelrc Normal file
View File

@ -0,0 +1,18 @@
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
],
"plugins": ["transform-vue-jsx", "transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
}
}
}

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

5
.eslintignore Normal file
View File

@ -0,0 +1,5 @@
/build/
/config/
/dist/
/*.js
/test/unit/coverage/

29
.eslintrc.js Normal file
View File

@ -0,0 +1,29 @@
// https://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint'
},
env: {
browser: true,
},
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard'
],
// required to lint *.vue files
plugins: [
'vue'
],
// add your custom rules here
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
}

19
.gitignore vendored Normal file
View File

@ -0,0 +1,19 @@
.DS_Store
node_modules/
/dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/test/unit/coverage/
/test/e2e/reports/
selenium-debug.log
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
# Visual Studio Code
.vscode

10
.postcssrc.js Normal file
View File

@ -0,0 +1,10 @@
// https://github.com/michael-ciniawsky/postcss-load-config
module.exports = {
"plugins": {
"postcss-import": {},
"postcss-url": {},
// to edit target browsers: use "browserslist" field in package.json
"autoprefixer": {}
}
}

3
Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM nginx
COPY dist/ /usr/share/nginx/html/
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

30
README.md Normal file
View File

@ -0,0 +1,30 @@
# cscomp
> A Vue.js project
## Build Setup
``` bash
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
# build for production with minification
npm run build
# build for production and view the bundle analyzer report
npm run build --report
# run unit tests
npm run unit
# run e2e tests
npm run e2e
# run all tests
npm test
```
For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).

41
build/build.js Normal file
View File

@ -0,0 +1,41 @@
'use strict'
require('./check-versions')()
process.env.NODE_ENV = 'production'
const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.prod.conf')
const spinner = ora('building for production...')
spinner.start()
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
if (err) throw err
webpack(webpackConfig, (err, stats) => {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
chunks: false,
chunkModules: false
}) + '\n\n')
if (stats.hasErrors()) {
console.log(chalk.red(' Build failed with errors.\n'))
process.exit(1)
}
console.log(chalk.cyan(' Build complete.\n'))
console.log(chalk.yellow(
' Tip: built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
))
})
})

54
build/check-versions.js Normal file
View File

@ -0,0 +1,54 @@
'use strict'
const chalk = require('chalk')
const semver = require('semver')
const packageConfig = require('../package.json')
const shell = require('shelljs')
function exec (cmd) {
return require('child_process').execSync(cmd).toString().trim()
}
const versionRequirements = [
{
name: 'node',
currentVersion: semver.clean(process.version),
versionRequirement: packageConfig.engines.node
}
]
if (shell.which('npm')) {
versionRequirements.push({
name: 'npm',
currentVersion: exec('npm --version'),
versionRequirement: packageConfig.engines.npm
})
}
module.exports = function () {
const warnings = []
for (let i = 0; i < versionRequirements.length; i++) {
const mod = versionRequirements[i]
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
warnings.push(mod.name + ': ' +
chalk.red(mod.currentVersion) + ' should be ' +
chalk.green(mod.versionRequirement)
)
}
}
if (warnings.length) {
console.log('')
console.log(chalk.yellow('To use this template, you must update following to modules:'))
console.log()
for (let i = 0; i < warnings.length; i++) {
const warning = warnings[i]
console.log(' ' + warning)
}
console.log()
process.exit(1)
}
}

BIN
build/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

101
build/utils.js Normal file
View File

@ -0,0 +1,101 @@
'use strict'
const path = require('path')
const config = require('../config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const packageConfig = require('../package.json')
exports.assetsPath = function (_path) {
const assetsSubDirectory = process.env.NODE_ENV === 'production'
? config.build.assetsSubDirectory
: config.dev.assetsSubDirectory
return path.posix.join(assetsSubDirectory, _path)
}
exports.cssLoaders = function (options) {
options = options || {}
const cssLoader = {
loader: 'css-loader',
options: {
sourceMap: options.sourceMap
}
}
const postcssLoader = {
loader: 'postcss-loader',
options: {
sourceMap: options.sourceMap
}
}
// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
scss: generateLoaders('sass'),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
}
// Generate loaders for standalone style files (outside of .vue)
exports.styleLoaders = function (options) {
const output = []
const loaders = exports.cssLoaders(options)
for (const extension in loaders) {
const loader = loaders[extension]
output.push({
test: new RegExp('\\.' + extension + '$'),
use: loader
})
}
return output
}
exports.createNotifierCallback = () => {
const notifier = require('node-notifier')
return (severity, errors) => {
if (severity !== 'error') return
const error = errors[0]
const filename = error.file && error.file.split('!').pop()
notifier.notify({
title: packageConfig.name,
message: severity + ': ' + error.name,
subtitle: filename || '',
icon: path.join(__dirname, 'logo.png')
})
}
}

22
build/vue-loader.conf.js Normal file
View File

@ -0,0 +1,22 @@
'use strict'
const utils = require('./utils')
const config = require('../config')
const isProduction = process.env.NODE_ENV === 'production'
const sourceMapEnabled = isProduction
? config.build.productionSourceMap
: config.dev.cssSourceMap
module.exports = {
loaders: utils.cssLoaders({
sourceMap: sourceMapEnabled,
extract: isProduction
}),
cssSourceMap: sourceMapEnabled,
cacheBusting: config.dev.cacheBusting,
transformToRequire: {
video: ['src', 'poster'],
source: 'src',
img: 'src',
image: 'xlink:href'
}
}

View File

@ -0,0 +1,92 @@
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
const createLintingRule = () => ({
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
formatter: require('eslint-friendly-formatter'),
emitWarning: !config.dev.showEslintErrorsInOverlay
}
})
module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
// ...(config.dev.useEslint ? [createLintingRule()] : []),
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client'), resolve('node_modules/view-ui-plus/dist/viewuiplus.min.js')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}

95
build/webpack.dev.conf.js Normal file
View File

@ -0,0 +1,95 @@
'use strict'
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const path = require('path')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT)
const devWebpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: config.dev.devtool,
// these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
],
},
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay
? { warnings: false, errors: true }
: false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: config.dev.poll,
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.*']
}
])
]
})
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port
portfinder.getPort((err, port) => {
if (err) {
reject(err)
} else {
// publish the new Port, necessary for e2e tests
process.env.PORT = port
// add port to devServer config
devWebpackConfig.devServer.port = port
// Add FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
},
onErrors: config.dev.notifyOnErrors
? utils.createNotifierCallback()
: undefined
}))
resolve(devWebpackConfig)
}
})
})

149
build/webpack.prod.conf.js Normal file
View File

@ -0,0 +1,149 @@
'use strict'
const path = require('path')
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const env = process.env.NODE_ENV === 'testing'
? require('../config/test.env')
: require('../config/prod.env')
const webpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true,
usePostCSS: true
})
},
devtool: config.build.productionSourceMap ? config.build.devtool : false,
output: {
path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
},
plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
'process.env': env
}),
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false
}
},
sourceMap: config.build.productionSourceMap,
parallel: true
}),
// extract css into its own file
new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css'),
// Setting the following option to `false` will not extract CSS from codesplit chunks.
// Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
// It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
// increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
allChunks: true,
}),
// Compress extracted CSS. We are using this plugin so that possible
// duplicated CSS from different components can be deduped.
new OptimizeCSSPlugin({
cssProcessorOptions: config.build.productionSourceMap
? { safe: true, map: { inline: false } }
: { safe: true }
}),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
}),
// keep module.id stable when vendor modules does not change
new webpack.HashedModuleIdsPlugin(),
// enable scope hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks (module) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, '../node_modules')
) === 0
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
// This instance extracts shared chunks from code splitted chunks and bundles them
// in a separate chunk, similar to the vendor chunk
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
new webpack.optimize.CommonsChunkPlugin({
name: 'app',
async: 'vendor-async',
children: true,
minChunks: 3
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.build.assetsSubDirectory,
ignore: ['.*']
}
])
]
})
if (config.build.productionGzip) {
const CompressionWebpackPlugin = require('compression-webpack-plugin')
webpackConfig.plugins.push(
new CompressionWebpackPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(' +
config.build.productionGzipExtensions.join('|') +
')$'
),
threshold: 10240,
minRatio: 0.8
})
)
}
if (config.build.bundleAnalyzerReport) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}
module.exports = webpackConfig

7
config/dev.env.js Normal file
View File

@ -0,0 +1,7 @@
'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, {
NODE_ENV: '"development"'
})

78
config/index.js Normal file
View File

@ -0,0 +1,78 @@
'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
// Use Eslint Loader?
// If true, your code will be linted during bundling and
// linting errors and warnings will be shown in the console.
useEslint: true,
// If true, eslint errors and warnings will also be shown in the error overlay
// in the browser.
showEslintErrorsInOverlay: false,
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-module-eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}

4
config/prod.env.js Normal file
View File

@ -0,0 +1,4 @@
'use strict'
module.exports = {
NODE_ENV: '"production"'
}

7
config/test.env.js Normal file
View File

@ -0,0 +1,7 @@
'use strict'
const merge = require('webpack-merge')
const devEnv = require('./dev.env')
module.exports = merge(devEnv, {
NODE_ENV: '"testing"'
})

12
index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>PyTorchBoot Project</title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

22
nginx/default.conf Normal file
View File

@ -0,0 +1,22 @@
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log /var/log/nginx/host.access.log main;
error_log /var/log/nginx/error.log error;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

17595
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

96
package.json Normal file
View File

@ -0,0 +1,96 @@
{
"name": "cscomp",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "jerk <123456@qq.com>",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"unit": "jest --config test/unit/jest.conf.js --coverage",
"e2e": "node test/e2e/runner.js",
"test": "npm run unit && npm run e2e",
"lint": "eslint --ext .js,.vue src test/unit test/e2e/specs",
"build": "node build/build.js"
},
"dependencies": {
"axios": "^0.26.1",
"echarts": "^5.5.0",
"echarts-gl": "^2.0.9",
"video.js": "^7.19.2",
"videojs-contrib-hls": "^5.15.0",
"view-design": "^4.7.0",
"view-ui-plus": "^1.3.16",
"vue": "^2.5.2",
"vue-router": "^3.0.1",
"xlsx": "^0.17.5"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-eslint": "^8.2.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-jest": "^21.0.2",
"babel-loader": "^7.1.1",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^2.0.1",
"chromedriver": "^2.27.2",
"copy-webpack-plugin": "^4.0.1",
"cross-spawn": "^5.0.1",
"css-loader": "^0.28.0",
"eslint": "^4.15.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^4.0.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"jest": "^22.0.4",
"jest-serializer-vue": "^0.3.0",
"nightwatch": "^0.9.12",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"selenium-server": "^3.0.1",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"three": "^0.128.0",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-jest": "^1.0.2",
"vue-loader": "^13.7.3",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.6.14",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.11.5",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}

11
src/App.vue Normal file
View File

@ -0,0 +1,11 @@
<template>
<div class="app">
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>

130
src/components/Main.vue Normal file
View File

@ -0,0 +1,130 @@
<style scoped>
.layout {
border: 0px solid #d7dde4;
background: #f5f7f9;
font-family:Verdana
}
.sub_menu {
display: flex;
flex-direction: column;
align-items: center;
}
.layout-logo {
width: auto;
height: 30px;
border-radius: 3px;
float: left;
position: relative;
top: 15px;
left: 15px;
right: 15px;
font-family: sans-serif;
font-size: 22px;
font-weight: bold;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
padding: 0 10px;
}
.layout-nav {
width: auto;
margin: 0 auto;
}
.layout-assistant {
width: auto;
margin: 0 auto;
height: inherit;
}
.layout-breadcrumb {
padding: 10px 15px 0;
}
.layout-content {
min-height: 800px;
margin: 15px;
overflow: hidden;
background: #fff;
border-radius: 4px;
}
.layout-content-main {
padding: 10px;
}
.layout-copy {
text-align: center;
padding: 10px 0 20px;
color: #9ea7b4;
}
</style>
<template>
<div class="layout">
<Menu mode="horizontal" theme="dark" active-name="1" @on-select="handleMenuSelect">
<div class="layout-logo">{{ project_name }}</div>
</Menu>
<Menu mode="horizontal" active-name="1" @on-select="handleSubMenuSelect" class="sub_menu">
<div class="layout-assistant">
<Menu-item name="1">
<Icon type="md-pie" size="16" />{{ sub_navi_name[0] }}
</Menu-item>
<Menu-item name="2">
<Icon type="ios-stats" size="16" />{{ sub_navi_name[1] }}
</Menu-item>
</div>
</Menu>
<div class="layout-breadcrumb" >
<Breadcrumb separator=">">
<Breadcrumb-item>{{ project_name }}</Breadcrumb-item>
<Breadcrumb-item>{{ sub_navi_name[curr_sub_navi_idx] }}</Breadcrumb-item>
</Breadcrumb>
</div>
<div class="layout-content">
<component :is="currentComponent"></component>
</div>
<div class="layout-copy">
PyTorchBoot &copy; Author: lexhofee@gmail.com
</div>
</div>
</template>
<script>
import Dashboard from '@/components/content/Dashboard.vue'
import Tensorboard from '@/components/content/Tensorboard.vue'
export default {
data() {
return {
project_name: "PyTorchBoot",
sub_navi_name: ["Project Dashboard", "Tensorboard"],
curr_sub_navi_idx: 0,
components: [Dashboard, Tensorboard],
};
},
mounted() {
},
computed: {
currentComponent() {
return this.components[this.curr_sub_navi_idx];
}
},
methods: {
handleMenuSelect(name) {
this.curr_navi_idx = parseInt(name) - 1;
},
handleSubMenuSelect(name) {
this.curr_sub_navi_idx = parseInt(name) - 1;
},
}
}
</script>

View File

@ -0,0 +1,56 @@
<template>
<div class="page404">
<div class="content">
<h1>404</h1>
<p>Oops! The page you're looking for doesn't exist.</p>
<router-link to="/" class="home-link">Go Back Home</router-link>
</div>
</div>
</template>
<script>
export default {
name: "Page404",
}
</script>
<style scoped>
.page404 {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f7f9;
color: #333;
font-family: 'PingFang SC', sans-serif;
}
.content {
text-align: center;
}
h1 {
font-size: 10rem;
margin: 0;
}
p {
font-size: 1.5rem;
}
.home-link {
display: inline-block;
margin-top: 20px;
padding: 10px 20px;
background-color: #001529;
color: #fff;
text-decoration: none;
border-radius: 5px;
font-size: 1rem;
transition: background-color 0.3s;
}
.home-link:hover {
background-color: #1890ff;
}
</style>

View File

@ -0,0 +1,363 @@
<template>
<div style="padding: 20px;">
<div style="display: flex; justify-content: center;">
<h1>Project Dashboard</h1>
</div>
<Divider />
<Row style="margin-top: 20px;">
<Col span="11">
<Card style="width:100%; margin-bottom: 10px;" ref="logContainer" >
<p slot="title" style="font-size: 18px; font-weight: bold; color: #464c5b;">
<Icon type="ios-list" size="20" style="color: #464c5b;" />
Logs
</p>
<div style="overflow-y: auto; max-height:200px; ">
<div v-for="(log, index) in logs.slice().reverse()" :key="index">
<Alert :type="log[1]" show-icon> <span style="font-weight: bold;">({{ log[0] }}) </span>{{log[2]}}</Alert>
</div>
</div>
</Card>
<Card style="width:100%; ">
<p slot="title" style="font-size: 18px; font-weight: bold; color: #464c5b;">
<Icon type="ios-apps" size="20" style="color: #464c5b;" />
Project Structure
</p>
<CellGroup>
<p style="font-size: 17px; color: #464c5b; padding-bottom: 5px; font-weight: bold;">Applications</p>
<Cell v-for="app_name in Object.keys(applications)" :key="app_name">
<Badge status="success" />
<span style=" padding-bottom: 3px;font-size: 13px; font-weight: bold;">{{ app_name }}</span>:
<Tag type="border" color="success"> {{ applications[app_name] }} </Tag>
<Button type="success" slot="extra" size="small" @click="run_app(app_name)" :disabled="running_apps.includes(app_name)">
<Icon type="ios-play" style="margin-right: 3px;" />Run
</Button>
<span v-if="running_apps.includes(app_name)">
<Icon type="ios-loading" size=18 class="demo-spin-icon-load" > </Icon> Running...
</span>
</Cell>
</CellGroup>
<Divider />
<CellGroup>
<p style="font-size: 17px; color: #464c5b; padding-bottom: 5px; font-weight: bold;">Components</p>
<div v-for="comp_type in Object.keys(components)" :key="comp_type">
<div v-if=" Object.keys(components[comp_type]).length > 0">
<Tag style="font-size: 14px; ">{{comp_type}}</Tag>
<Cell v-for="comp_name in Object.keys(components[comp_type])" :key="comp_name" >
<Badge :status="comments[comp_type][comp_name] != null ? 'warning' : 'success'"/>
<span style=" padding-bottom: 3px; font-size: 13px; font-weight: bold;">{{ comp_name }}</span>:
<Tag type="border" :color="comments[comp_type][comp_name] != null ? 'warning' : 'success'"> {{ components[comp_type][comp_name] }} </Tag>
<Tag color="red" v-if="comments[comp_type][comp_name] != null" slot="extra">{{comments[comp_type][comp_name]}}</Tag>
</Cell>
</div>
</div>
</CellGroup>
</Card>
</Col>
<Col span="11" offset="1">
<Card style="width:100%; margin-bottom: 10px;">
<p slot="title" style="font-size: 18px; font-weight: bold; color: #464c5b;">
<Icon type="md-laptop" size="20" style="color: #464c5b;" />
Machine Status
</p>
<!-- CPU Usage -->
<Row>
<span style="font-weight: bold;">Project CPU Usage
(<span :style="{ color: get_progress_color(cpu['usage_percent']) }">{{ cpu['usage_percent'] }}%</span>)
</span>
<Progress
:percent="cpu['usage_percent']"
:stroke-color="get_progress_color(cpu['usage_percent'])"
/>
</Row>
<!-- Memory Usage -->
<Row>
<p style="font-weight: bold;">
Memory
(<span :style="{ color: get_progress_color(parseFloat((memory['used']/memory['total']*100).toFixed(1))) }">{{ memory['used'].toFixed(2) }} GB </span>
/{{ memory['total'].toFixed(2) }} GB)
</p>
<Progress
:percent="parseFloat((memory['used']/memory['total']*100).toFixed(1))"
:stroke-color="get_progress_color(parseFloat((memory['used']/memory['total']*100).toFixed(1)))"
/>
</Row>
<!-- GPU Usage -->
<Row v-for="(gpu, index) in gpus" :key="index">
<p style="font-weight: bold;">
{{ gpu["name"] }}
<span style="color: blue;">[gpu:{{ index }}]</span>
(<span :style="{ color: get_progress_color(parseFloat((gpu['memory_used']/gpu['memory_total']*100).toFixed(1))) }">{{ gpu['memory_used'] }} MB </span>
/{{ gpu['memory_total'] }} MB)
</p>
<Progress
:percent="parseFloat((gpu['memory_used']/gpu['memory_total']*100).toFixed(1))"
:stroke-color="get_progress_color(parseFloat((gpu['memory_used']/gpu['memory_total']*100).toFixed(1)))"
/>
</Row>
</Card>
<Card style="width:100%; margin-bottom: 10px;" v-for="app_name in Object.keys(progress)" :key="app_name">
<p slot="title" style="font-size: 18px; font-weight: bold; color: #464c5b; ">
<Icon type="ios-play" style="margin-right: 3px;" />
Running Application: <span style="color: green;">{{ app_name }}</span>
</p>
<Row style="margin-bottom: 10px; margin-left: 10px; margin-right: 10px;">
<Col span="24">
<Card v-for="runner_name in Object.keys(progress[app_name]) " style="margin-right: 15px;" :key="runner_name">
<p style="font-weight: bold; font-size: 16px;"><Badge :status="isAllProgressFull(app_name, runner_name) ? 'success' : 'processing'" />{{ runner_name }} </p>
<Divider />
<div v-for="progress_name in Object.keys(progress[app_name][runner_name])" style="margin-left: 25px;" :key="progress_name">
<span style="font-weight: bold;">{{ progress_name }}</span>
<Tag :color="progress[app_name][runner_name][progress_name][0] === progress[app_name][runner_name][progress_name][1] ? 'green' : 'geekblue'">
{{ progress[app_name][runner_name][progress_name][0] }}/<span style="font-weight: bold;">{{ progress[app_name][runner_name][progress_name][1] }}</span>
</Tag>
<Progress
:percent="parseFloat((progress[app_name][runner_name][progress_name][0] / progress[app_name][runner_name][progress_name][1] * 100).toFixed(1))"
status="active"
style="padding-right: 5%;"
/>
</div >
<div v-if="app_name in curr_status && runner_name in curr_status[app_name]" style="margin-left: 25px;">
<div v-for="status_name in Object.keys(curr_status[app_name][runner_name])" :key="status_name" style="margin-left: 5px;">
<span style="font-weight: bold;">{{ status_name }} : </span>
<span v-if="typeof curr_status[app_name][runner_name][status_name] === 'number'">
{{ parseFloat(curr_status[app_name][runner_name][status_name].toFixed(5)) }}
<template v-if="curr_status[app_name][runner_name][status_name] - last_status[app_name][runner_name][status_name] > 0">
<Icon type="md-arrow-dropup" size="18" style="color: green;" />
<span style="color: green;">
+{{ parseFloat((curr_status[app_name][runner_name][status_name] - last_status[app_name][runner_name][status_name]).toFixed(5)) }}
</span>
</template>
<template v-else-if="curr_status[app_name][runner_name][status_name] - last_status[app_name][runner_name][status_name] < 0">
<Icon type="md-arrow-dropdown" size="18" style="color: red;" />
<span style="color: red;">
{{ parseFloat((curr_status[app_name][runner_name][status_name] - last_status[app_name][runner_name][status_name]).toFixed(5)) }}
</span>
</template>
</span>
<span v-else style="color: blue;" >{{ curr_status[app_name][runner_name][status_name] }}</span>
</div>
</div>
</Card>
</Col>
</Row>
<Divider />
</Card>
<Card style="width:100%; ">
<p slot="title" style="font-size: 18px; font-weight: bold; color: #464c5b;">
<Icon type="md-settings" size="20" style="color: #464c5b;" />
Configuration
</p>
<Row style="margin-bottom: 10px; margin-left: 10px; margin-right: 10px;">
<Col span="12">
<p style="font-size: 16px; color: #464c5b;">Select Configuration: </p>
</Col>
<Col span="12">
<Select v-model="selected_config" style="width: 100%;" filterable
placeholder="please select..." >
<Option v-for="item in Object.keys(this.configs)" :value="item" :key="item">{{ item }}</Option>
</Select>
</Col>
</Row>
<Divider />
<Card>
<Tree :data="config_data"></Tree>
</Card>
</Card>
</Col>
</Row>
</div>
</template>
<script>
import * as echarts from 'echarts';
import 'echarts-gl';
import { TooltipComponent } from 'echarts/components';
import { Col } from 'view-design';
echarts.use([TooltipComponent]);
export default {
name: "Dashboard",
components: {
},
watch: {
selected_config: {
handler: function (val, oldVal) {
this.config_data = this.convertToTree(this.configs[val]);
this.config_data = Array.isArray(this.config_data) ? this.config_data : [this.config_data];
},
immediate: true
}
},
computed: {
},
data() {
return {
root_path: "",
running_apps: [],
show_app_panel: false,
components: {},
comments: {},
applications: {},
configs: {},
selected_config: "",
config_data: [],
curr_status: {},
last_status: {},
progress: {},
logs: [],
cpu: {},
memory: {},
gpus: {},
};
},
mounted() {
console.log("mounted");
this.get_project_structure();
this.startStatusCheck();
},
methods: {
get_progress_color(percent) {
if (percent < 50) {
return "green";
} else if (percent < 70) {
return "orange";
} else {
return "red";
}
},
convertToTree(data) {
if (typeof data !== 'object' || data === null) {
return data;
}
return Object.keys(data).map(key => {
const node = { title: key };
const children = this.convertToTree(data[key]);
if (children && Array.isArray(children)) {
node.children = children;
node.expand = true;
} else if (children !== null) {
node.title = node.title + " : " + String(children);
}
return node;
});
},
get_project_structure() {
const params = {};
this.$ajax.postjson('/project/structure', params)
.then((data) => {
this.root_path = data.root_path;
this.components = data.components;
this.comments = data.comments;
this.applications = data.applications;
this.configs = data.configs;
this.selected_config = Object.keys(this.configs)[0];
});
},
run_app(app_name) {
const params = {
app_name: app_name
};
this.$ajax.postjson('/project/run_app', params)
.then((data) => {
if(data.status == "success") {
this.$Message.success(data.message);
this.startStatusCheck();
} else {
this.$Message.error(data.message);
}
});
},
get_status() {
const params = {};
this.last_status = this.curr_status;
this.$ajax.postjson('/project/get_status', params)
.then((data) => {
this.curr_status = data.curr_status;
this.logs = data.logs;
this.progress = data.progress;
this.running_apps = data.running_apps;
this.cpu = data.cpu;
this.memory = data.memory;
this.gpus = data.gpus;
console.log('cpu-----------------', this.cpu)
if (this.logs.length > 0) {
this.show_app_panel = true;
}
});
},
startStatusCheck() {
this.stopStatusCheck();
this.statusInterval = setInterval(() => {
this.get_status();
}, 1000);
},
stopStatusCheck() {
if (this.statusInterval) {
clearInterval(this.statusInterval);
this.statusInterval = null;
}
},
isAllProgressFull(app_name, runner_name) {
const progress = this.progress[app_name][runner_name];
return Object.keys(progress).every(
(progress_name) =>
progress[progress_name][0] === progress[progress_name][1]
);
},
}
}
</script>
<style scoped>
.disabled-row {
opacity: 0.5;
pointer-events: none;
}
.disabled-text {
color: gray !important;
}
.disabled-tag {
pointer-events: none;
cursor: not-allowed;
color: gray !important;
}
.demo-spin-icon-load{
animation: ani-demo-spin 1s linear infinite;
}
</style>

View File

@ -0,0 +1,103 @@
<template>
<div style="padding: 20px;">
<div style="display: flex; justify-content: center;">
<h1>Tensorboard</h1>
</div>
<Divider />
<Alert :type="notice_status" show-icon>
{{ notice_msg }}
</Alert>
<Row style="padding-right: 20%; padding-left: 15%;">
<Col :span="6">
<span style="font-size: 16px; font-weight: bold;">Tensorboard Log Directory</span>
</Col>
<Col :span="15">
<AutoComplete
v-model="log_dir"
:data="tensorboard_dirs"
placeholder="Enter or choose one 'log_dir' ..."
style="margin-bottom: 20px;">
</AutoComplete>
</Col>
<Col offset="1">
<Button icon="ios-play" type="primary" @click="run_tensorboard">Run</Button>
</Col>
</Row>
<Divider />
<!-- TensorBoard iframe -->
<Row type="flex" style="margin-top: 20px;">
<Col v-for="(url, log_dir) in running_tensorboards" :key="url" :span="8" style="margin-right: 10px;">
<Card>
<p slot="title" style="font-weight: bold;">TensorBoard</p>
<a :href="url" target="_blank" slot="extra">{{ url }}</a>
<iframe :src="url" width="100%" height="400px" frameborder="0"></iframe>
<Divider />
<Tag>Log Directory:</Tag>
<Input v-model="log_dir" type="textarea" readonly placeholder="Enter something..." />
</Card>
</Col>
</Row>
</div>
</template>
<script>
export default {
name: 'Tensorboard',
data() {
return {
log_dir: "", // Input field for the log directory
notice_msg: "Please enter the log directory to run TensorBoard.",
notice_status: "info",
tensorboard_dirs: [],
running_tensorboards: {}
}
},
mounted () {
this.get_tensorboard_dirs();
this.get_running_tensorboards();
},
methods: {
run_tensorboard() {
const params = { log_dir: this.log_dir };
this.$ajax.postjson("/tensorboard/run", params)
.then((data) => {
if (data.status === "success") {
this.notice_msg = data.message;
this.notice_status = "success";
} else if (data.status === "warning") {
this.tensorboardUrl = data.url;
this.notice_msg = data.message;
this.notice_status = "warning";
}
else {
this.notice_msg = data.message;
this.notice_status = "error";
}
this.get_running_tensorboards();
});
},
get_tensorboard_dirs(){
const params = { };
this.$ajax.postjson("/tensorboard/dirs", params)
.then((data) => {
this.tensorboard_dirs = data.tensorboard_dirs;
});
},
get_running_tensorboards(){
const params = { };
this.$ajax.postjson("/tensorboard/running_tensorboards", params)
.then((data) => {
this.running_tensorboards = data.running_tensorboards;
});
}
}
}
</script>
<style scoped></style>

21
src/main.js Normal file
View File

@ -0,0 +1,21 @@
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
//设置iview
import ViewUI from 'view-design'
import 'view-design/dist/styles/iview.css'
Vue.use(ViewUI)
//设置ajax
import ajax from '@/utils/ajax'
Vue.prototype.$ajax=ajax
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})

35
src/router/index.js Normal file
View File

@ -0,0 +1,35 @@
import Vue from 'vue'
import Router from 'vue-router'
import ViewUI from 'view-design'
import 'view-design/dist/styles/iview.css'
import Page404 from '@/components/Page404.vue'
import Main from '@/components/Main.vue'
Vue.use(ViewUI)
import XLSX from 'xlsx'
Vue.use(XLSX)
import ajax from '@/utils/ajax'
Vue.prototype.$ajax = ajax
Vue.config.productionTip = false
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Main',
component: Main,
meta: { title: 'PyTorch Boot Project' }
},
{
path: '*',
name: 'Page404',
component: Page404,
meta: { title: 'PyTorch Boot Project' }
}
]
})

95
src/utils/ajax.js Normal file
View File

@ -0,0 +1,95 @@
//设置axios
import qs from 'qs';
import axios from 'axios'
import { Message } from 'view-design'
export default {
post(url, params) {
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.transformRequest = [
function (data) {
return qs.stringify(data)
}
];
var res = axios.post(`${url}`, params).then((res) => {
console.log("res:", res)
if (res.status == 200) {
if (res.data.exception != undefined && res.data.exception) {
//统一处理异常
Message.error(res.data.msg)
return Promise.reject(res.data)
} else {
return res.data;
}
}
else
Message.error("server error")
})
return res;
},
postjson(url, params) {
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=utf-8'
axios.defaults.transformRequest = [
function (data) {
return JSON.stringify(data)
}
];
var res = axios.post(`${url}`, params).then((res) => {
console.log("res:", res)
if (res.status == 200) {
if (res.data.exception != undefined && res.data.exception) {
Message.error(res.data.msg)
return Promise.reject(res.data)
} else {
return res.data;
}
}
else
Message.error("server error")
})
return res;
},
getServerHost() {
return serverHost;
},
postfile(url, params, formData) {
console.log("postfile:", url, params)
axios.defaults.headers.post['Content-Type'] = 'multipart/form-data;'
axios.defaults.transformRequest = [
function (data) {
return data;
}
];
var res = axios.post(`${url}`, params).then((res) => {
console.log("res:", res)
if (res.status == 200) {
if (res.data.exception != undefined && res.data.exception) {
Message.error(res.data.msg)
return Promise.reject(res.data)
} else {
return res.data;
}
}
else
Message.error("server error")
})
return res;
},
download(url, fileName) {
axios({
method: 'get',
url: `${url}`,
responseType: 'blob'
}).then(res => {
const blob = new Blob([res.data]);
console.log(blob.size)
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
})
}
}

0
static/.gitkeep Normal file
View File

View File

@ -0,0 +1,27 @@
// A custom Nightwatch assertion.
// The assertion name is the filename.
// Example usage:
//
// browser.assert.elementCount(selector, count)
//
// For more information on custom assertions see:
// http://nightwatchjs.org/guide#writing-custom-assertions
exports.assertion = function (selector, count) {
this.message = 'Testing if element <' + selector + '> has count: ' + count
this.expected = count
this.pass = function (val) {
return val === this.expected
}
this.value = function (res) {
return res.value
}
this.command = function (cb) {
var self = this
return this.api.execute(function (selector) {
return document.querySelectorAll(selector).length
}, [selector], function (res) {
cb.call(self, res)
})
}
}

View File

@ -0,0 +1,46 @@
require('babel-register')
var config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
test_settings: {
default: {
selenium_port: 4444,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
}

48
test/e2e/runner.js Normal file
View File

@ -0,0 +1,48 @@
// 1. start the dev server using production config
process.env.NODE_ENV = 'testing'
const webpack = require('webpack')
const DevServer = require('webpack-dev-server')
const webpackConfig = require('../../build/webpack.prod.conf')
const devConfigPromise = require('../../build/webpack.dev.conf')
let server
devConfigPromise.then(devConfig => {
const devServerOptions = devConfig.devServer
const compiler = webpack(webpackConfig)
server = new DevServer(compiler, devServerOptions)
const port = devServerOptions.port
const host = devServerOptions.host
return server.listen(port, host)
})
.then(() => {
// 2. run the nightwatch test suite against it
// to run in additional browsers:
// 1. add an entry in test/e2e/nightwatch.conf.js under "test_settings"
// 2. add it to the --env flag below
// or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
// For more information on Nightwatch's config file, see
// http://nightwatchjs.org/guide#settings-file
let opts = process.argv.slice(2)
if (opts.indexOf('--config') === -1) {
opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js'])
}
if (opts.indexOf('--env') === -1) {
opts = opts.concat(['--env', 'chrome'])
}
const spawn = require('cross-spawn')
const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' })
runner.on('exit', function (code) {
server.close()
process.exit(code)
})
runner.on('error', function (err) {
server.close()
throw err
})
})

19
test/e2e/specs/test.js Normal file
View File

@ -0,0 +1,19 @@
// For authoring Nightwatch tests, see
// http://nightwatchjs.org/guide#usage
module.exports = {
'default e2e tests': function (browser) {
// automatically uses dev Server port from /config.index.js
// default: http://localhost:8080
// see nightwatch.conf.js
const devServer = browser.globals.devServerURL
browser
.url(devServer)
.waitForElementVisible('#app', 5000)
.assert.elementPresent('.hello')
.assert.containsText('h1', 'Welcome to Your Vue.js App')
.assert.elementCount('img', 1)
.end()
}
}

7
test/unit/.eslintrc Normal file
View File

@ -0,0 +1,7 @@
{
"env": {
"jest": true
},
"globals": {
}
}

30
test/unit/jest.conf.js Normal file
View File

@ -0,0 +1,30 @@
const path = require('path')
module.exports = {
rootDir: path.resolve(__dirname, '../../'),
moduleFileExtensions: [
'js',
'json',
'vue'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest'
},
testPathIgnorePatterns: [
'<rootDir>/test/e2e'
],
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
setupFiles: ['<rootDir>/test/unit/setup'],
mapCoverage: true,
coverageDirectory: '<rootDir>/test/unit/coverage',
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!src/router/index.js',
'!**/node_modules/**'
]
}

3
test/unit/setup.js Normal file
View File

@ -0,0 +1,3 @@
import Vue from 'vue'
Vue.config.productionTip = false

View File

@ -0,0 +1,11 @@
import Vue from 'vue'
import HelloWorld from '@/components/HelloWorld'
describe('HelloWorld.vue', () => {
it('should render correct contents', () => {
const Constructor = Vue.extend(HelloWorld)
const vm = new Constructor().$mount()
expect(vm.$el.querySelector('.hello h1').textContent)
.toEqual('Welcome to Your Vue.js App')
})
})

24
vue.config.js Normal file
View File

@ -0,0 +1,24 @@
/**
* 解决跨域问题
* @type {{devServer: {proxy: {"/api": {changeOrigin: boolean, pathRewrite: {"^/api": string}, target: string}}, host: string, open: boolean}}}
*/
module.exports = {
devServer: {
host: 'localhost',
open: true, // 自动打开浏览器
// 代理配置表在这里可以配置特定的请求代理到对应的API接口
// 例如将'localhost:8080/api/xxx'代理到'www.example.com/api/xxx'
proxy: {
'/api': { // 匹配所有以 '/api'开头的请求路径
target: 'http://localhost:9000', // 代理目标的基础路径
// secure: false, // 如果是https接口需要配置这个参数
changeOrigin: true, // 支持跨域
pathRewrite: { // 重写路径: 去掉路径中开头的'/api'
'^/api': '',
'^/api': '/'
}
}
}
}
}