@postxl/generator 1.1.0 → 1.2.0
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/helpers/branded.types.d.ts +29 -29
- package/dist/helpers/branded.types.js +3 -1
- package/dist/utils/checksum.d.ts +1 -1
- package/dist/utils/lockfile.d.ts +1 -1
- package/dist/utils/path.d.ts +2 -2
- package/dist/utils/string-functions.d.ts +2 -2
- package/dist/utils/vfs.class.js +38 -17
- package/package.json +3 -3
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
* - `ImportPaths`: FilePath | PackageName
|
|
32
32
|
*/
|
|
33
33
|
import z from 'zod';
|
|
34
|
-
declare const zGeneratorInterfaceId: z.ZodBranded<z.ZodString, "PXL.GeneratorInterfaceId">;
|
|
34
|
+
declare const zGeneratorInterfaceId: z.core.$ZodBranded<z.ZodString, "PXL.GeneratorInterfaceId", "out">;
|
|
35
35
|
/**
|
|
36
36
|
* A generator interface id that is used identify what interface a generator implements.
|
|
37
37
|
*/
|
|
38
38
|
export type GeneratorInterfaceId = z.infer<typeof zGeneratorInterfaceId>;
|
|
39
|
-
export declare const toGeneratorInterfaceId: (input: string) => string & z.
|
|
40
|
-
declare const zTypeName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.TypeName">, "PXL.Importable">;
|
|
39
|
+
export declare const toGeneratorInterfaceId: (input: string) => string & z.core.$brand<"PXL.GeneratorInterfaceId">;
|
|
40
|
+
declare const zTypeName: z.core.$ZodBranded<z.core.$ZodBranded<z.ZodString, "PXL.TypeName", "out">, "PXL.Importable", "out">;
|
|
41
41
|
/**
|
|
42
42
|
* A type name that is used to refer to a type in the generated code.
|
|
43
43
|
*/
|
|
44
44
|
export type TypeName = z.infer<typeof zTypeName>;
|
|
45
|
-
export declare const toTypeName: (input: string) => string & z.
|
|
45
|
+
export declare const toTypeName: (input: string) => string & z.core.$brand<"PXL.TypeName"> & z.core.$brand<"PXL.Importable">;
|
|
46
46
|
/**
|
|
47
47
|
* A TypeName that is annotated with the kind of the type.
|
|
48
48
|
* Note: This is used when distinguishing between kinds is required at runtime.
|
|
@@ -59,80 +59,80 @@ export declare const toAnnotatedTypeName: (name: TypeName) => AnnotatedTypeName;
|
|
|
59
59
|
* Type guard to check if a given type is an AnnotatedTypeName.
|
|
60
60
|
*/
|
|
61
61
|
export declare const isAnnotatedTypeName: (t: string | AnnotatedTypeName) => t is AnnotatedTypeName;
|
|
62
|
-
declare const zFunctionName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.FunctionName">, "PXL.Importable">;
|
|
62
|
+
declare const zFunctionName: z.core.$ZodBranded<z.core.$ZodBranded<z.ZodString, "PXL.FunctionName", "out">, "PXL.Importable", "out">;
|
|
63
63
|
/**
|
|
64
64
|
* A function name that is used to refer to a function in the generated code.
|
|
65
65
|
*/
|
|
66
66
|
export type FunctionName = z.infer<typeof zFunctionName>;
|
|
67
|
-
export declare const toFunctionName: (input: string) => string & z.
|
|
68
|
-
declare const zVariableName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.VariableName">, "PXL.Importable">;
|
|
67
|
+
export declare const toFunctionName: (input: string) => string & z.core.$brand<"PXL.FunctionName"> & z.core.$brand<"PXL.Importable">;
|
|
68
|
+
declare const zVariableName: z.core.$ZodBranded<z.core.$ZodBranded<z.ZodString, "PXL.VariableName", "out">, "PXL.Importable", "out">;
|
|
69
69
|
/**
|
|
70
70
|
* A variable name that is used to refer to a variable in the generated code.
|
|
71
71
|
*/
|
|
72
72
|
export type VariableName = z.infer<typeof zVariableName>;
|
|
73
|
-
export declare const toVariableName: (input: string) => string & z.
|
|
74
|
-
declare const zPostXlPackageName: z.ZodBranded<z.
|
|
73
|
+
export declare const toVariableName: (input: string) => string & z.core.$brand<"PXL.VariableName"> & z.core.$brand<"PXL.Importable">;
|
|
74
|
+
declare const zPostXlPackageName: z.core.$ZodBranded<z.ZodString, "PXL.PackageName", "out">;
|
|
75
75
|
/**
|
|
76
76
|
* A package name that is used to refer to a package in the generated code.
|
|
77
77
|
*/
|
|
78
|
-
export declare const toPostXlPackageName: (input: string) => string & z.
|
|
79
|
-
export declare const toPackageName: (input: string) => string & z.
|
|
78
|
+
export declare const toPostXlPackageName: (input: string) => string & z.core.$brand<"PXL.PackageName">;
|
|
79
|
+
export declare const toPackageName: (input: string) => string & z.core.$brand<"PXL.PackageName">;
|
|
80
80
|
/**
|
|
81
81
|
* A package name that is used to refer to a package name that is provided via
|
|
82
82
|
* in package.json or is a NodeJS module.
|
|
83
83
|
* E.g. "fs", "random", "@nestjs/common".
|
|
84
84
|
*/
|
|
85
85
|
export type PackageName = z.infer<typeof zPostXlPackageName>;
|
|
86
|
-
declare const zClassName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.ClassName">, "PXL.Importable">;
|
|
86
|
+
declare const zClassName: z.core.$ZodBranded<z.core.$ZodBranded<z.ZodString, "PXL.ClassName", "out">, "PXL.Importable", "out">;
|
|
87
87
|
/**
|
|
88
88
|
* A class name that is used to refer to a class in the generated code.
|
|
89
89
|
*/
|
|
90
90
|
export type ClassName = z.infer<typeof zClassName>;
|
|
91
|
-
export declare const toClassName: (input: string) => string & z.
|
|
92
|
-
declare const zConstantName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.ConstantName">, "PXL.Importable">;
|
|
91
|
+
export declare const toClassName: (input: string) => string & z.core.$brand<"PXL.ClassName"> & z.core.$brand<"PXL.Importable">;
|
|
92
|
+
declare const zConstantName: z.core.$ZodBranded<z.core.$ZodBranded<z.ZodString, "PXL.ConstantName", "out">, "PXL.Importable", "out">;
|
|
93
93
|
/**
|
|
94
94
|
* A constant name that is used to refer to a constant in the generated code.
|
|
95
95
|
*/
|
|
96
96
|
export type ConstantName = z.infer<typeof zConstantName>;
|
|
97
|
-
export declare const toConstantName: (input: string) => string & z.
|
|
98
|
-
declare const zConstantValue: z.ZodBranded<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "PXL.ConstantValue">;
|
|
97
|
+
export declare const toConstantName: (input: string) => string & z.core.$brand<"PXL.ConstantName"> & z.core.$brand<"PXL.Importable">;
|
|
98
|
+
declare const zConstantValue: z.core.$ZodBranded<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "PXL.ConstantValue", "out">;
|
|
99
99
|
/**
|
|
100
100
|
* A constant value that is used in the generated code.
|
|
101
101
|
*/
|
|
102
102
|
export type ConstantValue = z.infer<typeof zConstantValue>;
|
|
103
|
-
export declare const toConstantValue: (input: string | number | boolean | null) => (string | number
|
|
104
|
-
declare const zDiscriminantValue: z.ZodBranded<z.ZodString, "PXL.DiscriminantValue">;
|
|
103
|
+
export declare const toConstantValue: (input: string | number | boolean | null) => (string & z.core.$brand<"PXL.ConstantValue">) | (number & z.core.$brand<"PXL.ConstantValue">) | (false & z.core.$brand<"PXL.ConstantValue">) | (true & z.core.$brand<"PXL.ConstantValue">);
|
|
104
|
+
declare const zDiscriminantValue: z.core.$ZodBranded<z.ZodString, "PXL.DiscriminantValue", "out">;
|
|
105
105
|
/**
|
|
106
106
|
* A discriminant value, used to discriminate union types.
|
|
107
107
|
*/
|
|
108
108
|
export type DiscriminantValue = z.infer<typeof zDiscriminantValue>;
|
|
109
|
-
export declare const toDiscriminantValue: (input: string) => string & z.
|
|
110
|
-
declare const zFileName: z.ZodBranded<z.ZodString, "PXL.FileName">;
|
|
109
|
+
export declare const toDiscriminantValue: (input: string) => string & z.core.$brand<"PXL.DiscriminantValue">;
|
|
110
|
+
declare const zFileName: z.core.$ZodBranded<z.ZodString, "PXL.FileName", "out">;
|
|
111
111
|
/**
|
|
112
112
|
* A file name that is used to refer to a file in the generated code.
|
|
113
113
|
*/
|
|
114
114
|
export type FileName = z.infer<typeof zFileName>;
|
|
115
|
-
export declare const toFileName: (input: string) => string & z.
|
|
116
|
-
declare const zFolderName: z.ZodBranded<z.ZodString, "PXL.FolderName">;
|
|
115
|
+
export declare const toFileName: (input: string) => string & z.core.$brand<"PXL.FileName">;
|
|
116
|
+
declare const zFolderName: z.core.$ZodBranded<z.ZodString, "PXL.FolderName", "out">;
|
|
117
117
|
/**
|
|
118
118
|
* A folder name that is used to refer to a folder in the generated code.
|
|
119
119
|
*/
|
|
120
120
|
export type FolderName = z.infer<typeof zFolderName>;
|
|
121
|
-
export declare const toFolderName: (input: string) => string & z.
|
|
122
|
-
declare const zFilePath: z.ZodBranded<z.ZodString, "PXL.FilePath">;
|
|
121
|
+
export declare const toFolderName: (input: string) => string & z.core.$brand<"PXL.FolderName">;
|
|
122
|
+
declare const zFilePath: z.core.$ZodBranded<z.ZodString, "PXL.FilePath", "out">;
|
|
123
123
|
/**
|
|
124
124
|
* A file path that is used to refer to a file in the generated code.
|
|
125
125
|
*/
|
|
126
126
|
export type FilePath = z.infer<typeof zFilePath>;
|
|
127
|
-
export declare const toFilePath: (input: string) => string & z.
|
|
128
|
-
declare const zBackendModuleName: z.ZodBranded<z.ZodString, "PXL.BackendModuleName">;
|
|
127
|
+
export declare const toFilePath: (input: string) => string & z.core.$brand<"PXL.FilePath">;
|
|
128
|
+
declare const zBackendModuleName: z.core.$ZodBranded<z.ZodString, "PXL.BackendModuleName", "out">;
|
|
129
129
|
/**
|
|
130
130
|
* A backend module name that is used to refer to a module in the backend.
|
|
131
131
|
* E.g. `@actions`.
|
|
132
132
|
*/
|
|
133
133
|
export type BackendModuleName = z.infer<typeof zBackendModuleName>;
|
|
134
|
-
export declare const toBackendModuleName: (input: string) => string & z.
|
|
135
|
-
declare const zBackendModuleLocation: z.ZodBranded<z.ZodString, "PXL.BackendModuleLocation">;
|
|
134
|
+
export declare const toBackendModuleName: (input: string) => string & z.core.$brand<"PXL.BackendModuleName">;
|
|
135
|
+
declare const zBackendModuleLocation: z.core.$ZodBranded<z.ZodString, "PXL.BackendModuleLocation", "out">;
|
|
136
136
|
/**
|
|
137
137
|
* A module location is a reference to a file in a locale backend module.
|
|
138
138
|
* E.g. `@actions/actions.types`.
|
|
@@ -143,7 +143,7 @@ declare const zBackendModuleLocation: z.ZodBranded<z.ZodString, "PXL.BackendModu
|
|
|
143
143
|
* Therefore, we need to reference the actual file together with the package name.
|
|
144
144
|
*/
|
|
145
145
|
export type BackendModuleLocation = z.infer<typeof zBackendModuleLocation>;
|
|
146
|
-
export declare const toBackendModuleLocation: (input: `@${string}`) => string & z.
|
|
146
|
+
export declare const toBackendModuleLocation: (input: `@${string}`) => string & z.core.$brand<"PXL.BackendModuleLocation">;
|
|
147
147
|
export type ImportableTypes = TypeName | FunctionName | ClassName | ConstantName | AnnotatedTypeName;
|
|
148
148
|
export type ImportPaths = FilePath | PackageName | BackendModuleLocation;
|
|
149
149
|
export {};
|
|
@@ -64,7 +64,9 @@ const toVariableName = (input) => zVariableName.parse(input);
|
|
|
64
64
|
exports.toVariableName = toVariableName;
|
|
65
65
|
const zPostXlPackageName = zod_1.default
|
|
66
66
|
.string()
|
|
67
|
-
.refine((name) => name.startsWith('@postxl/'),
|
|
67
|
+
.refine((name) => name.startsWith('@postxl/'), {
|
|
68
|
+
error: (issue) => `Package name must start with "@postxl/", got "${issue.input}"!`,
|
|
69
|
+
})
|
|
68
70
|
.brand('PXL.PackageName');
|
|
69
71
|
/**
|
|
70
72
|
* A package name that is used to refer to a package in the generated code.
|
package/dist/utils/checksum.d.ts
CHANGED
package/dist/utils/lockfile.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { VirtualFileSystem } from './vfs.class';
|
|
3
|
-
declare const zLockFile: z.
|
|
3
|
+
declare const zLockFile: z.ZodPipe<z.ZodRecord<z.core.$ZodBranded<z.ZodString, "PXL.PosixPath", "out">, z.core.$ZodBranded<z.ZodString, "PXL.Checksum", "out">>, z.ZodTransform<Map<string & z.core.$brand<"PXL.PosixPath">, string & z.core.$brand<"PXL.Checksum">>, Record<string & z.core.$brand<"PXL.PosixPath">, string & z.core.$brand<"PXL.Checksum">>>>;
|
|
4
4
|
type LockFile = z.infer<typeof zLockFile>;
|
|
5
5
|
export declare function writeLockFile(lockFilePath: string, vfs: VirtualFileSystem): Promise<void>;
|
|
6
6
|
export declare function readLockFile(lockFilePath: string): Promise<LockFile | undefined>;
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const zPosixPath: z.ZodBranded<z.ZodString, "PXL.PosixPath">;
|
|
2
|
+
export declare const zPosixPath: z.core.$ZodBranded<z.ZodString, "PXL.PosixPath", "out">;
|
|
3
3
|
/**
|
|
4
4
|
* A path string that has been normalized to use the unix path separator.
|
|
5
5
|
*/
|
|
6
6
|
export type PosixPath = z.infer<typeof zPosixPath>;
|
|
7
|
-
export declare const POSIX_ROOT: string & z.
|
|
7
|
+
export declare const POSIX_ROOT: string & z.core.$brand<"PXL.PosixPath">;
|
|
8
8
|
/**
|
|
9
9
|
* Normalizes a unix or Windows path to use the unix path separator. Additionally,
|
|
10
10
|
* it normalizes the path so that every path is considered absolute.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const zTypescript: z.ZodBranded<z.ZodString, "PXL.Typescript">;
|
|
2
|
+
export declare const zTypescript: z.core.$ZodBranded<z.ZodString, "PXL.Typescript", "out">;
|
|
3
3
|
export type Typescript = z.infer<typeof zTypescript>;
|
|
4
|
-
export declare function ts(input: string): string & z.
|
|
4
|
+
export declare function ts(input: string): string & z.core.$brand<"PXL.Typescript">;
|
|
5
5
|
export declare function trimLines(input: string): string;
|
|
6
6
|
/**
|
|
7
7
|
* Removes leading and trailing newlines from the input string.
|
package/dist/utils/vfs.class.js
CHANGED
|
@@ -34,8 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.VirtualFileSystem = void 0;
|
|
37
|
-
const fs = __importStar(require("fs/promises"));
|
|
38
37
|
const minimatch_1 = require("minimatch");
|
|
38
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
39
39
|
const utils_1 = require("@postxl/utils");
|
|
40
40
|
const fs_utils_1 = require("./fs-utils");
|
|
41
41
|
const Path = __importStar(require("./path"));
|
|
@@ -186,33 +186,54 @@ class VirtualFileSystem {
|
|
|
186
186
|
this.#files.set(basePath, content.unwrap());
|
|
187
187
|
}
|
|
188
188
|
async #readDirectory({ diskPath, targetPath, filter, recursive, }) {
|
|
189
|
-
const entries = await
|
|
190
|
-
|
|
191
|
-
throw new Error(entries.unwrapErr());
|
|
192
|
-
}
|
|
193
|
-
for (const entry of entries.unwrap()) {
|
|
189
|
+
const entries = await this.#readDirEntries(diskPath);
|
|
190
|
+
for (const entry of entries) {
|
|
194
191
|
const entryName = Path.normalize(entry.name);
|
|
195
192
|
const entryPath = Path.join(diskPath, entryName);
|
|
196
193
|
const relativePath = Path.join(targetPath, entryName);
|
|
197
|
-
if (
|
|
194
|
+
if (this.#shouldSkipEntry(relativePath, filter)) {
|
|
198
195
|
continue;
|
|
199
196
|
}
|
|
200
197
|
if (recursive && entry.isDirectory()) {
|
|
201
|
-
await this.#
|
|
198
|
+
await this.#processDirectory(entryPath, relativePath, filter, recursive);
|
|
202
199
|
}
|
|
203
200
|
else if (entry.isFile()) {
|
|
204
|
-
|
|
205
|
-
if (!this.matchesPattern(relativePath)) {
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
const content = await (0, fs_utils_1.readFile)(entryPath);
|
|
209
|
-
if (content.isErr()) {
|
|
210
|
-
throw content.unwrapErr();
|
|
211
|
-
}
|
|
212
|
-
this.#files.set(relativePath, content.unwrap());
|
|
201
|
+
await this.#processFile(entryPath, relativePath);
|
|
213
202
|
}
|
|
214
203
|
}
|
|
215
204
|
}
|
|
205
|
+
async #readDirEntries(diskPath) {
|
|
206
|
+
const entries = await utils_1.Result.fromPromise(() => fs.readdir(diskPath, { withFileTypes: true }), () => `Folder "${diskPath}" does not exist`);
|
|
207
|
+
if (entries.isErr()) {
|
|
208
|
+
throw new Error(entries.unwrapErr());
|
|
209
|
+
}
|
|
210
|
+
return entries.unwrap();
|
|
211
|
+
}
|
|
212
|
+
#shouldSkipEntry(relativePath, filter) {
|
|
213
|
+
return filter ? !filter(relativePath) : false;
|
|
214
|
+
}
|
|
215
|
+
async #processDirectory(diskPath, relativePath, filter, recursive) {
|
|
216
|
+
await this.#readDirectory({ diskPath, targetPath: relativePath, filter, recursive });
|
|
217
|
+
}
|
|
218
|
+
async #processFile(entryPath, relativePath) {
|
|
219
|
+
if (!this.matchesPattern(relativePath)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const content = await (0, fs_utils_1.readFile)(entryPath);
|
|
223
|
+
if (content.isErr()) {
|
|
224
|
+
throw content.unwrapErr();
|
|
225
|
+
}
|
|
226
|
+
const finalPath = this.#resolveFinalPath(relativePath);
|
|
227
|
+
this.#files.set(finalPath, content.unwrap());
|
|
228
|
+
}
|
|
229
|
+
#resolveFinalPath(relativePath) {
|
|
230
|
+
// Handle .gitignore.template files: rename them to .gitignore
|
|
231
|
+
// This is necessary because npm/pnpm exclude .gitignore files from published packages
|
|
232
|
+
if (relativePath.endsWith('.gitignore.template')) {
|
|
233
|
+
return relativePath.replace(/\.gitignore\.template$/, '.gitignore');
|
|
234
|
+
}
|
|
235
|
+
return relativePath;
|
|
236
|
+
}
|
|
216
237
|
/**
|
|
217
238
|
* Transforms the content of all files using the provided function.
|
|
218
239
|
* An optional filter function can be provided to select specific files.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/generator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Core package that orchestrates the code generation of a PXL project",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"jszip": "3.10.1",
|
|
47
47
|
"minimatch": "^10.1.1",
|
|
48
48
|
"p-limit": "3.1.0",
|
|
49
|
-
"@postxl/schema": "^1.
|
|
50
|
-
"@postxl/utils": "^1.
|
|
49
|
+
"@postxl/schema": "^1.2.0",
|
|
50
|
+
"@postxl/utils": "^1.2.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/diff": "8.0.0"
|