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

Figure out what development flow will be without cli.js #1226

Open
lmgyuan opened this issue Jun 28, 2024 · 5 comments
Open

Figure out what development flow will be without cli.js #1226

lmgyuan opened this issue Jun 28, 2024 · 5 comments
Assignees

Comments

@lmgyuan
Copy link
Collaborator

lmgyuan commented Jun 28, 2024

research what would be the best developer experience for local development of generator to see if new features (but not only) work with templates.

I still want to be able to locally run easily generator, modify some dummy asyncapi document that in is generator, add something to react-template that is generator, and see if after generation the feature I added works - and last thing I would do is add tests

2 options:

  • we deprecate CLI but cli.js goes into some subfolder and we still use it but only for development
  • we create some really dummy script that we can invoke during development - and this script uses generator as library, same as the integration tests
@lmgyuan
Copy link
Collaborator Author

lmgyuan commented Jun 28, 2024

According to our internal meeting, we want to first deprecae the use of cli.js in our "test:cli": "node cli.js ./test/docs/dummy.yml ./test/test-templates/react-template -o test/output --force-write --debug && test -e test/output/test-file.md". For example, in package.json, we will replace it with "test:cli": node generate_test_script.js. Then, we will add a script like the following to the code base:

const path = require('path');
const fs = require('fs');
const Generator = require('@asyncapi/generator');

// Define paths from environment variables with fallbacks
const ASYNCAPI_DOCUMENT_PATH = process.env.ASYNCAPI_DOCUMENT_PATH || './test/docs/dummy.yml'; // path to your AsyncAPI document
const TEMPLATE_PATH = process.env.TEMPLATE_PATH || './test/test-templates/react-template'; // path to your template
const OUTPUT_DIR = process.env.OUTPUT_DIR || './test/output'; // output directory

// Initialize the generator
const generator = new Generator(
    TEMPLATE_PATH,
    OUTPUT_DIR,
    {
        entrypoint: 'index.html', // specify the entrypoint if needed
        noOverwriteGlobs: [], // glob patterns to exclude from overwriting
        forceWrite: true, // same as --force-write
        debug: true // same as --debug
    }
);

// Function to generate documents
async function generateDocs() {
    try {
        // Ensure output directory exists or create it
        fs.mkdirSync(OUTPUT_DIR, { recursive: true });

        // Generate the files based on the AsyncAPI document and the template
        await generator.generate(ASYNCAPI_DOCUMENT_PATH);

        // Check if a specific file exists
        const checkFilePath = path.join(OUTPUT_DIR, 'test-file.md');
        if (fs.existsSync(checkFilePath)) {
            console.log('File exists:', checkFilePath);
        } else {
            console.log('File does not exist:', checkFilePath);
        }
        console.log('Generation complete!');
    } catch (error) {
        console.error('Error during generation:', error);
    }
}

// Run the generation function
generateDocs();

This script is not final, so open for discussions! Also, please leave comments on what we should do to inform our users about deprecating the cli.js in generator. We are also interested in hardcoding a message for people when they use to say things like "cli.js is about to be deprecated, please adjust your codebase accordingly" etc.

@lmgyuan
Copy link
Collaborator Author

lmgyuan commented Jun 28, 2024

This issue is open for discussion and thoughts! Please leave comments whenever you see fit and let's get this thing going!

: )

@Gmin2
Copy link
Collaborator

Gmin2 commented Jun 29, 2024

const Generator = require('@asyncapi/generator');

This is wrong we need to import the local generator construct and then use it

@derberg
Copy link
Member

derberg commented Jul 24, 2024

Hey @lmgyuan

I can't recall why that was closed. Reopening for now, feel free to close again but with comment why.

We should figure out final shape of the script.

We also have to agree when we will add this script. Should we wait one year, and add it the same time we remove cli.js or maybe we just add it now, as it is and gradually improve over time, and stop using cli.js for development immediately

@derberg
Copy link
Member

derberg commented Sep 16, 2024

@lmgyuan any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants