"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _fs=require("fs");
var _path=_interopRequireDefault(require("path"));
var _corenode=require("corenode");function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable});keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key])})}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}}return target}var _default=function(){var _ref=(0,_asyncToGenerator2.default)(

function*(params){
return new Promise(function(){var _ref2=(0,_asyncToGenerator2.default)(function*(resolve,reject){
{
const version=(0,_corenode.getVersion)();
const devRuntime=(0,_corenode.getProjectEnv)().devRuntime;
const pkgs=(0,_corenode.getPackages)();

let opt={
license:"MIT",
originGit:(0,_corenode.getGit)(),
headPackage:devRuntime.headPackage,
force:false};

if(params){
opt=_objectSpread(_objectSpread({},opt),params);
}

pkgs.forEach(packageName=>{
const name=`${opt.headPackage?`@${opt.headPackage}/`:""}${packageName}`;
const pkgPath=_path.default.resolve(process.cwd(),`./packages/${packageName}`);

const readmePath=_path.default.resolve(pkgPath,`./README.md`);
const pkgJSONPath=_path.default.resolve(pkgPath,`./package.json`);

const pkgJSONExists=(0,_fs.existsSync)(pkgJSONPath);
const readmeExist=(0,_fs.existsSync)(readmePath);

if(opt.force||!pkgJSONExists){
const json={
name,
version,
main:"dist/index.js",
types:"dist/index.d.ts",
publishConfig:{
access:"public"}};



if(!pkgJSONExists){
json.version=version;
json.files=["dist","load.module.js"];
}

if(opt.originGit){
json.repository={
type:"git",
url:opt.originGit};

}

if(opt.license){
json.license=opt.license;
}

if(pkgJSONExists){
const pkg=require(pkgJSONPath);
[
"dependencies",
"devDependencies",
"peerDependencies",
"bin",
"files",
"types",
"sideEffects",
"main",
"module"].
forEach(key=>{
if(pkg[key])json[key]=pkg[key];
});
}
(0,_fs.writeFileSync)(pkgJSONPath,`${JSON.stringify(json,null,2)}\n`);
}

if(packageName!==opt.headPackage){
if(opt.force||!readmeExist){
(0,_fs.writeFileSync)(readmePath,`# ${name}\n`);
}
}
});
return resolve(pkgs);
}
});return function(_x2,_x3){return _ref2.apply(this,arguments)}}());
});return function(_x){return _ref.apply(this,arguments)}}();exports.default=_default;