Skip to content

Commit

Permalink
Merge pull request #122 from srleecode/17.2.8
Browse files Browse the repository at this point in the history
fix(121): fixed issue with / at end of grouping folder
  • Loading branch information
srleecode authored Jan 6, 2024
2 parents 9311308 + 438ca7d commit 1724ccc
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 337 deletions.
584 changes: 292 additions & 292 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@srleecode/domain",
"version": "17.2.7",
"version": "17.2.8",
"private": true,
"description": "Nrwl nx plugin to allow operations at the domain level",
"homepage": "https://github.com/srleecode/domain",
Expand All @@ -26,7 +26,7 @@
"workspace-generator": "nx workspace-generator"
},
"dependencies": {
"@nx/devkit": "17.2.7",
"@nx/devkit": "17.2.8",
"@storybook/builder-webpack5": "7.5.3",
"@storybook/core-server": "7.5.3",
"@storybook/manager-webpack5": "6.5.16",
Expand All @@ -52,24 +52,24 @@
"husky": "^8.0.3",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"nx": "17.2.7",
"nx": "17.2.8",
"prettier": "3.1.0",
"rimraf": "^5.0.5",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"tslib": "^2.6.2",
"typescript": "5.2.2",
"yarn": "^1.22.21",
"@nx/workspace": "17.2.7",
"@nx/storybook": "17.2.7",
"@nx/js": "17.2.7",
"@nx/eslint-plugin": "17.2.7",
"@nx/cypress": "17.2.7",
"@nx/plugin": "17.2.7",
"@nx/node": "17.2.7",
"@nx/jest": "17.2.7",
"@nx/angular": "17.2.7",
"@nx/eslint": "17.2.7"
"@nx/workspace": "17.2.8",
"@nx/storybook": "17.2.8",
"@nx/js": "17.2.8",
"@nx/eslint-plugin": "17.2.8",
"@nx/cypress": "17.2.8",
"@nx/plugin": "17.2.8",
"@nx/node": "17.2.8",
"@nx/jest": "17.2.8",
"@nx/angular": "17.2.8",
"@nx/eslint": "17.2.8"
},
"engines": {
"node": ">=18.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ describe('setupDomainTestGenerator', () => {
tree = createTreeWithEmptyWorkspace();
tree.write(`libs/test-app/test-domain/shell/src.index.ts`, '');
await createApplicationLayerGenerator(tree, {
groupingFolder: 'libs/test-app/test-domain',
groupingFolder: 'libs/test-app/test-domain/',
buildable: true,
strict: false,
enableIvy: true,
publishable: false,
});
await setupDomainTestGenerator(tree, {
groupingFolder: 'libs/test-app/test-domain',
groupingFolder: 'libs/test-app/test-domain/',
type: 'e2e',
});
}, 240000);

it('should move cypress directory from apps to libs', async () => {
expect(
tree.exists(`libs/test-app/test-domain/.e2e/cypress.config.ts`)
tree.exists(`libs/test-app/test-domain/.e2e/cypress.config.ts`),
).toBe(true);
});

it('should update cypress cypress project name to correct name', async () => {
expect(
readProjectConfiguration(tree, 'e2e-test-app-test-domain')
readProjectConfiguration(tree, 'e2e-test-app-test-domain'),
).toBeDefined();
});

it('should delete dev server target from e2e target', async () => {
const projectConfig = readProjectConfiguration(
tree,
'e2e-test-app-test-domain'
'e2e-test-app-test-domain',
);
const e2eTarget = projectConfig.targets['e2e'];
expect(e2eTarget.options.devServerTarget).toBeUndefined();
Expand All @@ -47,28 +47,28 @@ describe('setupDomainTestGenerator', () => {

it('should remove page object file', () => {
expect(
tree.exists(`libs/test-app/test-domain/.e2e/src/support/app.po.ts`)
tree.exists(`libs/test-app/test-domain/.e2e/src/support/app.po.ts`),
).toBe(false);
});

it('should remove custom commands file', () => {
expect(
tree.exists(`libs/test-app/test-domain/.e2e/src/support/commands.ts`)
tree.exists(`libs/test-app/test-domain/.e2e/src/support/commands.ts`),
).toBe(false);
});

it('should reset index.ts to an empty file', () => {
expect(
tree
.read(`libs/test-app/test-domain/.e2e/src/support/index.ts`)
.toString()
.toString(),
).toBe('');
});

it('should add existing domain libraries as implicit dependencies', () => {
const projectConfig = readProjectConfiguration(
tree,
'e2e-test-app-test-domain'
'e2e-test-app-test-domain',
);
expect(projectConfig.implicitDependencies).toEqual([
'test-app-test-domain-shell',
Expand All @@ -78,7 +78,7 @@ describe('setupDomainTestGenerator', () => {
it('should add tags', () => {
const projectConfig = readProjectConfiguration(
tree,
'e2e-test-app-test-domain'
'e2e-test-app-test-domain',
);
expect(projectConfig.tags).toEqual([
'app:test-app',
Expand All @@ -105,7 +105,7 @@ describe('setupDomainTestGenerator', () => {
it('should replace e2e with the ct target', () => {
const projectConfig = readProjectConfiguration(
tree,
'ct-test-app-test-domain'
'ct-test-app-test-domain',
);
const ctTarget = projectConfig.targets['ct'];
expect(ctTarget).toEqual({
Expand Down
14 changes: 9 additions & 5 deletions packages/domain/generators/cypress/domain-test/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import { ProjectType } from '@nx/workspace';

export async function setupDomainTestGenerator(
tree: Tree,
options: SetupDomainTestGeneratorSchema
options: SetupDomainTestGeneratorSchema,
): Promise<void> {
const { groupingFolder, type } = options;
let { groupingFolder } = options;
const { type } = options;
groupingFolder = groupingFolder.endsWith('/')
? groupingFolder.slice(0, -1)
: groupingFolder;
validateGroupingFolder(tree, groupingFolder);
const dasherisedFolderPath = getDasherizedFolderPath(tree, groupingFolder);
const projectName = `${type}-${dasherisedFolderPath}`;
Expand All @@ -37,12 +41,12 @@ export async function setupDomainTestGenerator(
implicitDependencies: getImplicitDependencies(
tree,
groupingFolder,
dasherisedFolderPath
dasherisedFolderPath,
),
targets: {},
tags: getTags(tree, groupingFolder, type),
},
true
true,
);

await cypressE2EConfigurationGenerator(tree, {
Expand All @@ -63,5 +67,5 @@ export async function setupDomainTestGenerator(
export default setupDomainTestGenerator;

export const setupDomainTestSchematic = convertNxGenerator(
setupDomainTestGenerator
setupDomainTestGenerator,
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('createDomainLayerGenerator', () => {
enableIvy: true,
publishable: false,
};
const groupingFolder = 'libs/test-app/test-domain';
const groupingFolder = 'libs/test-app/test-domain/';
beforeEach(() => {
jest.clearAllMocks();
tree = createTreeWithEmptyWorkspace();
Expand All @@ -44,7 +44,7 @@ describe('createDomainLayerGenerator', () => {
groupingFolders.app,
ApplicationType.Angular,
true,
schema
schema,
);
});
it('should add jest junit reporter config when addJestJunitReporter is true', async () => {
Expand All @@ -58,4 +58,15 @@ describe('createDomainLayerGenerator', () => {
.toString();
expect(jestConfig).toMatch('jest-junit');
});
it('should add create correct domain name in tsconfig', async () => {
await createDomainLayerGenerator(tree, {
...commonLibraryOptions,
groupingFolder,
addJestJunitReporter: true,
});
const jestConfig = tree
.read(`${groupingFolder}/domain/project.json`)
.toString();
expect(jestConfig).toMatch('"name": "test-app-test-domain-domain"');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ describe('removeLibraryGenerator', () => {

it('should pass correct parameters to @nx/workspace:remove generator', async () => {
await removeLibraryGenerator(tree, {
libraryFolder: 'libs/test-app/test-domain/feature-test-example',
libraryFolder: 'libs/test-app/test-domain/feature-test-example/',
});
expect(nrwlWorkspaceMock.removeGenerator).toHaveBeenCalledWith(
expect.anything(),
{
forceRemove: true,
projectName: 'test-app-test-domain-feature-test-example',
skipFormat: false,
}
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ export const addDomainLibrary = async (
appGroupingFolder: string,
applicationType: ApplicationType,
removeLintOverrides: boolean,
schema?: Partial<Schema> & { addJestJunitReporter?: boolean }
schema?: Partial<Schema> & { addJestJunitReporter?: boolean },
): Promise<void> => {
groupingFolderPath = groupingFolderPath.endsWith('/')
? groupingFolderPath.slice(0, -1)
: groupingFolderPath;
const libraryCommonOptions = getLibraryCommonOptions(
tree,
name,
type,
groupingFolderPath,
schema
schema,
);
if (applicationType === ApplicationType.Angular) {
await libraryGenerator(tree, {
Expand All @@ -44,7 +47,7 @@ export const addDomainLibrary = async (
}
const dasherisedGroupingFolder = getDasherizedFolderPath(
tree,
groupingFolderPath
groupingFolderPath,
);
const e2eProjectName = `e2e-${dasherisedGroupingFolder}`;
const projectName = `${dasherisedGroupingFolder}-${libraryCommonOptions.name}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const getLibraryCommonOptions = (
name: string,
type: string,
groupingFolder: string,
createLibrarySchema: AngularCreateLibrarySchema
createLibrarySchema: AngularCreateLibrarySchema,
): LibraryCommonOptions => {
const { buildable, strict, enableIvy, publishable } = createLibrarySchema;
const libraryName = name ? `${type}-${dasherize(name)}` : type;
const domain = `${getDasherizedFolderPath(tree, groupingFolder)}`;
if (tree.children(`${groupingFolder}/${libraryName}`).length > 1) {
throw new Error(
`project already exists in: ${groupingFolder}/${libraryName}`
`project already exists in: ${groupingFolder}/${libraryName}`,
);
}
const npmScope = getNpmScope(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@ import { getDomainPath } from './get-domain-path';

export const getDasherizedFolderPath = (
tree: Tree,
groupingFolderPath: string
): string => getDomainPath(tree, groupingFolderPath).replace(/\//g, '-');
groupingFolderPath: string,
): string => {
const domainPath = getDomainPath(tree, groupingFolderPath).replace(
/\//g,
'-',
);
if (domainPath.endsWith('-')) {
return domainPath.slice(0, -1);
}
return domainPath;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { getWorkspaceLayout } from './get-workspace-layout';

export const getDomainPath = (
tree: Tree,
groupingFolderPath: string
groupingFolderPath: string,
): string => {
const workspaceLayout = getWorkspaceLayout(tree);
return (getNormalisedPath(groupingFolderPath) || '').replace(
`${workspaceLayout.libsDir}/`,
''
'',
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { GroupingFolders } from './model/grouping-folders.model';

export const getGroupingFolders = (
tree: Tree,
groupingFolderPath: string
groupingFolderPath: string,
): GroupingFolders => {
const groupingFolders = getDomainPath(tree, groupingFolderPath).split('/');
return {
app: groupingFolders?.[0],
domain: groupingFolders.slice(1),
domain: groupingFolders.slice(1).filter((folder) => folder),
};
};
2 changes: 1 addition & 1 deletion packages/domain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@srleecode/domain",
"version": "17.2.7",
"version": "17.2.8",
"main": "index.js",
"executors": "./executors.json",
"generators": "./generators.json",
Expand Down

0 comments on commit 1724ccc

Please sign in to comment.