@postxl/generators 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend-core/template/apps/api/src/e2e.ts +13 -4
- package/dist/e2e/e2e.generator.js +2 -14
- package/dist/e2e/e2e.generator.js.map +1 -1
- package/dist/e2e/generators/docker-sh.generator.d.ts +2 -0
- package/dist/e2e/generators/docker-sh.generator.js +25 -0
- package/dist/e2e/generators/docker-sh.generator.js.map +1 -0
- package/dist/frontend-core/template/src/context-providers/auth-context-provider.tsx +2 -5
- package/package.json +1 -1
- package/dist/e2e/template/scripts/docker.sh +0 -17
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
import { INestApplication } from '@nestjs/common'
|
|
73
73
|
|
|
74
74
|
import { getMemoryUsage } from 'apps/api/src/console.logger'
|
|
75
|
+
import { Mutex } from 'async-mutex'
|
|
75
76
|
import express, { Express, Request, Response } from 'express'
|
|
76
77
|
import http, { Server } from 'node:http'
|
|
77
78
|
import { format } from 'node:util'
|
|
@@ -159,13 +160,21 @@ const defaultBackendId = zSpecId.parse('default-backend')
|
|
|
159
160
|
const backends = new Map<SpecId, Backend>()
|
|
160
161
|
const usedPorts = new Set<Port>()
|
|
161
162
|
|
|
163
|
+
// Mutex to prevent race conditions when allocating ports
|
|
164
|
+
const portAllocationMutex = new Mutex()
|
|
165
|
+
|
|
162
166
|
async function getNextAvailablePort(): Promise<Port> {
|
|
167
|
+
const release = await portAllocationMutex.acquire()
|
|
163
168
|
let port: Port = 4000 as Port
|
|
164
|
-
|
|
165
|
-
port
|
|
169
|
+
try {
|
|
170
|
+
while (usedPorts.has(port) || !(await checkPortAvailability(port))) {
|
|
171
|
+
port = (port + 1) as Port
|
|
172
|
+
}
|
|
173
|
+
usedPorts.add(port)
|
|
174
|
+
return port
|
|
175
|
+
} finally {
|
|
176
|
+
release()
|
|
166
177
|
}
|
|
167
|
-
usedPorts.add(port)
|
|
168
|
-
return port
|
|
169
178
|
}
|
|
170
179
|
|
|
171
180
|
async function startBackend(spec: SpecId, isDefault: boolean): Promise<Backend_Running> {
|
|
@@ -36,8 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.generator = exports.generatorId = void 0;
|
|
37
37
|
const path = __importStar(require("node:path"));
|
|
38
38
|
const Generator = __importStar(require("@postxl/generator"));
|
|
39
|
+
const docker_sh_generator_1 = require("./generators/docker-sh.generator");
|
|
39
40
|
const model_test_id_generator_1 = require("./generators/model-test-id.generator");
|
|
40
|
-
const DOCKER_SH_FILENAME = 'docker.sh';
|
|
41
41
|
const PACKAGE_JSON_FILENAME = 'package.json';
|
|
42
42
|
exports.generatorId = Generator.toGeneratorInterfaceId('e2e');
|
|
43
43
|
exports.generator = {
|
|
@@ -61,20 +61,7 @@ exports.generator = {
|
|
|
61
61
|
targetPath: '/e2e',
|
|
62
62
|
filter: (filePath) => !filePath.endsWith(PACKAGE_JSON_FILENAME),
|
|
63
63
|
});
|
|
64
|
-
await vfs.loadFolder({
|
|
65
|
-
diskPath: path.resolve(__dirname, './template/scripts'),
|
|
66
|
-
targetPath: '/scripts',
|
|
67
|
-
filter: (filePath) => !filePath.endsWith(DOCKER_SH_FILENAME),
|
|
68
|
-
});
|
|
69
64
|
// Load files with template substitution
|
|
70
|
-
const dockerShContent = await Generator.generateFromTemplate({
|
|
71
|
-
file: path.resolve(__dirname, './template/scripts', DOCKER_SH_FILENAME),
|
|
72
|
-
context: templateContext,
|
|
73
|
-
});
|
|
74
|
-
if (dockerShContent.isErr()) {
|
|
75
|
-
throw new Error(`Failed to generate docker.sh: ${dockerShContent.unwrapErr().message}`);
|
|
76
|
-
}
|
|
77
|
-
vfs.write(`/scripts/${DOCKER_SH_FILENAME}`, dockerShContent.unwrap());
|
|
78
65
|
const packageJsonContent = await Generator.generateFromTemplate({
|
|
79
66
|
file: path.resolve(__dirname, './template/e2e', PACKAGE_JSON_FILENAME),
|
|
80
67
|
context: templateContext,
|
|
@@ -85,6 +72,7 @@ exports.generator = {
|
|
|
85
72
|
vfs.write(`/e2e/${PACKAGE_JSON_FILENAME}`, packageJsonContent.unwrap());
|
|
86
73
|
// write dynamic files
|
|
87
74
|
vfs.write('/e2e/support/model-test-ids.ts', (0, model_test_id_generator_1.generateModelTestIds)(context.e2e));
|
|
75
|
+
vfs.write('/scripts/docker.sh', (0, docker_sh_generator_1.generateDockerSh)(context));
|
|
88
76
|
context.vfs.insertFromVfs({ vfs, targetPath: '/' });
|
|
89
77
|
return context;
|
|
90
78
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"e2e.generator.js","sourceRoot":"","sources":["../../src/e2e/e2e.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiC;AAEjC,6DAA8C;AAI9C,kFAA2E;AAE3E,MAAM,
|
|
1
|
+
{"version":3,"file":"e2e.generator.js","sourceRoot":"","sources":["../../src/e2e/e2e.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiC;AAEjC,6DAA8C;AAI9C,0EAAmE;AACnE,kFAA2E;AAE3E,MAAM,qBAAqB,GAAG,cAAc,CAAA;AAsB/B,QAAA,WAAW,GAAG,SAAS,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;AAErD,QAAA,SAAS,GAAiC;IACrD,EAAE,EAAE,mBAAW;IACf,QAAQ,EAAE,CAAC,mBAAW,CAAC;IAEvB,QAAQ,EAAE,CAAiD,GAAY,EAAiB,EAAE;QACxF,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;QACvF,OAAO;YACL,GAAG,GAAG;YACN,GAAG,EAAE;gBACH,OAAO,EAAE,EAAE;aACZ;SACF,CAAA;IACH,CAAC;IAED,QAAQ,EAAE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AA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateDockerSh = generateDockerSh;
|
|
4
|
+
function generateDockerSh({ schema: { projectType, slug } }) {
|
|
5
|
+
const mountPath = projectType === 'workspace' ? '../../' : '${PWD}';
|
|
6
|
+
const workDir = projectType === 'workspace' ? `/pxl/projects/${slug}/e2e` : '/pxl/e2e';
|
|
7
|
+
return /*sh*/ String.raw `#!/bin/bash
|
|
8
|
+
# This script should only be run via 'pnpm docker' in the project root!
|
|
9
|
+
# Define a name for the image
|
|
10
|
+
IMAGE_NAME="e2e-pxl-env"
|
|
11
|
+
|
|
12
|
+
# Build the image from the Dockerfile in the current directory
|
|
13
|
+
docker build -t $IMAGE_NAME ./e2e/
|
|
14
|
+
|
|
15
|
+
# Run a container from the built image
|
|
16
|
+
# Add user mapping only on Linux/WSL to avoid permission issues with mounted volumes
|
|
17
|
+
USER_FLAG=""
|
|
18
|
+
if [[ "$(uname)" = "Linux" ]]; then
|
|
19
|
+
USER_FLAG="-u $(id -u):$(id -g)"
|
|
20
|
+
fi
|
|
21
|
+
${projectType === 'workspace' ? '# Mount the entire monorepo to preserve pnpm workspace symlinks' : ''}
|
|
22
|
+
docker run -p 3030:3030 $USER_FLAG -v ${mountPath}:/pxl -w ${workDir} --rm -it $IMAGE_NAME /bin/bash
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=docker-sh.generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker-sh.generator.js","sourceRoot":"","sources":["../../../src/e2e/generators/docker-sh.generator.ts"],"names":[],"mappings":";;AAEA,4CAoBC;AApBD,SAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAiB;IAC/E,MAAM,SAAS,GAAG,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;IACnE,MAAM,OAAO,GAAG,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,iBAAiB,IAAI,MAAM,CAAC,CAAC,CAAC,UAAU,CAAA;IACtF,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;EAcxB,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;wCAC9D,SAAS,YAAY,OAAO;CACnE,CAAA;AACD,CAAC"}
|
|
@@ -73,8 +73,8 @@ keycloak.onAuthError = () => {
|
|
|
73
73
|
|
|
74
74
|
export function AuthProvider({ children }: Readonly<{ children: React.ReactNode }>) {
|
|
75
75
|
const [user, setUser] = React.useState<AppUser | null>(null)
|
|
76
|
-
const [isAuthenticated, setIsAuthenticated] = useState(
|
|
77
|
-
const [isInitComplete, setIsInitComplete] = useState(
|
|
76
|
+
const [isAuthenticated, setIsAuthenticated] = useState(!APP_CONFIG.AUTH)
|
|
77
|
+
const [isInitComplete, setIsInitComplete] = useState(!APP_CONFIG.AUTH)
|
|
78
78
|
|
|
79
79
|
const trpc = useTRPC()
|
|
80
80
|
|
|
@@ -137,9 +137,6 @@ export function AuthProvider({ children }: Readonly<{ children: React.ReactNode
|
|
|
137
137
|
|
|
138
138
|
if (APP_CONFIG.AUTH) {
|
|
139
139
|
void initKeycloak()
|
|
140
|
-
} else {
|
|
141
|
-
setIsAuthenticated(true)
|
|
142
|
-
setIsInitComplete(true)
|
|
143
140
|
}
|
|
144
141
|
}, [logout])
|
|
145
142
|
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Define a name for the image
|
|
4
|
-
IMAGE_NAME="e2e-pxl-env"
|
|
5
|
-
|
|
6
|
-
# Build the image from the Dockerfile in the current directory
|
|
7
|
-
docker build -t $IMAGE_NAME ./e2e/
|
|
8
|
-
|
|
9
|
-
# Run a container from the built image
|
|
10
|
-
# Add user mapping only on Linux/WSL to avoid permission issues with mounted volumes
|
|
11
|
-
USER_FLAG=""
|
|
12
|
-
if [[ "$(uname)" = "Linux" ]]; then
|
|
13
|
-
USER_FLAG="-u $(id -u):$(id -g)"
|
|
14
|
-
fi
|
|
15
|
-
|
|
16
|
-
docker run -p 3030:3030 $USER_FLAG -v ${PWD}:/pxl -w /pxl/e2e --rm -it $IMAGE_NAME /bin/bash
|
|
17
|
-
|