Skip to content

Commit d4711ce

Browse files
committed
fix(nx-plugin): update build output
1 parent c07a852 commit d4711ce

File tree

7 files changed

+85
-18
lines changed

7 files changed

+85
-18
lines changed

Diff for: packages/nx-plugin/executors.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"executors": {
33
"update-api": {
4-
"implementation": "./dist/executors/update-api/index.js",
4+
"implementation": "./dist/updateApi.js",
55
"schema": "./dist/executors/update-api/schema.json",
66
"description": "Updates the OpenAPI spec file and generates new client code if needed."
77
}

Diff for: packages/nx-plugin/generators.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"generators": {
55
"openapi-client": {
6-
"factory": "./dist/generators/openapi-client/index.js",
6+
"factory": "./dist/openapiClient.js",
77
"schema": "./dist/generators/openapi-client/schema.json",
88
"description": "Generate an OpenAPI client library from an OpenAPI spec file."
99
}

Diff for: packages/nx-plugin/package.json

+17-13
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"nx",
2626
"swagger"
2727
],
28-
"type": "commonjs",
29-
"main": "./dist/index.js",
28+
"type": "module",
29+
"main": "./dist/index.cjs",
3030
"module": "./dist/index.js",
3131
"types": "./dist/index.d.ts",
3232
"scripts": {
@@ -38,16 +38,20 @@
3838
"prepublishOnly": "pnpm build"
3939
},
4040
"exports": {
41-
"./package.json": "./package.json",
4241
".": {
43-
"development": "./src/index.ts",
44-
"types": "./dist/index.d.ts",
45-
"import": "./dist/index.js",
46-
"default": "./dist/index.js"
47-
}
42+
"import": {
43+
"types": "./dist/index.d.ts",
44+
"default": "./dist/index.js"
45+
},
46+
"require": {
47+
"types": "./dist/index.d.cts",
48+
"default": "./dist/index.cjs"
49+
}
50+
},
51+
"./package.json": "./package.json"
4852
},
49-
"executors": "./executors.json",
50-
"generators": "./generators.json",
53+
"executors": "./dist/executors.json",
54+
"generators": "./dist/generators.json",
5155
"dependencies": {
5256
"@hey-api/json-schema-ref-parser": "1.0.4",
5357
"@hey-api/openapi-ts": "workspace:*",
@@ -59,13 +63,13 @@
5963
},
6064
"devDependencies": {
6165
"@config/vite-base": "workspace:*",
66+
"ts-node": "10.9.2",
6267
"typescript": "5.8.3",
6368
"vitest": "3.1.1"
6469
},
6570
"files": [
71+
"package.json",
6672
"dist",
67-
"LICENSE.md",
68-
"generators.json",
69-
"executors.json"
73+
"LICENSE.md"
7074
]
7175
}

Diff for: packages/nx-plugin/scripts/copy-json-files.mts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
copyFileSync,
3+
existsSync,
4+
mkdirSync,
5+
readdirSync,
6+
statSync,
7+
} from 'node:fs';
8+
import { dirname, extname, join, resolve } from 'node:path';
9+
import { fileURLToPath } from 'node:url';
10+
11+
// Get current directory
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = dirname(__filename);
14+
15+
// Function to recursively create directories
16+
function ensureDirectoryExists(dirPath: string) {
17+
if (!existsSync(dirPath)) {
18+
mkdirSync(dirPath, { recursive: true });
19+
}
20+
}
21+
22+
// Function to recursively copy JSON files from source to destination
23+
function copyJsonFiles(sourceDir: string, targetDir: string) {
24+
// Read all files and directories in the source directory
25+
const items = readdirSync(sourceDir);
26+
27+
for (const item of items) {
28+
const sourcePath = join(sourceDir, item);
29+
const targetPath = join(targetDir, item);
30+
31+
const stats = statSync(sourcePath);
32+
33+
if (stats.isDirectory()) {
34+
// Recursively copy JSON files from subdirectories
35+
copyJsonFiles(sourcePath, targetPath);
36+
} else if (stats.isFile() && extname(item).toLowerCase() === '.json') {
37+
// Copy JSON files
38+
ensureDirectoryExists(dirname(targetPath));
39+
copyFileSync(sourcePath, targetPath);
40+
console.log(`Copied: ${sourcePath} -> ${targetPath}`);
41+
}
42+
}
43+
}
44+
45+
// Copy JSON files from src to dist
46+
const sourceDir = resolve(__dirname, '../src');
47+
const targetDir = resolve(__dirname, '../dist');
48+
49+
console.log('Copying JSON files from src to dist...');
50+
copyJsonFiles(sourceDir, targetDir);
51+
console.log('JSON files copying completed.');

Diff for: packages/nx-plugin/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
export * from './executors/update-api';
2-
export * from './generators/openapi-client';
31
export * from './utils';
42
export * from './vars';

Diff for: packages/nx-plugin/tsup.config.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ export default defineConfig((options) => ({
1414
},
1515
clean: true,
1616
dts: true,
17-
entry: ['src/index.ts'],
17+
entry: {
18+
index: 'src/index.ts',
19+
openapiClient: 'src/generators/openapi-client/index.ts',
20+
updateApi: 'src/executors/update-api/index.ts',
21+
},
1822
format: ['cjs', 'esm'],
1923
minify: !options.watch,
24+
onSuccess: 'node --loader ts-node/esm scripts/copy-json-files.mts',
25+
outDir: 'dist',
26+
outExtension({ format }) {
27+
return {
28+
js: format === 'cjs' ? '.cjs' : '.js',
29+
};
30+
},
2031
shims: false,
2132
sourcemap: true,
2233
treeshake: true,

Diff for: pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)