Skip to content

Commit f041755

Browse files
TheUnderScorerAndrii Tsok
andauthored
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 <andrii@tsok.xyz>
1 parent dba3baf commit f041755

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ $ nx semantic-release app-c --repositoryUrl "https://github.com/TheUnderScorer/n
138138
139139
| Token | Expands into |
140140
| --------------- | --------------------------------------------------------------------------------------------- |
141-
| ${PROJECT_DIR} | Resolves to the current project direcory (ex. `/Users/theunderscorer/nx-monorepo/apps/app-a`) |
141+
| ${RELATIVE_PROJECT_DIR} | Resolves to the current project relative directory within the current workspace (ex. `apps/app-a`) |
142+
| ${PROJECT_DIR} | Resolves to the current project directory (ex. `/Users/theunderscorer/nx-monorepo/apps/app-a`) |
142143
| ${PROJECT_NAME} | Resolves to the current project name (ex. `app-a`) |
143-
| ${WORKSPACE_DIR}| Resolves to the current workspace direcory (ex. `/Users/theunderscorer/nx-monorepo`) |
144+
| ${WORKSPACE_DIR}| Resolves to the current workspace directory (ex. `/Users/theunderscorer/nx-monorepo`) |
144145
145146
146147
Every available option support tokens - this included nested objects and arrays.

packages/nx-semantic-release/src/config/apply-tokens.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const requiredOptions: SemanticReleaseOptions = {
1414

1515
const mockTokens: ConfigTokensDict = {
1616
projectDir: 'apps/app-a',
17+
relativeProjectDir: 'apps/app-a',
1718
projectName: 'app-a',
1819
workspaceDir: '.',
1920
};

packages/nx-semantic-release/src/config/apply-tokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SemanticReleaseOptions } from '../executors/semantic-release/semantic-r
22
import deepMap from 'deep-map';
33

44
export interface ConfigTokensDict {
5+
relativeProjectDir: string;
56
projectDir: string;
67
projectName: string;
78
workspaceDir: string;
@@ -13,6 +14,7 @@ export function applyTokensToSemanticReleaseOptions(
1314
) {
1415
const replaceTokens = (value: string): string => {
1516
return value
17+
.replaceAll('${RELATIVE_PROJECT_DIR}', tokens.relativeProjectDir)
1618
.replaceAll('${PROJECT_DIR}', tokens.projectDir)
1719
.replaceAll('${PROJECT_NAME}', tokens.projectName)
1820
.replaceAll('${WORKSPACE_DIR}', tokens.workspaceDir);

packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from "path";
12
import {
23
createProjectGraphAsync,
34
ExecutorContext,
@@ -140,6 +141,7 @@ export function resolveOptions(
140141

141142
return applyTokensToSemanticReleaseOptions(mergedOptions, {
142143
projectName: context.projectName as string,
144+
relativeProjectDir: path.relative(context.cwd, getDefaultProjectRoot(context)),
143145
projectDir: getDefaultProjectRoot(context),
144146
workspaceDir: workspaceRoot,
145147
});

packages/nx-semantic-release/src/generators/setup-project/setup-project.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from "path";
12
import { SemanticReleaseOptions } from '../../executors/semantic-release/semantic-release';
23
import {
34
Tree,
@@ -27,6 +28,7 @@ export async function setupProject(
2728
const semanticReleaseConfig = applyTokensToSemanticReleaseOptions(options, {
2829
projectName,
2930
projectDir: projectConfig.root,
31+
relativeProjectDir: path.relative(workspaceRoot, projectConfig.root),
3032
workspaceDir: workspaceRoot,
3133
});
3234

0 commit comments

Comments
 (0)