UNPKG

2.22 kBJavaScriptView Raw
1"use strict";const e=require("bluebird"),r=e.promisifyAll(require("fs-extra")),n=require("lodash"),t=require("path"),i=require("os"),o=require("./progress"),c=require("fs"),u=function(){return i.homedir()},s=function(n){return l(n).then(()=>r.readFileAsync(n)).catch(r=>e.reject(r))},a=function(e){return r.readdirAsync(e).then(function(e){return n.isEmpty(e)})},l=function(e){return r.statAsync(e)},d=function(e){try{return r.statSync(e),!0}catch(e){return!1}},f=function(e){return r.ensureDirAsync(e)},y=function(n,t,i){return new e((e,o)=>{var c=r.createReadStream(n),u=r.createWriteStream(t,{mode:i});c.on("error",o),u.on("error",o),u.on("open",function(){c.pipe(u)}),u.once("finish",function(r){return r?o(r):e(!0)})})},h=function(e){return-1===e.indexOf(".zip")},p=function(n,i,o){return f(n).then(()=>r.readdirAsync(n)).then(o=>{var c=o.map(o=>{var c=t.resolve(n,o),u=t.resolve(i,o),s=r.statSync(c);d(u);return-1!==o.indexOf(".zip")?e.resolve(!0):s.isDirectory()?f(u).then(()=>p(c,u)):y(c,u,s.mode).then(function(){}).catch(e=>{Console.error("Copying "+u+": failed")})});return e.all(c)})},v=function(e,n){return r.writeFileAsync(e,n)},j=function(e){return r.removeAsync(e)},m=function(e){return r.unlinkAsync(e)},A=function(n){return r.readdirAsync(n).then(r=>~r.indexOf("build")?j(t.join(n,"build")):e.resolve(!0))},x=()=>{const n=t.join(process.cwd(),"index.json");return r.readFileAsync(n,"utf8").then(r=>{try{var n=JSON.parse(r);return n.name&&n.description&&n.triggers&&n.actions&&n.version?e.resolve(n):e.reject("invalid index.json file")}catch(r){return e.reject("invalid path or invalid index.json")}}).catch(r=>e.reject("invalid path or invalid index.json"))},g=function(){return x().then(e=>s(t.join(config.APP_DIR,".flowapprc")).then(e=>e.toString()))},D=function(r){return r=r||t.join(config.APP_DIR,".history.json"),c.existsSync(r)||c.writeFile(r,"",function(r){return r?e.reject("Error while creating history file"):e.resolve(!0)}),e.resolve(!0)};function F(){}module.exports={isEmptyDirectory:a,writeFile:v,copyFile:y,fileExist:d,readFile:s,deleteFile:m,ensureDirectory:f,copyDirectory:p,removeDirectory:j,getHomeDirectory:u,getLinkedApp:g,cleanPreviousBuild:A,getIndex:x,createHistoryFile:D};
\No newline at end of file