UNPKG

1.89 kBJavaScriptView Raw
1"use strict";const e=require("child_process"),n=e.spawn,r=require("path"),i=require("bluebird"),t=i.promisifyAll,o=t(require("fs-extra")),c=require("os"),s=require("./messagehandler").messagesHandler;function a(){return/^win/i.test(c.platform())}function u(e,r,t){var o="";return a()&&(e+=".cmd"),new i((i,c)=>{var s=n(e,r,t);s.stdout.on("data",function(e){o=e.toString()}),s.stderr.on("data",function(e){e.toString()}),s.on("error",c),s.on("close",function(e){e&&c("Something went wrong while executing npm install in connector's directory :-( "),i(o)})})}function l(e,n){n=n||[];try{return u("npm",["install"].concat(n),{cwd:e})}catch(e){return i.reject(e)}}function d(e){e=r.join(e,"package-lock.json");try{return u("rm",[e])}catch(e){return i.reject(e)}}function f(e){try{const n=o.statSync(e).size/1e6;return n>10?(console.log(s("SOURCE_SIZE_LIMIT")+"SIZE: "+n),i.reject("SOURCE_SIZE_LIMIT")):i.resolve()}catch(e){return i.reject(e)}}function p(e,n,t){return i.coroutine(function*(){var i=yield o.readFileAsync(r.join(e,"index.json"),"utf8"),c=yield o.readFileAsync(r.join(e,"package.json"),"utf8");i=JSON.parse(i),(c=JSON.parse(c)).name=String(n).replace(/\s+/g,"_").toLowerCase(),c.description=t,i.name=n,i.description=t,yield o.writeFileAsync(r.join(e,"package.json"),JSON.stringify(c,null,2)),yield o.writeFileAsync(r.join(e,"index.json"),JSON.stringify(i,null,2))})()}function g(){return new i((e,n)=>{if(!require(r.join(config.APP_DIR,"package.json")).dependencies["@builtioflow/cli-sdk"])return l(config.APP_DIR,["@builtioflow/cli-sdk"]).then(e).catch(n);e(!0)})}function j(){try{return!!require(r.join(config.APP_DIR,"package.json")).dependencies["@builtioflow/cli-sdk"]}catch(e){Console.error(e)}}function y(e){return require("latest-version")(e)}module.exports={npmInstall:l,isValidApp:g,isValidAppSync:j,executeCommand:u,finishApp:p,sizeLimit:f,rmPackageLock:d,packageLatest:y};
\No newline at end of file