Skip to content

--continue flag not recognizing dna file #334

@rbencii

Description

@rbencii

Proposed index.js

"use strict";

const path = require("path");
const isLocal = typeof process.pkg === "undefined";
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);

const fs = require("fs");
const { Command } = require("commander");
const program = new Command();
const chalk = require("chalk");

const { startCreating, buildSetup } = require(path.join(
  basePath,
  "/src/main.js"
));

program
  .name("generate")
  .argument("[dna-file]", "DNA file to continue generation from")
  .option("-c, --continue", "Continue generation mode")
  .action((dnaFile, options) => {
    console.log(chalk.green("generator started"));
    
    if (dnaFile || options.continue) {
      console.log(
        chalk.bgCyanBright("\n continuing generation using _dna.json file \n")
      );
    }
    
    buildSetup();
    let dna = null;
    
    if (dnaFile) {
      try {
        const dnaFilePath = path.resolve(dnaFile);
        
        if (!fs.existsSync(dnaFilePath)) {
          console.error(chalk.red(`Error: DNA file not found at: ${dnaFilePath}`));
          process.exit(1);
        }
        
        const storedGenomes = JSON.parse(fs.readFileSync(dnaFilePath, 'utf8'));
        dna = new Set(storedGenomes);
        console.log(chalk.green(`Loaded ${storedGenomes.length} DNA entries`));
        
      } catch (error) {
        console.error(chalk.red(`Error reading DNA file: ${error.message}`));
        process.exit(1);
      }
    }
    
    startCreating(dna);
  });

program.parse();

Usage

# Continue generation with DNA file
node generate.js build/_dna.json

# Continue generation with flag (if no file specified)
node generate.js -c

# Both can be used together
node generate.js build/_dna.json -c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions