Skip to content

Commit

Permalink
优化编译脚本, 完善多端打包脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
lanyuanxiaoyao committed Dec 23, 2020
1 parent 3e4faed commit bb53c62
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public/node_modules
public/preload.js
public/plugin.js
public/squirrel
public/plugin.json
public/logo.png

# local env files
.env.local
Expand Down
3 changes: 2 additions & 1 deletion public_utools/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"main": "index.html",
"preload": "preload.js",
"pluginSetting": {
"single": true
"single": true,
"height": 580
},
"features": [
{
Expand Down
15 changes: 9 additions & 6 deletions scripts/pre-build-electron.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const path = require('path')
const fs = require('fs')
const {copyFilesSync} = require('./utils')
const {batchCopyFilesSync, batchDeleteFilesSync, listDirExcludeFiles} = require('./utils')

batchDeleteFilesSync(listDirExcludeFiles(path.join(__dirname, '..', 'public'), ['index.html']))

let publicPath = path.join(__dirname, '..', 'public')
let publicSourcePath = path.join(__dirname, '..', 'public_electron')
Expand All @@ -10,8 +12,9 @@ if (!fs.existsSync(distPath)) {
fs.mkdirSync(distPath)
}

copyFilesSync(path.join(publicSourcePath, 'preload.js'), `${publicPath}/preload.js`)
copyFilesSync(path.join(publicSourcePath, 'preload.js'), `${distPath}/preload.js`)

copyFilesSync(path.join(publicSourcePath, 'squirrel'), `${publicPath}/squirrel`)
copyFilesSync(path.join(publicSourcePath, 'squirrel'), `${distPath}/squirrel`)
batchCopyFilesSync([
[path.join(publicSourcePath, 'preload.js'), `${publicPath}/preload.js`],
[path.join(publicSourcePath, 'preload.js'), `${distPath}/preload.js`],
[path.join(publicSourcePath, 'squirrel'), `${publicPath}/squirrel`],
[path.join(publicSourcePath, 'squirrel'), `${distPath}/squirrel`]
])
15 changes: 11 additions & 4 deletions scripts/pre-build-utools.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
const path = require('path')
const {copyFilesSync} = require('./utils')
const {batchCopyFilesSync, batchDeleteFilesSync, listDirExcludeFiles} = require('./utils')

batchDeleteFilesSync(listDirExcludeFiles(path.join(__dirname, '..', 'public'), ['index.html']))

let publicPath = path.join(__dirname, '..', 'public')
let publicSourcePath = path.join(__dirname, '..', 'public_utools')

copyFilesSync(path.join(publicSourcePath, 'preload.js'), `${publicPath}/preload.js`)
copyFilesSync(path.join(publicSourcePath, 'plugin.json'), `${publicPath}/plugin.json`)
copyFilesSync(path.join(publicSourcePath, 'squirrel'), `${publicPath}/squirrel`)
batchCopyFilesSync([
[path.join(publicSourcePath, 'preload.js'), `${publicPath}/preload.js`],
[path.join(publicSourcePath, 'plugin.json'), `${publicPath}/plugin.json`],
[path.join(publicSourcePath, 'squirrel'), `${publicPath}/squirrel`],
[path.join(publicSourcePath, 'node_modules'), `${publicPath}/node_modules`],

[path.join(__dirname, '..', 'icons', 'icon.png'), `${publicPath}/logo.png`],
])
27 changes: 27 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,37 @@ const copyFilesSyncRecursive = (source, destination) => {
}
}

const deleteFilesSyncRecursive = source => {
let stat = fs.statSync(source)
if (!stat.isDirectory()) {
fs.rmSync(source)
} else {
let names = fs.readdirSync(source)
names.forEach(name => deleteFilesSyncRecursive(path.join(source, name)))
fs.rmdirSync(source)
}
}

module.exports = {
copyFilesSync: (source, destination) => {
console.log('copy: ', source, destination)
copyFilesSyncRecursive(source, destination)
},
batchCopyFilesSync: pairs => {
console.log('copy: ', pairs)
pairs.forEach(pair => copyFilesSyncRecursive(pair[0], pair[1]))
},
deleteFilesSync: source => {
console.log('delete: ', source)
deleteFilesSyncRecursive(source)
},
batchDeleteFilesSync: paths => {
console.log('delete: ', paths)
paths.forEach(p => deleteFilesSyncRecursive(p))
},
listDirExcludeFiles: (source, names) => {
let fileNames = fs.readdirSync(source)
return fileNames.filter(n => names.indexOf(n) < 0).map(n => path.join(source, n))
}
}

0 comments on commit bb53c62

Please sign in to comment.