From f041755e09a9a00a6dca0352f94aad2995bffaa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Tue, 31 Oct 2023 13:37:10 +0200 Subject: [PATCH] feat: add RELATIVE_PROJECT_DIR token * feat: RELATIVE_PROJECT_DIR token * feat: RELATIVE_PROJECT_DIR token * docs: add infoamtion about RELATIVE_PROJECT_DIR * chore: type in readme * test: add relativeProjectDir to mock tokens --------- Co-authored-by: Andrii Tsok --- README.md | 5 +++-- packages/nx-semantic-release/src/config/apply-tokens.spec.ts | 1 + packages/nx-semantic-release/src/config/apply-tokens.ts | 2 ++ .../src/executors/semantic-release/semantic-release.ts | 2 ++ .../src/generators/setup-project/setup-project.ts | 2 ++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89962b37..5fc4f931 100644 --- a/README.md +++ b/README.md @@ -138,9 +138,10 @@ $ nx semantic-release app-c --repositoryUrl "https://github.com/TheUnderScorer/n | Token | Expands into | | --------------- | --------------------------------------------------------------------------------------------- | -| ${PROJECT_DIR} | Resolves to the current project direcory (ex. `/Users/theunderscorer/nx-monorepo/apps/app-a`) | +| ${RELATIVE_PROJECT_DIR} | Resolves to the current project relative directory within the current workspace (ex. `apps/app-a`) | +| ${PROJECT_DIR} | Resolves to the current project directory (ex. `/Users/theunderscorer/nx-monorepo/apps/app-a`) | | ${PROJECT_NAME} | Resolves to the current project name (ex. `app-a`) | -| ${WORKSPACE_DIR}| Resolves to the current workspace direcory (ex. `/Users/theunderscorer/nx-monorepo`) | +| ${WORKSPACE_DIR}| Resolves to the current workspace directory (ex. `/Users/theunderscorer/nx-monorepo`) | Every available option support tokens - this included nested objects and arrays. diff --git a/packages/nx-semantic-release/src/config/apply-tokens.spec.ts b/packages/nx-semantic-release/src/config/apply-tokens.spec.ts index 41dac0b7..f2f44bfb 100644 --- a/packages/nx-semantic-release/src/config/apply-tokens.spec.ts +++ b/packages/nx-semantic-release/src/config/apply-tokens.spec.ts @@ -14,6 +14,7 @@ const requiredOptions: SemanticReleaseOptions = { const mockTokens: ConfigTokensDict = { projectDir: 'apps/app-a', + relativeProjectDir: 'apps/app-a', projectName: 'app-a', workspaceDir: '.', }; diff --git a/packages/nx-semantic-release/src/config/apply-tokens.ts b/packages/nx-semantic-release/src/config/apply-tokens.ts index b54d0e6f..a50dfe31 100644 --- a/packages/nx-semantic-release/src/config/apply-tokens.ts +++ b/packages/nx-semantic-release/src/config/apply-tokens.ts @@ -2,6 +2,7 @@ import { SemanticReleaseOptions } from '../executors/semantic-release/semantic-r import deepMap from 'deep-map'; export interface ConfigTokensDict { + relativeProjectDir: string; projectDir: string; projectName: string; workspaceDir: string; @@ -13,6 +14,7 @@ export function applyTokensToSemanticReleaseOptions( ) { const replaceTokens = (value: string): string => { return value + .replaceAll('${RELATIVE_PROJECT_DIR}', tokens.relativeProjectDir) .replaceAll('${PROJECT_DIR}', tokens.projectDir) .replaceAll('${PROJECT_NAME}', tokens.projectName) .replaceAll('${WORKSPACE_DIR}', tokens.workspaceDir); diff --git a/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts b/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts index bb45db13..bcda0cd9 100644 --- a/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts +++ b/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts @@ -1,3 +1,4 @@ +import path from "path"; import { createProjectGraphAsync, ExecutorContext, @@ -140,6 +141,7 @@ export function resolveOptions( return applyTokensToSemanticReleaseOptions(mergedOptions, { projectName: context.projectName as string, + relativeProjectDir: path.relative(context.cwd, getDefaultProjectRoot(context)), projectDir: getDefaultProjectRoot(context), workspaceDir: workspaceRoot, }); diff --git a/packages/nx-semantic-release/src/generators/setup-project/setup-project.ts b/packages/nx-semantic-release/src/generators/setup-project/setup-project.ts index a8f6b72c..fe970c54 100644 --- a/packages/nx-semantic-release/src/generators/setup-project/setup-project.ts +++ b/packages/nx-semantic-release/src/generators/setup-project/setup-project.ts @@ -1,3 +1,4 @@ +import path from "path"; import { SemanticReleaseOptions } from '../../executors/semantic-release/semantic-release'; import { Tree, @@ -27,6 +28,7 @@ export async function setupProject( const semanticReleaseConfig = applyTokensToSemanticReleaseOptions(options, { projectName, projectDir: projectConfig.root, + relativeProjectDir: path.relative(workspaceRoot, projectConfig.root), workspaceDir: workspaceRoot, });