Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return BluebirdPromise.map(matchers, async (matcher: FileMatcher) => {
const fromStat = await statOrNull(matcher.from)
if (fromStat == null) {
log.warn({from: matcher.from}, `file source doesn't exist`)
return
}
if (fromStat.isFile()) {
const toStat = await statOrNull(matcher.to)
// https://github.com/electron-userland/electron-builder/issues/1245
if (toStat != null && toStat.isDirectory()) {
return await copyOrLinkFile(matcher.from, path.join(matcher.to, path.basename(matcher.from)), fromStat, isUseHardLink)
}
await ensureDir(path.dirname(matcher.to))
return await copyOrLinkFile(matcher.from, matcher.to, fromStat)
}
if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
matcher.prependPattern("**/*")
}
log.debug({matcher}, "copying files using pattern")
return await copyDir(matcher.from, matcher.to, {filter: matcher.createFilter(), transformer, isUseHardLink: isUseHardLink ? USE_HARD_LINKS : null})
})
}
export async function reactCra(projectDir: string): Promise {
if ((await statOrNull(path.join(projectDir, "public", "electron.js"))) == null) {
// noinspection SpellCheckingInspection
log.warn("public/electron.js not found. Please see https://medium.com/@kitze/%EF%B8%8F-from-react-to-an-electron-app-ready-for-production-a0468ecb1da3")
}
return {
directories: {
buildResources: "assets"
},
files: ["build/**/*"],
extraMetadata: {
main: "build/electron.js"
}
}}
await executeAppBuilderAndWriteJson(["encode-plist"], {[propertyListOutputFile]: plistInfo})
}
// now build the package
const args = [
"--root", rootPath,
"--component-plist", propertyListOutputFile,
]
use(this.options.installLocation || "/Applications", it => args.push("--install-location", it!))
if (options.scripts != null) {
args.push("--scripts", path.resolve(this.packager.info.buildResourcesDir, options.scripts))
}
else if (options.scripts !== null) {
const dir = path.join(this.packager.info.buildResourcesDir, "pkg-scripts")
const stat = await statOrNull(dir)
if (stat != null && stat.isDirectory()) {
args.push("--scripts", dir)
}
}
args.push(packageOutputFile)
await exec("pkgbuild", args)
}
}
return BluebirdPromise.map(matchers, async (matcher: FileMatcher) => {
const fromStat = await statOrNull(matcher.from)
if (fromStat == null) {
log.warn({from: matcher.from}, `file source doesn't exist`)
return
}
if (fromStat.isFile()) {
const toStat = await statOrNull(matcher.to)
// https://github.com/electron-userland/electron-builder/issues/1245
if (toStat != null && toStat.isDirectory()) {
return await copyOrLinkFile(matcher.from, path.join(matcher.to, path.basename(matcher.from)), fromStat, isUseHardLink)
}
await ensureDir(path.dirname(matcher.to))
return await copyOrLinkFile(matcher.from, matcher.to, fromStat)
}
async isFile() {
const info = await statOrNull(this.actual)
if (info == null) {
throw new Error(`Path ${this.actual} doesn't exist`)
}
if (!info.isFile()) {
throw new Error(`Path ${this.actual} is not a file`)
}
}
async isDirectory() {
const file = this.actual
const info = await statOrNull(file)
if (info == null) {
throw new Error(`Path ${file} doesn't exist`)
}
if (!info.isDirectory()) {
throw new Error(`Path ${file} is not a directory`)
}
}
async function unpack(prepareOptions: PrepareApplicationStageDirectoryOptions, options: ElectronDownloadOptions, distMacOsAppName: string) {
const packager = prepareOptions.packager
const out = prepareOptions.appOutDir
let dist: string | null | undefined = packager.config.electronDist
if (dist != null) {
const zipFile = `electron-v${options.version}-${prepareOptions.platformName}-${options.arch}.zip`
const resolvedDist = path.resolve(packager.projectDir, dist)
if ((await statOrNull(path.join(resolvedDist, zipFile))) != null) {
options.cache = resolvedDist
dist = null
}
}
let isFullCleanup = false
if (dist == null) {
if (isSafeToUnpackElectronOnRemoteBuildServer(packager)) {
return
}
await executeAppBuilder(["unpack-electron", "--configuration", JSON.stringify([options]), "--output", out, "--distMacOsAppName", distMacOsAppName])
}
else {
isFullCleanup = true
const source = packager.getElectronSrcDir(dist)
export async function computeDefaultAppDirectory(projectDir: string, userAppDir: string | null | undefined): Promise {
if (userAppDir != null) {
const absolutePath = path.resolve(projectDir, userAppDir)
const stat = await statOrNull(absolutePath)
if (stat == null) {
throw new InvalidConfigurationError(`Application directory ${userAppDir} doesn't exist`)
}
else if (!stat.isDirectory()) {
throw new InvalidConfigurationError(`Application directory ${userAppDir} is not a directory`)
}
else if (projectDir === absolutePath) {
log.warn({appDirectory: userAppDir}, `Specified application directory equals to project dir — superfluous or wrong configuration`)
}
return absolutePath
}
for (const dir of DEFAULT_APP_DIR_NAMES) {
const absolutePath = path.join(projectDir, dir)
const packageJson = path.join(absolutePath, "package.json")
const stat = await statOrNull(packageJson)
taskManager.add(async () => {
const userPluginDir = path.join(packager.info.buildResourcesDir, pluginArch)
const stat = await statOrNull(userPluginDir)
if (stat != null && stat.isDirectory()) {
scriptGenerator.addPluginDir(pluginArch, userPluginDir)
}
})