Skip to content

Commit

Permalink
Fix broken build number
Browse files Browse the repository at this point in the history
  • Loading branch information
proAlexandr committed May 27, 2019
1 parent 1d02a6f commit 630cd6b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
45 changes: 29 additions & 16 deletions .electron-vue/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ if (process.env.BUILD_TARGET === 'clean') clean()
else if (process.env.BUILD_TARGET === 'web') web()
else build()

function clean () {
function clean() {
del.sync(['build/*', '!build/icons', '!build/icons/icon.*'])
console.log(`\n${doneLog}\n`)
process.exit()
}

async function build () {
await setBuildVersionAndNumber()
async function build() {
const [ver, buildNumber] = await setBuildVersionAndNumber()

del.sync(['dist/electron/*', '!.gitkeep'])

Expand Down Expand Up @@ -64,7 +64,15 @@ async function build () {
process.exit(1)
})

pack(rendererConfig).then(result => {
pack({
...rendererConfig,
plugins: [
...rendererConfig.plugins,
new webpack.DefinePlugin({
'process.env.BUILD': `"${buildNumber}"`
}),
]
}).then(result => {
results += result + '\n\n'
m.success('renderer')
}).catch(err => {
Expand All @@ -84,14 +92,19 @@ async function build () {
}

async function setBuildVersionAndNumber() {
const { version } = packageJson
const buildNumber = dateFormat(new Date(), 'yyyyddmm-HHMMss', true)

await mkdirp(path.resolve(__dirname, '../build'))
return Promise.all([
fs.writeFile(path.resolve(__dirname, '../build/.number'), dateFormat(new Date(), "yyyyddmm-HHMMss", true)),
fs.writeFile(path.resolve(__dirname, '../build/.version'), packageJson.version),
await Promise.all([
fs.writeFile(path.resolve(__dirname, '../build/.number'), buildNumber),
fs.writeFile(path.resolve(__dirname, '../build/.version'), version),
])

return [version, buildNumber]
}

function pack (config) {
function pack(config) {
return new Promise((resolve, reject) => {
config.mode = 'production'
webpack(config, (err, stats) => {
Expand All @@ -103,10 +116,10 @@ function pack (config) {
chunks: false,
colors: true
})
.split(/\r?\n/)
.forEach(line => {
err += ` ${line}\n`
})
.split(/\r?\n/)
.forEach(line => {
err += ` ${line}\n`
})

reject(err)
} else {
Expand All @@ -119,7 +132,7 @@ function pack (config) {
})
}

function web () {
function web() {
del.sync(['dist/web/*', '!.gitkeep'])
webConfig.mode = 'production'
webpack(webConfig, (err, stats) => {
Expand Down Expand Up @@ -147,11 +160,11 @@ async function prepareLogo() {
.background('none')
.rotate('none', 45)
.resize(512, 512)
.write(path.resolve(__dirname, '../build/icons/256x256.png'), function (err) {
.write(path.resolve(__dirname, '../build/icons/256x256.png'), function(err) {
if (err) reject(err)
else resolve()
});
})
})

return createIconsDir.then(() => Promise.all([x256]) )
return createIconsDir.then(() => Promise.all([x256]))
}
16 changes: 2 additions & 14 deletions .electron-vue/webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ let rendererConfig = {
],
module: {
rules: [
// {
// test: /\.(js|vue)$/,
// enforce: 'pre',
// exclude: /node_modules/,
// use: {
// loader: 'eslint-loader',
// options: {
// formatter: require('eslint-friendly-formatter')
// }
// }
// },
{
test: /\.scss$/,
use: ['vue-style-loader', 'css-loader', 'sass-loader']
Expand Down Expand Up @@ -121,7 +110,7 @@ let rendererConfig = {
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({filename: 'styles.css'}),
new MiniCssExtractPlugin({ filename: 'styles.css' }),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
Expand Down Expand Up @@ -179,8 +168,7 @@ if (process.env.NODE_ENV === 'production') {
}
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
'process.env.BUILD': `"${process.env.BUILD}"`
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/components/Layout/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export default {
},
methods: {
showVerbose() {
const message = `Version label: ${this.version}\nVersion: ${packageJs.version}\nBuild: ${process.env.BUILD}`
const message = [
`Version label: ${this.version}`,
`Version: ${packageJs.version}`,
`Build: ${process.env.BUILD}`,
`Env: ${process.env.NODE_ENV}`
].join('\n')
showMessageBox(message)
}
}
Expand Down

0 comments on commit 630cd6b

Please sign in to comment.