From 401da6f06eb8922c7ec1d61c52ab381ac1ff924b Mon Sep 17 00:00:00 2001 From: Lukasz Gornicki Date: Tue, 31 Mar 2020 15:12:21 +0200 Subject: [PATCH] feat: use latest generator (#6) --- README.md | 16 +++++++++------- dist/index.js | 44 ++++++++++++++------------------------------ lib/index.js | 2 +- package-lock.json | 6 +++--- package.json | 2 +- 5 files changed, 28 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index b94b91e6f..d72c6b363 100644 --- a/README.md +++ b/README.md @@ -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/markdown-template@0.3.0` 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` @@ -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 @@ -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 @@ -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}}' ``` @@ -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 diff --git a/dist/index.js b/dist/index.js index 53d519c41..d53a8e74a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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'; @@ -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 { /** @@ -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)); @@ -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. @@ -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 }); @@ -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) @@ -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); @@ -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); @@ -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); diff --git a/lib/index.js b/lib/index.js index fa7ff686a..e726f06eb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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'; diff --git a/package-lock.json b/package-lock.json index 6ee4c2efd..802171630 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,9 @@ "integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w==" }, "@asyncapi/generator": { - "version": "0.35.2", - "resolved": "https://registry.npmjs.org/@asyncapi/generator/-/generator-0.35.2.tgz", - "integrity": "sha512-7vU/TEdqpcn09Wk6heXWmkSe4d3iI7G6Dsm44LKAbDMSFTfkLF/J7fSLkUIdqswUK354MPf0adDpVmT4chFWuA==", + "version": "0.36.0", + "resolved": "https://registry.npmjs.org/@asyncapi/generator/-/generator-0.36.0.tgz", + "integrity": "sha512-SpPpwRIGw1Sqxf+AUTHBsnkVnsvZD+txE70z9f2C4zkQq0qNx+X9k9O8W0LsfVJ/LNSATUpz64P28U9XEcO6ow==", "requires": { "@asyncapi/openapi-schema-parser": "^1.0.0", "@asyncapi/parser": "^0.16.0", diff --git a/package.json b/package.json index c2c8c62f9..9773cdba3 100644 --- a/package.json +++ b/package.json @@ -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"