-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: de-coupled @angular-devkit from executors
- Loading branch information
Showing
20 changed files
with
440 additions
and
555 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
10 changes: 10 additions & 0 deletions
10
packages/nx-electron/src/executors/build/executor.compat.ts
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,10 @@ | ||
import { convertNxExecutor, ExecutorContext } from '@nrwl/devkit'; | ||
|
||
import executor from './executor'; | ||
|
||
function executorAdapter(options: any, context: ExecutorContext): | ||
Promise<{ success: boolean; }> | AsyncIterableIterator<{ success: boolean; }> { | ||
return executor(options, context); | ||
} | ||
|
||
export default convertNxExecutor(executorAdapter); |
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 |
---|---|---|
@@ -1,94 +1,86 @@ | ||
import { join, resolve } from 'path'; | ||
import { from, Observable } from 'rxjs'; | ||
import { concatMap, map, tap } from 'rxjs/operators'; | ||
|
||
import { BuilderContext, createBuilder } from '@angular-devkit/architect'; | ||
import { BuildResult, runWebpack } from '@angular-devkit/build-webpack'; | ||
import { JsonObject } from '@angular-devkit/core'; | ||
import { map, tap } from 'rxjs/operators'; | ||
import { eachValueFrom } from 'rxjs-for-await'; | ||
|
||
import { ExecutorContext } from '@nrwl/devkit'; | ||
import { runWebpack } from '@nrwl/workspace/src/utilities/run-webpack'; | ||
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph'; | ||
import { calculateProjectDependencies, checkDependentProjectsHaveBeenBuilt, createTmpTsConfig } from '@nrwl/workspace/src/utils/buildable-libs-utils'; | ||
import { calculateProjectDependencies, checkDependentProjectsHaveBeenBuilt, createTmpTsConfig } from '@nrwl/workspace/src/utilities/buildable-libs-utils'; | ||
|
||
import { getElectronWebpackConfig } from '../../utils/electron.config'; | ||
import { normalizeBuildOptions } from '../../utils/normalize'; | ||
import { BuildBuilderOptions } from '../../utils/types'; | ||
import { getSourceRoot } from '../../utils/workspace'; | ||
import { MAIN_OUTPUT_FILENAME } from '../../utils/config'; | ||
import { generatePackageJson } from '../../utils/generate-package-json'; | ||
import webpack from 'webpack'; | ||
|
||
try { | ||
require('dotenv').config(); | ||
} catch (e) {} | ||
|
||
export type ElectronBuildEvent = { | ||
outfile: string; | ||
success: boolean; | ||
}; | ||
|
||
export interface BuildElectronBuilderOptions extends BuildBuilderOptions { | ||
optimization?: boolean; | ||
sourceMap?: boolean; | ||
buildLibsFromSource?: boolean; | ||
generatePackageJson?: boolean; | ||
implicitDependencies: Array<string>; | ||
externalDependencies: 'all' | 'none' | Array<string>; | ||
} | ||
|
||
export type ElectronBuildEvent = BuildResult & { | ||
outfile: string; | ||
}; | ||
export interface NormalizedBuildElectronBuilderOptions extends BuildElectronBuilderOptions { | ||
webpackConfig: string; | ||
} | ||
|
||
export default createBuilder<JsonObject & BuildElectronBuilderOptions>(run); | ||
|
||
function run( options: JsonObject & BuildElectronBuilderOptions, context: BuilderContext): Observable<ElectronBuildEvent> { | ||
export function executor(rawOptions: BuildElectronBuilderOptions, context: ExecutorContext): AsyncIterableIterator<ElectronBuildEvent> { | ||
const { sourceRoot, projectRoot } = getSourceRoot(context); | ||
const normalizedOptions = normalizeBuildOptions( rawOptions, context.root, sourceRoot, projectRoot); | ||
const projGraph = readCachedProjectGraph(); | ||
|
||
if (!options.buildLibsFromSource) { | ||
const { target, dependencies } = calculateProjectDependencies( projGraph, context); | ||
if (!normalizedOptions.buildLibsFromSource) { | ||
const { target, dependencies } = | ||
calculateProjectDependencies(projGraph, context.root, context.projectName, context.targetName, context.configurationName); | ||
|
||
options.tsConfig = createTmpTsConfig( | ||
join(context.workspaceRoot, options.tsConfig), | ||
context.workspaceRoot, | ||
target.data.root, | ||
dependencies | ||
); | ||
normalizedOptions.tsConfig = createTmpTsConfig(normalizedOptions.tsConfig, context.root, target.data.root, dependencies); | ||
|
||
if (!checkDependentProjectsHaveBeenBuilt(context, dependencies)) { | ||
if (!checkDependentProjectsHaveBeenBuilt(context.root, context.projectName, context.targetName, dependencies)) { | ||
return { success: false } as any; | ||
} | ||
} | ||
|
||
return from(getSourceRoot(context)).pipe( | ||
map(({ sourceRoot, projectRoot }) => | ||
normalizeBuildOptions(options, context.workspaceRoot, sourceRoot, projectRoot) | ||
), | ||
tap((normalizedOptions) => { | ||
if (normalizedOptions.generatePackageJson) { | ||
generatePackageJson( | ||
context.target.project, | ||
projGraph, | ||
normalizedOptions | ||
); | ||
} | ||
}), | ||
map(options => { | ||
let config = getElectronWebpackConfig(options); | ||
if (options.webpackConfig) { | ||
config = require(options.webpackConfig)(config, { | ||
options, | ||
configuration: context.target.configuration | ||
}); | ||
} | ||
config.entry['preload'] = join(options.sourceRoot, 'app/api/preload.ts'); | ||
return config; | ||
}), | ||
concatMap(config => | ||
runWebpack(config, context, { | ||
logging: stats => { | ||
context.logger.info(stats.toString(config.stats)); | ||
} | ||
if (normalizedOptions.generatePackageJson) { | ||
generatePackageJson(context.projectName, projGraph, normalizedOptions); | ||
} | ||
|
||
let config = getElectronWebpackConfig(normalizedOptions); | ||
if (normalizedOptions.webpackConfig) { | ||
config = require(normalizedOptions.webpackConfig)(config, { | ||
normalizedOptions, | ||
configuration: context.configurationName, | ||
}); | ||
} | ||
config.entry['preload'] = join(normalizedOptions.sourceRoot, 'app/api/preload.ts'); | ||
|
||
|
||
return eachValueFrom( | ||
runWebpack(config, webpack).pipe( | ||
tap((stats) => { | ||
console.info(stats.toString(config.stats)); | ||
}), | ||
map((stats) => { | ||
return { | ||
success: !stats.hasErrors(), | ||
outfile: resolve(context.root, normalizedOptions.outputPath, MAIN_OUTPUT_FILENAME) | ||
} as ElectronBuildEvent; | ||
}) | ||
), | ||
map((buildEvent: BuildResult) => { | ||
buildEvent.outfile = resolve( | ||
context.workspaceRoot, | ||
options.outputPath, | ||
MAIN_OUTPUT_FILENAME | ||
); | ||
return buildEvent as ElectronBuildEvent; | ||
}) | ||
) | ||
); | ||
} | ||
|
||
export default executor; |
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
5 changes: 5 additions & 0 deletions
5
packages/nx-electron/src/executors/execute/executor.compat.ts
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,5 @@ | ||
import { convertNxExecutor } from '@nrwl/devkit'; | ||
|
||
import executor from './executor'; | ||
|
||
export default convertNxExecutor(executor); |
Oops, something went wrong.