Skip to content

Commit

Permalink
fixed the gist link in integration test and removed some extra whites…
Browse files Browse the repository at this point in the history
…paces
  • Loading branch information
ibishal committed Sep 3, 2024
1 parent 6d1cba9 commit 57b15fa
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
1 change: 0 additions & 1 deletion template/README.md.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { File } = require('@asyncapi/generator-react-sdk');

function ReadmeFile({ asyncapi }) {
console.log("Hello", asyncapi.info().description());
return (
<File name={'README.md'}>
{`# ${asyncapi.info().title()}
Expand Down
3 changes: 2 additions & 1 deletion template/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const start = async () => {
console.info(\`Listening on port \${config.port}\`);
};
start();`}
start();
`}
</File>
);
}
Expand Down
11 changes: 4 additions & 7 deletions template/src/api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ function routeRender({ asyncapi }) {

const imports = Object.entries(channels).map(([channelName, channel]) => {
const allOperationIds = getOperationIds(channel);
if (!allOperationIds) return ''; // Skip channels with no operations
if (!allOperationIds) return '';
return `const { ${allOperationIds} } = require('./services/${kebabCase(channelName)}');`;
}).filter(Boolean).join('\n');

const routes = Object.entries(channels).map(([channelName, channel]) => {
// Safely check for subscribe and publish operations
const subscribeOp = channel.subscribe ? channel.subscribe() : null;
const publishOp = channel.publish ? channel.publish() : null;

return `router.ws('${pathResolve(channelName)}', async (ws, req) => {
const path = pathParser(req.path);
console.log(\`\${yellow(path)} client connected.\`);
${subscribeOp ? `await ${subscribeOp.id()}(ws);` : ''}
${publishOp ? `ws.on('message', async (msg) => {
console.log(\`\${yellow(path)} message was received:\`);
console.log(util.inspect(msg, { depth: null, colors: true }));
await ${publishOp.id()}(ws, { message: msg, path, query: req.query });
});` : ''}
});`;
}).join('\n\n');
}).join('\n');

return (
<File name="routes.js">
Expand All @@ -36,11 +34,10 @@ const { Router } = require('express');
const { pathParser } = require('../lib/path');
const { yellow } = require('../lib/colors');
${imports}
const router = Router();
module.exports = router;
${routes}`}
${routes}
`}
</File>
);
}
Expand Down
5 changes: 3 additions & 2 deletions template/src/lib/asyncapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports.init = async () => {
try {
content = fs.readFileSync(path.resolve(__dirname, '../../asyncapi.json'), { encoding: 'utf8' });
} catch (err) {
throw new Error('Could not find asyncapi.yaml or asyncapi.json file in the root directory of the project.');
throw new Error('Coud not find asyncapi.yaml or asyncapi.json file in the root directory of the project.');
}
}
Expand All @@ -35,7 +35,8 @@ module.exports.init = async () => {
return cached;
};
module.exports.get = () => cached;`}
module.exports.get = () => cached;
`}
</File>
);
}
Expand Down
3 changes: 2 additions & 1 deletion template/src/lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ function colorsFile() {
<File name="colors.js">
{`module.exports.yellow = (text) => {
return \`\\x1b[33m\${text}\\x1b[0m\`;
};`}
};
`}
</File>
);
}
Expand Down
3 changes: 2 additions & 1 deletion template/src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const yamlConfig = require('node-yaml-config');
const config = yamlConfig.load(path.join(__dirname, '../../config/common.yml'));
module.exports = config;`}
module.exports = config;
`}
</File>
);
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fetch = require('node-fetch');
const console = require('console');

const MAIN_TEST_RESULT_PATH = path.join('test', 'temp', ' integrationTestResult');
const URL = 'https://raw.githubusercontent.com/asyncapi/generator/master/test/docs/ws.yml';
const URL = 'https://raw.githubusercontent.com/asyncapi/generator/master/apps/generator/test/docs/ws.yml';

describe('template integration test using generator', () => {
const generateFolderName = () => {
Expand Down

0 comments on commit 57b15fa

Please sign in to comment.