Skip to content
Permalink
Browse files

refactor(publisher): make dryRun object storage make more sense

  • Loading branch information
MarshallOfSound authored and malept committed Aug 27, 2017
1 parent 288edbc commit f8d807ede8041b35550ad1089f6f7e2d868e46ee
Showing with 17 additions and 26 deletions.
  1. +7 −7 src/api/make.js
  2. +8 −11 src/api/publish.js
  3. +1 −7 src/util/publish-state.js
  4. +1 −1 test/slow/api_spec_slow.js
@@ -146,7 +146,7 @@ export default async (providedOptions = {}) => {
// eslint-disable-next-line no-loop-func
await asyncOra(`Making for target: ${target.cyan} - On platform: ${platform.cyan} - For arch: ${targetArch.cyan}`, async () => {
try {
const output = await maker({
const artifacts = await maker({
dir: packageDir,
appName,
targetPlatform: platform,
@@ -155,12 +155,12 @@ export default async (providedOptions = {}) => {
packageJSON,
});

output.platform = platform;
output.arch = targetArch;
output.packageJSON = packageJSON;
output.forgeConfig = forgeConfig;

outputs.push(output);
outputs.push({
artifacts,
packageJSON,
platform,
arch: targetArch,
});
} catch (err) {
if (err) {
throw {
@@ -60,12 +60,12 @@ const publish = async (providedOptions = {}) => {

let packageJSON = await readPackageJSON(dir);

let forgeConfig = await getForgeConfig(dir);
const forgeConfig = await getForgeConfig(dir);

if (dryRunResume) {
d('attempting to resume from dry run');
const publishes = await PublishState.loadFromDirectory(dryRunDir);
for (const states of publishes) {
for (const publishStates of publishes) {
d('publishing for given state set');
await publish({
dir,
@@ -74,9 +74,9 @@ const publish = async (providedOptions = {}) => {
tag,
target,
makeOptions,
dryRun,
dryRun: false,
dryRunResume: false,
makeResults: states.map(({ state }) => state),
makeResults: publishStates.map(({ state }) => state),
});
}
return;
@@ -92,22 +92,19 @@ const publish = async (providedOptions = {}) => {

for (const makeResult of makeResults) {
packageJSON = makeResult.packageJSON;
forgeConfig = makeResult.forgeConfig;
makeOptions.platform = makeResult.platform;
makeOptions.arch = makeResult.arch;

for (const makePath of makeResult.paths) {
for (const makePath of makeResult.artifacts) {
if (!await fs.exists(makePath)) {
throw `Attempted to resume a dry run but an artifact (${makePath}) could not be found`;
}
}
}

makeResults = makeResults.map(makeResult => makeResult.paths);
}

if (dryRun) {
d('saving results of make in dry run state');
d('saving results of make in dry run state', makeResults);
await fs.remove(dryRunDir);
await PublishState.saveToDirectory(dryRunDir, makeResults);
return;
@@ -118,8 +115,8 @@ const publish = async (providedOptions = {}) => {
throw 'Failed to locate publishable Electron application';
}

const artifacts = makeResults.reduce((accum, arr) => {
accum.push(...arr);
const artifacts = makeResults.reduce((accum, makeResult) => {
accum.push(...makeResult.artifacts);
return accum;
}, []);

@@ -34,13 +34,7 @@ export default class PublishState {
const id = crypto.createHash('md5').update(JSON.stringify(artifacts)).digest('hex');
for (const artifact of artifacts) {
const state = new PublishState(path.resolve(directory, id, 'null'), '', false);
state.setState({
paths: Array.from(artifact),
platform: artifact.platform,
arch: artifact.arch,
packageJSON: artifact.packageJSON,
forgeConfig: artifact.forgeConfig,
});
state.setState(artifact);
await state.saveToDisk();
}
}
@@ -247,7 +247,7 @@ describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
if (shouldPass) {
it(`successfully makes for config: ${JSON.stringify(optionsFetcher(), 2)}`, async () => {
const outputs = await forge.make(optionsFetcher());
for (const outputArr of outputs) {
for (const outputArr of outputs.artifacts) {
for (const output of outputArr) {
expect(await fs.exists(output)).to.equal(true);
}

0 comments on commit f8d807e

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