Skip to content

Commit

Permalink
feat: added compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
bennymeg committed Nov 23, 2021
1 parent 38be401 commit 0a15d54
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 14 deletions.
22 changes: 22 additions & 0 deletions packages/nx-electron/executors.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
{
"$schema": "http://json-schema.org/schema",
"executors": {
"build": {
"implementation": "./src/executors/build/executor",
"schema": "./src/executors/build/schema.json",
"description": "Build an Electron application"
},
"execute": {
"implementation": "./src/executors/execute/executor",
"schema": "./src/executors/execute/schema.json",
"description": "Execute an Electron application"
},
"package": {
"implementation": "./src/executors/package/executor",
"schema": "./src/executors/package/schema.json",
"description": "Package an Electron application"
},
"make": {
"implementation": "./src/executors/package/executor",
"schema": "./src/executors/package/schema.json",
"description": "Make an Electron application"
}
},
"builders": {
"build": {
"implementation": "./src/executors/build/executor.compat",
"schema": "./src/executors/build/schema.json",
Expand Down
22 changes: 20 additions & 2 deletions packages/nx-electron/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"$schema": "http://json-schema.org/schema",
"name": "nx-electron",
"version": "0.0.1",
"extends": ["@nrwl/workspace"],
"generators": {
"nx-electron": {
"application": {
"factory": "./src/generators/nx-electron/generator",
"schema": "./src/generators/nx-electron/schema.json",
"aliases": ["app, application"],
"aliases": ["app"],
"x-type": "application",
"description": "Generate an nx-electron application"
},
"init": {
Expand All @@ -16,5 +18,21 @@
"aliases": ["ng-add"],
"hidden": true
}
},
"schematics": {
"application": {
"factory": "./src/generators/nx-electron/generator.compat",
"schema": "./src/generators/nx-electron/schema.json",
"aliases": ["app"],
"x-type": "application",
"description": "Generate an nx-electron application"
},
"init": {
"factory": "./src/generators/init/generator.compat",
"schema": "./src/generators/init/schema.json",
"description": "Initialize the nx-electron plugin",
"aliases": ["ng-add"],
"hidden": true
}
}
}
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/nx-electron",
"version": "12.0.0-alpha.1",
"version": "12.0.0-alpha.2",
"main": "src/index.js",
"description": "Electron Plugin for Nx",
"author": "Benny Megidish",
Expand Down
5 changes: 5 additions & 0 deletions packages/nx-electron/src/generators/init/generator.compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxGenerator } from '@nrwl/devkit';

import generator from './generator';

export default convertNxGenerator(generator);
12 changes: 7 additions & 5 deletions packages/nx-electron/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addDependenciesToPackageJson, convertNxGenerator, formatFiles, GeneratorCallback, Tree, updateJson } from '@nrwl/devkit';
import { addDependenciesToPackageJson, formatFiles, GeneratorCallback, Tree, updateJson } from '@nrwl/devkit';
import { Schema } from './schema';
import { nxElectronVersion, electronVersion, electronBuilderVersion, rimrafVersion, exitZeroVersion } from '../../utils/versions';
import { setDefaultCollection } from '@nrwl/workspace/src/utilities/set-default-collection';
Expand Down Expand Up @@ -36,7 +36,10 @@ function addScripts(tree: Tree) {
return updateJson(tree, 'package.json', json => {
json.scripts = json.scripts || {};

json.scripts["postinstall"] = "exitzero electron-builder install-app-deps";
const postinstall = json.scripts["postinstall"];
json.scripts["postinstall"] = (postinstall && postinstall !== '') ?
`${postinstall} && exitzero electron-builder install-app-deps` :
"exitzero electron-builder install-app-deps";

return json;
});
Expand All @@ -49,7 +52,7 @@ function normalizeOptions(schema: Schema) {
};
}

export async function initGenerator(tree: Tree, schema: Schema) {
export async function generator(tree: Tree, schema: Schema) {
const options = normalizeOptions(schema);

setDefaultCollection(tree, 'nx-electron');
Expand All @@ -76,5 +79,4 @@ export async function initGenerator(tree: Tree, schema: Schema) {
};
}

export default initGenerator;
export const initSchematic = convertNxGenerator(initGenerator);
export default generator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxGenerator } from '@nrwl/devkit';

import generator from './generator';

export default convertNxGenerator(generator);
9 changes: 3 additions & 6 deletions packages/nx-electron/src/generators/nx-electron/generator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
addProjectConfiguration,
convertNxGenerator,
formatFiles,
generateFiles,
GeneratorCallback,
getWorkspaceLayout,
joinPathFragments,
logger,
names,
offsetFromRoot,
ProjectConfiguration,
Expand All @@ -26,7 +24,7 @@ import { jestProjectGenerator } from '@nrwl/jest';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';

import { Schema } from './schema';
import { initGenerator } from '../init/generator';
import { generator as initGenerator } from '../init/generator';

export interface NormalizedSchema extends Schema {
appProjectRoot: string;
Expand Down Expand Up @@ -210,7 +208,7 @@ export async function addLintingToApplication(
return lintTask;
}

export async function applicationGenerator(tree: Tree, schema: Schema) {
export async function generator(tree: Tree, schema: Schema) {
const options = normalizeOptions(tree, schema);

const tasks: GeneratorCallback[] = [];
Expand Down Expand Up @@ -284,5 +282,4 @@ function normalizeOptions(host: Tree, options: Schema): NormalizedSchema {
};
}

export default applicationGenerator;
export const applicationSchematic = convertNxGenerator(applicationGenerator);
export default generator;

0 comments on commit 0a15d54

Please sign in to comment.