GeezerVison is showing github.com — feat(codegen): add demo slots & add new cli option solutionOptions · huihao/lowcode-engine@2bd40d7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/bin/lowcode-code-generator.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ program | 14 | 14 | .option('-c, --cwd <cwd>', 'specify the working directory', '.') | 15 | 15 | .option('-q, --quiet', 'be quiet, do not output anything unless get error', false) | 16 | 16 | .option('-v, --verbose', 'be verbose, output more information', false) | | 17 | + .option('--solution-options <options>', 'specify the solution options', '{}') | 17 | 18 | .arguments('[input-schema] ali lowcode schema JSON file') | 18 | 19 | .action(function doGenerate(inputSchema, command) { | 19 | 20 | var options = command.opts(); | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/cli/run.ts +16-2Lines changed: 16 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ export async function run( | 25 | 25 | output?: string; | 26 | 26 | quiet?: boolean; | 27 | 27 | verbose?: boolean; | | 28 | + solutionOptions?: string; | 28 | 29 | }, | 29 | 30 | ): Promise<number> { | 30 | 31 | try { | @@ -41,14 +42,27 @@ export async function run( | 41 | 42 | ); | 42 | 43 | } | 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 | + | 44 | 58 | // 读取 Schema | 45 | 59 | const schema = await loadSchemaFile(schemaFile); | 46 | 60 |
| 47 | 61 | // 创建一个项目构建器 | 48 | 62 | const createProjectBuilder = await getProjectBuilderFactory(options.solution, { | 49 | 63 | quiet: options.quiet, | 50 | 64 | }); | 51 | | - const builder = createProjectBuilder(); | | 65 | + const builder = createProjectBuilder(solutionOptions); | 52 | 66 |
| 53 | 67 | // 生成代码 | 54 | 68 | const generatedSourceCodes = await builder.generateProject(schema); | @@ -75,7 +89,7 @@ export async function run( | 75 | 89 | async function getProjectBuilderFactory( | 76 | 90 | solution: string, | 77 | 91 | { quiet }: { quiet?: boolean }, | 78 | | -): Promise<() => IProjectBuilder> { | | 92 | +): Promise<(options: {[prop: string]: any}) => IProjectBuilder> { | 79 | 93 | if (solution in CodeGenerator.solutions) { | 80 | 94 | return CodeGenerator.solutions[solution as 'icejs' | 'rax']; | 81 | 95 | } | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/generator/ProjectBuilder.ts +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -241,6 +241,15 @@ export class ProjectBuilder implements IProjectBuilder { | 241 | 241 | }); | 242 | 242 | } | 243 | 243 |
| | 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 | + | 244 | 253 | // TODO: 更多 slots 的处理??是不是可以考虑把 template 中所有的 slots 都处理下? | 245 | 254 |
| 246 | 255 | // Post Process | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/types/core.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ export enum FileType { | 25 | 25 | TS = 'ts', | 26 | 26 | TSX = 'tsx', | 27 | 27 | JSON = 'json', | | 28 | + MD = 'md', | 28 | 29 | } | 29 | 30 |
| 30 | 31 | export enum ChunkType { | |
|