UNPKG

create-defuss

Version:

Checks out git projects from sub-directories. Originally for jump-starting defuss projects from templates.

14 lines (13 loc) 3.71 kB
var m=Object.defineProperty;var u=(o,s)=>m(o,"name",{value:s,configurable:!0});import{createRequire as h}from"node:module";const k=h(import.meta.url);import{p as y}from"./git-B92u1z1f.mjs";import{join as r}from"node:path";import{tmpdir as $}from"node:os";import{existsSync as l,readFileSync as F,rmSync as E,readdirSync as S}from"node:fs";import"node:child_process";const g="https://github.com/kyr0/defuss/tree/main/packages/create";async function T(){const o=r($(),`create-defuss-e2e-${Date.now()}`);console.log("\u{1F9EA} E2E Test for create-defuss"),console.log("=".repeat(50)),console.log(`Test URL: ${g}`),console.log(`Test Directory: ${o}`),console.log("=".repeat(50));let s=!0;const e=[];try{console.log(` \u{1F4E5} Running sparse checkout... `),y(g,o),console.log(` \u{1F50D} Running verification checks... `),l(o)?e.push({test:"Destination folder created",passed:!0}):(e.push({test:"Destination folder created",passed:!1,message:"Folder does not exist"}),s=!1);const t=r(o,"package.json");if(l(t)){e.push({test:"package.json exists",passed:!0});try{const n=JSON.parse(F(t,"utf-8"));e.push({test:"package.json is valid JSON",passed:!0}),n.name==="create-defuss"?e.push({test:"Package name is correct",passed:!0}):(e.push({test:"Package name is correct",passed:!1,message:`Expected 'create-defuss', got '${n.name}'`}),s=!1),x(n)?(e.push({test:"No workspace:* versions in package.json",passed:!1,message:"Found workspace:* references"}),s=!1):e.push({test:"No workspace:* versions in package.json",passed:!0})}catch(n){e.push({test:"package.json is valid JSON",passed:!1,message:n.message}),s=!1}}else e.push({test:"package.json exists",passed:!1,message:"File not found"}),s=!1;const i=r(o,"src");if(l(i)){e.push({test:"src folder exists",passed:!0});const n=["cli.ts","git.ts"];for(const p of n)l(r(i,p))?e.push({test:`src/${p} exists`,passed:!0}):(e.push({test:`src/${p} exists`,passed:!1,message:"File not found"}),s=!1)}else e.push({test:"src folder exists",passed:!1,message:"Folder not found"}),s=!1;const f=r(o,".git");l(f)?e.push({test:"Git repository initialized",passed:!0}):(e.push({test:"Git repository initialized",passed:!1,message:".git folder not found"}),s=!1),console.log(` \u{1F4C1} Files in checkout:`),d(o,"",2)}catch(t){console.error(` \u274C Test execution failed:`,t.message),s=!1,e.push({test:"Checkout execution",passed:!1,message:t.message})}finally{console.log(` \u{1F9F9} Cleaning up test directory...`),l(o)&&(E(o,{recursive:!0,force:!0}),console.log("\u2705 Test directory removed"))}console.log(` `+"=".repeat(50)),console.log("\u{1F4CA} TEST RESULTS"),console.log("=".repeat(50));for(const t of e){const i=t.passed?"\u2705":"\u274C",f=t.message?` (${t.message})`:"";console.log(`${i} ${t.test}${f}`)}const c=e.filter(t=>t.passed).length,a=e.length;console.log(` `+"=".repeat(50)),console.log(`\u{1F4C8} Summary: ${c}/${a} tests passed`),console.log("=".repeat(50)),s?(console.log(` \u2705 E2E TEST PASSED`),process.exit(0)):(console.log(` \u274C E2E TEST FAILED`),process.exit(1))}u(T,"runE2ETest");function x(o){const s=["dependencies","devDependencies","peerDependencies","optionalDependencies"];for(const e of s){const c=o[e];if(!(!c||typeof c!="object")){for(const a of Object.values(c))if(typeof a=="string"&&a.startsWith("workspace:"))return!0}}return!1}u(x,"checkForWorkspaceRefs");function d(o,s,e){if(e<=0){console.log(`${s}...`);return}const c=S(o);for(const a of c){if(a===".git"||a==="node_modules"){console.log(`${s}${a}/`);continue}const t=r(o,a);try{k("fs").lstatSync(t).isDirectory()?(console.log(`${s}${a}/`),d(t,s+" ",e-1)):console.log(`${s}${a}`)}catch{console.log(`${s}${a}`)}}}u(d,"listFilesRecursively"),T(); //# sourceMappingURL=e2e.mjs.map