Skip to content

Commit

Permalink
build: add option to createNodes function (#863)
Browse files Browse the repository at this point in the history
* build: add option to createNodes function

* build: work in progress

---------

Co-authored-by: khalilou88 <[email protected]>
  • Loading branch information
khalilou88 and khalilou88 authored Feb 9, 2024
1 parent acb554c commit 2bddd03
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
5 changes: 5 additions & 0 deletions packages/common/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export interface TemplateOptionsType {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[k: string]: any;
}
export type NxMavenPluginOptions = {
mavenRootDirectory: string;
localRepoRelativePath: string;
};
export type NxGradlePluginOptions = { gradleRootDirectory: string };
11 changes: 7 additions & 4 deletions packages/nx-gradle/src/graph/create-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { NxGradlePluginOptions } from '@jnxplus/common';
import { CreateNodes, ProjectConfiguration, workspaceRoot } from '@nx/devkit';
import { execSync } from 'child_process';
import * as path from 'path';
import { getExecutable, getGradleRootDirectory } from '../utils';
import { getExecutable } from '../utils';
import { getGradleProjects, getProjectRoot, outputFile } from './graph-utils';

export const createNodes: CreateNodes = [
export const createNodes: CreateNodes<NxGradlePluginOptions> = [
'nx.json',
() => {
(_, opts) => {
const command = `${getExecutable()} :projectDependencyTask --outputFile=${outputFile}`;

const gradleRootDirectory = getGradleRootDirectory();
const gradleRootDirectory = opts?.gradleRootDirectory
? opts.gradleRootDirectory
: '';

execSync(command, {
cwd: path.join(workspaceRoot, gradleRootDirectory),
Expand Down
8 changes: 4 additions & 4 deletions packages/nx-maven/src/graph/create-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TargetsType } from '@jnxplus/common';
import { NxMavenPluginOptions, TargetsType } from '@jnxplus/common';
import { CreateNodes, ProjectConfiguration, readJsonFile } from '@nx/devkit';
import { existsSync } from 'fs';
import * as path from 'path';
Expand All @@ -9,10 +9,10 @@ import {
getWorkspaceData,
} from './graph-utils';

export const createNodes: CreateNodes = [
export const createNodes: CreateNodes<NxMavenPluginOptions> = [
'nx.json',
() => {
const workspaceData: WorkspaceDataType = getWorkspaceData();
(_, opts) => {
const workspaceData: WorkspaceDataType = getWorkspaceData(opts);
const mavenProjects: MavenProjectType[] = workspaceData.projects;

const projects: Record<string, ProjectConfiguration> = {};
Expand Down
13 changes: 9 additions & 4 deletions packages/nx-maven/src/graph/graph-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NxMavenPluginOptions } from '@jnxplus/common';
import { readXml } from '@jnxplus/xml';
import {
NxJsonConfiguration,
Expand All @@ -13,7 +14,6 @@ import {
getArtifactId,
getGroupId,
getLocalRepositoryPath,
getMavenRootDirectory,
getVersion,
} from '../utils';

Expand Down Expand Up @@ -49,16 +49,21 @@ const cache = flatCache.load(
);
const key = 'workspace-data';

export function getWorkspaceData() {
const mavenRootDirectory = getMavenRootDirectory();
export function getWorkspaceData(opts: NxMavenPluginOptions | undefined) {
const mavenRootDirectory = opts?.mavenRootDirectory
? opts.mavenRootDirectory
: '';
const mavenRootDirAbsolutePath = path.join(workspaceRoot, mavenRootDirectory);

const projects: MavenProjectType[] = [];
addProjects(mavenRootDirAbsolutePath, projects, '');

//TODO calculate versions here

const localRepositoryPath = getLocalRepositoryPath(mavenRootDirAbsolutePath);
const localRepositoryPath = getLocalRepositoryPath(
opts,
mavenRootDirAbsolutePath,
);

const data: WorkspaceDataType = {
mavenRootDirAbsolutePath: mavenRootDirAbsolutePath,
Expand Down
14 changes: 11 additions & 3 deletions packages/nx-maven/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
DependencyManagementType,
FrameworkType,
LanguageType,
NxMavenPluginOptions,
} from '@jnxplus/common';
import { readXmlTree, xmlToString } from '@jnxplus/xml';
import {
Expand Down Expand Up @@ -386,11 +387,18 @@ function getLocalRepoRelativePath(): string {
return '';
}

export function getLocalRepositoryPath(mavenRootDirAbsolutePath: string) {
export function getLocalRepositoryPath(
opts: NxMavenPluginOptions | undefined,
mavenRootDirAbsolutePath: string,
) {
let localRepositoryPath;
const localRepoRelativePath = getLocalRepoRelativePath();
const localRepoRelativePath = opts?.localRepoRelativePath
? opts.localRepoRelativePath
: '';
if (localRepoRelativePath) {
const mavenRootDirectory = getMavenRootDirectory();
const mavenRootDirectory = opts?.mavenRootDirectory
? opts.mavenRootDirectory
: '';
localRepositoryPath = joinPathFragments(
mavenRootDirectory,
localRepoRelativePath,
Expand Down

0 comments on commit 2bddd03

Please sign in to comment.