Skip to content

Commit

Permalink
feat: add RELATIVE_PROJECT_DIR token
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
TheUnderScorer and AndriiTsok authored Oct 31, 2023
1 parent dba3baf commit f041755
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const requiredOptions: SemanticReleaseOptions = {

const mockTokens: ConfigTokensDict = {
projectDir: 'apps/app-a',
relativeProjectDir: 'apps/app-a',
projectName: 'app-a',
workspaceDir: '.',
};
Expand Down
2 changes: 2 additions & 0 deletions packages/nx-semantic-release/src/config/apply-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "path";
import {
createProjectGraphAsync,
ExecutorContext,
Expand Down Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "path";
import { SemanticReleaseOptions } from '../../executors/semantic-release/semantic-release';
import {
Tree,
Expand Down Expand Up @@ -27,6 +28,7 @@ export async function setupProject(
const semanticReleaseConfig = applyTokensToSemanticReleaseOptions(options, {
projectName,
projectDir: projectConfig.root,
relativeProjectDir: path.relative(workspaceRoot, projectConfig.root),
workspaceDir: workspaceRoot,
});

Expand Down

0 comments on commit f041755

Please sign in to comment.