Skip to content

Commit

Permalink
fix(build): remove font duplication, fixes #694
Browse files Browse the repository at this point in the history
  • Loading branch information
nklayman committed Mar 30, 2020
1 parent 2ef85a7 commit 8fc65fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 50 deletions.
15 changes: 0 additions & 15 deletions __tests__/commands.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,6 @@ describe('electron:build', () => {
expect(builder.build.mock.calls[0][0].config.shouldBe).toBe('expected')
})

test('Fonts folder is copied to css if it exists', async () => {
// Mock existence of fonts folder
fs.existsSync.mockReturnValueOnce(true)
await runCommand('electron:build')
// css/fonts folder was created
expect(fs.ensureDirSync).toBeCalledWith(
'projectPath/dist_electron/bundled/css/fonts'
)
// fonts was copied to css/fonts
expect(fs.copySync).toBeCalledWith(
'projectPath/dist_electron/bundled/fonts',
'projectPath/dist_electron/bundled/css/fonts'
)
})

test('.js and .ts are merged into file extensions', async () => {
await runCommand('electron:build')

Expand Down
64 changes: 29 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,6 @@ module.exports = (api, options) => {
)
// Prevent electron-builder from installing app deps
fs.ensureDirSync(`${outputDir}/bundled/node_modules`)
// Copy fonts to css/fonts. Fixes some issues with static font imports
if (fs.existsSync(api.resolve(outputDir + '/bundled/fonts'))) {
fs.ensureDirSync(api.resolve(outputDir + '/bundled/css/fonts'))
fs.copySync(
api.resolve(outputDir + '/bundled/fonts'),
api.resolve(outputDir + '/bundled/css/fonts')
)
}

if (bundleMainProcess) {
// Build the main process into the renderer process output dir
Expand Down Expand Up @@ -210,7 +202,7 @@ module.exports = (api, options) => {
buildApp()
}
}
function buildApp () {
function buildApp() {
info('Building app with electron-builder:')
// Build the app using electron builder
builder
Expand Down Expand Up @@ -319,31 +311,32 @@ module.exports = (api, options) => {
let child
let firstBundleCompleted = false
// Function to kill Electron process
const killElectron = () => new Promise(resolve => {
if (!child || child.killed) {
return resolve()
}

const currentChild = child
currentChild.on('exit', () => {
resolve()
})
const killElectron = () =>
new Promise(resolve => {
if (!child || child.killed) {
return resolve()
}

// Attempt to kill gracefully
if (process.platform === 'win32') {
currentChild.send('graceful-exit')
} else {
currentChild.kill('SIGTERM')
}
const currentChild = child
currentChild.on('exit', () => {
resolve()
})

// Kill unconditionally after 2 seconds if unsuccessful
setTimeout(() => {
if (!currentChild.killed) {
warn(`Force killing Electron (process #${currentChild.pid})`)
currentChild.kill('SIGKILL')
// Attempt to kill gracefully
if (process.platform === 'win32') {
currentChild.send('graceful-exit')
} else {
currentChild.kill('SIGTERM')
}
}, 2000)
})

// Kill unconditionally after 2 seconds if unsuccessful
setTimeout(() => {
if (!currentChild.killed) {
warn(`Force killing Electron (process #${currentChild.pid})`)
currentChild.kill('SIGKILL')
}
}, 2000)
})

// Initial start of Electron
startElectron()
Expand Down Expand Up @@ -382,7 +375,7 @@ module.exports = (api, options) => {
})
}

async function launchElectron () {
async function launchElectron() {
firstBundleCompleted = true
// Don't exit process when electron is killed
if (child) {
Expand Down Expand Up @@ -472,7 +465,7 @@ module.exports = (api, options) => {
}
}

function onChildExit () {
function onChildExit() {
process.exit(0)
}
}
Expand Down Expand Up @@ -518,7 +511,7 @@ module.exports = (api, options) => {
)
}

function bundleMain ({
function bundleMain({
mode,
api,
args,
Expand Down Expand Up @@ -570,7 +563,8 @@ function bundleMain ({
}
})
// Enable/disable nodeIntegration
envVars.ELECTRON_NODE_INTEGRATION = args.headless || pluginOptions.nodeIntegration || false
envVars.ELECTRON_NODE_INTEGRATION =
args.headless || pluginOptions.nodeIntegration || false
config.plugin('env').use(webpack.EnvironmentPlugin, [envVars])

if (args.debug) {
Expand Down

0 comments on commit 8fc65fd

Please sign in to comment.