-
-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publisher-nucleus): add publisher-nucleus to add nucleus upload …
…support to v6
- Loading branch information
1 parent
9714be3
commit 131665c
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@electron-forge/publisher-nucleus", | ||
"version": "6.0.0-beta.5", | ||
"description": "Nucleus publisher for Electron Forge", | ||
"repository": "https:/electron-userland/electron-forge", | ||
"author": "Samuel Attard", | ||
"license": "MIT", | ||
"main": "dist/PublisherNucleus.js", | ||
"typings": "dist/PublisherNucleus.d.ts", | ||
"scripts": { | ||
"test": "exit 0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.0.0", | ||
"mocha": "^5.0.0" | ||
}, | ||
"engines": { | ||
"node": ">= 6.0" | ||
}, | ||
"dependencies": { | ||
"@electron-forge/async-ora": "6.0.0-beta.5", | ||
"@electron-forge/publisher-base": "6.0.0-beta.5", | ||
"@electron-forge/shared-types": "6.0.0-beta.5", | ||
"debug": "^3.0.0", | ||
"form-data": "^2.1.4", | ||
"node-fetch": "^2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export interface PublisherNucleusConfig { | ||
/** | ||
* Hostname (with https?://) of your instance of Nucleus | ||
*/ | ||
host: string; | ||
/** | ||
* App ID of your target application in Nucleus | ||
*/ | ||
appId: number; | ||
/** | ||
* Channel ID of your target application in Nucleus | ||
*/ | ||
channelId: string; | ||
/** | ||
* Authentication token for your app, you can find this on the Nucleus web UI | ||
*/ | ||
token: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import PublisherBase, { PublisherOptions } from '@electron-forge/publisher-base'; | ||
import { asyncOra } from '@electron-forge/async-ora'; | ||
import { ForgePlatform, ForgeArch } from '@electron-forge/shared-types'; | ||
import debug from 'debug'; | ||
import FormData from 'form-data'; | ||
import fs from 'fs'; | ||
import fetch from 'node-fetch'; | ||
import path from 'path'; | ||
|
||
import { PublisherNucleusConfig } from './Config'; | ||
|
||
const d = debug('electron-forge:publish:nucleus'); | ||
|
||
export default class PublisherNucleus extends PublisherBase<PublisherNucleusConfig> { | ||
name = 'nucleus'; | ||
|
||
async publish({ makeResults }: PublisherOptions) { | ||
const { config } = this; | ||
|
||
for (const [i, makeResult] of makeResults.entries()) { | ||
const msg = `Uploading result (${i}/${makeResults.length})`; | ||
d(msg); | ||
|
||
await asyncOra(msg, async () => { | ||
const data = new FormData(); | ||
data.append('platform', makeResult.platform); | ||
data.append('arch', makeResult.arch); | ||
data.append('version', makeResult.packageJSON.version); | ||
|
||
let i = 0; | ||
for (const artifactPath of makeResult.artifacts) { | ||
// Skip the RELEASES file, it is automatically generated on the server | ||
if (path.basename(artifactPath).toLowerCase() === 'releases') continue; | ||
data.append('file' + i, fs.createReadStream(artifactPath)); | ||
i += 1; | ||
} | ||
|
||
const response = await fetch(`${config.host}/rest/app/${config.appId}/channel/${config.channelId}/upload`, { | ||
headers: { | ||
Authorization: config.token, | ||
}, | ||
method: 'POST', | ||
body: data, | ||
}); | ||
|
||
if (response.status !== 200) { | ||
throw `Unexpected response code from Nucleus: ${response.status}\n\nBody:\n${await response.text()}`; | ||
} | ||
}); | ||
} | ||
} | ||
} |