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

make it easy to test override package.json files #42

Open
dmose opened this issue May 18, 2012 · 1 comment
Open

make it easy to test override package.json files #42

dmose opened this issue May 18, 2012 · 1 comment

Comments

@dmose
Copy link

dmose commented May 18, 2012

Right now, unless I'm mistaken, one needs to land a package.json file in volojs/repos before one can actually test whether or not it works.

Perhaps an "--with-package-json=path/to/overide/package.json" switch?

@ljluestc
Copy link

ljluestc commented Dec 3, 2023

#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const program = require('commander');

program
  .option('--with-package-json <path>', 'Specify an override package.json file')
  .parse(process.argv);

// Function to load the package.json file
function loadPackageJson(packageJsonPath) {
  try {
    return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
  } catch (error) {
    console.error(`Error reading ${packageJsonPath}: ${error.message}`);
    process.exit(1);
  }
}

// Main logic
if (program.withPackageJson) {
  // If the --with-package-json option is provided, load the override package.json
  const overridePackageJsonPath = path.resolve(process.cwd(), program.withPackageJson);
  const overridePackageJson = loadPackageJson(overridePackageJsonPath);

  console.log('Loaded override package.json:', overridePackageJson);
} else {
  console.error('Please specify the --with-package-json option to load an override package.json');
  process.exit(1);
}

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

No branches or pull requests

2 participants