"use strict";var e=this&&this.__awaiter||function(e,t,o,n){return new(o||(o=Promise))((function(i,r){function s(e){try{a(n.next(e))}catch(e){r(e)}}function u(e){try{a(n.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.startClean=void 0;const o=t(require("../../log")),n=require("../../config"),i=t(require("path")),r=require("../../common/Constants"),s=require("../../util/FsUtil"),u=require("../../common/message"),a=/oh_modules|oh-package.*-lock.json5/,l=/oh-package.*-lock.json5/;function c(t,n){return e(this,void 0,void 0,(function*(){try{o.default.debug("",`begin to clean module: ${t}`);const e=yield s.FsUtil.readdir(t);for(const o of e){if(!a.test(o))continue;if(n.keepLockfile&&l.test(o))continue;const e=i.default.join(t,o);(yield s.FsUtil.exists(e))&&(yield s.FsUtil.remove(e))}o.default.debug("",`clean module: ${t} succeed.`)}catch(e){throw new Error((0,u.format)(u.Messages.Clean.CleanModuleFailed,{modulePath:t,msg:(null==e?void 0:e.message)||e}))}}))}exports.startClean=function(t){return e(this,void 0,void 0,(function*(){o.default.debug("","startClean.");const a=n.config.getProjectRoot(),l=n.config.getModuleRoots();if(!a||!(yield s.FsUtil.exists(i.default.join(a,r.Constants.MyPackageJson))))throw new Error(u.Messages.Parameterization.NotFoundProjectRootError);l.length?yield function(t,n,i){return e(this,void 0,void 0,(function*(){o.default.debug("",`clean all modules under: ${t}`);const e=[...n,t],r=[];e.forEach((e=>{r.push(c(e,i))})),yield Promise.all(r)}))}(a,l,t):yield c(a,t)}))};