|
1 | | -import { loadDocument, type ZModelServices } from '@zenstackhq/language'; |
2 | | -import { isDataSource, isPlugin, Model } from '@zenstackhq/language/ast'; |
3 | | -import { getLiteral } from '@zenstackhq/language/utils'; |
| 1 | +import { loadDocument } from '@zenstackhq/language'; |
| 2 | +import { isDataSource } from '@zenstackhq/language/ast'; |
4 | 3 | import { PrismaSchemaGenerator } from '@zenstackhq/sdk'; |
5 | 4 | import colors from 'colors'; |
6 | 5 | import fs from 'node:fs'; |
7 | 6 | import path from 'node:path'; |
8 | | -import { fileURLToPath } from 'node:url'; |
9 | 7 | import { CliError } from '../cli-error'; |
10 | | -import { PLUGIN_MODULE_NAME } from '../constants'; |
11 | 8 |
|
12 | 9 | export function getSchemaFile(file?: string) { |
13 | 10 | if (file) { |
@@ -50,63 +47,6 @@ export async function loadSchemaDocument(schemaFile: string) { |
50 | 47 | return loadResult.model; |
51 | 48 | } |
52 | 49 |
|
53 | | -export async function getPluginDocuments(services: ZModelServices, fileName: string): Promise<string[]> { |
54 | | - // parse the user document (without validation) |
55 | | - const parseResult = services.parser.LangiumParser.parse(fs.readFileSync(fileName, { encoding: 'utf-8' })); |
56 | | - const parsed = parseResult.value as Model; |
57 | | - |
58 | | - // balk if there are syntax errors |
59 | | - if (parseResult.lexerErrors.length > 0 || parseResult.parserErrors.length > 0) { |
60 | | - return []; |
61 | | - } |
62 | | - |
63 | | - // traverse plugins and collect "plugin.zmodel" documents |
64 | | - const result: string[] = []; |
65 | | - for (const decl of parsed.declarations.filter(isPlugin)) { |
66 | | - const providerField = decl.fields.find((f) => f.name === 'provider'); |
67 | | - if (!providerField) { |
68 | | - continue; |
69 | | - } |
70 | | - |
71 | | - const provider = getLiteral<string>(providerField.value); |
72 | | - if (!provider) { |
73 | | - continue; |
74 | | - } |
75 | | - |
76 | | - let pluginModelFile: string | undefined; |
77 | | - |
78 | | - // first try to treat provider as a path |
79 | | - let providerPath = path.resolve(path.dirname(fileName), provider); |
80 | | - if (fs.existsSync(providerPath)) { |
81 | | - if (fs.statSync(providerPath).isDirectory()) { |
82 | | - providerPath = path.join(providerPath, 'index.js'); |
83 | | - } |
84 | | - |
85 | | - // try plugin.zmodel next to the provider file |
86 | | - pluginModelFile = path.resolve(path.dirname(providerPath), PLUGIN_MODULE_NAME); |
87 | | - if (!fs.existsSync(pluginModelFile)) { |
88 | | - // try to find upwards |
89 | | - pluginModelFile = findUp([PLUGIN_MODULE_NAME], path.dirname(providerPath)); |
90 | | - } |
91 | | - } |
92 | | - |
93 | | - if (!pluginModelFile) { |
94 | | - // try loading it as a ESM module |
95 | | - try { |
96 | | - const resolvedUrl = import.meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`); |
97 | | - pluginModelFile = fileURLToPath(resolvedUrl); |
98 | | - } catch { |
99 | | - // noop |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - if (pluginModelFile && fs.existsSync(pluginModelFile)) { |
104 | | - result.push(pluginModelFile); |
105 | | - } |
106 | | - } |
107 | | - return result; |
108 | | -} |
109 | | - |
110 | 50 | export function handleSubProcessError(err: unknown) { |
111 | 51 | if (err instanceof Error && 'status' in err && typeof err.status === 'number') { |
112 | 52 | process.exit(err.status); |
|
0 commit comments