Skip to content

Commit 2bd40d7

Browse files
committed
feat(codegen): add demo slots & add new cli option solutionOptions
1 parent 1ca940c commit 2bd40d7

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

modules/code-generator/bin/lowcode-code-generator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ program
1414
.option('-c, --cwd <cwd>', 'specify the working directory', '.')
1515
.option('-q, --quiet', 'be quiet, do not output anything unless get error', false)
1616
.option('-v, --verbose', 'be verbose, output more information', false)
17+
.option('--solution-options <options>', 'specify the solution options', '{}')
1718
.arguments('[input-schema] ali lowcode schema JSON file')
1819
.action(function doGenerate(inputSchema, command) {
1920
var options = command.opts();

modules/code-generator/src/cli/run.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export async function run(
2525
output?: string;
2626
quiet?: boolean;
2727
verbose?: boolean;
28+
solutionOptions?: string;
2829
},
2930
): Promise<number> {
3031
try {
@@ -41,14 +42,27 @@ export async function run(
4142
);
4243
}
4344

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+
4458
// 读取 Schema
4559
const schema = await loadSchemaFile(schemaFile);
4660

4761
// 创建一个项目构建器
4862
const createProjectBuilder = await getProjectBuilderFactory(options.solution, {
4963
quiet: options.quiet,
5064
});
51-
const builder = createProjectBuilder();
65+
const builder = createProjectBuilder(solutionOptions);
5266

5367
// 生成代码
5468
const generatedSourceCodes = await builder.generateProject(schema);
@@ -75,7 +89,7 @@ export async function run(
7589
async function getProjectBuilderFactory(
7690
solution: string,
7791
{ quiet }: { quiet?: boolean },
78-
): Promise<() => IProjectBuilder> {
92+
): Promise<(options: {[prop: string]: any}) => IProjectBuilder> {
7993
if (solution in CodeGenerator.solutions) {
8094
return CodeGenerator.solutions[solution as 'icejs' | 'rax'];
8195
}

modules/code-generator/src/generator/ProjectBuilder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ export class ProjectBuilder implements IProjectBuilder {
241241
});
242242
}
243243

244+
// demo
245+
if (parseResult.project && builders.demo) {
246+
const { files } = await builders.demo.generateModule(parseResult.project);
247+
buildResult.push({
248+
path: this.template.slots.demo.path,
249+
files,
250+
});
251+
}
252+
244253
// TODO: 更多 slots 的处理??是不是可以考虑把 template 中所有的 slots 都处理下?
245254

246255
// Post Process

modules/code-generator/src/types/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export enum FileType {
2525
TS = 'ts',
2626
TSX = 'tsx',
2727
JSON = 'json',
28+
MD = 'md',
2829
}
2930

3031
export enum ChunkType {

0 commit comments

Comments
 (0)