{"size": 960, "ext": "js", "max_stars_repo_path": "scripts/dist-pack.js", "max_stars_repo_name": "erkobridee/helpers", "max_stars_repo_stars_event_min_datetime": "2021-04-06T07:24:21.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-06T07:24:21.000Z", "max_issues_repo_path": "scripts/dist-pack.js", "max_issues_repo_name": "erkobridee/my-ghp-lib", "max_issues_repo_issues_event_min_datetime": "2021-03-22T10:14:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-22T10:14:55.000Z", "max_forks_repo_path": "scripts/dist-pack.js", "max_forks_repo_name": "erkobridee/helpers", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 20.4255319149, "max_line_length": 76, "alphanum_fraction": 0.640625}
const path = require('path');
const fse = require('fs-extra');

const removeAttributes = (fromObject, attributes) => {
  if (!fromObject || !Array.isArray(attributes) || attributes.length <= 0) {
    return fromObject;
  }
  return Object.entries(fromObject)
    .filter((entry) => !attributes.includes(entry[0]))
    .reduce((acc, entry) => ({ ...acc, [entry[0]]: entry[1] }), {});
};

const packageNotAllowedAttributes = [
  'main',
  'module',
  'browser',
  'types',
  'files',
  'buildConfig',
  'packageFilesMap',
  'scripts',
  'devDependencies',
];

const rootPackageJsonPath = path.resolve('package.json');

let pkg = require(rootPackageJsonPath);

const packFiles = pkg.packageFilesMap;

pkg = removeAttributes(pkg, packageNotAllowedAttributes);

pkg = {
  ...packFiles,
  ...pkg,
};

pkg = JSON.stringify(pkg, null, 2);

(async () => {
  try {
    await fse.outputFile('dist-pack/package.json', pkg);
  } catch (e) {
    console.error(e);
  }
})();
