@vaadin/hilla-generator-cli 24.7.0-alpha9 → 24.7.0-beta2
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/GeneratorIO.d.ts +29 -31
- package/GeneratorIO.js +108 -119
- package/GeneratorIO.js.map +1 -7
- package/GeneratorIOException.d.ts +1 -2
- package/GeneratorIOException.js +5 -8
- package/GeneratorIOException.js.map +1 -7
- package/index.d.ts +0 -1
- package/index.js +27 -32
- package/index.js.map +1 -7
- package/package.json +9 -31
- package/utils.d.ts +1 -2
- package/utils.js +13 -16
- package/utils.js.map +1 -7
- package/GeneratorIO.d.ts.map +0 -1
- package/GeneratorIOException.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/utils.d.ts.map +0 -1
package/GeneratorIO.d.ts
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
3
|
-
import type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';
|
|
1
|
+
import { type PluginConstructor } from "@vaadin/hilla-generator-core/Plugin.js";
|
|
2
|
+
import type LoggerFactory from "@vaadin/hilla-generator-utils/LoggerFactory.js";
|
|
4
3
|
export default class GeneratorIO {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
4
|
+
#private;
|
|
5
|
+
static readonly INDEX_FILENAME = "generated-file-list.txt";
|
|
6
|
+
["constructor"]: typeof GeneratorIO;
|
|
7
|
+
readonly cwd: string;
|
|
8
|
+
constructor(outputDir: string, logger: LoggerFactory);
|
|
9
|
+
/**
|
|
10
|
+
* Gets the list of files generated the last time. The info is found in {@link INDEX_FILENAME}.
|
|
11
|
+
* @returns a list of files that have been generated by us
|
|
12
|
+
*/
|
|
13
|
+
getGeneratedFiles(): Promise<Set<string>>;
|
|
14
|
+
/**
|
|
15
|
+
* Cleans the output directory by keeping the generated files and deleting the rest of the given files.
|
|
16
|
+
*
|
|
17
|
+
* @returns a set containing deleted filenames
|
|
18
|
+
*/
|
|
19
|
+
cleanOutputDir(generatedFiles: string[], filesToDelete: Set<string>): Promise<Set<string>>;
|
|
20
|
+
createFileIndex(filenames: string[]): Promise<void>;
|
|
21
|
+
writeGeneratedFiles(files: readonly File[]): Promise<string[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Checks that a file exists (is visible)
|
|
24
|
+
* @param path - the file path to check
|
|
25
|
+
*/
|
|
26
|
+
static exists(path: string): Promise<boolean>;
|
|
27
|
+
loadPlugin(modulePath: string): Promise<PluginConstructor>;
|
|
28
|
+
resolveGeneratedFile(filename: string): string;
|
|
29
|
+
read(path: string): Promise<string>;
|
|
30
|
+
write(filename: string, content: string): Promise<void>;
|
|
32
31
|
}
|
|
33
|
-
//# sourceMappingURL=GeneratorIO.d.ts.map
|
package/GeneratorIO.js
CHANGED
|
@@ -3,124 +3,113 @@ import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
|
-
import Plugin
|
|
6
|
+
import Plugin from "@vaadin/hilla-generator-core/Plugin.js";
|
|
7
7
|
import GeneratorIOException from "./GeneratorIOException.js";
|
|
8
|
-
const
|
|
9
|
-
class GeneratorIO {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
async write(filename, content) {
|
|
116
|
-
const filePath = join(this.#outputDir, filename);
|
|
117
|
-
this.#logger.global.debug(`Writing file ${filePath}.`);
|
|
118
|
-
const dir = dirname(filePath);
|
|
119
|
-
await mkdir(dir, { recursive: true });
|
|
120
|
-
return writeFile(filePath, content, "utf-8");
|
|
121
|
-
}
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
export default class GeneratorIO {
|
|
10
|
+
static INDEX_FILENAME = "generated-file-list.txt";
|
|
11
|
+
cwd;
|
|
12
|
+
#logger;
|
|
13
|
+
#outputDir;
|
|
14
|
+
constructor(outputDir, logger) {
|
|
15
|
+
this.cwd = process.cwd();
|
|
16
|
+
this.#outputDir = isAbsolute(outputDir) ? outputDir : resolve(this.cwd, outputDir);
|
|
17
|
+
this.#logger = logger;
|
|
18
|
+
logger.global.debug(`Output directory: ${this.#outputDir}`);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the list of files generated the last time. The info is found in {@link INDEX_FILENAME}.
|
|
22
|
+
* @returns a list of files that have been generated by us
|
|
23
|
+
*/
|
|
24
|
+
async getGeneratedFiles() {
|
|
25
|
+
const files = new Set();
|
|
26
|
+
try {
|
|
27
|
+
const indexFileContents = await this.read(this.resolveGeneratedFile(this.constructor.INDEX_FILENAME));
|
|
28
|
+
indexFileContents.split("\n").filter((n) => n.length).forEach((fileName) => files.add(fileName));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if (!(e instanceof Error && "code" in e && e.code === "ENOENT")) {
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return files;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Cleans the output directory by keeping the generated files and deleting the rest of the given files.
|
|
38
|
+
*
|
|
39
|
+
* @returns a set containing deleted filenames
|
|
40
|
+
*/
|
|
41
|
+
async cleanOutputDir(generatedFiles, filesToDelete) {
|
|
42
|
+
this.#logger.global.debug(`Cleaning ${this.#outputDir}`);
|
|
43
|
+
await mkdir(this.#outputDir, { recursive: true });
|
|
44
|
+
generatedFiles.forEach((filename) => {
|
|
45
|
+
this.#logger.global.debug(`File ${filename} was re-written, should not delete it`);
|
|
46
|
+
filesToDelete.delete(filename);
|
|
47
|
+
});
|
|
48
|
+
const deletedFiles = new Set(await Promise.all([...filesToDelete].map(async (filename) => {
|
|
49
|
+
const resolved = this.resolveGeneratedFile(filename);
|
|
50
|
+
if (await GeneratorIO.exists(resolved)) {
|
|
51
|
+
this.#logger.global.debug(`Deleting file ${filename}.`);
|
|
52
|
+
await rm(resolved);
|
|
53
|
+
}
|
|
54
|
+
return filename;
|
|
55
|
+
})));
|
|
56
|
+
return deletedFiles;
|
|
57
|
+
}
|
|
58
|
+
async createFileIndex(filenames) {
|
|
59
|
+
await this.write(this.constructor.INDEX_FILENAME, filenames.join("\n"));
|
|
60
|
+
}
|
|
61
|
+
async writeGeneratedFiles(files) {
|
|
62
|
+
await this.createFileIndex(files.map((file) => file.name));
|
|
63
|
+
this.#logger.global.debug(`created index`);
|
|
64
|
+
return Promise.all(files.map(async (file) => {
|
|
65
|
+
const newFileContent = await file.text();
|
|
66
|
+
let oldFileContent;
|
|
67
|
+
try {
|
|
68
|
+
oldFileContent = await this.read(this.resolveGeneratedFile(file.name));
|
|
69
|
+
} catch (_e) {}
|
|
70
|
+
if (newFileContent !== oldFileContent) {
|
|
71
|
+
this.#logger.global.debug(`writing file ${file.name}`);
|
|
72
|
+
await this.write(file.name, await file.text());
|
|
73
|
+
} else {
|
|
74
|
+
this.#logger.global.debug(`File ${file.name} stayed the same`);
|
|
75
|
+
}
|
|
76
|
+
return file.name;
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks that a file exists (is visible)
|
|
81
|
+
* @param path - the file path to check
|
|
82
|
+
*/
|
|
83
|
+
static async exists(path) {
|
|
84
|
+
try {
|
|
85
|
+
await access(path, constants.F_OK);
|
|
86
|
+
return true;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async loadPlugin(modulePath) {
|
|
92
|
+
this.#logger.global.debug(`Loading plugin: ${modulePath}`);
|
|
93
|
+
const module = await import(pathToFileURL(require.resolve(modulePath)).toString());
|
|
94
|
+
const ctr = module.default;
|
|
95
|
+
if (!Object.prototype.isPrototypeOf.call(Plugin, ctr)) {
|
|
96
|
+
throw new GeneratorIOException(`Plugin '${modulePath}' is not an instance of a Plugin class`);
|
|
97
|
+
}
|
|
98
|
+
return ctr;
|
|
99
|
+
}
|
|
100
|
+
resolveGeneratedFile(filename) {
|
|
101
|
+
return resolve(this.#outputDir, filename);
|
|
102
|
+
}
|
|
103
|
+
async read(path) {
|
|
104
|
+
this.#logger.global.debug(`Reading file: ${path}`);
|
|
105
|
+
return readFile(path, "utf8");
|
|
106
|
+
}
|
|
107
|
+
async write(filename, content) {
|
|
108
|
+
const filePath = join(this.#outputDir, filename);
|
|
109
|
+
this.#logger.global.debug(`Writing file ${filePath}.`);
|
|
110
|
+
const dir = dirname(filePath);
|
|
111
|
+
await mkdir(dir, { recursive: true });
|
|
112
|
+
return writeFile(filePath, content, "utf-8");
|
|
113
|
+
}
|
|
122
114
|
}
|
|
123
|
-
|
|
124
|
-
GeneratorIO as default
|
|
125
|
-
};
|
|
126
|
-
//# sourceMappingURL=GeneratorIO.js.map
|
|
115
|
+
//# sourceMappingURL=./GeneratorIO.js.map
|
package/GeneratorIO.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/GeneratorIO.ts"],
|
|
4
|
-
"sourcesContent": ["import { constants } from 'node:fs';\nimport { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type File from '@vaadin/hilla-generator-core/File.js';\nimport Plugin, { type PluginConstructor } from '@vaadin/hilla-generator-core/Plugin.js';\nimport type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport GeneratorIOException from './GeneratorIOException.js';\n\nconst require = createRequire(import.meta.url);\n\ntype PluginConstructorModule = Readonly<{\n default: PluginConstructor;\n}>;\n\nexport default class GeneratorIO {\n static readonly INDEX_FILENAME = 'generated-file-list.txt';\n declare ['constructor']: typeof GeneratorIO;\n readonly cwd: string;\n readonly #logger: LoggerFactory;\n readonly #outputDir: string;\n\n constructor(outputDir: string, logger: LoggerFactory) {\n this.cwd = process.cwd();\n this.#outputDir = isAbsolute(outputDir) ? outputDir : resolve(this.cwd, outputDir);\n this.#logger = logger;\n\n logger.global.debug(`Output directory: ${this.#outputDir}`);\n }\n\n /**\n * Gets the list of files generated the last time. The info is found in {@link INDEX_FILENAME}.\n * @returns a list of files that have been generated by us\n */\n async getGeneratedFiles(): Promise<Set<string>> {\n const files = new Set<string>();\n try {\n const indexFileContents = await this.read(this.resolveGeneratedFile(this.constructor.INDEX_FILENAME));\n indexFileContents\n .split('\\n')\n .filter((n) => n.length)\n .forEach((fileName) => files.add(fileName));\n } catch (e) {\n // non-existing file is OK, all other errors must be rethrown\n if (!(e instanceof Error && 'code' in e && e.code === 'ENOENT')) {\n throw e;\n }\n }\n return files;\n }\n\n /**\n * Cleans the output directory by keeping the generated files and deleting the rest of the given files.\n *\n * @returns a set containing deleted filenames\n */\n async cleanOutputDir(generatedFiles: string[], filesToDelete: Set<string>): Promise<Set<string>> {\n this.#logger.global.debug(`Cleaning ${this.#outputDir}`);\n await mkdir(this.#outputDir, { recursive: true });\n\n generatedFiles.forEach((filename) => {\n this.#logger.global.debug(`File ${filename} was re-written, should not delete it`);\n filesToDelete.delete(filename);\n });\n\n const deletedFiles = new Set(\n await Promise.all(\n [...filesToDelete].map(async (filename) => {\n const resolved = this.resolveGeneratedFile(filename);\n if (await GeneratorIO.exists(resolved)) {\n this.#logger.global.debug(`Deleting file ${filename}.`);\n await rm(resolved);\n }\n return filename;\n }),\n ),\n );\n\n return deletedFiles;\n }\n\n async createFileIndex(filenames: string[]): Promise<void> {\n await this.write(this.constructor.INDEX_FILENAME, filenames.join('\\n'));\n }\n\n async writeGeneratedFiles(files: readonly File[]): Promise<string[]> {\n await this.createFileIndex(files.map((file) => file.name));\n this.#logger.global.debug(`created index`);\n\n return Promise.all(\n files.map(async (file) => {\n const newFileContent = await file.text();\n let oldFileContent;\n try {\n oldFileContent = await this.read(this.resolveGeneratedFile(file.name));\n } catch (_e) {}\n\n if (newFileContent !== oldFileContent) {\n this.#logger.global.debug(`writing file ${file.name}`);\n await this.write(file.name, await file.text());\n } else {\n this.#logger.global.debug(`File ${file.name} stayed the same`);\n }\n return file.name;\n }),\n );\n }\n\n /**\n * Checks that a file exists (is visible)\n * @param path - the file path to check\n */\n // eslint-disable-next-line class-methods-use-this\n static async exists(path: string): Promise<boolean> {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n }\n\n async loadPlugin(modulePath: string): Promise<PluginConstructor> {\n this.#logger.global.debug(`Loading plugin: ${modulePath}`);\n const module: PluginConstructorModule = await import(pathToFileURL(require.resolve(modulePath)).toString());\n const ctr: PluginConstructor = module.default;\n\n if (!Object.prototype.isPrototypeOf.call(Plugin, ctr)) {\n throw new GeneratorIOException(`Plugin '${modulePath}' is not an instance of a Plugin class`);\n }\n\n return ctr;\n }\n\n resolveGeneratedFile(filename: string): string {\n return resolve(this.#outputDir, filename);\n }\n\n async read(path: string): Promise<string> {\n this.#logger.global.debug(`Reading file: ${path}`);\n return readFile(path, 'utf8');\n }\n\n async write(filename: string, content: string): Promise<void> {\n const filePath = join(this.#outputDir, filename);\n this.#logger.global.debug(`Writing file ${filePath}.`);\n const dir = dirname(filePath);\n await mkdir(dir, { recursive: true });\n return writeFile(filePath, content, 'utf-8');\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,QAAQ,OAAO,UAAU,IAAI,iBAAiB;AACvD,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY,MAAM,eAAe;AACnD,SAA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AAO,OAAO,eAAe,SAAS,GAAG;EACtD,MAAM,MAAM,QAAQ,SAAS;AAC7B,QAAM,MAAM,KAAK,EAAE,WAAW,KAAM,EAAC;AACrC,SAAO,UAAU,UAAU,SAAS,QAAQ;CAC7C;AACF","names":["#logger","#outputDir","outputDir: string","logger: LoggerFactory","generatedFiles: string[]","filesToDelete: Set<string>","filenames: string[]","files: readonly File[]","path: string","modulePath: string","module: PluginConstructorModule","ctr: PluginConstructor","filename: string","content: string"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-cli/src/GeneratorIO.ts"],"sourcesContent":["import { constants } from 'node:fs';\nimport { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport Plugin, { type PluginConstructor } from '@vaadin/hilla-generator-core/Plugin.js';\nimport type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport GeneratorIOException from './GeneratorIOException.js';\n\nconst require = createRequire(import.meta.url);\n\ntype PluginConstructorModule = Readonly<{\n default: PluginConstructor;\n}>;\n\nexport default class GeneratorIO {\n static readonly INDEX_FILENAME = 'generated-file-list.txt';\n declare ['constructor']: typeof GeneratorIO;\n readonly cwd: string;\n readonly #logger: LoggerFactory;\n readonly #outputDir: string;\n\n constructor(outputDir: string, logger: LoggerFactory) {\n this.cwd = process.cwd();\n this.#outputDir = isAbsolute(outputDir) ? outputDir : resolve(this.cwd, outputDir);\n this.#logger = logger;\n\n logger.global.debug(`Output directory: ${this.#outputDir}`);\n }\n\n /**\n * Gets the list of files generated the last time. The info is found in {@link INDEX_FILENAME}.\n * @returns a list of files that have been generated by us\n */\n async getGeneratedFiles(): Promise<Set<string>> {\n const files = new Set<string>();\n try {\n const indexFileContents = await this.read(this.resolveGeneratedFile(this.constructor.INDEX_FILENAME));\n indexFileContents\n .split('\\n')\n .filter((n) => n.length)\n .forEach((fileName) => files.add(fileName));\n } catch (e) {\n // non-existing file is OK, all other errors must be rethrown\n if (!(e instanceof Error && 'code' in e && e.code === 'ENOENT')) {\n throw e;\n }\n }\n return files;\n }\n\n /**\n * Cleans the output directory by keeping the generated files and deleting the rest of the given files.\n *\n * @returns a set containing deleted filenames\n */\n async cleanOutputDir(generatedFiles: string[], filesToDelete: Set<string>): Promise<Set<string>> {\n this.#logger.global.debug(`Cleaning ${this.#outputDir}`);\n await mkdir(this.#outputDir, { recursive: true });\n\n generatedFiles.forEach((filename) => {\n this.#logger.global.debug(`File ${filename} was re-written, should not delete it`);\n filesToDelete.delete(filename);\n });\n\n const deletedFiles = new Set(\n await Promise.all(\n [...filesToDelete].map(async (filename) => {\n const resolved = this.resolveGeneratedFile(filename);\n if (await GeneratorIO.exists(resolved)) {\n this.#logger.global.debug(`Deleting file ${filename}.`);\n await rm(resolved);\n }\n return filename;\n }),\n ),\n );\n\n return deletedFiles;\n }\n\n async createFileIndex(filenames: string[]): Promise<void> {\n await this.write(this.constructor.INDEX_FILENAME, filenames.join('\\n'));\n }\n\n async writeGeneratedFiles(files: readonly File[]): Promise<string[]> {\n await this.createFileIndex(files.map((file) => file.name));\n this.#logger.global.debug(`created index`);\n\n return Promise.all(\n files.map(async (file) => {\n const newFileContent = await file.text();\n let oldFileContent;\n try {\n oldFileContent = await this.read(this.resolveGeneratedFile(file.name));\n } catch (_e) {}\n\n if (newFileContent !== oldFileContent) {\n this.#logger.global.debug(`writing file ${file.name}`);\n await this.write(file.name, await file.text());\n } else {\n this.#logger.global.debug(`File ${file.name} stayed the same`);\n }\n return file.name;\n }),\n );\n }\n\n /**\n * Checks that a file exists (is visible)\n * @param path - the file path to check\n */\n // eslint-disable-next-line class-methods-use-this\n static async exists(path: string): Promise<boolean> {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n }\n\n async loadPlugin(modulePath: string): Promise<PluginConstructor> {\n this.#logger.global.debug(`Loading plugin: ${modulePath}`);\n const module: PluginConstructorModule = await import(pathToFileURL(require.resolve(modulePath)).toString());\n const ctr: PluginConstructor = module.default;\n\n if (!Object.prototype.isPrototypeOf.call(Plugin, ctr)) {\n throw new GeneratorIOException(`Plugin '${modulePath}' is not an instance of a Plugin class`);\n }\n\n return ctr;\n }\n\n resolveGeneratedFile(filename: string): string {\n return resolve(this.#outputDir, filename);\n }\n\n async read(path: string): Promise<string> {\n this.#logger.global.debug(`Reading file: ${path}`);\n return readFile(path, 'utf8');\n }\n\n async write(filename: string, content: string): Promise<void> {\n const filePath = join(this.#outputDir, filename);\n this.#logger.global.debug(`Writing file ${filePath}.`);\n const dir = dirname(filePath);\n await mkdir(dir, { recursive: true });\n return writeFile(filePath, content, 'utf-8');\n }\n}\n"],"version":3}
|
package/GeneratorIOException.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
class GeneratorIOException extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export default class GeneratorIOException extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(`[GeneratorIOException]: ${message}`);
|
|
4
|
+
}
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
GeneratorIOException as default
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=GeneratorIOException.js.map
|
|
6
|
+
//# sourceMappingURL=./GeneratorIOException.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/GeneratorIOException.ts"],
|
|
4
|
-
"sourcesContent": ["export default class GeneratorIOException extends Error {\n constructor(message: string) {\n super(`[GeneratorIOException]: ${message}`);\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,MAAO,6BAA2C,MAAM;AAAA,EACtD,YAAY,SAAiB;AAC3B,UAAM,2BAA2B,OAAO,EAAE;AAAA,EAC5C;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"mappings":"AAAA,eAAe,MAAM,6BAA6B,MAAM;CACtD,YAAYA,SAAiB;AAC3B,SAAO,0BAA0B,QAAQ,EAAE;CAC5C;AACF","names":["message: string"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-cli/src/GeneratorIOException.ts"],"sourcesContent":["export default class GeneratorIOException extends Error {\n constructor(message: string) {\n super(`[GeneratorIOException]: ${message}`);\n }\n}\n"],"version":3}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -3,11 +3,7 @@ import LoggerFactory from "@vaadin/hilla-generator-utils/LoggerFactory.js";
|
|
|
3
3
|
import meow from "meow";
|
|
4
4
|
import GeneratorIO from "./GeneratorIO.js";
|
|
5
5
|
import { processInput } from "./utils.js";
|
|
6
|
-
const {
|
|
7
|
-
flags: { outputDir, plugin: plugins, verbose },
|
|
8
|
-
input: [input]
|
|
9
|
-
} = meow(
|
|
10
|
-
`
|
|
6
|
+
const { flags: { outputDir, plugin: plugins, verbose }, input: [input] } = meow(`
|
|
11
7
|
Usage:
|
|
12
8
|
tsgen
|
|
13
9
|
(will read JSON from stdin)
|
|
@@ -19,36 +15,35 @@ Options:
|
|
|
19
15
|
-o, --output-dir Output directory
|
|
20
16
|
-p, --plugin <path> Use the plugin loadable by <path>.
|
|
21
17
|
--version Show the app version
|
|
22
|
-
`,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
);
|
|
18
|
+
`, {
|
|
19
|
+
flags: {
|
|
20
|
+
outputDir: {
|
|
21
|
+
default: "frontend/generated",
|
|
22
|
+
shortFlag: "o",
|
|
23
|
+
type: "string"
|
|
24
|
+
},
|
|
25
|
+
plugin: {
|
|
26
|
+
default: [],
|
|
27
|
+
isMultiple: true,
|
|
28
|
+
shortFlag: "p",
|
|
29
|
+
type: "string"
|
|
30
|
+
},
|
|
31
|
+
verbose: {
|
|
32
|
+
shortFlag: "v",
|
|
33
|
+
type: "boolean"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
importMeta: import.meta
|
|
37
|
+
});
|
|
44
38
|
const logger = new LoggerFactory({ verbose });
|
|
45
39
|
const io = new GeneratorIO(outputDir, logger);
|
|
46
|
-
const resolvedPlugins = await Promise.all(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const resolvedPlugins = await Promise.all(Array.from(new Set(plugins), async (pluginPath) => io.loadPlugin(pluginPath)));
|
|
41
|
+
const generator = new Generator(resolvedPlugins, {
|
|
42
|
+
logger,
|
|
43
|
+
outputDir
|
|
44
|
+
});
|
|
50
45
|
const files = await generator.process(await processInput(io, input));
|
|
51
46
|
const filesToDelete = await io.getGeneratedFiles();
|
|
52
47
|
const generatedFiles = await io.writeGeneratedFiles(files);
|
|
53
48
|
await io.cleanOutputDir(generatedFiles, filesToDelete);
|
|
54
|
-
//# sourceMappingURL
|
|
49
|
+
//# sourceMappingURL=./index.js.map
|
package/index.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Generator from '@vaadin/hilla-generator-core/Generator.js';\nimport LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport meow from 'meow';\nimport GeneratorIO from './GeneratorIO.js';\nimport { processInput } from './utils.js';\n\nconst {\n flags: { outputDir, plugin: plugins, verbose },\n input: [input],\n} = meow(\n `\nUsage:\n tsgen\n (will read JSON from stdin)\n tsgen <OpenAPI JSON string>\n tsgen <OpenAPI file path>\n\nOptions:\n -h, --help Show this screen\n -o, --output-dir Output directory\n -p, --plugin <path> Use the plugin loadable by <path>.\n --version Show the app version\n`,\n {\n flags: {\n outputDir: {\n default: 'frontend/generated',\n shortFlag: 'o',\n type: 'string',\n },\n plugin: {\n default: [],\n isMultiple: true,\n shortFlag: 'p',\n type: 'string',\n },\n verbose: {\n shortFlag: 'v',\n type: 'boolean',\n },\n },\n importMeta: import.meta,\n },\n);\n\nconst logger = new LoggerFactory({ verbose });\n\nconst io = new GeneratorIO(outputDir, logger);\n\nconst resolvedPlugins = await Promise.all(\n Array.from(new Set(plugins), async (pluginPath) => io.loadPlugin(pluginPath)),\n);\nconst generator = new Generator(resolvedPlugins, { logger, outputDir });\n\nconst files = await generator.process(await processInput(io, input));\nconst filesToDelete = await io.getGeneratedFiles();\nconst generatedFiles = await io.writeGeneratedFiles(files);\n\nawait io.cleanOutputDir(generatedFiles, filesToDelete);\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,eAAe;AACtB,OAAO,mBAAmB;AAC1B,OAAO,UAAU;AACjB,OAAO,iBAAiB;AACxB,SAAS,oBAAoB;AAE7B,MAAM;AAAA,EACJ,OAAO,EAAE,WAAW,QAAQ,SAAS,QAAQ;AAAA,EAC7C,OAAO,CAAC,KAAK;AACf,IAAI;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA;AAAA,IACE,OAAO;AAAA,MACL,WAAW;AAAA,QACT,SAAS;AAAA,QACT,WAAW;AAAA,QACX,MAAM;AAAA,MACR;AAAA,MACA,QAAQ;AAAA,QACN,SAAS,CAAC;AAAA,QACV,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,MAAM;AAAA,MACR;AAAA,MACA,SAAS;AAAA,QACP,WAAW;AAAA,QACX,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,YAAY;AAAA,EACd;AACF;AAEA,MAAM,SAAS,IAAI,cAAc,EAAE,QAAQ,CAAC;AAE5C,MAAM,KAAK,IAAI,YAAY,WAAW,MAAM;AAE5C,MAAM,kBAAkB,MAAM,QAAQ;AAAA,EACp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M,GAAG,eAAe,gBAAgB,cAAc","names":[],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-cli/src/index.ts"],"sourcesContent":["import Generator from '@vaadin/hilla-generator-core/Generator.js';\nimport LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport meow from 'meow';\nimport GeneratorIO from './GeneratorIO.js';\nimport { processInput } from './utils.js';\n\nconst {\n flags: { outputDir, plugin: plugins, verbose },\n input: [input],\n} = meow(\n `\nUsage:\n tsgen\n (will read JSON from stdin)\n tsgen <OpenAPI JSON string>\n tsgen <OpenAPI file path>\n\nOptions:\n -h, --help Show this screen\n -o, --output-dir Output directory\n -p, --plugin <path> Use the plugin loadable by <path>.\n --version Show the app version\n`,\n {\n flags: {\n outputDir: {\n default: 'frontend/generated',\n shortFlag: 'o',\n type: 'string',\n },\n plugin: {\n default: [],\n isMultiple: true,\n shortFlag: 'p',\n type: 'string',\n },\n verbose: {\n shortFlag: 'v',\n type: 'boolean',\n },\n },\n importMeta: import.meta,\n },\n);\n\nconst logger = new LoggerFactory({ verbose });\n\nconst io = new GeneratorIO(outputDir, logger);\n\nconst resolvedPlugins = await Promise.all(\n Array.from(new Set(plugins), async (pluginPath) => io.loadPlugin(pluginPath)),\n);\nconst generator = new Generator(resolvedPlugins, { logger, outputDir });\n\nconst files = await generator.process(await processInput(io, input));\nconst filesToDelete = await io.getGeneratedFiles();\nconst generatedFiles = await io.writeGeneratedFiles(files);\n\nawait io.cleanOutputDir(generatedFiles, filesToDelete);\n"],"version":3}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-generator-cli",
|
|
3
|
-
"version": "24.7.0-
|
|
3
|
+
"version": "24.7.0-beta2",
|
|
4
4
|
"description": "A Hilla tool to generate TypeScript code from the OpenAPI document",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,14 +9,12 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"clean:build": "git clean -fx . -e .vite -e node_modules",
|
|
12
|
-
"build": "
|
|
13
|
-
"build:esbuild": "tsx ../../../scripts/build.ts",
|
|
14
|
-
"build:dts": "tsc --isolatedModules -p tsconfig.build.json",
|
|
15
|
-
"build:copy": "cd src && copyfiles **/*.d.ts ..",
|
|
12
|
+
"build": "tsx ../../../scripts/fast-build.ts",
|
|
16
13
|
"lint": "eslint src test",
|
|
17
14
|
"lint:fix": "eslint src test --fix",
|
|
18
|
-
"test": "
|
|
19
|
-
"test:coverage": "
|
|
15
|
+
"test": "vitest --run",
|
|
16
|
+
"test:coverage": "vitest --run --coverage",
|
|
17
|
+
"test:watch": "vitest",
|
|
20
18
|
"typecheck": "tsc --noEmit"
|
|
21
19
|
},
|
|
22
20
|
"repository": {
|
|
@@ -45,29 +43,9 @@
|
|
|
45
43
|
"tsgen": "bin/index.js"
|
|
46
44
|
},
|
|
47
45
|
"dependencies": {
|
|
48
|
-
"@vaadin/hilla-generator-core": "24.7.0-
|
|
49
|
-
"@vaadin/hilla-generator-utils": "24.7.0-
|
|
50
|
-
"get-stdin": "
|
|
51
|
-
"meow": "
|
|
52
|
-
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@types/chai": "^4.3.20",
|
|
55
|
-
"@types/chai-as-promised": "^7.1.8",
|
|
56
|
-
"@types/mocha": "^10.0.10",
|
|
57
|
-
"@types/node": "^20.17.12",
|
|
58
|
-
"@types/sinon": "^10.0.20",
|
|
59
|
-
"@types/sinon-chai": "^3.2.12",
|
|
60
|
-
"@vaadin/hilla-generator-core": "24.7.0-alpha9",
|
|
61
|
-
"c8": "^10.1.3",
|
|
62
|
-
"chai": "^4.5.0",
|
|
63
|
-
"chai-as-promised": "^7.1.2",
|
|
64
|
-
"concurrently": "^9.1.2",
|
|
65
|
-
"copyfiles": "^2.4.1",
|
|
66
|
-
"mocha": "^11.1.0",
|
|
67
|
-
"monocart-coverage-reports": "^2.11.5",
|
|
68
|
-
"pino": "^9.6.0",
|
|
69
|
-
"sinon": "^16.1.3",
|
|
70
|
-
"sinon-chai": "^3.7.0",
|
|
71
|
-
"type-fest": "^4.32.0"
|
|
46
|
+
"@vaadin/hilla-generator-core": "24.7.0-beta2",
|
|
47
|
+
"@vaadin/hilla-generator-utils": "24.7.0-beta2",
|
|
48
|
+
"get-stdin": "9.0.0",
|
|
49
|
+
"meow": "13.2.0"
|
|
72
50
|
}
|
|
73
51
|
}
|
package/utils.d.ts
CHANGED
package/utils.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { isAbsolute, resolve } from "path";
|
|
2
2
|
import getStdin from "get-stdin";
|
|
3
|
-
async function processInput(io, raw) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
export async function processInput(io, raw) {
|
|
4
|
+
if (raw) {
|
|
5
|
+
let result = raw;
|
|
6
|
+
if (result.startsWith("'") || result.startsWith("\"")) {
|
|
7
|
+
result = raw.substring(1, raw.length - 1);
|
|
8
|
+
}
|
|
9
|
+
if (result.startsWith("{")) {
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
return io.read(isAbsolute(result) ? result : resolve(io.cwd, result));
|
|
13
|
+
}
|
|
14
|
+
return getStdin();
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
processInput
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=utils.js.map
|
|
16
|
+
//# sourceMappingURL=./utils.js.map
|
package/utils.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { isAbsolute, resolve } from 'path';\nimport getStdin from 'get-stdin';\nimport type GeneratorIO from './GeneratorIO.js';\n\nexport async function processInput(io: GeneratorIO, raw?: string): Promise<string> {\n if (raw) {\n let result = raw;\n\n if (result.startsWith(\"'\") || result.startsWith('\"')) {\n result = raw.substring(1, raw.length - 1);\n }\n\n if (result.startsWith('{')) {\n return result;\n }\n\n return io.read(isAbsolute(result) ? result : resolve(io.cwd, result));\n }\n\n return getStdin();\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY,eAAe;AACpC,OAAO,cAAc;AAGrB,eAAsB,aAAa,IAAiB,KAA+B;AACjF,MAAI,KAAK;AACP,QAAI,SAAS;AAEb,QAAI,OAAO,WAAW,GAAG,KAAK,OAAO,WAAW,GAAG,GAAG;AACpD,eAAS,IAAI,UAAU,GAAG,IAAI,SAAS,CAAC;AAAA,IAC1C;AAEA,QAAI,OAAO,WAAW,GAAG,GAAG;AAC1B,aAAO;AAAA,IACT;AAEA,WAAO,GAAG,KAAK,WAAW,MAAM,IAAI,SAAS,QAAQ,GAAG,KAAK,MAAM,CAAC;AAAA,EACtE;AAEA,SAAO,SAAS;AAClB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"mappings":"AAAA,SAAS,YAAY,qBAAsB;AAC3C,OAAO,yBAA0B;AAGjC,OAAO,eAAe,aAAaA,IAAiBC,KAA+B;AACjF,KAAI,KAAK;EACP,IAAI,SAAS;AAEb,MAAI,OAAO,WAAW,IAAI,IAAI,OAAO,WAAW,KAAI,EAAE;AACpD,YAAS,IAAI,UAAU,GAAG,IAAI,SAAS,EAAE;EAC1C;AAED,MAAI,OAAO,WAAW,IAAI,EAAE;AAC1B,UAAO;EACR;AAED,SAAO,GAAG,KAAK,WAAW,OAAO,GAAG,SAAS,QAAQ,GAAG,KAAK,OAAO,CAAC;CACtE;AAED,QAAO,UAAU;AAClB","names":["io: GeneratorIO","raw?: string"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-cli/src/utils.ts"],"sourcesContent":["import { isAbsolute, resolve } from 'path';\nimport getStdin from 'get-stdin';\nimport type GeneratorIO from './GeneratorIO.js';\n\nexport async function processInput(io: GeneratorIO, raw?: string): Promise<string> {\n if (raw) {\n let result = raw;\n\n if (result.startsWith(\"'\") || result.startsWith('\"')) {\n result = raw.substring(1, raw.length - 1);\n }\n\n if (result.startsWith('{')) {\n return result;\n }\n\n return io.read(isAbsolute(result) ? result : resolve(io.cwd, result));\n }\n\n return getStdin();\n}\n"],"version":3}
|
package/GeneratorIO.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GeneratorIO.d.ts","sourceRoot":"","sources":["src/GeneratorIO.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,IAAI,MAAM,sCAAsC,CAAC;AAC7D,OAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,KAAK,aAAa,MAAM,gDAAgD,CAAC;AAShF,MAAM,CAAC,OAAO,OAAO,WAAW;;IAC9B,MAAM,CAAC,QAAQ,CAAC,cAAc,6BAA6B;IACnD,CAAC,aAAa,CAAC,EAAE,OAAO,WAAW,CAAC;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAIT,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa;IAQpD;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAiB/C;;;;OAIG;IACG,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAyB1F,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,mBAAmB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAuBpE;;;OAGG;WAEU,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS7C,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAYhE,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIxC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnC,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAO9D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GeneratorIOException.d.ts","sourceRoot":"","sources":["src/GeneratorIOException.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,KAAK;gBACzC,OAAO,EAAE,MAAM;CAG5B"}
|
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":""}
|
package/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAEhD,wBAAsB,YAAY,CAAC,EAAE,EAAE,WAAW,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBjF"}
|