8000 feat: Added electron builder config function (#221) · electron-userland/electron-webpack@c4cf411 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c4cf411

Browse files
VictorLeach96develar
authored andcommitted
feat: Added electron builder config function (#221)
* Added electron builder config function * Moved config to seperate file * Moved electron builder config into seperate ts file * Removed unneeded source map support
1 parent 377b0eb commit c4cf411

File tree

8 files changed

+68
-35
lines changed

8 files changed

+68
-35
lines changed

packages/electron-webpack/electron-builder.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/electron-webpack/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"out",
99
"*.js",
1010
"scheme.json",
11-
"electron-builder.yml",
1211
"tsconfig-base.json",
1312
"vendor"
1413
],
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { readJson } from "fs-extra-p"
2+
import { Lazy } from "lazy-val"
3+
import * as path from "path"
4+
import { orNullIfFileNotExist } from "./util"
5+
import { getConfig } from "read-config-file"
6+
7+
export { ElectronWebpackConfiguration } from "./core"
8+
9+
export async function getPackageMetadata() {
10+
const projectDir = process.cwd()
11+
return await orNullIfFileNotExist(readJson(path.join(projectDir, "package.json")))
12+
}
13+
14+
export async function getElectronWebpackConfig() {
15+
const projectDir = process.cwd()
16+
const packageMetadata = await getPackageMetadata()
17+
const electronWebpackConfig = ((await getConfig({
18+
packageKey: "electronWebpack",
19+
configFilename: "electron-webpack",
20+
projectDir,
21+
packageMetadata: new Lazy(() => Promise.resolve(packageMetadata))
22+
})) || {} as any).result || {}
23+
return electronWebpackConfig
24+
}

packages/electron-webpack/src/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ElectronWebpackConfiguration {
1616
main?: ElectronWebpackConfigurationMain | null
1717

1818
commonSourceDirectory?: string | null
19+
commonDistDirectory?: string | null
1920

2021
title?: string | boolean | null
2122

packages/electron-webpack/src/dev/dev-runner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { configure } from "../main"
1010
import { getFreePort, orNullIfFileNotExist } from "../util"
1111
import { DelayedFunction, getCommonEnv, logError, logProcess, logProcessErrorOutput } from "./devUtil"
1212
import { startRenderer } from "./WebpackDevServerManager"
13+
import { getElectronWebpackConfig } from "../config"
1314

1415
const projectDir = process.cwd()
1516

@@ -19,7 +20,8 @@ const debug = require("debug")("electron-webpack")
1920

2021
// do not remove main.js to allow IDE to keep breakpoints
2122
async function emptyMainOutput() {
22-
const outDir = path.join(projectDir, "dist", "main")
23+
const electronWebpackConfig = await getElectronWebpackConfig()
24+
const outDir = path.join(projectDir, electronWebpackConfig.commonDistDirectory, "main")
2325
const files = await orNullIfFileNotExist(readdir(outDir))
2426
if (files == null) {
2527
return
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { getElectronWebpackConfig } from "./config"
2+
3+
export default async function() {
4+
const electronWebpackConfig = await getElectronWebpackConfig()
5+
return {
6+
extraMetadata: {
7+
main: "main.js"
8+
},
9+
files: [
10+
{
11+
from: ".",
12+
filter: ["package.json"]
13+
},
14+
{
15+
from: electronWebpackConfig.commonDistDirectory + "/main"
16+
},
17+
{
18+
from: electronWebpackConfig.commonDistDirectory + "/renderer"
19+
},
20+
{
21+
from: electronWebpackConfig.commonDistDirectory + "/renderer-dll"
22+
}
23+
],
24+
extraResources: [
25+
{
26+
from: "static",
27+
to: "static"
28+
}
29+
]
30+
}
31+
}

packages/electron-webpack/src/main.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import BluebirdPromise from "bluebird-lst"
22
import { readJson } from "fs-extra-p"
33
import { Lazy } from "lazy-val"
44
import * as path from "path"
5-
import { getConfig, validateConfig } from "read-config-file"
5+
import { validateConfig } from "read-config-file"
66
import { deepAssign } from "read-config-file/out/deepAssign"
77
import "source-map-support/register"
88
import { Configuration, Plugin, RuleSetRule } from "webpack"
@@ -13,7 +13,8 @@ import { ConfigurationEnv, ConfigurationType, ElectronWebpackConfiguration, Pack
1313
import { BaseTarget } from "./targets/BaseTarget"
1414
import { MainTarget } from "./targets/MainTarget"
1515
import { BaseRendererTarget, RendererTarget } from "./targets/RendererTarget"
16-
import { getFirstExistingFile, orNullIfFileNotExist } from "./util"
16+
import { getFirstExistingFile } from "./util"
17+
import { getElectronWebpackConfig, getPackageMetadata } from "./config"
1718

1819
export { ElectronWebpackConfiguration } from "./core"
1920

@@ -59,6 +60,7 @@ export class WebpackConfigurator {
5960

6061
readonly sourceDir: string
6162
readonly commonSourceDirectory: string
63+
readonly commonDistDirectory: string
6264

6365
readonly debug = _debug(`electron-webpack:${this.type}`)
6466

@@ -109,6 +111,7 @@ export class WebpackConfigurator {
109111

110112
const commonSourceDirectory = this.electronWebpackConfiguration.commonSourceDirectory
111113
this.commonSourceDirectory = commonSourceDirectory == null ? path.join(this.projectDir, "src", "common") : path.resolve(this.projectDir, commonSourceDirectory)
114+
this.commonDistDirectory = path.resolve(this.projectDir, this.electronWebpackConfiguration.commonDistDirectory || "dist")
112115
}
113116

114117
/**
@@ -139,10 +142,6 @@ export class WebpackConfigurator {
139142
}
140143
}
141144

142-
get commonDistDirectory() {
143-
return path.join(this.projectDir, "dist")
144-
}
145-
146145
hasDependency(name: string) {
147146
return name in this.metadata.dependencies || this.hasDevDependency(name)
148147
}
@@ -155,7 +154,7 @@ export class WebpackConfigurator {
155154
* Returns the names of devDependencies that match a given string or regex.
156155
* If no matching dependencies are found, an empty array is returned.
157156
*
158-
* @return list of matching dependency names, e.g. `['@babel/preset-react', '@babel/preset-stage-0']`
157+
* @return list of matching dependency names, e.g. `["@babel/preset-react", "@babel/preset-stage-0"]`
159158
*/
160159
getMatchingDevDependencies(options: GetMatchingDevDependenciesOptions = {}) {
161160
const includes = options.includes || []
@@ -306,14 +305,7 @@ export async function createConfigurator(type: ConfigurationType, env: Configura
306305
env = {}
307306
}
308307

309-
const projectDir = (env.configuration || {}).projectDir || process.cwd()
310-
const packageMetadata = await orNullIfFileNotExist(readJson(path.join(projectDir, "package.json")))
311-
const electronWebpackConfig = ((await getConfig({
312-
packageKey: "electronWebpack",
313-
configFilename: "electron-webpack",
314-
projectDir,
315-
packageMetadata: new Lazy(() => Promise.resolve(packageMetadata))
316-
})) || {} as any).result || {}
308+
const electronWebpackConfig = await getElectronWebpackConfig()
317309
if (env.configuration != null) {
318310
deepAssign(electronWebpackConfig, env.configuration)
319311
}
@@ -328,6 +320,7 @@ How to fix:
328320
* Found? Check that the option in the appropriate place. e.g. "sourceDirectory" only in the "main" or "renderer", not in the root.
329321
`
330322
})
323+
const packageMetadata = await getPackageMetadata()
331324
return new WebpackConfigurator(type, env, electronWebpackConfig, packageMetadata)
332325
}
333326

packages/electron-webpack/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"skipLibCheck": true
77
},
88
"include": [
9-
"**/*.ts", "typings/*.d.ts"
9+
"**/*.ts", "src/electron-builder.ts", "typings/*.d.ts"
1010
]
1111
}

0 commit comments

Comments
 (0)
0