Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 2.23 KB

README-CN.md

File metadata and controls

68 lines (49 loc) · 2.23 KB

English | 简体中文

NPM version Node.js CI codecov npm download

Darabonba Java 生成器

安装

Darabonba 生成器只能在 Node.js 环境下运行。建议使用 NPM 包管理工具安装。在终端输入以下命令进行安装:

npm install @darabonba/java-generator

使用示例

'use strict';

const path = require('path');
const fs = require('fs');
const parser = require('@darabonba/parser');
const JavaGenerator = require('@darabonba/java-generator');

const sourceDir = "<Darabonda package directory>";
const outputDir = "<Generate output directory>";

// generate AST data by parser
let packageMetaFilePath = path.join(sourceDir, 'Darafile');
let packageMeta = JSON.parse(fs.readFileSync(packageMetaFilePath, 'utf8'));
let mainFile = path.join(sourceDir, packageMeta.main);
let ast = parser.parse(fs.readFileSync(mainFile, 'utf8'), mainFile);

// initialize generator
let generatorConfig = {
  ...darabonbaPackageMeta,
  pkgDir: sourceDir,
  outputDir
};
let generator = new JavaGenerator(generatorConfig);

// generate Java code by generator
generator.visit(ast);
// The execution result will be output in the 'outputDir'

问题反馈

提出问题, 不符合指南的问题可能会立即关闭。

发布日志

发布详情会更新在 release notes 文件中

许可证

Apache-2.0 Copyright (c) 2009-present, Alibaba Cloud All rights reserved.