@platforma-sdk/bootstrap 3.1.19 → 3.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
`).map((i,c)=>c===0?i:r+i).join(`
|
|
11
11
|
`);return`${(i=>de.format.colorize().colorize(i,i))(e)}: ${n}`}),transports:[new de.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function _r(a){return Sr.randomBytes(Math.ceil(a/2)).toString("hex").slice(0,a)}function Nr(a){return a.startsWith("~")?h.join(D.homedir(),a.slice(1)):a}function Pe(a,e){m.existsSync(a)||(m.mkdirSync(a,{recursive:!0}),e!=null&&e.mode&&m.chmodSync(a,e.mode))}function Cr(a){try{if(D.platform()!=="win32")return le.execSync(`ps -p ${a} -o comm=`,{encoding:"utf8"}).trim();const e=`wmic process where processid=${a} get Caption`,t=le.execSync(e,{encoding:"utf8"}).split(`
|
|
12
12
|
`);return t.length<=1?"":t[1].trim()}catch{return""}}function Mr(a){const e=le.execSync(`docker compose ls --filter name=${a} --format json`,{encoding:"utf8"}).trim(),t=JSON.parse(e);for(const r of t)if(r.Name===a)return r}const Ae=["Python"],hr=["Tengo","Python"],jr=x.z.union([x.z.literal("Tengo"),x.z.literal("Python")]),Br=x.z.object({npmOrgName:x.z.string().min(1),orgName:x.z.string().min(1,{message:"Organization name must be provided"}),blockName:x.z.string().min(1,{message:"Block name must be provided"}),softwarePlatforms:x.z.array(jr).refine(a=>new Set(a).size===a.length,{message:"Must be an array of unique software platforms"})});async function Ur(a){const{npmOrgName:e,orgName:t,blockName:r,softwarePlatforms:n}=Gr(),s=h.join(process.cwd(),r);a.info("Downloading boilerplate code..."),await qr("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip","platforma-block-boilerplate-main",s);const i=hr.filter(o=>n.indexOf(o)<0),c=Ae.length==i.length;a.info(`Keep platforms '${n}', remove: '${i}'. Will remove all platforms? ${c}`);for(const o of i)await Jr(s,o);c&&await Hr(s),a.info("Replace everything in the template with provided options..."),Wr(s,[{from:/@platforma-open(?!.*runenv-python-3)/g,to:`@${e}`},{from:/my-org/g,to:t},{from:/block-boilerplate/g,to:r}])}function Gr(){let a=Q.question('Write an organization name for npm. Default is "platforma-open": ');a===""&&(a="platforma-open");let e="";for(;e.length<1;)e=Q.question('Write an organization name, e.g. "my-org": ');let t="";for(;t.length<1;)t=Q.question('Write a name of the block, e.g. "hello-world": ');const r=Q.keyInYN("Create package for block's software?");let n=["Tengo"];if(r)for(;n.length<hr.length;){const i=Q.keyInSelect(Ae,"Choose software platform:");if(i<0)break;n.push(Ae[i])}n=Array.from(new Set(n)).sort();const s=Br.safeParse({npmOrgName:a,orgName:e,blockName:t,softwarePlatforms:n});if(!s.success&&s.error.issues.length)throw new Error(s.error.issues.map(i=>i.message).join("; "));return s.data}async function qr(a,e,t){const n=await(await fetch(a)).blob(),s=await _.mkdtemp(h.join(D.tmpdir(),"create-repo")),i=h.join(s,"packed-repo.zip"),c=Lr.Writable.toWeb(m.createWriteStream(i));await n.stream().pipeTo(c);const o=h.join(s,"unpacked-repo");await _.mkdir(o),await Ar(i,o),await _.cp(h.join(o,e),t,{recursive:!0})}async function Jr(a,e){const t=e.toLowerCase();await X(h.join(a,"ui","src","pages","MainPage.vue"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await X(h.join(a,"model","src","index.ts"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await X(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}.*exec.builder.*[\\s\\S]*?\\n\\n`,"g")),await X(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}Message.*\\n`,"g")),await X(h.join(a,"workflow","src","wf.test.ts"),new RegExp(`.*${t}Message.*\\n.*expect.*\\n\\n`,"g")),await _.rm(h.join(a,"software",`src_${t}`),{recursive:!0}),await je(h.join(a,"software","package.json"),r=>{const n=JSON.parse(r);return delete n["block-software"].artifacts[`hello-${t}-artifact`],delete n["block-software"].entrypoints[`hello-world-${t}`],JSON.stringify(n,null,2)})}async function Hr(a){await _.rm(h.join(a,"software"),{recursive:!0}),await je(h.join(a,"workflow","package.json"),e=>{const t=JSON.parse(e);return delete t.dependencies["@platforma-open/my-org.block-boilerplate.software"],JSON.stringify(t,null,2)}),await X(h.join(a,"pnpm-workspace.yaml"),/.*- software$\n/gm)}async function Wr(a,e){const t=await zr(a);for(const{from:r,to:n}of e)for(const s of t)await yr(s,r,n)}async function zr(a){return(await _.readdir(a,{withFileTypes:!0,recursive:!0})).filter(t=>t.isFile()).map(t=>h.join(t.parentPath,t.name))}async function je(a,e){const t=await _.readFile(a),r=e(t.toString());await _.writeFile(a,r)}async function yr(a,e,t){return await je(a,r=>r.replaceAll(e,t))}async function X(a,e){return await yr(a,e,"")}const Z=class Z extends u.Command{async run(){const{flags:e}=await this.parse(Z),t=A(e["log-level"]);await Ur(t)}};l(Z,"description","Helps to create a new block by downloading a block's template."),l(Z,"examples",["<%= name %>"]),l(Z,"flags",{...L});let Ie=Z;function br(...a){return h.resolve(__dirname,"..",...a)}function V(...a){return br("assets",...a)}function ke(...a){return m.readFileSync(br(...a))}function lr(a){return a||(a=ge.getDefaultPlVersion()),`quay.io/milaboratories/platforma:${a}`}const G=class G{constructor(e){l(this,"state",{currentInstance:""});l(this,"filePath");l(this,"dirPath");e=e??h.resolve(D.homedir(),".config","pl-bootstrap");const t=h.join(e,"state.json");this.dirPath=e,this.filePath=t,m.existsSync(e)||m.mkdirSync(e,{recursive:!0}),m.existsSync(t)&&(this.state=JSON.parse(ke(t).toString()))}static getStateInstance(){return G.instance||(G.instance=new G),G.instance}path(...e){return h.join(this.dirPath,...e)}instanceDir(e,...t){return e?this.path("data",e,...t):this.path("data")}binaries(...e){return this.path("binaries",...e)}writeState(){m.writeFileSync(this.filePath,JSON.stringify(this.state))}get instanceList(){return m.existsSync(this.instanceDir())?m.readdirSync(this.instanceDir()).filter(t=>this.instanceExists(t)):[]}instanceExists(e){return m.existsSync(this.instanceDir(e,"instance.json"))}getInstanceInfo(e){const t=this.instanceDir(e,"instance.json");if(!m.existsSync(t))throw new Error(`platforma backend instance '${e}' does not exist or is corrupted`);const r=JSON.parse(ke(t).toString());return{name:e,...r}}setInstanceInfo(e,t){m.existsSync(this.instanceDir(e))||m.mkdirSync(this.instanceDir(e),{recursive:!0});const r=this.instanceDir(e,"instance.json");let n={};m.existsSync(r)&&(n=JSON.parse(ke(r).toString())),m.writeFileSync(r,JSON.stringify({...n,...t}))}isInstanceActive(e){switch(e.type){case"docker":{const r=Mr(`pl-${e.name}`);return r?r.Status.trim().startsWith("running"):!1}case"process":return e.pid?dr(e.pid):!1;default:throw U(),new Error("cli logic error: unknown service type, cannot check its state")}}get isActive(){for(const e of this.instanceList){const t=this.getInstanceInfo(e);if(this.isInstanceActive(t))return!0}return!1}isValidPID(e){return dr(e)}get currentInstance(){const e=this.state.currentInstance;if(e&&this.instanceExists(e))return this.getInstanceInfo(e)}get currentInstanceName(){return this.state.currentInstance}set currentInstanceName(e){this.state.currentInstance=e,this.writeState()}selectInstance(e){if(!this.instanceExists(e))throw new Error(`instance '${e}' does not exist`);this.state.currentInstance=e,this.writeState()}};l(G,"instance");let Oe=G;function dr(a){const e=Cr(a);return e==="platforma"||e.endsWith("/platforma")||e.endsWith("\\platforma")}const f=Oe.getStateInstance();function Se(a,e,t){const r=[],n=[];for(const s of e){const i={cwd:s.workdir,env:{...s.envs,...t==null?void 0:t.env},...s.runOpts,...t};if(s.async){const c=Yr(a,s.cmd,s.args,i);n.push(c)}else{const c=Vr(a,s.cmd,s.args,i);if(r.push(c),c.error||c.status!==0)break}}return{executed:r,spawned:n}}function Yr(a,e,t,r){var c;a.debug(`Running:
|
|
13
|
-
env: ${JSON.stringify(r.env)}
|
|
14
13
|
cmd: ${JSON.stringify([e,...t])}
|
|
15
14
|
wd: ${(c=r.cwd)==null?void 0:c.toString()}`),r.env={...process.env,...r.env},a.debug(" spawning child process");const n=le.spawn(e,t,r);let s=!1;const i=()=>{n.kill("SIGINT"),s=!0};return a.debug(" setting up signal handler"),process.on("SIGINT",i),n.on("close",o=>{process.removeListener("SIGINT",i),s&&process.exit(o)}),n}function Vr(a,e,t,r){return a.debug(`Running:
|
|
16
15
|
cmd: ${JSON.stringify([e,...t])}
|