Skip to content

Commit

Permalink
refactor(publisher): make dryRun object storage make more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored and malept committed Aug 27, 2017
1 parent 288edbc commit f8d807e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
14 changes: 7 additions & 7 deletions src/api/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions src/api/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}, []);

Expand Down
8 changes: 1 addition & 7 deletions src/util/publish-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/slow/api_spec_slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit f8d807e

Please sign in to comment.