Skip to content

Commit

Permalink
feat: use latest generator (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored Mar 31, 2020
1 parent eff5bf9 commit 401da6f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 42 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ This action generates whatever you want using your AsyncAPI document. It uses [A

Template for the generator. Official templates are listed here https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate. You can pass template as npm package, url to git repository, link to tar file or local template.

**Default** points to `@asyncapi/markdown-template` template.
**Default** points to `@asyncapi/[email protected]` template.

> We recommend to always specify the version of the template to not encounter any issues with the action in case of release of the template that is not compatible with given version of the generator.
### `filepath`

Expand Down Expand Up @@ -40,7 +42,7 @@ In case all defaults are fine for you, just add such step:

```
- name: Generating Markdown from my AsyncAPI document
uses: asyncapi/github-action-for-generator@v0.1.0
uses: asyncapi/github-action-for-generator@v0.2.0
```

### Using all possible inputs
Expand All @@ -49,9 +51,9 @@ In case you do not want to use defaults, you for example want to use different t

```
- name: Generating HTML from my AsyncAPI document
uses: asyncapi/github-action-for-generator@v0.1.0
uses: asyncapi/github-action-for-generator@v0.2.0
with:
template: '@asyncapi/html-template' #In case of template from npm, because of @ it must be in quotes
template: '@asyncapi/html-template@0.3.0' #In case of template from npm, because of @ it must be in quotes
filepath: docs/api/my-asyncapi.yml
parameters: baseHref=/test-experiment/ sidebarOrganization=byTags #space separated list of key/values
output: generated-html
Expand All @@ -64,7 +66,7 @@ In case you want to have more steps in your workflow after generation and you ne
```
- name: Generating Markdown from my AsyncAPI document
id: generation
uses: asyncapi/github-action-for-generator@v0.1.0
uses: asyncapi/github-action-for-generator@v0.2.0
- name: Another step where I want to know what files were generated so I can pass it to another step and process them forward if needed
run: echo '${{steps.generation.outputs.files}}'
```
Expand Down Expand Up @@ -97,9 +99,9 @@ jobs:
#In case you do not want to use defaults, you for example want to use different template
- name: Generating HTML from my AsyncAPI document
uses: asyncapi/github-action-for-generator@v0.1.0
uses: asyncapi/github-action-for-generator@v0.2.0
with:
template: '@asyncapi/html-template' #In case of template from npm, because of @ it must be in quotes
template: '@asyncapi/html-template@0.3.0' #In case of template from npm, because of @ it must be in quotes
filepath: docs/api/my-asyncapi.yml
parameters: baseHref=/test-experiment/ sidebarOrganization=byTags #space separated list of key/values
output: generated-html
Expand Down
44 changes: 14 additions & 30 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39580,7 +39580,7 @@ const Generator = __webpack_require__(585);
const path = __webpack_require__(622);
const { paramParser, createOutputDir, listOutputFiles } = __webpack_require__(421);

const DEFAULT_TEMPLATE = '@asyncapi/markdown-template';
const DEFAULT_TEMPLATE = '@asyncapi/markdown-template@0.3.0';
const DEFAULT_FILEPATH = 'asyncapi.yml';
const DEFAULT_OUTPUT = 'output';

Expand Down Expand Up @@ -42831,37 +42831,20 @@ parser.registerSchemaParser([
'application/raml+yaml;version=1.0',
], ramlDtParser);

const FILTERS_DIRNAME = '.filters';
const PARTIALS_DIRNAME = '.partials';
const HOOKS_DIRNAME = '.hooks';
const NODE_MODULES_DIRNAME = 'node_modules';
const FILTERS_DIRNAME = 'filters';
const HOOKS_DIRNAME = 'hooks';
const CONFIG_FILENAME = '.tp-config.json';
const PACKAGE_JSON_FILENAME = 'package.json';
const PACKAGE_LOCK_FILENAME = 'package-lock.json';
const ROOT_DIR = path.resolve(__dirname, '..');
const DEFAULT_TEMPLATES_DIR = path.resolve(ROOT_DIR, 'node_modules');
const TEMPLATE_CONTENT_DIRNAME = 'template';

const shouldIgnoreFile = filePath =>
filePath.startsWith(`.git${path.sep}`)
|| filePath.startsWith(`${PARTIALS_DIRNAME}${path.sep}`)
|| filePath.startsWith(`${FILTERS_DIRNAME}${path.sep}`)
|| filePath.startsWith(`${HOOKS_DIRNAME}${path.sep}`)
|| path.basename(filePath) === CONFIG_FILENAME
|| path.basename(filePath) === PACKAGE_JSON_FILENAME
|| path.basename(filePath) === PACKAGE_LOCK_FILENAME
|| filePath.startsWith(`${NODE_MODULES_DIRNAME}${path.sep}`);
filePath.startsWith(`.git${path.sep}`);

const shouldIgnoreDir = dirPath =>
dirPath === '.git'
|| dirPath.startsWith(`.git${path.sep}`)
|| dirPath === PARTIALS_DIRNAME
|| dirPath.startsWith(`${PARTIALS_DIRNAME}${path.sep}`)
|| dirPath === FILTERS_DIRNAME
|| dirPath.startsWith(`${FILTERS_DIRNAME}${path.sep}`)
|| dirPath === HOOKS_DIRNAME
|| dirPath.startsWith(`${HOOKS_DIRNAME}${path.sep}`)
|| dirPath === NODE_MODULES_DIRNAME
|| dirPath.startsWith(`${NODE_MODULES_DIRNAME}${path.sep}`);
|| dirPath.startsWith(`.git${path.sep}`);

class Generator {
/**
Expand Down Expand Up @@ -42949,13 +42932,14 @@ class Generator {
const { name: templatePkgName, path: templatePkgPath } = await this.installTemplate(this.install);
this.templateDir = templatePkgPath;
this.templateName = templatePkgName;
this.templateContentDir = path.resolve(this.templateDir, TEMPLATE_CONTENT_DIRNAME);
this.configNunjucks();
await this.loadTemplateConfig();
this.registerHooks();
await this.registerFilters();

if (this.entrypoint) {
const entrypointPath = path.resolve(this.templateDir, this.entrypoint);
const entrypointPath = path.resolve(this.templateContentDir, this.entrypoint);
if (!(await exists(entrypointPath))) throw new Error(`Template entrypoint "${entrypointPath}" couldn't be found.`);
if (this.output === 'fs') {
await this.generateFile(asyncapiDocument, path.basename(entrypointPath), path.dirname(entrypointPath));
Expand Down Expand Up @@ -43065,7 +43049,7 @@ class Generator {
*
* @example
* const Generator = require('asyncapi-generator');
* const content = await Generator.getTemplateFile('html', '.partials/content.html');
* const content = await Generator.getTemplateFile('html', 'partials/content.html');
*
* @static
* @param {String} templateName Name of the template to generate.
Expand Down Expand Up @@ -43212,7 +43196,7 @@ class Generator {
return new Promise((resolve, reject) => {
xfs.mkdirpSync(this.targetDir);

const walker = xfs.walk(this.templateDir, {
const walker = xfs.walk(this.templateContentDir, {
followLinks: false
});

Expand All @@ -43224,7 +43208,7 @@ class Generator {
if (Object.prototype.hasOwnProperty.call(fileNamesForSeparation, prop)) {
if (stats.name.includes(`$$${prop}$$`)) {
await this.generateSeparateFiles(asyncapiDocument, fileNamesForSeparation[prop], prop, stats.name, root);
const templateFilePath = path.relative(this.templateDir, path.resolve(root, stats.name));
const templateFilePath = path.relative(this.templateContentDir, path.resolve(root, stats.name));
fs.unlink(path.resolve(this.targetDir, templateFilePath), next);
wasSeparated = true;
//The filename can only contain 1 specifier (message, scheme etc)
Expand All @@ -43244,7 +43228,7 @@ class Generator {

walker.on('directory', async (root, stats, next) => {
try {
const relativeDir = path.relative(this.templateDir, path.resolve(root, stats.name));
const relativeDir = path.relative(this.templateContentDir, path.resolve(root, stats.name));
const dirPath = path.resolve(this.targetDir, relativeDir);
if (!shouldIgnoreDir(relativeDir)) {
xfs.mkdirpSync(dirPath);
Expand Down Expand Up @@ -43301,7 +43285,7 @@ class Generator {
*/
async generateSeparateFile(asyncapiDocument, name, component, template, fileName, baseDir) {
try {
const relativeBaseDir = path.relative(this.templateDir, baseDir);
const relativeBaseDir = path.relative(this.templateContentDir, baseDir);
const newFileName = fileName.replace(`\$\$${template}\$\$`, filenamify(name, { replacement: '-', maxLength: 255 }));
const targetFile = path.resolve(this.targetDir, relativeBaseDir, newFileName);
const relativeTargetFile = path.relative(this.targetDir, targetFile);
Expand Down Expand Up @@ -43333,7 +43317,7 @@ class Generator {
async generateFile(asyncapiDocument, fileName, baseDir) {
try {
const sourceFile = path.resolve(baseDir, fileName);
const relativeSourceFile = path.relative(this.templateDir, sourceFile);
const relativeSourceFile = path.relative(this.templateContentDir, sourceFile);
const targetFile = path.resolve(this.targetDir, relativeSourceFile);
const relativeTargetFile = path.relative(this.targetDir, targetFile);

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Generator = require('@asyncapi/generator');
const path = require('path');
const { paramParser, createOutputDir, listOutputFiles } = require('./utils');

const DEFAULT_TEMPLATE = '@asyncapi/markdown-template';
const DEFAULT_TEMPLATE = '@asyncapi/markdown-template@0.3.0';
const DEFAULT_FILEPATH = 'asyncapi.yml';
const DEFAULT_OUTPUT = 'output';

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@actions/core": "^1.2.3",
"@asyncapi/generator": "^0.35.2",
"@asyncapi/generator": "^0.36.0",
"@zeit/ncc": "^0.20.5",
"jest": "^24.9.0",
"readdirp": "^3.4.0"
Expand Down

0 comments on commit 401da6f

Please sign in to comment.