Skip to content

Commit

Permalink
fix: packager returns promise instead of observable #135
Browse files Browse the repository at this point in the history
  • Loading branch information
bennymeg committed Jan 27, 2022
1 parent 5beb469 commit 753997a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 47 deletions.
2 changes: 1 addition & 1 deletion packages/nx-electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nx-electron",
"version": "12.0.0-beta.3",
"version": "12.0.0-beta.4",
"main": "src/index.js",
"description": "Electron Plugin for Nx",
"author": "Benny Megidish",
Expand Down
11 changes: 2 additions & 9 deletions packages/nx-electron/src/executors/package/executor.compat.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { convertNxExecutor, ExecutorContext } from '@nrwl/devkit';
import { convertNxExecutor } from '@nrwl/devkit';

import executor from './executor';

function executorAdapter(options: any, context: ExecutorContext):
Promise<{ success: boolean; }> | AsyncIterableIterator<{ success: boolean; }> {
return executor(options, context).toPromise()
.then<any>(output => { success: output.success })
.catch(error => { success: false });
}

export default convertNxExecutor(executorAdapter);
export default convertNxExecutor(executor);
66 changes: 30 additions & 36 deletions packages/nx-electron/src/executors/package/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,36 @@ export interface PackageElectronBuilderOutput {
outputPath: string | string[];
}

export function executor(rawOptions: PackageElectronBuilderOptions, context: ExecutorContext): Observable<PackageElectronBuilderOutput> {
return from(of(getSourceRoot(context))).pipe(
tap(_ => {
logger.warn(stripIndents`
*********************************************************
DO NOT FORGET TO REBUILD YOUR FRONTEND & BACKEND PROJECTS
FOR PRODUCTION BEFORE PACKAGING / MAKING YOUR ARTIFACT!
*********************************************************`);
}),
map(({ sourceRoot, projectRoot }) =>
normalizePackagingOptions(rawOptions, context.root, sourceRoot)
),
map(options =>
mergePresetOptions(options)
),
map(options =>
addMissingDefaultOptions(options)
),
concatMap(async (options) => {
await beforeBuild(options.root, options.sourcePath, options.name);

const platforms: Platform[] = _createPlatforms(options.platform);
const targets: Map<Platform, Map<Arch, string[]>> = _createTargets(platforms, null, options.arch);
const baseConfig: Configuration = _createBaseConfig(options, context);
const config: Configuration = _createConfigFromOptions(options, baseConfig);
const normalizedOptions: CliOptions = _normalizeBuilderOptions(targets, config, rawOptions);
const outputPath = await build(normalizedOptions);

return { success: true, outputPath };
}),
catchError(error => {
console.error(error);

return of({ success: false, outputPath: null });
})
);
export async function executor(rawOptions: PackageElectronBuilderOptions, context: ExecutorContext): Promise<{ success: boolean; }> {
logger.warn(stripIndents`
*********************************************************
DO NOT FORGET TO REBUILD YOUR FRONTEND & BACKEND PROJECTS
FOR PRODUCTION BEFORE PACKAGING / MAKING YOUR ARTIFACT!
*********************************************************`);
let success: boolean = false;

try {
const { sourceRoot, projectRoot } = getSourceRoot(context);

let options = normalizePackagingOptions(rawOptions, context.root, sourceRoot);
options = mergePresetOptions(options);
options = addMissingDefaultOptions(options);

const platforms: Platform[] = _createPlatforms(options.platform);
const targets: Map<Platform, Map<Arch, string[]>> = _createTargets(platforms, null, options.arch);
const baseConfig: Configuration = _createBaseConfig(options, context);
const config: Configuration = _createConfigFromOptions(options, baseConfig);
const normalizedOptions: CliOptions = _normalizeBuilderOptions(targets, config, rawOptions);

await beforeBuild(options.root, options.sourcePath, options.name);
await build(normalizedOptions);

success = true;
} catch (error) {
logger.error(error);
}

return { success };
}

async function beforeBuild(projectRoot: string, sourcePath: string, appName: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-electron/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const nxVersion = '^12.10.0';
export const nxElectronVersion = '^12.0.0-beta.3';
export const nxElectronVersion = '^12.0.0-beta.4';
export const electronVersion = '^16.0.2';
export const electronBuilderVersion = '^22.14.5';
export const rimrafVersion = '^3.0.2';
Expand Down

0 comments on commit 753997a

Please sign in to comment.