From b822ffdcdf522621c6bc402b40088d89fd58e000 Mon Sep 17 00:00:00 2001 From: Mintu Date: Sat, 23 Mar 2024 17:55:53 +0530 Subject: [PATCH 1/7] added the transpile script --- package.json | 3 ++- scripts/copy-sources.js | 22 ++++++++++++++++++---- scripts/transpile.js | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 scripts/transpile.js diff --git a/package.json b/package.json index b9fcdc736..6c2d5b669 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "generate:readme:toc": "markdown-toc -i README.md", "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION", "copy:sources": "node ./scripts/copy-sources.js", - "prepublishOnly": "npm run generate:assets", + "prepublishOnly": "npm run generate:assets && npm run transpile", + "transpile": "node ./scripts/transpile.js", "test": "npm run test:library && npm run test:generator" }, "publishConfig": { diff --git a/scripts/copy-sources.js b/scripts/copy-sources.js index 0a899c84b..9cfcf7ef2 100644 --- a/scripts/copy-sources.js +++ b/scripts/copy-sources.js @@ -5,19 +5,33 @@ */ const util = require('util'); -const fs = require('fs'); +const fs = require('fs-extra'); const path = require('path'); const copyFile = util.promisify(fs.copyFile); +const { exec } = require('child_process'); // source (node_modules): destination (template) const filesToCopy = { - "@asyncapi/react-component/browser/standalone/without-parser.js": "js/asyncapi-ui.min.js", - "@asyncapi/react-component/styles/default.min.css": "css/asyncapi.min.css", + "node_modules/@asyncapi/react-component/browser/standalone/without-parser.js": "js/asyncapi-ui.min.js", + "node_modules/@asyncapi/react-component/styles/default.min.css": "css/asyncapi.min.css", }; async function copyFiles() { + await new Promise((resolve) => { + exec('npm run transpile', (err, stdout, stderr) => { + if (err) { + console.error(`Error during template transpilation: ${err}`); + return; + } + if (stdout) console.log(stdout); + if (stderr) console.log('Template transpilation error:', stderr); + resolve(); + }); + }); const operations = Object.entries(filesToCopy).map(([source, destination]) => { - return copyFile(path.join(__dirname, '../node_modules', source), path.join(__dirname, '../template', destination)); + const sourcePath = path.join(__dirname, '../', source); + const destinationPath = path.join(__dirname, '../template', destination); + return fs.copy(sourcePath, destinationPath, { overwrite: true }); }); await Promise.all(operations); } diff --git a/scripts/transpile.js b/scripts/transpile.js new file mode 100644 index 000000000..fd28a9875 --- /dev/null +++ b/scripts/transpile.js @@ -0,0 +1,15 @@ +const { transpileFiles } = require('@asyncapi/generator-react-sdk'); +const path = require('path') + +async function transpileTemplate() { + const templateContentDir = path.join(__dirname, '../template'); + console.log("templateContentDir",templateContentDir) + const outputDir = path.join(__dirname, '../__transpiled'); + console.log("outputDir",outputDir) + + await transpileFiles(templateContentDir, outputDir, { recursive: true }); +} + +transpileTemplate().catch((err) => console.log('Error during template transpilation:', err)); + +module.exports = { transpileTemplate } \ No newline at end of file From 529f30af5eaa02f770833e960c623d4d11b4fe50 Mon Sep 17 00:00:00 2001 From: Mintu Date: Sat, 23 Mar 2024 18:06:15 +0530 Subject: [PATCH 2/7] modified copy-source.js --- scripts/copy-sources.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/copy-sources.js b/scripts/copy-sources.js index 9cfcf7ef2..ddb1bb657 100644 --- a/scripts/copy-sources.js +++ b/scripts/copy-sources.js @@ -29,9 +29,7 @@ async function copyFiles() { }); }); const operations = Object.entries(filesToCopy).map(([source, destination]) => { - const sourcePath = path.join(__dirname, '../', source); - const destinationPath = path.join(__dirname, '../template', destination); - return fs.copy(sourcePath, destinationPath, { overwrite: true }); + return copyFile(path.join(__dirname, '../node_modules', source), path.join(__dirname, '../template', destination)); }); await Promise.all(operations); } From 0bdf806e53f2e6214d118ae7f07802e29cfd2656 Mon Sep 17 00:00:00 2001 From: Mintu Date: Sat, 23 Mar 2024 18:23:05 +0530 Subject: [PATCH 3/7] removed copying it from node_modules --- scripts/copy-sources.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/copy-sources.js b/scripts/copy-sources.js index ddb1bb657..c8aae0bf8 100644 --- a/scripts/copy-sources.js +++ b/scripts/copy-sources.js @@ -12,8 +12,8 @@ const { exec } = require('child_process'); // source (node_modules): destination (template) const filesToCopy = { - "node_modules/@asyncapi/react-component/browser/standalone/without-parser.js": "js/asyncapi-ui.min.js", - "node_modules/@asyncapi/react-component/styles/default.min.css": "css/asyncapi.min.css", + "@asyncapi/react-component/browser/standalone/without-parser.js": "js/asyncapi-ui.min.js", + "@asyncapi/react-component/styles/default.min.css": "css/asyncapi.min.css", }; async function copyFiles() { From c23439994469729f3325386543b0f7c622c71360 Mon Sep 17 00:00:00 2001 From: Mintu Date: Sat, 23 Mar 2024 18:35:38 +0530 Subject: [PATCH 4/7] cleanup of sonarcloud warnings --- scripts/copy-sources.js | 14 ++------------ scripts/transpile.js | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/scripts/copy-sources.js b/scripts/copy-sources.js index c8aae0bf8..9a8ca5e67 100644 --- a/scripts/copy-sources.js +++ b/scripts/copy-sources.js @@ -8,7 +8,7 @@ const util = require('util'); const fs = require('fs-extra'); const path = require('path'); const copyFile = util.promisify(fs.copyFile); -const { exec } = require('child_process'); +const { main } = require('./transpile') // source (node_modules): destination (template) const filesToCopy = { @@ -17,17 +17,7 @@ const filesToCopy = { }; async function copyFiles() { - await new Promise((resolve) => { - exec('npm run transpile', (err, stdout, stderr) => { - if (err) { - console.error(`Error during template transpilation: ${err}`); - return; - } - if (stdout) console.log(stdout); - if (stderr) console.log('Template transpilation error:', stderr); - resolve(); - }); - }); + await main() const operations = Object.entries(filesToCopy).map(([source, destination]) => { return copyFile(path.join(__dirname, '../node_modules', source), path.join(__dirname, '../template', destination)); }); diff --git a/scripts/transpile.js b/scripts/transpile.js index fd28a9875..2e28142e0 100644 --- a/scripts/transpile.js +++ b/scripts/transpile.js @@ -1,15 +1,19 @@ const { transpileFiles } = require('@asyncapi/generator-react-sdk'); const path = require('path') -async function transpileTemplate() { - const templateContentDir = path.join(__dirname, '../template'); - console.log("templateContentDir",templateContentDir) - const outputDir = path.join(__dirname, '../__transpiled'); - console.log("outputDir",outputDir) - - await transpileFiles(templateContentDir, outputDir, { recursive: true }); +async function main(){ + async function transpileTemplate() { + const templateContentDir = path.join(__dirname, '../template'); + console.log("templateContentDir",templateContentDir) + const outputDir = path.join(__dirname, '../__transpiled'); + console.log("outputDir",outputDir) + + await transpileFiles(templateContentDir, outputDir, { recursive: true }); + } + + transpileTemplate().catch((err) => console.log('Error during template transpilation:', err)); } -transpileTemplate().catch((err) => console.log('Error during template transpilation:', err)); +main() -module.exports = { transpileTemplate } \ No newline at end of file +module.exports = { main } \ No newline at end of file From 54ae478cf9b77296ff734b98ccc6e41a14731e1f Mon Sep 17 00:00:00 2001 From: Mintu Date: Sat, 23 Mar 2024 18:36:33 +0530 Subject: [PATCH 5/7] cleanup --- scripts/copy-sources.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/copy-sources.js b/scripts/copy-sources.js index 9a8ca5e67..071d53c8a 100644 --- a/scripts/copy-sources.js +++ b/scripts/copy-sources.js @@ -5,7 +5,7 @@ */ const util = require('util'); -const fs = require('fs-extra'); +const fs = require('fs'); const path = require('path'); const copyFile = util.promisify(fs.copyFile); const { main } = require('./transpile') From eff727c7dda7f74ba1ffb8a0e11a324624b3b6f1 Mon Sep 17 00:00:00 2001 From: Mintu Date: Sun, 24 Mar 2024 14:58:19 +0530 Subject: [PATCH 6/7] added files key in package.json and remove changes made in copy-files --- package.json | 3 +++ scripts/copy-sources.js | 2 -- scripts/transpile.js | 20 ++++++-------------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 6c2d5b669..aa69f52a6 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ ], "author": "Fran Mendez (fmvilas.com)", "license": "Apache-2.0", + "files": [ + "__transpiled" + ], "repository": { "type": "git", "url": "git+https://github.com/asyncapi/html-template.git" diff --git a/scripts/copy-sources.js b/scripts/copy-sources.js index 071d53c8a..0a899c84b 100644 --- a/scripts/copy-sources.js +++ b/scripts/copy-sources.js @@ -8,7 +8,6 @@ const util = require('util'); const fs = require('fs'); const path = require('path'); const copyFile = util.promisify(fs.copyFile); -const { main } = require('./transpile') // source (node_modules): destination (template) const filesToCopy = { @@ -17,7 +16,6 @@ const filesToCopy = { }; async function copyFiles() { - await main() const operations = Object.entries(filesToCopy).map(([source, destination]) => { return copyFile(path.join(__dirname, '../node_modules', source), path.join(__dirname, '../template', destination)); }); diff --git a/scripts/transpile.js b/scripts/transpile.js index 2e28142e0..871c7c6ec 100644 --- a/scripts/transpile.js +++ b/scripts/transpile.js @@ -1,19 +1,11 @@ const { transpileFiles } = require('@asyncapi/generator-react-sdk'); const path = require('path') -async function main(){ - async function transpileTemplate() { - const templateContentDir = path.join(__dirname, '../template'); - console.log("templateContentDir",templateContentDir) - const outputDir = path.join(__dirname, '../__transpiled'); - console.log("outputDir",outputDir) - - await transpileFiles(templateContentDir, outputDir, { recursive: true }); - } - - transpileTemplate().catch((err) => console.log('Error during template transpilation:', err)); +async function transpileTemplate() { + const templateContentDir = path.join(__dirname, '../template'); + console.log("templateContentDir",templateContentDir) + const outputDir = path.join(__dirname, '../__transpiled'); + await transpileFiles(templateContentDir, outputDir, {recursive: true}) } -main() - -module.exports = { main } \ No newline at end of file +transpileTemplate().catch((err) => console.log('Error during template transpilation:', err)); \ No newline at end of file From e2c420fdca3a9421d2cc7ef1cbf1617c933e8f92 Mon Sep 17 00:00:00 2001 From: Mintu Date: Sun, 24 Mar 2024 17:43:19 +0530 Subject: [PATCH 7/7] added try catch statement and added some console log --- scripts/transpile.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/transpile.js b/scripts/transpile.js index 871c7c6ec..371c72d79 100644 --- a/scripts/transpile.js +++ b/scripts/transpile.js @@ -1,11 +1,16 @@ -const { transpileFiles } = require('@asyncapi/generator-react-sdk'); -const path = require('path') +const { transpileFiles } = require("@asyncapi/generator-react-sdk"); +const path = require("path"); async function transpileTemplate() { - const templateContentDir = path.join(__dirname, '../template'); - console.log("templateContentDir",templateContentDir) - const outputDir = path.join(__dirname, '../__transpiled'); - await transpileFiles(templateContentDir, outputDir, {recursive: true}) + try { + const templateContentDir = path.join(__dirname, "../template"); + console.log("Template content directory:", templateContentDir); + const outputDir = path.join(__dirname, "../__transpiled"); + console.log("Output directory for transpiled files:", outputDir); + await transpileFiles(templateContentDir, outputDir, { recursive: true }); + } catch (error) { + console.log("Error during template transpilation:", err) + } } -transpileTemplate().catch((err) => console.log('Error during template transpilation:', err)); \ No newline at end of file +transpileTemplate();