Commit 33e5776f by 杨明

init

1 parent 59aa8259
{
"comments": false,
"env": {
"test": {
"presets": [
["env", {
"targets": { "node": 7 }
}],
"stage-0"
],
"plugins": ["istanbul"]
},
"main": {
"presets": [
["env", {
"targets": { "node": 7 }
}],
"stage-0"
]
},
"renderer": {
"presets": [
["env", {
"modules": false
}],
"stage-0"
]
},
"web": {
"presets": [
["env", {
"modules": false
}],
"stage-0"
]
}
},
"plugins": ["transform-runtime"]
}
"use strict";
process.env.NODE_ENV = "production";
const { say } = require("cfonts");
const chalk = require("chalk");
const del = require("del");
const Multispinner = require("multispinner");
const { spawn } = require("child_process");
const webpack = require("webpack");
const Listr = require("listr");
const mainConfig = require("./webpack.main.config");
const rendererConfig = require("./webpack.renderer.config");
const webConfig = require("./webpack.web.config");
const doneLog = chalk.bgGreen.white(" DONE ") + " ";
const errorLog = chalk.bgRed.white(" ERROR ") + " ";
const okayLog = chalk.bgBlue.white(" OKAY ") + " ";
const isCI = process.env.CI || false;
if (process.env.BUILD_TARGET === "clean") clean();
else if (process.env.BUILD_TARGET === "web") web();
else build();
function clean() {
del.sync(["build/*", "!build/icons", "!build/icons/icon.*"]);
console.log(`\n${doneLog}\n`);
process.exit();
}
async function build() {
greeting();
del.sync(["dist/electron/*", "!.gitkeep"]);
const tasks1 = ["main", "renderer"];
const m = new Multispinner(tasks1, {
preText: "building",
postText: "process",
});
let results = "";
const tasks = new Listr(
[
{
title: "building master process",
task: async () => {
await pack(mainConfig)
.then((result) => {
results += result + "\n\n";
})
.catch((err) => {
console.log(`\n ${errorLog}failed to build main process`);
console.error(`\n${err}\n`);
});
},
},
{
title: "building renderer process",
task: async () => {
await pack(rendererConfig)
.then((result) => {
results += result + "\n\n";
})
.catch((err) => {
console.log(`\n ${errorLog}failed to build renderer process`);
console.error(`\n${err}\n`);
});
},
},
],
{ concurrent: 2 }
);
await tasks
.run()
.then(() => {
process.stdout.write("\x1B[2J\x1B[0f");
console.log(`\n\n${results}`);
console.log(
`${okayLog}take it away ${chalk.yellow("`electron-builder`")}\n`
);
process.exit();
})
.catch((err) => {
process.exit(1);
});
}
function pack(config) {
return new Promise((resolve, reject) => {
config.mode = "production";
webpack(config, (err, stats) => {
if (err) reject(err.stack || err);
else if (stats.hasErrors()) {
let err = "";
stats
.toString({
chunks: false,
colors: true,
})
.split(/\r?\n/)
.forEach((line) => {
err += ` ${line}\n`;
});
reject(err);
} else {
resolve(
stats.toString({
chunks: false,
colors: true,
})
);
}
});
});
}
function web() {
del.sync(["dist/web/*", "!.gitkeep"]);
webConfig.mode = "production";
webpack(webConfig, (err, stats) => {
if (err || stats.hasErrors()) console.log(err);
console.log(
stats.toString({
chunks: false,
colors: true,
})
);
process.exit();
});
}
function greeting() {
const cols = process.stdout.columns;
let text = "";
if (cols > 85) text = "lets-build";
else if (cols > 60) text = "lets-|build";
else text = false;
if (text && !isCI) {
say(text, {
colors: ["yellow"],
font: "simple3d",
space: false,
});
} else console.log(chalk.yellow.bold("\n lets-build"));
console.log();
}
const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
hotClient.subscribe(event => {
/**
* Reload browser when HTMLWebpackPlugin emits a new index.html
*
* Currently disabled until jantimon/html-webpack-plugin#680 is resolved.
* https://github.com/SimulatedGREG/electron-vue/issues/437
* https://github.com/jantimon/html-webpack-plugin/issues/680
*/
// if (event.action === 'reload') {
// window.location.reload()
// }
/**
* Notify `mainWindow` when `main` process is compiling,
* giving notice for an expected reload of the `electron` process
*/
if (event.action === 'compiling') {
document.body.innerHTML += `
<style>
#dev-client {
background: #4fc08d;
border-radius: 4px;
bottom: 20px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
color: #fff;
font-family: 'Source Sans Pro', sans-serif;
left: 20px;
padding: 8px 12px;
position: absolute;
}
</style>
<div id="dev-client">
Compiling Main Process...
</div>
`
}
})
'use strict'
const chalk = require('chalk')
const electron = require('electron')
const path = require('path')
const { say } = require('cfonts')
const { spawn } = require('child_process')
const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
const webpackHotMiddleware = require('webpack-hot-middleware')
const mainConfig = require('./webpack.main.config')
const rendererConfig = require('./webpack.renderer.config')
let electronProcess = null
let manualRestart = false
let hotMiddleware
function logStats (proc, data) {
let log = ''
log += chalk.yellow.bold(`┏ ${proc} Process ${new Array((19 - proc.length) + 1).join('-')}`)
log += '\n\n'
if (typeof data === 'object') {
data.toString({
colors: true,
chunks: false
}).split(/\r?\n/).forEach(line => {
log += ' ' + line + '\n'
})
} else {
log += ` ${data}\n`
}
log += '\n' + chalk.yellow.bold(`┗ ${new Array(28 + 1).join('-')}`) + '\n'
console.log(log)
}
function startRenderer () {
return new Promise((resolve, reject) => {
rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)
rendererConfig.mode = 'development'
const compiler = webpack(rendererConfig)
hotMiddleware = webpackHotMiddleware(compiler, {
log: false,
heartbeat: 2500
})
compiler.hooks.compilation.tap('compilation', compilation => {
compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
hotMiddleware.publish({ action: 'reload' })
cb()
})
})
compiler.hooks.done.tap('done', stats => {
logStats('Renderer', stats)
})
const server = new WebpackDevServer(
compiler,
{
contentBase: path.join(__dirname, '../'),
quiet: true,
hot: true,
before (app, ctx) {
// app.use(hotMiddleware)
ctx.middleware.waitUntilValid(() => {
resolve()
})
}
}
)
server.listen(9080)
})
}
function startMain () {
return new Promise((resolve, reject) => {
mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
mainConfig.mode = 'development'
const compiler = webpack(mainConfig)
compiler.hooks.watchRun.tapAsync('watch-run', (compilation, done) => {
logStats('Main', chalk.white.bold('compiling...'))
hotMiddleware.publish({ action: 'compiling' })
done()
})
compiler.watch({}, (err, stats) => {
if (err) {
console.log(err)
return
}
logStats('Main', stats)
if (electronProcess && electronProcess.kill) {
manualRestart = true
process.kill(electronProcess.pid)
electronProcess = null
startElectron()
setTimeout(() => {
manualRestart = false
}, 5000)
}
resolve()
})
})
}
function startElectron () {
var args = [
'--inspect=5858',
path.join(__dirname, '../dist/electron/main.js')
]
// detect yarn or npm and process commandline args accordingly
if (process.env.npm_execpath.endsWith('yarn.js')) {
args = args.concat(process.argv.slice(3))
} else if (process.env.npm_execpath.endsWith('npm-cli.js')) {
args = args.concat(process.argv.slice(2))
}
electronProcess = spawn(electron, args)
electronProcess.stdout.on('data', data => {
electronLog(data, 'blue')
})
electronProcess.stderr.on('data', data => {
electronLog(data, 'red')
})
electronProcess.on('close', () => {
if (!manualRestart) process.exit()
})
}
function electronLog (data, color) {
let log = ''
data = data.toString().split(/\r?\n/)
data.forEach(line => {
log += ` ${line}\n`
})
if (/[0-9A-z]+/.test(log)) {
console.log(
chalk[color].bold('┏ Electron -------------------') +
'\n\n' +
log +
chalk[color].bold('┗ ----------------------------') +
'\n'
)
}
}
function greeting () {
const cols = process.stdout.columns
let text = ''
if (cols > 104) text = 'electron-vue'
else if (cols > 76) text = 'electron-|vue'
else text = false
if (text) {
say(text, {
colors: ['yellow'],
font: 'simple3d',
space: false
})
} else console.log(chalk.yellow.bold('\n electron-vue'))
console.log(chalk.blue(' getting ready...') + '\n')
}
function init () {
greeting()
Promise.all([startRenderer(), startMain()])
.then(() => {
startElectron()
})
.catch(err => {
console.error(err)
})
}
init()
'use strict'
process.env.BABEL_ENV = 'main'
const path = require('path')
const { dependencies } = require('../package.json')
const webpack = require('webpack')
const MinifyPlugin = require("babel-minify-webpack-plugin")
let mainConfig = {
entry: {
main: path.join(__dirname, '../src/main/index.js')
},
externals: [
...Object.keys(dependencies || {})
],
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.node$/,
use: 'node-loader'
}
]
},
node: {
__dirname: process.env.NODE_ENV !== 'production',
__filename: process.env.NODE_ENV !== 'production'
},
output: {
filename: '[name].js',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '../dist/electron')
},
plugins: [
new webpack.NoEmitOnErrorsPlugin()
],
resolve: {
extensions: ['.js', '.json', '.node']
},
target: 'electron-main'
}
/**
* Adjust mainConfig for development settings
*/
if (process.env.NODE_ENV !== 'production') {
mainConfig.plugins.push(
new webpack.DefinePlugin({
'__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
})
)
}
/**
* Adjust mainConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
mainConfig.plugins.push(
new MinifyPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
})
)
}
module.exports = mainConfig
'use strict'
process.env.BABEL_ENV = 'renderer'
const path = require('path')
const { dependencies } = require('../package.json')
const webpack = require('webpack')
const MinifyPlugin = require("babel-minify-webpack-plugin")
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
/**
* List of node_modules to include in webpack bundle
*
* Required for specific packages like Vue UI libraries
* that provide pure *.vue files that need compiling
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals
*/
let whiteListedModules = ['vue']
let rendererConfig = {
devtool: '#cheap-module-eval-source-map',
entry: {
renderer: path.join(__dirname, '../src/renderer/main.js')
},
externals: [
...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d))
],
module: {
rules: [
{
test: /\.less$/,
use: ['vue-style-loader', 'css-loader', 'less-loader']
},
{
test: /\.css$/,
use: ['vue-style-loader', 'css-loader']
},
{
test: /\.html$/,
use: 'vue-html-loader'
},
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.node$/,
use: 'node-loader'
},
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
extractCSS: process.env.NODE_ENV === 'production',
loaders: {
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
scss: 'vue-style-loader!css-loader!sass-loader',
less: 'vue-style-loader!css-loader!less-loader'
}
}
}
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
use: {
loader: 'url-loader',
query: {
limit: 10000,
name: 'imgs/[name]--[folder].[ext]'
}
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'media/[name]--[folder].[ext]'
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: {
loader: 'url-loader',
query: {
limit: 10000,
name: 'fonts/[name]--[folder].[ext]'
}
}
}
]
},
node: {
__dirname: process.env.NODE_ENV !== 'production',
__filename: process.env.NODE_ENV !== 'production'
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({filename: 'styles.css'}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options,
},
process,
};
},
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new webpack.NoEmitOnErrorsPlugin()
],
output: {
filename: '[name].js',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '../dist/electron')
},
resolve: {
alias: {
'@': path.join(__dirname, '../src/renderer'),
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['.js', '.vue', '.json', '.css', '.node']
},
target: 'electron-renderer'
}
/**
* Adjust rendererConfig for development settings
*/
if (process.env.NODE_ENV !== 'production') {
rendererConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
})
)
}
/**
* Adjust rendererConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
rendererConfig.devtool = ''
rendererConfig.plugins.push(
new MinifyPlugin(),
new CopyWebpackPlugin([
{
from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/electron/static'),
ignore: ['.*']
}
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
)
}
module.exports = rendererConfig
'use strict'
process.env.BABEL_ENV = 'web'
const path = require('path')
const webpack = require('webpack')
const MinifyPlugin = require("babel-minify-webpack-plugin")
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
let webConfig = {
devtool: '#cheap-module-eval-source-map',
entry: {
web: path.join(__dirname, '../src/renderer/main.js')
},
module: {
rules: [
{
test: /\.less$/,
use: ['vue-style-loader', 'css-loader', 'less-loader']
},
{
test: /\.css$/,
use: ['vue-style-loader', 'css-loader']
},
{
test: /\.html$/,
use: 'vue-html-loader'
},
{
test: /\.js$/,
use: 'babel-loader',
include: [ path.resolve(__dirname, '../src/renderer') ],
exclude: /node_modules/
},
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
extractCSS: true,
loaders: {
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
scss: 'vue-style-loader!css-loader!sass-loader',
less: 'vue-style-loader!css-loader!less-loader'
}
}
}
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
use: {
loader: 'url-loader',
query: {
limit: 10000,
name: 'imgs/[name].[ext]'
}
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: {
loader: 'url-loader',
query: {
limit: 10000,
name: 'fonts/[name].[ext]'
}
}
}
]
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({filename: 'styles.css'}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options,
},
process,
};
},
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: false
}),
new webpack.DefinePlugin({
'process.env.IS_WEB': 'true'
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
output: {
filename: '[name].js',
path: path.join(__dirname, '../dist/web')
},
resolve: {
alias: {
'@': path.join(__dirname, '../src/renderer'),
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['.js', '.vue', '.json', '.css']
},
target: 'web'
}
/**
* Adjust webConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
webConfig.devtool = ''
webConfig.plugins.push(
new MinifyPlugin(),
new CopyWebpackPlugin([
{
from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/web/static'),
ignore: ['.*']
}
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
)
}
module.exports = webConfig
.DS_Store
dist/electron/*
dist/web/*
build/*
!build/icons
coverage
node_modules/
npm-debug.log
npm-debug.log.*
thumbs.db
!.gitkeep
# Commented sections below can be used to run tests on the CI server
# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing
osx_image: xcode8.3
sudo: required
dist: trusty
language: c
matrix:
include:
- os: osx
- os: linux
env: CC=clang CXX=clang++ npm_config_clang=1
compiler: clang
cache:
directories:
- node_modules
- "$HOME/.electron"
- "$HOME/.cache"
addons:
apt:
packages:
- libgnome-keyring-dev
- icnsutils
#- xvfb
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install git-lfs; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils; fi
install:
#- export DISPLAY=':99.0'
#- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- nvm install 10
- curl -o- -L https://yarnpkg.com/install.sh | bash
- source ~/.bashrc
- npm install -g xvfb-maybe
- yarn
before_script:
- git lfs pull
script:
#- xvfb-maybe node_modules/.bin/karma start test/unit/karma.conf.js
#- yarn run pack && xvfb-maybe node_modules/.bin/mocha test/e2e
- yarn run build
branches:
only:
- master
# sendEmail
> An electron-vue project
#### Build Setup
```bash
# install dependencies
npm install
# serve with hot reload at localhost:9080
npm run dev
# build electron application for production
npm run build
# run unit & end-to-end tests
npm test
```
---
This project was generated with [electron-vue](https://github.com/SimulatedGREG/electron-vue)@[8d4ed60](https://github.com/SimulatedGREG/electron-vue/tree/8d4ed607d65300381a8f47d97923eb07832b1a9a) using [vue-cli](https://github.com/vuejs/vue-cli). Documentation about the original structure can be found [here](https://simulatedgreg.gitbooks.io/electron-vue/content/index.html).
# Commented sections below can be used to run tests on the CI server
# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing
version: 0.1.{build}
branches:
only:
- master
image: Visual Studio 2017
platform:
- x64
cache:
- node_modules
- '%APPDATA%\npm-cache'
- '%USERPROFILE%\.electron'
- '%USERPROFILE%\AppData\Local\Yarn\cache'
init:
- git config --global core.autocrlf input
install:
- ps: Install-Product node 8 x64
- git reset --hard HEAD
- yarn
- node --version
build_script:
#- yarn test
- yarn build
test: off
No preview for this file type
No preview for this file type
File mode changed
File mode changed
This diff could not be displayed because it is too large.
{
"name": "sendEmail",
"version": "0.0.1",
"author": "yangming <yangming@didihu.com.cn>",
"description": "An electron-vue project",
"license": null,
"main": "./dist/electron/main.js",
"scripts": {
"build": "node .electron-vue/build.js && electron-builder",
"win32": "node .electron-vue/build.js && electron-builder --platform=win32 --arch=ia32",
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "node .electron-vue/dev-runner.js",
"e2e": "npm run pack && mocha test/e2e",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"test": "npm run unit && npm run e2e",
"unit": "karma start test/unit/karma.conf.js",
"postinstall": ""
},
"build": {
"productName": "sendEmail",
"appId": "com.example.yourapp",
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/icon.icns"
},
"win": {
"icon": "build/icons/icon.ico"
},
"linux": {
"icon": "build/icons"
}
},
"dependencies": {
"axios": "^0.18.0",
"multispinner": "^0.2.1",
"vue": "^2.5.16",
"compressing": "^1.5.1",
"element-ui": "^2.15.6",
"nodemailer": "^6.7.3",
"vue-electron": "^1.0.6",
"vue-router": "^3.0.1",
"vuex": "^3.0.1",
"vuex-electron": "^1.0.0"
},
"devDependencies": {
"ajv": "^6.5.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"babel-minify-webpack-plugin": "^0.3.1",
"cfonts": "^2.1.2",
"chalk": "^2.4.1",
"copy-webpack-plugin": "^4.5.1",
"cross-env": "^5.1.6",
"css-loader": "^0.28.11",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^2.0.4",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
"electron-builder": "^20.19.2",
"mini-css-extract-plugin": "0.4.0",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"inject-loader": "^4.0.1",
"karma": "^2.0.2",
"karma-chai": "^0.1.0",
"karma-coverage": "^1.1.2",
"karma-electron": "^6.0.0",
"karma-mocha": "^1.3.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^3.0.0",
"listr": "^0.14.3",
"require-dir": "^1.0.0",
"spectron": "^3.8.0",
"babel-plugin-istanbul": "^4.1.6",
"chai": "^4.1.2",
"mocha": "^5.2.0",
"node-loader": "^0.6.0",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1",
"vue-html-loader": "^1.2.4",
"vue-loader": "^15.2.4",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.16",
"webpack-cli": "^3.0.8",
"webpack": "^4.15.1",
"webpack-dev-server": "^3.1.4",
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.3"
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>email-model</title>
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
</script>
<% } %>
</head>
<body>
<div id="app"></div>
<!-- Set `__static` path to static files in production -->
<% if (!process.browser) { %>
<script>
if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
</script>
<% } %>
<!-- webpack builds are automatically injected -->
</body>
</html>
/**
* This file is used specifically and only for development. It installs
* `electron-debug` & `vue-devtools`. There shouldn't be any need to
* modify this file, but it can be used to extend your development
* environment.
*/
/* eslint-disable */
// Install `electron-debug` with `devtron`
require("electron-debug")({ showDevTools: true });
// Install `vue-devtools`
require("electron").app.on("ready", () => {
let installExtension = require("electron-devtools-installer");
installExtension
.default(installExtension.VUEJS_DEVTOOLS)
.then(() => {})
.catch((err) => {
console.log("Unable to install `vue-devtools`: \n", err);
});
});
// Require `main` process to boot app
require("./index");
import { app, BrowserWindow } from "electron";
import "../renderer/store";
import { ipcMain } from "electron";
var path = require("path");
var nodemailer = require("nodemailer");
const compressing = require("compressing");
const { exec } = require("child_process");
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== "development") {
global.__static = require("path")
.join(__dirname, "/static")
.replace(/\\/g, "\\\\");
}
let mainWindow;
const winURL =
process.env.NODE_ENV === "development"
? `http://localhost:9080`
: `file://${__dirname}/index.html`;
function createWindow() {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
height: 563,
useContentSize: true,
width: 1000,
});
mainWindow.loadURL(winURL);
mainWindow.on("closed", () => {
mainWindow = null;
});
}
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
ipcMain.on("aaa", (event, data) => {
event.sender.send("bbb", 1);
});
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});
ipcMain.on("send-email", (event, data) => {
var dataInfo = data.emailForm;
var {
title,
pass,
fromPeople,
toPeople,
ccPeople,
fileInfo,
htmlContent,
isFile,
} = dataInfo;
var attachments = [];
if (fileInfo.length > 0 && isFile == 1) {
fileInfo.forEach((fileItem) => {
attachments.push({
filename: fileItem.fileName,
path: fileItem.filePath,
});
});
}
var transporter = nodemailer.createTransport({
service: "IMAP",
secureConnection: true, // 使用 SSL
host: "smtphz.qiye.163.com",
port: 465,
auth: {
user: fromPeople,
pass, //授权码
},
});
var mailOptions = {
from: fromPeople, // 发送者
to: toPeople, // 接受者,可以同时发送多个,以逗号隔开
cc: ccPeople, // 抄送者,可以同时发送多个,以逗号隔开
subject: title, // 标题
//text: '', // 文本
html: htmlContent,
attachments,
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
event.sender.send("send-message", {
code: -1,
info: err,
});
return;
}
event.sender.send("send-message", {
code: 0,
info: "ok",
});
});
});
ipcMain.on("send-build", (event, data) => {
var fileInfo = data.fileInfo;
const disk = fileInfo.path.split(":")[0];
const packageParth = fileInfo.path;
let build = exec(`cd /d ${packageParth} && npm run build`, (err) => {
if (err) throw err;
});
build.stdout.pipe(process.stdout);
build.on("exit", () => {
compress();
});
function compress() {
compressing.zip
.compressDir(
path.join(fileInfo.filePath.split(".zip")[0]),
path.join(fileInfo.filePath)
)
.then(() => {
event.sender.send("build-message", {
code: 0,
info: "ok",
});
})
.catch((err) => {
event.sender.send("build-message", {
code: -1,
info: err,
});
});
}
});
import { ipcMain } from "electron";
var path = require("path");
var nodemailer = require("nodemailer");
const compressing = require("compressing");
const { exec } = require("child_process");
ipcMain.on("send-email", (event, data) => {
var dataInfo = data.emailForm;
var { title, pass, fromPeople, toPeople, ccPeople, fileInfo, htmlContent } =
dataInfo;
var attachments = [];
fileInfo.forEach((fileItem) => {
attachments.push({
filename: fileItem.fileName,
path: fileItem.filePath,
});
});
var transporter = nodemailer.createTransport({
service: "IMAP",
secureConnection: true, // 使用 SSL
host: "smtphz.qiye.163.com",
port: 465,
auth: {
user: fromPeople,
pass, //授权码
},
});
var mailOptions = {
from: fromPeople, // 发送者
to: toPeople, // 接受者,可以同时发送多个,以逗号隔开
cc: ccPeople, // 抄送者,可以同时发送多个,以逗号隔开
subject: title, // 标题
//text: '', // 文本
html: htmlContent,
attachments,
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
event.sender.send("send-message", {
code: -1,
info: err,
});
return;
}
event.sender.send("send-message", {
code: 0,
info: "ok",
});
});
});
ipcMain.on("send-build", (event, data) => {
var fileInfo = data.fileInfo;
const disk = fileInfo.path.split(":")[0];
const packageParth = fileInfo.path;
let build = exec(`cd /${disk} ${packageParth} && npm run build`, (err) => {
if (err) throw err;
});
build.stdout.pipe(process.stdout);
build.on("exit", () => {
compress();
});
function compress() {
compressing.zip
.compressDir(
path.join(fileInfo.filePath.split(".zip")[0]),
path.join(fileInfo.filePath)
)
.then(() => {
event.sender.send("build-message", {
code: 0,
info: "ok",
});
})
.catch((err) => {
event.sender.send("build-message", {
code: -1,
info: err,
});
});
}
});
<template>
<div id="app">
<router-view></router-view>
</div>
</template>
<script>
export default {
name: "sendEmail",
};
</script>
<style>
/* CSS */
</style>
<template>
<div class="main">
<div class="main-form">
<el-form
:model="emailForm"
:rules="rules"
ref="ruleForm"
label-width="80px"
class="demo-ruleForm"
>
<el-form-item label="邮件标题" prop="title">
<el-input v-model="emailForm.title"></el-input>
</el-form-item>
<el-form-item label="授权码" prop="pass">
<el-input v-model="emailForm.pass"></el-input>
</el-form-item>
<el-form-item label="发送人" prop="fromPeople">
<el-input v-model="emailForm.fromPeople"></el-input>
</el-form-item>
<el-form-item label="收件人" prop="toPeople">
<el-input v-model="emailForm.toPeople"></el-input>
</el-form-item>
<el-form-item label="抄送人" prop="ccPeople">
<el-input
type="textarea"
:rows="3"
v-model="emailForm.ccPeople"
></el-input>
</el-form-item>
<el-form-item label="携带附件">
<el-radio-group v-model="emailForm.isFile">
<el-radio label="1">是</el-radio>
<el-radio label="2">否</el-radio>
</el-radio-group>
</el-form-item>
<div class="file-panel" v-if="emailForm.isFile == 1">
<div
class="file-panel-item"
v-for="(item, index) in emailForm.fileInfo"
:key="index"
>
<i class="el-icon-close" @click="removeFile(index)"></i>
<el-form-item
label="项目路径"
:prop="`fileInfo[${index}].path`"
:rules="{
required: true,
message: '请输入项目路径',
trigger: 'blur',
}"
>
<el-input v-model="item.path"></el-input>
</el-form-item>
<el-form-item
label="附件路径"
:prop="`fileInfo[${index}].filePath`"
:rules="{
required: true,
message: '请输入附件路径',
trigger: 'blur',
}"
>
<el-input v-model="item.filePath"></el-input>
</el-form-item>
</div>
<div class="add-item">
<el-button @click="addFile">添加</el-button>
</div>
</div>
</el-form>
</div>
<div
class="textarea-content"
contenteditable="true"
v-html="emailForm.htmlContent"
></div>
<div class="add-item">
<el-button @click="submitForm">发送</el-button>
</div>
<div class="loading-containner" v-if="loading">
<div class="loading-box">打包中</div>
</div>
</div>
</template>
<script>
import { util } from "../../utils/util";
export default {
name: "HelloWorld",
data() {
return {
loading: false,
emailForm: {
title: "【提测】【SCRM-V2.0.0-0330】 嘀加企微管家前端第二轮提测",
pass: "xqGTv2AXbyEPJkKm",
fromPeople: "yangming@didihu.com.cn",
toPeople: "yangming@didihu.com.cn",
ccPeople: util.ccPeople,
fileInfo: [
{
path: "D:\\project\\git\\scrm-micro-drainage1.0.2\\scrm-micro-drainage",
filePath:
"D:\\project\\git\\scrm-micro-drainage1.0.2\\dist\\drainage.zip",
},
],
htmlContent: util.htmlContent,
isFile: "1",
},
rules: {
pass: [{ required: true, message: "请输入授权码", trigger: "blur" }],
path: [{ required: true, message: "请输入项目路径", trigger: "blur" }],
fromPeople: [
{ required: true, message: "请输入发送人", trigger: "blur" },
],
toPeople: [
{ required: true, message: "请输入收件人", trigger: "blur" },
],
ccPeople: [
{ required: true, message: "请输入抄送人", trigger: "blur" },
],
title: [{ required: true, message: "请输入邮件标配", trigger: "blur" }],
},
};
},
mounted() {
const text = JSON.parse(localStorage.getItem("text"));
if (text) {
this.emailForm = JSON.parse(localStorage.getItem("text"));
}
},
watch: {
emailForm: {
handler(val) {
const { fromPeople, toPeople, ccPeople } = util.deepClone(
this.emailForm
);
this.emailForm.fromPeople = util.regexEmail(fromPeople);
this.emailForm.toPeople = util.regexEmail(toPeople);
this.emailForm.ccPeople = util.regexEmail(ccPeople);
},
deep: true,
},
},
methods: {
submitForm() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
this.handleBuild();
} else {
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
addFile() {
this.emailForm.fileInfo.push({
path: "",
fileName: "",
filePath: "",
});
},
removeFile(index) {
this.emailForm.fileInfo.splice(index, 1);
},
submit() {
this.emailForm.htmlContent =
document.querySelector(".textarea-content").innerHTML;
let formData = {
emailForm: this.emailForm,
};
this.$electron.ipcRenderer.send("send-email", formData);
this.$electron.ipcRenderer.on("send-message", (event, arg) => {
if (arg.code == 0) {
this.$message({
message: "发送成功",
type: "success",
});
localStorage.setItem("text", JSON.stringify(this.emailForm));
} else {
this.$message.error("发送失败");
}
this.loading = false;
});
},
handleBuild() {
this.loading = true;
let buildNum = 0;
const fileInfo = this.emailForm.fileInfo;
if (!fileInfo || fileInfo.length == 0 || this.emailForm.isFile == 2) {
this.submit();
return;
}
fileInfo.forEach((item) => {
let index = item.filePath.lastIndexOf("\\") + 1;
let fileName = item.filePath.substring(index);
if (!fileName.includes("zip")) {
this.$message.error("请检查附件路径");
this.loading = false;
return;
}
item.fileName = fileName;
let formData = {
fileInfo: item,
};
this.$electron.ipcRenderer.send("send-build", formData);
this.$electron.ipcRenderer.on("build-message", (event, arg) => {
if (arg.code == 0) {
buildNum++;
} else {
this.$message.error("打包失败");
this.loading = false;
}
if (buildNum == fileInfo.length) {
this.submit();
}
});
});
},
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.main-form {
width: 800px;
margin: 0 auto;
}
.textarea-content {
width: 800px;
border: 1px solid #666666;
margin: 0 auto;
}
.file-panel {
box-shadow: 0px 10px 20px 0px rgba(88, 80, 255, 0.1);
padding: 10px;
}
.file-panel-item {
border: 1px solid #ebeef5;
padding: 30px 20px 0px;
margin-bottom: 10px;
position: relative;
}
.el-icon-close {
position: absolute;
right: 5px;
top: 5px;
font-size: 20px;
cursor: pointer;
}
.add-item {
text-align: center;
margin-top: 10px;
}
.loading-containner {
top: 0px;
left: 0px;
position: fixed;
width: 100%;
background: rgba(255, 255, 255, 0.8);
z-index: 5000;
height: 100%;
}
.loading-box {
position: absolute;
top: 50%;
left: 50%;
margin-top: -28px;
margin-left: -88px;
width: 176px;
font-size: 14px;
color: #ffffff;
line-height: 54px;
text-align: center;
height: 54px;
background: #666666;
border-radius: 2px;
}
.loading-box::after {
content: "";
position: absolute;
top: 0%;
bottom: 0;
animation: dot 3s infinite steps(3, start);
color: #ffffff;
}
@keyframes dot {
33.33% {
content: ".";
}
66.67% {
content: ". .";
}
100% {
content: ". . .";
}
}
</style>
<template>
<div>
<div class="title">Information</div>
<div class="items">
<div class="item">
<div class="name">Path:</div>
<div class="value">{{ path }}</div>
</div>
<div class="item">
<div class="name">Route Name:</div>
<div class="value">{{ name }}</div>
</div>
<div class="item">
<div class="name">Vue.js:</div>
<div class="value">{{ vue }}</div>
</div>
<div class="item">
<div class="name">Electron:</div>
<div class="value">{{ electron }}</div>
</div>
<div class="item">
<div class="name">Node:</div>
<div class="value">{{ node }}</div>
</div>
<div class="item">
<div class="name">Platform:</div>
<div class="value">{{ platform }}</div>
</div>
</div>
</div>
</template>
<script>
export default {
data () {
return {
electron: process.versions.electron,
name: this.$route.name,
node: process.versions.node,
path: this.$route.path,
platform: require('os').platform(),
vue: require('vue/package.json').version
}
}
}
</script>
<style scoped>
.title {
color: #888;
font-size: 18px;
font-weight: initial;
letter-spacing: .25px;
margin-top: 10px;
}
.items { margin-top: 8px; }
.item {
display: flex;
margin-bottom: 6px;
}
.item .name {
color: #6a6a6a;
margin-right: 6px;
}
.item .value {
color: #35495e;
font-weight: bold;
}
</style>
import Vue from "vue";
import axios from "axios";
import App from "./App";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.config.productionTip = false;
if (!process.env.IS_WEB) Vue.use(require("vue-electron"));
Vue.http = Vue.prototype.$http = axios;
Vue.config.productionTip = false;
Vue.use(ElementUI);
/* eslint-disable no-new */
new Vue({
components: { App },
router,
store,
template: "<App/>",
}).$mount("#app");
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'landing-page',
component: require('@/components/LandingPage').default
},
{
path: '*',
redirect: '/'
}
]
})
import Vue from 'vue'
import Vuex from 'vuex'
import { createPersistedState, createSharedMutations } from 'vuex-electron'
import modules from './modules'
Vue.use(Vuex)
export default new Vuex.Store({
modules,
plugins: [
createPersistedState(),
createSharedMutations()
],
strict: process.env.NODE_ENV !== 'production'
})
const state = {
main: 0
}
const mutations = {
DECREMENT_MAIN_COUNTER (state) {
state.main--
},
INCREMENT_MAIN_COUNTER (state) {
state.main++
}
}
const actions = {
someAsyncTask ({ commit }) {
// do something async
commit('INCREMENT_MAIN_COUNTER')
}
}
export default {
state,
mutations,
actions
}
/**
* The file enables `@/store/index.js` to import all vuex modules
* in a one-shot manner. There should not be any reason to edit this file.
*/
const files = require.context('.', false, /\.js$/)
const modules = {}
files.keys().forEach(key => {
if (key === './index.js') return
modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
})
export default modules
File mode changed
{
"env": {
"mocha": true
},
"globals": {
"assert": true,
"expect": true,
"should": true,
"__static": true
}
}
'use strict'
// Set BABEL_ENV to use proper env config
process.env.BABEL_ENV = 'test'
// Enable use of ES6+ on required files
require('babel-register')({
ignore: /node_modules/
})
// Attach Chai APIs to global scope
const { expect, should, assert } = require('chai')
global.expect = expect
global.should = should
global.assert = assert
// Require all JS files in `./specs` for Mocha to consume
require('require-dir')('./specs')
import utils from "../utils";
describe("Launch", function () {
beforeEach(utils.beforeEach);
afterEach(utils.afterEach);
it("shows the proper application title", function () {
return this.app.client.getTitle().then((title) => {
expect(title).to.equal("sendEmail");
});
});
});
import electron from 'electron'
import { Application } from 'spectron'
export default {
afterEach () {
this.timeout(10000)
if (this.app && this.app.isRunning()) {
return this.app.stop()
}
},
beforeEach () {
this.timeout(10000)
this.app = new Application({
path: electron,
args: ['dist/electron/main.js'],
startTimeout: 10000,
waitTimeout: 10000
})
return this.app.start()
}
}
import Vue from 'vue'
Vue.config.devtools = false
Vue.config.productionTip = false
// require all test files (files that ends with .spec.js)
const testsContext = require.context('./specs', true, /\.spec$/)
testsContext.keys().forEach(testsContext)
// require all src files except main.js for coverage.
// you can also change this to match only the subset of files that
// you want coverage for.
const srcContext = require.context('../../src/renderer', true, /^\.\/(?!main(\.js)?$)/)
srcContext.keys().forEach(srcContext)
'use strict'
const path = require('path')
const merge = require('webpack-merge')
const webpack = require('webpack')
const baseConfig = require('../../.electron-vue/webpack.renderer.config')
const projectRoot = path.resolve(__dirname, '../../src/renderer')
// Set BABEL_ENV to use proper preset config
process.env.BABEL_ENV = 'test'
let webpackConfig = merge(baseConfig, {
devtool: '#inline-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"testing"'
})
]
})
// don't treat dependencies as externals
delete webpackConfig.entry
delete webpackConfig.externals
delete webpackConfig.output.libraryTarget
// apply vue option to apply isparta-loader on js
webpackConfig.module.rules
.find(rule => rule.use.loader === 'vue-loader').use.options.loaders.js = 'babel-loader'
module.exports = config => {
config.set({
browsers: ['visibleElectron'],
client: {
useIframe: false
},
coverageReporter: {
dir: './coverage',
reporters: [
{ type: 'lcov', subdir: '.' },
{ type: 'text-summary' }
]
},
customLaunchers: {
'visibleElectron': {
base: 'Electron',
flags: ['--show']
}
},
frameworks: ['mocha', 'chai'],
files: ['./index.js'],
preprocessors: {
'./index.js': ['webpack', 'sourcemap']
},
reporters: ['spec', 'coverage'],
singleRun: true,
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
}
})
}
import Vue from 'vue'
import LandingPage from '@/components/LandingPage'
describe('LandingPage.vue', () => {
it('should render correct contents', () => {
const vm = new Vue({
el: document.createElement('div'),
render: h => h(LandingPage)
}).$mount()
expect(vm.$el.querySelector('.title').textContent).to.contain('Welcome to your new project!')
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!