Skip to content
Permalink
Browse files

feat(publisher-nucleus): add publisher-nucleus to add nucleus upload …

…support to v6
  • Loading branch information
MarshallOfSound committed May 3, 2018
1 parent 9714be3 commit 131665cbdae1abd55a6f177d4539d7a03a60336c
@@ -0,0 +1,28 @@
{
"name": "@electron-forge/publisher-nucleus",
"version": "6.0.0-beta.5",
"description": "Nucleus publisher for Electron Forge",
"repository": "https://github.com/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"
}
}
@@ -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;
}
@@ -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()}`;
}
});
}
}
}

0 comments on commit 131665c

Please sign in to comment.
You can’t perform that action at this time.