Skip to content

Commit 2d33bd1

Browse files
committed
fix(build): support nested pages, closes #786
1 parent 00e573a commit 2d33bd1

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

__tests__/commands.spec.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,17 @@ describe('electron:build', () => {
344344
await runCommand('electron:build', {
345345
pages: {
346346
index: stringConfig ? '' : { filename: 'index.html' },
347-
subpage: stringConfig ? '' : { filename: 'subpage.html' }
347+
subpage: stringConfig ? '' : { filename: 'subdir/subpage.html' }
348348
}
349349
})
350350
expect(fs.writeFileSync).toBeCalledWith(
351351
`dist_electron${path.sep}bundled${path.sep}legacy-assets-index.html.json`,
352352
'[]'
353353
)
354354
expect(fs.writeFileSync).toBeCalledWith(
355-
`dist_electron${path.sep}bundled${path.sep}legacy-assets-subpage.html.json`,
355+
`dist_electron${path.sep}bundled${path.sep}${
356+
stringConfig ? '' : 'subdir' + path.sep
357+
}legacy-assets-subpage.html.json`,
356358
'[]'
357359
)
358360
}
@@ -546,7 +548,7 @@ describe('electron:serve', () => {
546548
// Call exit callback because app should have quit
547549
await exitCb()
548550
// Flush promises, only required on node v10 for some reason
549-
await (() => new Promise(resolve => setImmediate(resolve)))()
551+
await (() => new Promise((resolve) => setImmediate(resolve)))()
550552
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
551553

552554
expect(execa).toHaveBeenCalledTimes(2)
@@ -629,7 +631,7 @@ describe('electron:serve', () => {
629631
// Call exit callback because app should have quit
630632
await exitCb()
631633
// Flush promises, only required on node v10 for some reason
632-
await (() => new Promise(resolve => setImmediate(resolve)))()
634+
await (() => new Promise((resolve) => setImmediate(resolve)))()
633635
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
634636
// Electron was killed and listeners removed
635637
if (isWin) {
@@ -695,7 +697,7 @@ describe('electron:serve', () => {
695697
// Call exit callback because app should have quit
696698
await exitCb()
697699
// Flush promises, only required on node v10 for some reason
698-
await (() => new Promise(resolve => setImmediate(resolve)))()
700+
await (() => new Promise((resolve) => setImmediate(resolve)))()
699701
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
700702
// Electron was killed and listeners removed
701703
if (isWin) {
@@ -721,7 +723,7 @@ describe('electron:serve', () => {
721723
// Call exit callback because app should have quit
722724
await exitCb()
723725
// Flush promises, only required on node v10 for some reason
724-
await (() => new Promise(resolve => setImmediate(resolve)))()
726+
await (() => new Promise((resolve) => setImmediate(resolve)))()
725727
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
726728
// Electron was killed and listeners removed
727729
if (isWin) {

index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,18 @@ module.exports = (api, options) => {
117117
// Mock data from legacy build
118118
const pages = options.pages || { index: '' }
119119
Object.keys(pages).forEach((page) => {
120-
if (pages[page].filename) {
121-
// If page is configured as an object, use the filename (without .html)
122-
page = pages[page].filename.replace(/\.html$/, '')
123-
}
120+
let pagePath
121+
// Use the filename option and fallback to the key
122+
pagePath = path.parse(pages[page].filename || page)
123+
pagePath.name = `legacy-assets-${pagePath.name || page}`
124+
pagePath.ext = '.html.json'
125+
// Delete the base so that name/ext is used when formatting
126+
delete pagePath.base
127+
// Make sure parent dir exists
128+
if (pagePath.dir)
129+
fs.ensureDirSync(path.join(bundleOutputDir, pagePath.dir))
124130
fs.writeFileSync(
125-
path.join(bundleOutputDir, `legacy-assets-${page}.html.json`),
131+
path.join(bundleOutputDir, path.format(pagePath)),
126132
'[]'
127133
)
128134
})
@@ -222,7 +228,7 @@ module.exports = (api, options) => {
222228
buildApp()
223229
}
224230
}
225-
function buildApp () {
231+
function buildApp() {
226232
info('Building app with electron-builder:')
227233
// Build the app using electron builder
228234
builder
@@ -415,7 +421,7 @@ module.exports = (api, options) => {
415421
})
416422
}
417423

418-
async function launchElectron () {
424+
async function launchElectron() {
419425
firstBundleCompleted = true
420426
// Don't exit process when electron is killed
421427
if (child) {
@@ -506,7 +512,7 @@ module.exports = (api, options) => {
506512
}
507513
}
508514

509-
function onChildExit () {
515+
function onChildExit() {
510516
process.exit(0)
511517
}
512518
}
@@ -553,7 +559,7 @@ module.exports = (api, options) => {
553559
)
554560
}
555561

556-
function bundleMain ({
562+
function bundleMain({
557563
mode,
558564
api,
559565
args,

0 commit comments

Comments
 (0)