Skip to content

Commit

Permalink
feat: reworked generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararok committed Jun 9, 2024
1 parent 70ece50 commit c4d5c3f
Show file tree
Hide file tree
Showing 99 changed files with 12,912 additions and 5,597 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
node_modules
dist
.verdaccio
.nx
.husky
coverage
tmp
2 changes: 1 addition & 1 deletion .github/actions/install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runs:
- name: PNPM install
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # 4.0.0
with:
version: 8.15.8
version: 9.2.0
run_install: false
- name: Get pnpm store directory
shell: bash
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ testem.log
.DS_Store
Thumbs.db

.nx/cache
.nx/cache
.nx/workspace-data
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
tmp
dist
coverage
.nx
.nx
/.nx/workspace-data
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,42 @@ Perfect for teams looking to combine the flexibility of Hexancore with the power
## Quick Start

```bash
npx create-nx-workspace <workspace-name> --pm pnpm --preset @hexancore/nx --nxCloud false --workspaceType integrated
npx create-nx-workspace <workspace-name> --pm pnpm --preset @hexancore/nx --nxCloud skip --workspaceType integrated
```

## Documentation

https://hexancore.github.io/hexancore/guide/getting-started
### Generators

#### app
Creates new application.

```bash
nx g @hexancore/nx:app <directory> --type <backend|frontend>
```

**Options**
- **directory** - Application directory, final: `apps/<directory>` and project name will be `app-<directory where all '/' replaced with '-'>`

- **type** - Application type
- backend
- frontend

#### lib

Creates new library.

```bash
nx g @hexancore/nx:lib <directory> --type <backend|frontend|shared>
```

**Options**
- **directory** - Library directory, final: `libs/<directory>` and project name will be `<directory where all '/' replaced with '-'>`

- **type** - Library type
- backend
- frontend
- shared

**More documentation**
https://hexancore.dev/guide/getting-started
4 changes: 2 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@nx/jest:jest": {
"cache": true,
"outputs": ["{options.outputFile}"],
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"inputs": ["default", "{workspaceRoot}/jest.preset.js"],
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"runInBand": true,
Expand All @@ -56,7 +56,7 @@
}
},
"@nx/js:tsc": {
"inputs": ["production", "^production"],
"inputs": ["production"],
"outputs": ["{options.outputPath}"],
"dependsOn": ["^build", "test"],
"cache": true,
Expand Down
59 changes: 43 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@nx-hexancore/source",
"version": "0.0.0",
"license": "MIT",
"author": "Andrzej Wasiak",
"scripts": {
"prepare": "node .husky/install.mjs",
"ci": "nx run-many --targets=lint,test,build,e2e --configuration=ci",
Expand All @@ -13,40 +14,66 @@
"directory": "packages/plugin"
},
"private": true,
"packageManager": "pnpm@8.15.8",
"packageManager": "pnpm@9.2.0",
"dependencies": {
"@nx/devkit": "19.1.1",
"create-nx-workspace": "19.1.1",
"@nx/devkit": "19.2.2",
"create-nx-workspace": "19.2.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@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",
"@intlify/unplugin-vue-i18n": "^4.0.0",
"@nx/eslint": "19.2.2",
"@nx/eslint-plugin": "19.2.2",
"@nx/jest": "19.2.2",
"@nx/js": "19.2.2",
"@nx/linter": "19.2.2",
"@nx/plugin": "19.2.2",
"@nx/storybook": "19.2.2",
"@nx/vite": "19.2.2",
"@nx/vue": "19.2.2",
"@nx/workspace": "19.2.2",
"@rollup/plugin-node-resolve": "^15.2.3",
"@storybook/addon-essentials": "^8.1.5",
"@storybook/addon-interactions": "^8.1.5",
"@storybook/builder-vite": "^8.1.5",
"@storybook/core-server": "^8.1.5",
"@storybook/test": "^8.1.5",
"@storybook/vue3": "^8.1.5",
"@storybook/vue3-vite": "^8.1.5",
"@swc-node/register": "1.9.2",
"@swc/cli": "~0.3.12",
"@swc/core": "~1.3.85",
"@swc/helpers": "~0.5.2",
"@swc/core": "1.5.7",
"@swc/helpers": "0.5.11",
"@types/jest": "^29.4.0",
"@types/node": "20.12.12",
"@typescript-eslint/eslint-plugin": "^7.3.0",
"@typescript-eslint/parser": "^7.3.0",
"@vitejs/plugin-basic-ssl": "^1.1.0",
"@vitejs/plugin-vue": "^5.0.4",
"@vitest/coverage-v8": "1.6.*",
"@vitest/ui": "1.6.*",
"autoprefixer": "^10.4.19",
"eslint": "~8.57.0",
"eslint-config-prettier": "^9.0.0",
"glob": "^10.4.1",
"husky": "^9.0.11",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.7.0",
"nx": "19.1.1",
"nx": "19.2.2",
"prettier": "^2.8.8",
"rollup": "^4.17.0",
"ts-jest": "^29.1.0",
"ts-node": "10.9.1",
"tsx": "^4.10.5",
"typescript": "~5.4.2",
"verdaccio": "^5.0.4"
"typescript": "5.4.5",
"unplugin-vue-components": "^0.27.0",
"verdaccio": "^5.0.4",
"vite": "^5.2.10",
"vite-plugin-dts": "3.9.1",
"vite-plugin-lib-inject-css": "2.1.1",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.6.*",
"vue-i18n": "^9.13.1"
},
"nx": {
"includedScripts": []
Expand Down
62 changes: 51 additions & 11 deletions packages/e2e/src/generators/library.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,74 @@
import { execNx, getTestWorkspaceRoot } from '../helper/functions';
import { existsSync } from 'fs';
import { existsSync, rmSync } from 'fs';
import { join } from 'path';

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

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

describe.each(['backend', 'frontend', 'shared'])('%s', (type) => {
test('should be created', () => {
expect(existsSync(join(workspaceRoot, `libs/acme/${type}`, 'package.json'))).toBeTruthy();
});

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

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

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

expect(existsSync(join(workspaceRoot, `dist/libs/acme/backend/src/index.js`))).toBeTruthy();
});
});

const expectedIndex = type === 'frontend' ? 'index.mjs' : 'src/index.js';
describe('shared', () => {
test('target build should pass', () => {
execNx(workspaceRoot, `run acme-shared:build`);

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


describe('frontend', () => {
test('target build should pass', () => {
execNx(workspaceRoot, `run acme-frontend:build`);

const distDir = 'dist/libs/acme/frontend';
const expectedDistFiles = [
'Asset/Style/variables.css',
'Component/Button/Button.css',
'Component/Button/Button.script.js',
'Component/Button/Button.vue.js'
].map((f) => `${distDir}/${f}`);

// only when run e2e tests it's appears.
if (existsSync(`${distDir}/ugin-vue_export-helper`)) {
rmSync(`${distDir}/ugin-vue_export-helper`);
}

expectedDistFiles.forEach((f) => {
expect(existsSync(join(workspaceRoot, f))).toBeTruthy();
});

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

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

});

11 changes: 7 additions & 4 deletions packages/e2e/src/helper/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function createTestWorkspace(name = 'test-workspace'): string {
const workspaceRoot = join(cwd, 'tmp', name);

if (existsSync(workspaceRoot)) {
execNx(workspaceRoot, 'reset');
execNx(workspaceRoot, 'reset', false);
rmSync(workspaceRoot, {
recursive: true,
force: true,
Expand Down Expand Up @@ -49,11 +49,14 @@ export function createTestWorkspace(name = 'test-workspace'): string {
return workspaceRoot;
}

export function execNx(workspaceRoot: string, command: string): void {
execSync(`nx ${command}`, {
export function execNx(workspaceRoot: string, command: string, liveOutput?: boolean): Buffer {
liveOutput = liveOutput ?? true;
const output = execSync(`nx ${command}`, {
cwd: workspaceRoot,
stdio: 'inherit',
stdio: liveOutput ? 'inherit' : undefined,
env: process.env,
timeout: 3 * 60 * 1000
});

return output;
}
5 changes: 3 additions & 2 deletions packages/e2e/src/helper/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
import { execSync } from 'child_process';
import { existsSync} from 'fs';
import { existsSync } from 'fs';
import { releasePublish, releaseVersion } from 'nx/release';
import { join } from 'path';

Expand All @@ -11,9 +11,10 @@ export default async () => {
const localRegistryTarget = '@nx-hexancore/source:local-registry';
const storage = './tmp/local-registry/storage';


const cwd = process.cwd();
process.env['PNPM_HOME'] = join(cwd, 'tmp', 'pnpm-store');
process.env['NODE_PENDING_DEPRECATION'] = '0';

if (existsSync(process.env['PNPM_HOME'])) {
execSync('pnpm store prune', {
env: process.env
Expand Down
3 changes: 1 addition & 2 deletions packages/e2e/src/helper/globalTeardown.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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');
execNx(workspaceRoot, 'reset', false);
}
};

1 change: 1 addition & 0 deletions packages/plugin/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_CJS_IGNORE_WARNING=true
28 changes: 0 additions & 28 deletions packages/plugin/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,6 @@
],
"rules": {}
},
{
"files": [
"*.json"
],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": [
"build"
],
"includeTransitiveDependencies": true,
"checkMissingDependencies": true,
"checkObsoleteDependencies": true,
"checkVersionMismatches": true,
"ignoredFiles": [
"vite.config.ts"
],
"ignoredDependencies": [
"ts-jest",
"tslib",
"@nx/devkit"
]
}
]
}
},
{
"files": [
"./package.json",
Expand Down
Loading

0 comments on commit c4d5c3f

Please sign in to comment.