MCPcopy Create free account
hub / github.com/alibaba/lowcode-engine / run

Function run

modules/code-generator/src/cli/run.ts:20–87  ·  view source on GitHub ↗
(
  args: string[],
  options: {
    solution: string;
    input?: string;
    output?: string;
    quiet?: boolean;
    verbose?: boolean;
    solutionOptions?: string;
  },
)

Source from the content-addressed store, hash-verified

18 * @returns {Promise<number>} 错误码
19 */
20export async function run(
21 args: string[],
22 options: {
23 solution: string;
24 input?: string;
25 output?: string;
26 quiet?: boolean;
27 verbose?: boolean;
28 solutionOptions?: string;
29 },
30): Promise<number> {
31 try {
32 const schemaFile = options.input || args[0];
33 if (!schemaFile) {
34 throw new Error(
35 'a schema file must be specified by `--input <schema.json>` or by the first positional argument',
36 );
37 }
38
39 if ((options.input && args.length > 0) || args.length > 1) {
40 throw new Error(
41 'only one schema file can be specified, either by `--input <schema.json>` or by the first positional argument',
42 );
43 }
44
45 let solutionOptions = {};
46
47 if (options.solutionOptions) {
48 try {
49 solutionOptions = JSON.parse(options.solutionOptions);
50 } catch (err: any) {
51 throw new Error(
52 `solution options parse error, error message is "${err.message}"`,
53 );
54 }
55 }
56
57
58 // 读取 Schema
59 const schema = await loadSchemaFile(schemaFile);
60
61 // 创建一个项目构建器
62 const createProjectBuilder = await getProjectBuilderFactory(options.solution, {
63 quiet: options.quiet,
64 });
65 const builder = createProjectBuilder(solutionOptions);
66
67 // 生成代码
68 const generatedSourceCodes = await builder.generateProject(schema);
69
70 // 输出到磁盘
71 const publisher = CodeGenerator.publishers.disk();
72
73 await publisher.publish({
74 project: generatedSourceCodes,
75 outputPath: options.output || 'generated',
76 projectSlug: 'example',
77 createProjectFolder: false,

Callers 1

cli.test.tsFile · 0.90

Calls 7

getErrorMessageFunction · 0.90
loadSchemaFileFunction · 0.85
getProjectBuilderFactoryFunction · 0.85
createProjectBuilderFunction · 0.85
parseMethod · 0.80
generateProjectMethod · 0.80
logMethod · 0.65

Tested by

no test coverage detected