const{deleteResource:deleteResource,createDir:createDir,readDir:readDir,getWebAppPath:getWebAppPath,readFileSync:readFileSync}=require("./wm-utils"),util=require("util"),fs=require("fs"),{executeSyncCmd:executeSyncCmd}=require("../build-util"),writeFile=util.promisify(fs.writeFile),ncp=util.promisify(require("ncp").ncp),updatePackageJson=async(e,a)=>{const t=`${e}/package.json`;let i=readFileSync(t,!0);i.name=a.name,i.version=a.version,-1!==i.dependencies["@wavemaker/variables"].indexOf("yalc")&&executeSyncCmd(`cd ${e} && yalc add @wavemaker/variables`,null,`Adding yalc variables dependency to ${e}`),await writeFile(t,JSON.stringify(i,null,4))},createAppSkeleton=async(e,a,t,i)=>{await deleteResource(a),await createDir(a,{recursive:!0}),await ncp(t+"/angular-app",a),await updatePackageJson(a,i);const r=getWebAppPath(e);if((await readDir(`${r}/themes`)).length){const e=`${r}/themes/`;await ncp(e,`${a}/src/assets/themes`)}(await readDir(`${r}/extensions`)).length&&await ncp(`${r}/extensions`,`${a}/src/app/extensions`),await ncp(`${r}/app.css`,`${a}/src/assets/app.css`),await ncp(`${r}/resources`,`${a}/resources`),await ncp(`${t}/.npmrc`,`${a}/.npmrc`)};module.exports={createAppSkeleton:createAppSkeleton};