Skip to content

Commit

Permalink
feat: rework + app generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararok committed May 31, 2024
1 parent d97175e commit efb2ad6
Show file tree
Hide file tree
Showing 101 changed files with 2,394 additions and 1,090 deletions.
59 changes: 33 additions & 26 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,57 @@
"default",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/eslint.config.js",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/src/test-setup.[jt]s",
"!{projectRoot}/test-setup.[jt]s"
"!{projectRoot}/test/**/?(*.)+(test).ts?(x)?(.snap)",
"!{projectRoot}/tsconfig.test.json",
"!{projectRoot}/jest.config.ts"
],
"sharedGlobals": []
},
"targetDefaults": {
"lint": {
"inputs": [
"default",
"{projectRoot}/**/*.ts",
"{workspaceRoot}/.eslintrc.json",
"{workspaceRoot}/.eslintignore"
],
"cache": true
},
"@nx/js:tsc": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
},
"@nx/eslint:lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json", "{workspaceRoot}/.eslintignore"],
"cache": true,
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json",
"{workspaceRoot}/.eslintignore"
]
"options": {
"lintFilePatterns": ["{projectRoot}/**/*.ts", "{projectRoot}/package.json"]
},
"configurations": {
"fix": {
"fix": true,
"cache": false
}
}
},
"@nx/jest:jest": {
"cache": true,
"outputs": ["{options.outputFile}"],
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"options": {
"passWithNoTests": true,
"runInBand": true
"jestConfig": "{projectRoot}/jest.config.ts",
"runInBand": true,
"passWithNoTests": true
},
"configurations": {
"watch": {
"watch": true
},
"ci": {
"ci": true,
"codeCoverage": true
},
"updateSnapshot": {
"updateSnapshot": true
}
}
},
"@nx/js:tsc": {
"inputs": ["production", "^production"],
"outputs": ["{options.outputPath}"],
"dependsOn": ["^build", "test"],
"cache": true,
"options": {
"outputPath": "dist/{projectRoot}",
"tsConfig": "{projectRoot}/tsconfig.build.json"
}
}
},
"release": {
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
"private": true,
"packageManager": "[email protected]",
"dependencies": {
"@nx/devkit": "19.1.0",
"create-nx-workspace": "19.0.4",
"@nx/devkit": "19.1.1",
"create-nx-workspace": "19.1.1",
"tslib": "^2.6.2"
},
"devDependencies": {
"@nx/eslint": "19.1.0",
"@nx/eslint-plugin": "19.1.0",
"@nx/jest": "19.1.0",
"@nx/js": "19.1.0",
"@nx/linter": "19.1.0",
"@nx/plugin": "19.1.0",
"@nx/workspace": "19.1.0",
"@nx/eslint": "19.1.1",
"@nx/eslint-plugin": "19.1.1",
"@nx/jest": "19.1.1",
"@nx/js": "19.1.1",
"@nx/linter": "19.1.1",
"@nx/plugin": "19.1.1",
"@nx/workspace": "19.1.1",
"@swc-node/register": "~1.8.0",
"@swc/cli": "~0.3.12",
"@swc/core": "~1.3.85",
Expand All @@ -35,7 +35,7 @@
"husky": "^9.0.11",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.7.0",
"nx": "19.1.0",
"nx": "19.1.1",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"ts-node": "10.9.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default {
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/e2e',
globalSetup: '<rootDir>/src/helper/startLocalRegistry.ts',
globalTeardown: '<rootDir>/src/helper/stopLocalRegistry.ts',
globalSetup: '<rootDir>/src/helper/globalSetup.ts',
globalTeardown: '<rootDir>/src/helper/globalTeardown.ts',
};
11 changes: 1 addition & 10 deletions packages/e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,13 @@
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"runInBand": true,
"codeCoverage": false,
"codeCoverage": false
},
"dependsOn": ["^build"]
},
"lint": {
"executor": "@nx/eslint:lint"
},
"lint-fix": {
"executor": "@nx/eslint:lint",
"options": {
"fix": true
}
}
}
}
23 changes: 7 additions & 16 deletions packages/e2e/src/generators/application.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
import { createTestWorkspace, execNx } from '../helper/functions';
import { execNx, getTestWorkspaceRoot } from '../helper/functions';
import { existsSync } from 'fs';
import { join } from 'path';

describe('Application', () => {
let workspaceRoot;
const workspaceRoot = getTestWorkspaceRoot();

beforeAll(() => {
workspaceRoot = createTestWorkspace('application-test');
});

afterAll(() => {
if (!workspaceRoot) {
return;
}
execNx(workspaceRoot, 'reset');
});

describe.each(['backend'])('Application[%s]', (type) => {
describe.each(['backend', 'frontend'])('Application[%s]', (type) => {
beforeAll(() => {
execNx(workspaceRoot, `g @hexancore/nx:app acme/${type} --type ${type}`);
});

test('should be created', () => {
expect(existsSync(join(workspaceRoot, `apps/acme/${type}`, 'package.json'))).toBeTruthy();
expect(existsSync(join(workspaceRoot, `apps/acme/${type}`, 'project.json'))).toBeTruthy();
});


test('target build should pass', () => {
execNx(workspaceRoot, `run app-acme-${type}:build`);

expect(existsSync(join(workspaceRoot, `dist/apps/acme/${type}/src/main.js`))).toBeTruthy();
const mainFile = type === 'frontend' ? 'index.html' : 'src/main.js';

expect(existsSync(join(workspaceRoot, `dist/apps/acme/${type}/${mainFile}`))).toBeTruthy();
});

test('target test should pass', () => {
Expand Down
21 changes: 6 additions & 15 deletions packages/e2e/src/generators/library.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { createTestWorkspace, execNx } from '../helper/functions';
import { execNx, getTestWorkspaceRoot } from '../helper/functions';
import { existsSync } from 'fs';
import { join } from 'path';

describe('Library', () => {
let workspaceRoot;
const workspaceRoot = getTestWorkspaceRoot();

beforeAll(() => {
workspaceRoot = createTestWorkspace('library-test');
});

afterAll(() => {
if (!workspaceRoot) {
return;
}
execNx(workspaceRoot, 'reset');
});

describe.each(['backend', 'shared'])('Library %s', (type) => {
describe.each(['backend', 'frontend', 'shared'])('Library %s', (type) => {
beforeAll(() => {
execNx(workspaceRoot, `g @hexancore/nx:lib acme/${type} --type ${type}`);
});
Expand All @@ -28,7 +17,9 @@ describe('Library', () => {
test('target build should pass', () => {
execNx(workspaceRoot, `run acme-${type}:build`);

expect(existsSync(join(workspaceRoot, `dist/libs/acme/${type}/src/index.js`))).toBeTruthy();
const expectedIndex = type === 'frontend' ? 'index.mjs' : 'src/index.js';

expect(existsSync(join(workspaceRoot, `dist/libs/acme/${type}/${expectedIndex}`))).toBeTruthy();
});

test('target test should pass', () => {
Expand Down
7 changes: 2 additions & 5 deletions packages/e2e/src/generators/preset.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { existsSync } from 'fs';
import { join } from 'path';

import { createTestWorkspace } from '../helper/functions';
import { getTestWorkspaceRoot } from '../helper/functions';

describe('Preset', () => {
let workspaceRoot: string;
const workspaceRoot = getTestWorkspaceRoot();

test('should be installed', () => {
workspaceRoot = createTestWorkspace('preset-test');

expect(existsSync(join(workspaceRoot, 'package.json'))).toBeTruthy();
});
});
Expand Down
16 changes: 14 additions & 2 deletions packages/e2e/src/helper/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import { execSync } from 'child_process';
import { join, dirname } from 'path';
import { existsSync, mkdirSync, rmSync } from 'fs';

export function createTestWorkspace(name: string): string {
export function getTestWorkspaceRoot(): string {
const root = process.env['TEST_WORKSPACE_ROOT'] ?? null;

if (!root) {
throw new Error('Empty env[TEST_WORKSPACE_ROOT]');
}

return root;
}

export function createTestWorkspace(name = 'test-workspace'): string {
process.env['HUSKY'] = '0';

const cwd = process.cwd();
Expand All @@ -13,6 +23,8 @@ export function createTestWorkspace(name: string): string {
rmSync(workspaceRoot, {
recursive: true,
force: true,
maxRetries: 3,
retryDelay: 3 * 1000,
});
}

Expand Down Expand Up @@ -42,6 +54,6 @@ export function execNx(workspaceRoot: string, command: string): void {
cwd: workspaceRoot,
stdio: 'inherit',
env: process.env,
timeout: 3*60*1000
timeout: 3 * 60 * 1000
});
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
import { existsSync, rmSync } from 'fs';
import { execSync } from 'child_process';
import { existsSync} from 'fs';
import { releasePublish, releaseVersion } from 'nx/release';
import { join } from 'path';

import { createTestWorkspace } from './functions';

export default async () => {
// local registry target to run
const localRegistryTarget = '@nx-hexancore/source:local-registry';
Expand All @@ -12,9 +15,8 @@ export default async () => {
const cwd = process.cwd();
process.env['PNPM_HOME'] = join(cwd, 'tmp', 'pnpm-store');
if (existsSync(process.env['PNPM_HOME'])) {
rmSync(process.env['PNPM_HOME'], {
recursive: true,
force: true,
execSync('pnpm store prune', {
env: process.env
});
}

Expand All @@ -38,4 +40,6 @@ export default async () => {
tag: 'e2e',
firstRelease: true,
});

process.env['TEST_WORKSPACE_ROOT'] = createTestWorkspace();
};
14 changes: 14 additions & 0 deletions packages/e2e/src/helper/globalTeardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { existsSync } from "fs";
import { execNx, getTestWorkspaceRoot } from "./functions";

export default () => {
if (global.stopLocalRegistry) {
global.stopLocalRegistry();
}

const workspaceRoot = getTestWorkspaceRoot();
if (existsSync(workspaceRoot)) {
execNx(workspaceRoot, 'reset');
}
};

5 changes: 0 additions & 5 deletions packages/e2e/src/helper/stopLocalRegistry.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"url": "https://andrzejwasiak.pl"
},
"dependencies": {
"@nx/devkit": "19.1.0",
"@nx/devkit": "19.1.1",
"tslib": "^2.6.2"
},
"files": [
Expand Down
Loading

0 comments on commit efb2ad6

Please sign in to comment.