// package.json 补充字段配置
var fs = require("fs");
const path = require("path");
const project = require("../../project");

/**
 * 配置npm发布可见文件目录
 * @param {*} projectName 项目名称
 */
async function configPackageJson(projectName) {
  let cwd = project.fs.rootDir();
  let packagePath = path.resolve(cwd, "package.json");
  let data = fs.readFileSync(packagePath);
  let appJson = JSON.parse(data);
  appJson.files = [
    "src",
    "example",
    "!example/android/app/build",
    "!example/android/build",
    "!example/node_modules",
    "!example/ios/Pods",
    "!node_modules",
    "lib",
    "android",
    "ios",
    "cpp",
    "!lib/typescript/example",
    "!**/__tests__",
    "!**/__fixtures__",
    "!**/__mocks__",
  ];
  appJson.files.push(`${projectName.replace(/-/g, "")}.podspec`);

  let packageStr = JSON.stringify(appJson, "", "\t");
  fs.writeFileSync(packagePath, packageStr);
}

module.exports = {
  configPackageJson,
};
