All files / platform/cli/src/commands/utils editPackageJson.js

0% Statements 0/10
100% Branches 0/0
0% Functions 0/1
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                                             
import fs from 'fs';
import path from 'path';
 
async function editPackageJson(options) {
  const { name, version, description, author, license, targetDir } = options;
 
  const ohifVersion = fs.readFileSync('./version.txt', 'utf8').trim();
 
  // read package.json from targetDir
  const dependenciesPath = path.join(targetDir, 'dependencies.json');
  const rawData = fs.readFileSync(dependenciesPath, 'utf8');
 
  const dataWithOHIFVersion = rawData.replace(/\{LATEST_OHIF_VERSION\}/g, ohifVersion);
  const packageJson = JSON.parse(dataWithOHIFVersion);
 
  // edit package.json
  const mergedObj = Object.assign(
    {
      name,
      version,
      description,
      author,
      license,
      main: `dist/umd/${name}/index.umd.js`,
      files: ['dist/**', 'public/**', 'README.md'],
    },
    packageJson
  );
 
  // write package.json back to targetDir
  const writePath = path.join(targetDir, 'package.json');
  fs.writeFileSync(writePath, JSON.stringify(mergedObj, null, 2));
 
  // remove the dependencies.json file
  fs.unlinkSync(dependenciesPath);
}
 
export default editPackageJson;