Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Raisel Melian committed Dec 5, 2018
2 parents 91eba18 + 5786146 commit 6f59013
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 17 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
node_modules
npm-debug.log
output
######################
# Intellij
######################
.idea/
*.iml
*.iws
*.ipr
*.ids
*.orig
out/
66 changes: 55 additions & 11 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const xfs = require('fs.extra');
const beautifier = require('./beautifier');
const registerPartial = require('./register-partial');
const parse = require('./parser');
const minimatch = require("minimatch");

const generator = module.exports;

Expand Down Expand Up @@ -50,22 +51,35 @@ const renderFile = (filePath, data) => new Promise((resolve, reject) => {
*/
const generateFile = options => new Promise((resolve, reject) => {
const templates_dir = options.templates_dir;
const template_config = options.template_config;
const target_dir = options.target_dir;
const file_name = options.file_name;
const root = options.root;
const data = options.data;
const source_path = path.resolve(root, file_name);

renderFile(path.resolve(root, file_name), data)
.then((parsed_content) => {
const template_path = path.relative(templates_dir, path.resolve(root, file_name));
const generated_path = path.resolve(target_dir, template_path);
if (isFileNonRenderable(file_name, template_config.nonRenderableFiles)) {
const template_path = path.relative(templates_dir, path.resolve(root, file_name));
const generated_path = path.resolve(target_dir, template_path);

fs.writeFile(generated_path, parsed_content, 'utf8', (err) => {
if (err) return reject(err);
resolve();
});
})
.catch(reject);
fs.copyFile(source_path, generated_path, (err) => {
if (err) return reject(err);
resolve();
});
} else {
renderFile(path.resolve(root, file_name), data)
.then((parsed_content) => {
const template_path = path.relative(templates_dir, path.resolve(root, file_name));
const generated_path = path.resolve(target_dir, template_path);

const stats = fs.statSync(source_path);
fs.writeFile(generated_path, parsed_content, {encoding: 'utf8', mode: stats.mode}, (err) => {
if (err) return reject(err);
resolve();
});
})
.catch(reject);
}
});

/**
Expand Down Expand Up @@ -130,6 +144,7 @@ const generateTopicFiles = options => new Promise((resolve, reject) => {
const generateDirectoryStructure = config => new Promise((resolve, reject) => {
const target_dir = config.target_dir;
const templates_dir = config.templates;
const template_config = resolveTemplateConfig(templates_dir);

xfs.mkdirpSync(target_dir);

Expand Down Expand Up @@ -159,7 +174,8 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
templates_dir,
target_dir,
data: config,
file_name: stats.name
file_name: stats.name,
template_config
});
}
next();
Expand Down Expand Up @@ -369,3 +385,31 @@ generator.getTemplateFile = ({
resolve(content);
});
});

/**
* check if a given file_name matches a list of Glob patterns
*
* @param {string} file name to check against a list of Glob patterns
* @param {string} list of Glob patterns
* @return {boolean} true | false
*/
function isFileNonRenderable (file_name, nonRenderableGlobs) {
if (!file_name || !nonRenderableGlobs) {
return false;
}

const isNonRenderable = function(globExp) {
return minimatch(file_name, globExp);
};

return nonRenderableGlobs.some(isNonRenderable);
}

function resolveTemplateConfig(templates_dir) {
try {
const config_path = path.resolve(templates_dir, ".tp-config");
return require(config_path);
} catch (e) {
return {};
}
}
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asyncapi-generator",
"version": "0.4.0",
"version": "0.5.0",
"description": "The AsyncAPI generator. It can generate documentation, code, anything!",
"main": "./lib/generator.js",
"bin": {
Expand Down Expand Up @@ -38,7 +38,8 @@
"mkdirp": "^0.5.1",
"openapi-sampler": "^1.0.0-beta.9",
"project-name-generator": "^2.1.5",
"z-schema": "^3.18.2"
"z-schema": "^3.18.2",
"minimatch": "^3.0.4"
},
"devDependencies": {}
}
5 changes: 4 additions & 1 deletion templates/java-spring/.helpers/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ module.exports = (Handlebars, _) => {
// Handlebars.registerHelper('json', function(context) {
// return JSON.stringify(context);
// });


Handlebars.registerHelper('schemeExists', (collection, scheme) => {
return _.some(collection, {'scheme': scheme});
});
};
5 changes: 5 additions & 0 deletions templates/java-spring/.tp-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"nonRenderableFiles": [
"**/*.jar"
]
}
11 changes: 9 additions & 2 deletions templates/java-spring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ ag -o ./src asyncapi.yaml java-spring
```

### Run it
To run the generated application you need the java virtual machine and gradle installed. After thats done go to the root folder of the generated code and run this command:
{{#if (schemeExists asyncapi.servers "amqp") }}
Start your RabbitMQ with:
```bash
gradle bootRun
docker-compose -f src/main/docker/rabbitmq.yml up -d
```
{{/if}}

Go to the root folder of the generated code and run this command (you need the JDK1.8):
```bash
./gradlew bootRun
```
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Oct 30 18:45:03 EDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
Empty file modified templates/java-spring/gradlew
100644 → 100755
Empty file.
7 changes: 7 additions & 0 deletions templates/java-spring/src/main/docker/rabbitmq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '2'
services:
rabbitmq:
image: rabbitmq:3.6.2-management
ports:
- 5672:5672
- 15672:15672
2 changes: 1 addition & 1 deletion templates/java-spring/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
amqp:
broker:
host: localhost
port: 32771
port: 5672
username: guest
password: guest
exchange:
Expand Down

0 comments on commit 6f59013

Please sign in to comment.