Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scripts that on release will publish transpiled template to npm #575

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 15 additions & 3 deletions scripts/copy-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@
*/

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));
});
Expand Down
15 changes: 15 additions & 0 deletions scripts/transpile.js
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add full sentence console log

const outputDir = path.join(__dirname, '../__transpiled');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console log this variable as well, but again, with full descriptive console log info

console.log("outputDir",outputDir)

await transpileFiles(templateContentDir, outputDir, { recursive: true });
}

transpileTemplate().catch((err) => console.log('Error during template transpilation:', err));

module.exports = { transpileTemplate }
Loading