Skip to content

Commit

Permalink
chore: refactor Publishers out of app-builder-lib into electron-publi…
Browse files Browse the repository at this point in the history
…sh and add to docs site (#8596)
  • Loading branch information
mmaietta authored Oct 16, 2024
1 parent d4ea0d9 commit e0b0e35
Show file tree
Hide file tree
Showing 33 changed files with 198 additions and 166 deletions.
10 changes: 10 additions & 0 deletions .changeset/fluffy-wolves-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"app-builder-lib": patch
"builder-util": patch
"dmg-builder": patch
"electron-builder": patch
"electron-builder-squirrel-windows": patch
"electron-publish": patch
---

chore: refactor files for publishing to electron-publish
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ nav:
- electron-builder: electron-builder/globals.md
- app-builder-lib: app-builder-lib/globals.md
- electron-updater: electron-updater/globals.md
- electron-publish: electron-publish/globals.md

- Configuration:
- Common Configuration: configuration.md
Expand Down
2 changes: 0 additions & 2 deletions packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"dotenv-expand": "^11.0.6",
"ejs": "^3.1.8",
"electron-publish": "workspace:*",
"form-data": "^4.0.0",
"fs-extra": "^10.1.0",
"hosted-git-info": "^4.1.0",
"is-ci": "^3.0.0",
Expand All @@ -76,7 +75,6 @@
"lazy-val": "^1.0.5",
"minimatch": "^10.0.0",
"resedit": "^1.7.0",
"sanitize-filename": "^1.6.3",
"semver": "^7.3.8",
"tar": "^6.1.12",
"temp-file": "^3.4.0"
Expand Down
15 changes: 10 additions & 5 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,8 @@
"string"
]
}
]
],
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
},
"releaseInfo": {
"$ref": "#/definitions/ReleaseInfo",
Expand Down Expand Up @@ -2742,7 +2743,8 @@
"string"
]
}
]
],
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
},
"releaseInfo": {
"$ref": "#/definitions/ReleaseInfo",
Expand Down Expand Up @@ -3383,7 +3385,8 @@
"string"
]
}
]
],
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
},
"releaseInfo": {
"$ref": "#/definitions/ReleaseInfo",
Expand Down Expand Up @@ -6453,7 +6456,8 @@
"string"
]
}
]
],
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
},
"publisherName": {
"anyOf": [
Expand Down Expand Up @@ -7547,7 +7551,8 @@
"string"
]
}
]
],
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
},
"releaseInfo": {
"$ref": "#/definitions/ReleaseInfo",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { prerelease } from "semver"
import { PlatformSpecificBuildOptions } from "./options/PlatformSpecificBuildOptions"
import { Packager } from "./packager"
import { expandMacro } from "./util/macroExpander"
import { sanitizeFileName } from "./util/filename"
import { sanitizeFileName } from "builder-util/out/filename"

// fpm bug - rpm build --description is not escaped, well... decided to replace quite to smart quote
// http://leancrew.com/all-this/2010/11/smart-quotes-in-javascript/
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublishOptions } from "electron-publish/out/publisher"
import { PublishOptions } from "electron-publish"
import { log, InvalidConfigurationError, executeFinally } from "builder-util"
import { asArray } from "builder-util-runtime"
import { Packager } from "./packager"
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import FpmTarget from "./targets/FpmTarget"
import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
import SnapTarget from "./targets/snap"
import { createCommonTarget } from "./targets/targetFactory"
import { sanitizeFileName } from "./util/filename"
import { sanitizeFileName } from "builder-util/out/filename"

export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
readonly executableName: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InvalidConfigurationError, isEmptyOrSpaces } from "builder-util"
import { sanitizeFileName } from "../util/filename"
import { sanitizeFileName } from "builder-util/out/filename"
import { WinPackager } from "../winPackager"

export interface CommonWindowsInstallerConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export interface PlatformSpecificBuildOptions extends TargetSpecificOptions, Fil
*/
readonly electronUpdaterCompatibility?: string | null

/**
* Publisher configuration. See [Auto Update](./publish.md) for more information.
*/
publish?: Publish

/**
Expand Down
22 changes: 14 additions & 8 deletions packages/app-builder-lib/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ import {
BitbucketOptions,
} from "builder-util-runtime"
import _debug from "debug"
import { getCiTag, PublishContext, Publisher, PublishOptions, UploadTask } from "electron-publish"
import { GitHubPublisher } from "electron-publish/out/gitHubPublisher"
import { MultiProgress } from "electron-publish/out/multiProgress"
import S3Publisher from "./s3/s3Publisher"
import SpacesPublisher from "./s3/spacesPublisher"
import {
BitbucketPublisher,
getCiTag,
GitHubPublisher,
KeygenPublisher,
PublishContext,
Publisher,
PublishOptions,
S3Publisher,
SnapStorePublisher,
SpacesPublisher,
UploadTask,
} from "electron-publish"
import { writeFile } from "fs/promises"
import * as isCi from "is-ci"
import * as path from "path"
Expand All @@ -28,10 +36,8 @@ import { Packager } from "../packager"
import { PlatformPackager } from "../platformPackager"
import { expandMacro } from "../util/macroExpander"
import { WinPackager } from "../winPackager"
import { SnapStorePublisher } from "./SnapStorePublisher"
import { createUpdateInfoTasks, UpdateInfoFileTask, writeUpdateInfoFiles } from "./updateInfoBuilder"
import { KeygenPublisher } from "./KeygenPublisher"
import { BitbucketPublisher } from "./BitbucketPublisher"
import { MultiProgress } from "electron-publish/out/multiProgress"

const publishForPrWarning =
"There are serious security concerns with PUBLISH_FOR_PULL_REQUEST=true (see the CircleCI documentation (https://circleci.com/docs/1.0/fork-pr-builds/) for details)" +
Expand Down
1 change: 1 addition & 0 deletions packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"https-proxy-agent": "^7.0.0",
"is-ci": "^3.0.0",
"js-yaml": "^4.1.0",
"sanitize-filename": "^1.6.3",
"source-map-support": "^0.5.19",
"stat-mode": "^1.0.0",
"temp-file": "^3.4.0"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/dmg-builder/src/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { findIdentity, isSignAllowed } from "app-builder-lib/out/codeSign/macCod
import { MacPackager } from "app-builder-lib/out/macPackager"
import { createBlockmap } from "app-builder-lib/out/targets/differentialUpdateInfoBuilder"
import { executeAppBuilderAsJson } from "app-builder-lib/out/util/appBuilder"
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
import { sanitizeFileName } from "builder-util/out/filename"
import { Arch, AsyncTaskManager, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, copyDir, copyFile, exists, statOrNull } from "builder-util"
import { CancellationToken } from "builder-util-runtime"
import { stat } from "fs-extra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
import { sanitizeFileName } from "builder-util/out/filename"
import { InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
import { getBinFromUrl } from "app-builder-lib/out/binDownload"
import { Arch, getArchSuffix, SquirrelWindowsOptions, Target } from "app-builder-lib"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
import { sanitizeFileName } from "builder-util/out/filename"
import { exec, log, spawn, TmpDir, unlinkIfExists } from "builder-util"
import * as chalk from "chalk"
import { getSignVendorPath } from "app-builder-lib/out/codeSign/windowsSignToolManager"
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export function configurePublishCommand(yargs: yargs.Argv): yargs.Argv {
.demandOption("files")
}

export async function publish(args: { files: string[]; version: string | undefined; config: string | undefined }) {
export async function publish(args: { files: string[]; version: string | undefined; configurationFilePath: string | undefined }) {
const uploadTasks = args.files.map(f => {
return {
file: path.resolve(f),
arch: null,
}
})
return publishArtifactsWithOptions(uploadTasks, args.version, args.config)
return publishArtifactsWithOptions(uploadTasks, args.version, args.configurationFilePath)
}

export async function publishArtifactsWithOptions(
Expand Down
5 changes: 3 additions & 2 deletions packages/electron-publish/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "electron-publish",
"version": "26.0.0-alpha.1",
"main": "out/publisher.js",
"main": "out/index.js",
"author": "Vladimir Krivosheev",
"license": "MIT",
"repository": {
Expand All @@ -19,11 +19,12 @@
"builder-util": "workspace:*",
"builder-util-runtime": "workspace:*",
"chalk": "^4.1.2",
"form-data": "^4.0.0",
"fs-extra": "^10.1.0",
"lazy-val": "^1.0.5",
"mime": "^2.5.2"
},
"typings": "./out/publisher.d.ts",
"typings": "./out/index.d.ts",
"devDependencies": {
"@types/mime": "2.0.3"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Arch, InvalidConfigurationError, isEmptyOrSpaces, log } from "builder-util"
import { httpExecutor } from "builder-util"
import { ClientRequest, RequestOptions } from "http"
import { HttpPublisher, PublishContext } from "electron-publish"
import { PublishContext } from "./"
import { HttpPublisher } from "./httpPublisher"
import { BitbucketOptions } from "builder-util-runtime/out/publishOptions"
import { configureRequestOptions, HttpExecutor } from "builder-util-runtime"
import * as FormData from "form-data"
Expand Down
4 changes: 3 additions & 1 deletion packages/electron-publish/src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ClientRequest } from "http"
import { Lazy } from "lazy-val"
import * as mime from "mime"
import { parse as parseUrl, UrlWithStringQuery } from "url"
import { getCiTag, HttpPublisher, PublishContext, PublishOptions } from "./publisher"
import { getCiTag } from "./publisher"
import { HttpPublisher } from "./httpPublisher"
import { PublishContext, PublishOptions } from "./index"

export interface Release {
id: number
Expand Down
69 changes: 69 additions & 0 deletions packages/electron-publish/src/httpPublisher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Arch } from "builder-util"
import { stat } from "fs-extra"
import { ClientRequest } from "http"
import { basename } from "path/posix"
import { Publisher } from "./publisher"
import { PublishContext, UploadTask } from "."

export abstract class HttpPublisher extends Publisher {
protected constructor(
protected readonly context: PublishContext,
private readonly useSafeArtifactName = false
) {
super(context)
}

async upload(task: UploadTask): Promise<any> {
const fileName = (this.useSafeArtifactName ? task.safeArtifactName : null) || basename(task.file)

if (task.fileContent != null) {
await this.doUpload(
fileName,
task.arch || Arch.x64,
task.fileContent.length,
(request, reject) => {
if (task.timeout) {
request.setTimeout(task.timeout, () => {
request.destroy()
reject(new Error("Request timed out"))
})
}
return request.end(task.fileContent)
},
task.file
)
return
}

const fileStat = await stat(task.file)

const progressBar = this.createProgressBar(fileName, fileStat.size)
return this.doUpload(
fileName,
task.arch || Arch.x64,
fileStat.size,
(request, reject) => {
if (progressBar != null) {
// reset (because can be called several times (several attempts)
progressBar.update(0)
}
if (task.timeout) {
request.setTimeout(task.timeout, () => {
request.destroy()
reject(new Error("Request timed out"))
})
}
return this.createReadStreamAndProgressBar(task.file, fileStat, progressBar, reject).pipe(request)
},
task.file
)
}

protected abstract doUpload(
fileName: string,
arch: Arch,
dataLength: number,
requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void,
file: string
): Promise<any>
}
35 changes: 35 additions & 0 deletions packages/electron-publish/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { CancellationToken } from "builder-util-runtime"
import { MultiProgress } from "./multiProgress"
import { Arch } from "builder-util"

export { SpacesPublisher } from "./s3/spacesPublisher"
export { KeygenPublisher } from "./keygenPublisher"
export { SnapStorePublisher } from "./snapStorePublisher"
export { S3Publisher } from "./s3/s3Publisher"
export { GitHubPublisher } from "./gitHubPublisher"
export { BitbucketPublisher } from "./bitbucketPublisher"

export type PublishPolicy = "onTag" | "onTagOrDraft" | "always" | "never"

export { ProgressCallback } from "./progress"

export interface PublishOptions {
publish?: PublishPolicy | null
}

export { Publisher, getCiTag } from "./publisher"
export { HttpPublisher } from "./httpPublisher"

export interface PublishContext {
readonly cancellationToken: CancellationToken
readonly progress: MultiProgress | null
}

export interface UploadTask {
file: string
fileContent?: Buffer | null

arch: Arch | null
safeArtifactName?: string | null
timeout?: number | null
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Arch, InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
import { httpExecutor } from "builder-util"
import { ClientRequest, RequestOptions } from "http"
import { HttpPublisher, PublishContext } from "electron-publish"
import { PublishContext } from "./"
import { HttpPublisher } from "./httpPublisher"
import { KeygenOptions } from "builder-util-runtime/out/publishOptions"
import { configureRequestOptions, HttpExecutor, parseJson } from "builder-util-runtime"
import { getCompleteExtname } from "../util/filename"
import { getCompleteExtname } from "builder-util/out/filename"

type RecursivePartial<T> = {
[P in keyof T]?: RecursivePartial<T[P]>
Expand Down
Loading

0 comments on commit e0b0e35

Please sign in to comment.