Code Monkey home page Code Monkey logo

darabonba-java-generator's Introduction

English | 简体中文

NPM version Node.js CI codecov npm download

Darabonba Code Generator for Java

Installation

Darabonba Code Generator was designed to work in Node.js. The preferred way to install the Generator is to use the NPM package manager. Simply type the following into a terminal window:

npm install @darabonba/java-generator

Usage

'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 = {
  ...packageMeta,
  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'

Issues

Opening an Issue, Issues not conforming to the guidelines may be closed immediately.

Changelog

Detailed changes for each release are documented in the release notes.

License

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

darabonba-java-generator's People

Contributors

atptro avatar dependabot[bot] avatar jacksontian avatar peze avatar wenzuochao avatar yndu13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

darabonba-java-generator's Issues

Error: `option.outputDir` should not empty;TypeError: Cannot read property 'packageInfo' of undefined;

Following the tutorial, Something went wrong
https://github.com/aliyun/darabonba/blob/master/doc/getting_started.md

1. Error: option.outputDir should not empty

Darafile:

{
  "scope": "hello",
  "name": "hello",
  "version": "1.0.0",
  "main": "./hello.dara",
}
dara codegen java ./tmp
Error: `option.outputDir` should not empty
at new Visitor (/usr/local/lib/node_modules/@darabonba/cli/node_modules/@darabonba/java-generator/lib/generator.js:102:13)

may be missing "package" in Darafile file

2. TypeError: Cannot read property 'packageInfo' of undefined

Darafile:

{
  "scope": "hello",
  "name": "hello",
  "version": "1.0.0",
  "main": "./hello.dara",
  "package": "hello",
}
dara codegen java ./tmp
TypeError: Cannot read property 'packageInfo' of undefined
at new Visitor (/usr/local/lib/node_modules/@darabonba/cli/node_modules/@darabonba/java-generator/lib/generator.js:111:36)

may be missing "java" in Darafile file

The correct Darafile is:

{
"scope": "hello",
"name": "hello",
"version": "1.0.0",
"main": "./hello.dara",
"package": "hello",
"java": {}
}

3. Some spelling problems were found when trying to find the parameters in "java"

"licenseNmae": Unknown word.

  const needParamsKeys = ['description', 'url',
    'licenseNmae', 'developerId',
    'licenseUrl', 'developerName',
    'developerEmail', 'scmConnection',
    'scmDeveloperConnection', 'scmUrl', 'groupId',
    'artifactId', 'version'
  ];

"tamplate": Unknown word.

maven 3.x 打包失败

感谢提供如此方便的工具,目前在使用过程中遇到了如下问题

生成代码后执行 mvn install 会报如下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign (sign-artifacts) on project openapi-sdk: Unable to execute gpg command: Error while executing process. Cannot run program "gpg": error=2, No such file or directory -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

排查后发现生成的 pom.xml 里面生成 bulid 的结构如下:

    <build>
        <plugins>
            <plugin>
            ...
            <plugin>
        <plugins>
      <build>      

这种写法应该是 maven 2.x 时的写法,而 maven 3.x 的结构有变化,应该如下:

<build>
   <pluginManagement>
   <plugins>
      <plugin></plugin>
      ...
       <plugin></plugin>
    </plugins>
</pluginManagement>
</build>

多了一个 pluginManagement

因为 maven 3 已经很普遍在使用了,希望可以加个配置用于兼容 maven 3 结构,感谢👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.