@keinar/aac-cli 1.1.2 → 1.2.0

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.
Files changed (2) hide show
  1. package/dist/index.cjs +30 -21
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1,16 +1,15 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var I=Object.create;var b=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var U=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Y(n))!j.call(t,i)&&i!==o&&b(t,i,{get:()=>n[i],enumerable:!(r=S(n,i))||r.enumerable});return t};var g=(t,n,o)=>(o=t!=null?I(_(t)):{},U(n||!t||!t.__esModule?b(o,"default",{value:t,enumerable:!0}):o,t));var N=require("commander"),s=g(require("@clack/prompts"),1),y=g(require("picocolors"),1);var f=require("fs/promises"),R=require("path"),c=g(require("@clack/prompts"),1),p=g(require("picocolors"),1);var w="1.50.0";function E(t){return`FROM mcr.microsoft.com/playwright:v${t}-jammy
2
+ "use strict";var Y=Object.create;var F=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var z=(e,o,r,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of G(o))!W.call(e,i)&&i!==r&&F(e,i,{get:()=>o[i],enumerable:!(l=q(o,i))||l.enumerable});return e};var k=(e,o,r)=>(r=e!=null?Y(H(e)):{},z(o||!e||!e.__esModule?F(r,"default",{value:e,enumerable:!0}):r,e));var M=require("commander"),p=k(require("@clack/prompts"),1),A=k(require("picocolors"),1);var P=require("fs/promises"),$=require("path"),s=k(require("@clack/prompts"),1),d=k(require("picocolors"),1);var b="1.50.0";function L(e){return`FROM mcr.microsoft.com/playwright:v${e}-jammy
3
3
 
4
4
  WORKDIR /app
5
5
 
6
6
  COPY package*.json ./
7
7
  RUN npm ci
8
- RUN npm install -g allure-commandline
9
8
 
10
9
  COPY . .
11
10
 
12
11
  RUN chmod +x /app/entrypoint.sh
13
- `}var O=`#!/bin/sh
12
+ `}var j=`#!/bin/sh
14
13
 
15
14
  FOLDER=$1
16
15
 
@@ -28,20 +27,25 @@ else
28
27
  echo "Running tests in folder: $FOLDER"
29
28
  npx playwright test "$FOLDER"
30
29
  fi
30
+ `;function N(e){let{pythonVersion:o,packageManager:r,installPlaywright:l,playwrightBrowser:i,extraSystemDeps:t}=e,a=`FROM ${l?`mcr.microsoft.com/playwright/python:v${b}-jammy`:`python:${o}-slim`}
31
31
 
32
- echo "Generating Allure Report..."
33
- npx allure generate allure-results --clean -o allure-report
34
- `,P=`FROM python:3.11-slim
32
+ `;return a+=`WORKDIR /app
35
33
 
36
- WORKDIR /app
34
+ `,t.length>0&&(a+=`RUN apt-get update && apt-get install -y --no-install-recommends \\
35
+ `,a+=` ${t.join(" ")} && \\
36
+ `,a+=` rm -rf /var/lib/apt/lists/*
37
37
 
38
- COPY requirements.txt ./
39
- RUN pip install --no-cache-dir -r requirements.txt
38
+ `),r==="poetry"?(a+=`RUN pip install poetry
39
+ `,a+=`COPY pyproject.toml poetry.lock ./
40
+ `,a+=`RUN poetry install --no-root
40
41
 
41
- COPY . .
42
+ `):(a+=`COPY requirements.txt ./
43
+ `,a+=`RUN pip install --no-cache-dir -r requirements.txt
42
44
 
43
- RUN chmod +x /app/entrypoint.sh
44
- `,C=`#!/bin/sh
45
+ `),a+=`COPY . .
46
+
47
+ `,a+=`RUN chmod +x /app/entrypoint.sh
48
+ `,a}function I(e){let o=e==="poetry"?"poetry run pytest":"pytest";return`#!/bin/sh
45
49
 
46
50
  FOLDER=$1
47
51
 
@@ -52,19 +56,24 @@ fi
52
56
 
53
57
  if [ -z "$FOLDER" ] || [ "$FOLDER" = "all" ]; then
54
58
  echo "Running ALL tests..."
55
- exec pytest
59
+ ${o}
56
60
  else
57
61
  echo "Running tests in folder: $FOLDER"
58
- exec pytest "$FOLDER"
62
+ ${o} "$FOLDER"
59
63
  fi
60
- `,$=`.git
64
+ `}var S=`.git
61
65
  .env
62
66
  node_modules
63
67
  __pycache__
64
68
  .venv
65
- `;async function G(t){try{let n=await(0,f.readFile)((0,R.join)(t,"package.json"),"utf-8"),o=JSON.parse(n),r=o.devDependencies?.["@playwright/test"]??o.dependencies?.["@playwright/test"];return r?r.replace(/^[^\d]*/,"")||w:w}catch{return w}}async function B(t,n){let o=t==="playwright",r;if(o){let i=await G(n);c.log.info(`Detected Playwright version: ${p.default.cyan("v"+i)}`),r=E(i)}else r=P;return[{name:".dockerignore",content:$,mode:420},{name:"entrypoint.sh",content:o?O:C,mode:493},{name:"Dockerfile",content:r,mode:420}]}async function H(t){try{return await(0,f.stat)(t),!0}catch{return!1}}function q(t){return t.replace(/\r\n/g,`
66
- `)}async function A(t,n){let o=await B(t,n),r=new Set;for(let a of o){let d=(0,R.join)(n,a.name);if(await H(d)){let m=await c.confirm({message:`File ${p.default.yellow(a.name)} already exists. Overwrite?`});c.isCancel(m)&&(c.cancel("Operation cancelled."),process.exit(0)),m||r.add(a.name)}}if(r.size===o.length){c.log.warn("All files were skipped. No changes were made.");return}let i=[];for(let a of o){if(r.has(a.name))continue;let d=(0,R.join)(n,a.name),m=q(a.content);await(0,f.writeFile)(d,m,{mode:a.mode}),i.push(a.name)}for(let a of i)c.log.success(`Created ${p.default.green(a)}`);c.note([`${p.default.bold("1.")} docker build -t your-username/my-automation-tests:latest .`,`${p.default.bold("2.")} docker push your-username/my-automation-tests:latest`,`${p.default.bold("3.")} Enter this image name in the AAC Dashboard.`].join(`
67
- `),`${p.default.green("\u2705")} Next steps to connect your project to the AAC`)}var D=require("child_process"),F=require("fs/promises"),v=require("path"),e=g(require("@clack/prompts"),1),l=g(require("picocolors"),1);async function W(t){try{let n=await(0,F.readFile)((0,v.join)(t,"package.json"),"utf-8"),o=JSON.parse(n);return o.name?o.name.replace(/^@[^/]+\//,""):null}catch{return null}}async function L(t){let n=await e.confirm({message:"Do you have a Docker Hub account?"});if(e.isCancel(n)){e.cancel("Deployment cancelled.");return}n||(e.note(`Create a free account at ${l.default.cyan("https://hub.docker.com")}
68
- Press Enter when you're ready to continue.`,l.default.yellow("Docker Hub Account Required")),await e.text({message:"Press Enter to continue...",defaultValue:"",placeholder:""}));let o=await e.text({message:"What is your Docker Hub username?",validate:u=>{if(!u.trim())return"Username is required."}});if(e.isCancel(o)){e.cancel("Deployment cancelled.");return}let r=await W(t),i;if(r){let u=await e.confirm({message:`Detected project name "${l.default.cyan(r)}". Use this for the image?`});if(e.isCancel(u)){e.cancel("Deployment cancelled.");return}if(u)i=r;else{let h=await e.text({message:"Enter the image name:",validate:T=>{if(!T.trim())return"Image name is required."}});if(e.isCancel(h)){e.cancel("Deployment cancelled.");return}i=h.trim()}}else{let u=await e.text({message:"Enter the image name:",validate:h=>{if(!h.trim())return"Image name is required."}});if(e.isCancel(u)){e.cancel("Deployment cancelled.");return}i=u.trim()}let a=`${o.trim()}/${i}:latest`,d=await e.confirm({message:"I need to log you into Docker. Send a login request?"});if(e.isCancel(d)){e.cancel("Deployment cancelled.");return}if(d){e.log.step("Opening Docker login...");try{(0,D.execSync)("docker login",{stdio:"inherit",cwd:t}),e.log.success("Docker login successful.")}catch{e.log.error("Docker login failed. Please try again manually.");return}}let m=await e.confirm({message:`Build multi-platform image ${l.default.cyan(a)} and push to Docker Hub?`});if(e.isCancel(m)||!m){e.log.warn("Build skipped."),e.note([`${l.default.bold("1.")} docker buildx create --name aac-builder --use`,`${l.default.bold("2.")} docker buildx build --platform linux/amd64,linux/arm64 -t ${a} --push .`].join(`
69
- `),"You can build manually later");return}let k=e.spinner();try{k.start("Setting up Docker Buildx builder..."),(0,D.execSync)("docker buildx create --name aac-builder --use",{stdio:"pipe",cwd:t}),k.stop("Buildx builder ready.")}catch{k.stop("Using existing Buildx builder.")}e.log.step(`Building & pushing ${l.default.cyan(a)}...`);try{(0,D.execSync)(`docker buildx build --platform linux/amd64,linux/arm64 -t ${a} --push .`,{stdio:"inherit",cwd:t}),e.log.success(`Image ${l.default.green(a)} pushed successfully!`),e.note(`Go to the ${l.default.bold("AAC Dashboard")} and enter:
70
- ${l.default.cyan(a)}`,l.default.green("\u2705 Deployment Complete"))}catch{e.log.error("Docker build failed. Check the output above for details.")}}var x=new N.Command;x.name("aac-cli").description("Agnostic Automation Center CLI \u2014 Prepare any test automation repo for the AAC platform").version("1.1.0");x.command("init").description("Generate AAC integration files and optionally build & push your Docker image").action(async()=>{s.intro(y.default.bgCyan(y.default.black(" AAC CLI ")));let t=await s.select({message:"Select your automation project framework:",options:[{value:"playwright",label:"Playwright (TypeScript/Node.js)"},{value:"pytest",label:"Pytest (Python)"}]});s.isCancel(t)&&(s.cancel("Operation cancelled."),process.exit(0));let n=s.spinner();n.start("Generating AAC integration files..."),await new Promise(i=>setTimeout(i,300)),n.stop("Files ready.");let o=process.cwd();await A(t,o);let r=await s.confirm({message:"Do you want to build and push the image to Docker Hub right now?"});s.isCancel(r)&&(s.cancel("Operation cancelled."),process.exit(0)),r&&await L(o),s.outro(y.default.green("Done!")+" "+y.default.dim("Run `aac-cli init` again anytime."))});x.parse();
69
+ `;var x=require("fs/promises"),h=require("path");async function D(e){try{return await(0,x.stat)(e),!0}catch{return!1}}async function V(e){let o=await D((0,h.join)(e,"requirements.txt")),r=await D((0,h.join)(e,"pyproject.toml")),l=await D((0,h.join)(e,"poetry.lock")),i="",t="pip",c=null;if(r){let w=await(0,x.readFile)((0,h.join)(e,"pyproject.toml"),"utf-8");if(l||w.includes("[tool.poetry]")){t="poetry",i+=w;let R=w.match(/python\s*=\s*"([^"]+)"/);if(R){let E=R[1].match(/(\d+\.\d+)/);E&&(c=E[1])}}}if(!c&&await D((0,h.join)(e,".python-version"))){let R=(await(0,x.readFile)((0,h.join)(e,".python-version"),"utf-8")).trim().match(/(\d+\.\d+)/);R&&(c=R[1])}if(o){let w=await(0,x.readFile)((0,h.join)(e,"requirements.txt"),"utf-8");i+=`
70
+ `+w}let a=i.includes("playwright")||i.includes("pytest-playwright"),y=i.includes("allure-pytest"),m=i.includes("selenium")||i.includes("pytest-selenium"),f=!a&&!m,g=null,O=i.match(/playwright==([\d.]+)/);return O&&(g=O[1]),{hasPlaywright:a,hasAllure:y,hasSelenium:m,isApiOnly:f,packageManager:t,pythonVersion:c,playwrightVersion:g}}async function K(e){try{let o=await(0,P.readFile)((0,$.join)(e,"package.json"),"utf-8"),r=JSON.parse(o),l=r.devDependencies?.["@playwright/test"]??r.dependencies?.["@playwright/test"];return l?l.replace(/^[^\d]*/,"")||b:b}catch{return b}}async function J(e,o){let r=e==="playwright",l,i;if(r){let t=await K(o);s.log.info(`Detected Playwright version: ${d.default.cyan("v"+t)}`),l=L(t),i=j}else{s.log.info(d.default.cyan("Analyzing project structure..."));let t=await V(o),c=null;if(!t.isApiOnly){let g=await s.select({message:"Which browser does your test suite use?",options:[{value:"chromium",label:"Chromium (default)"},{value:"firefox",label:"Firefox"},{value:"webkit",label:"Webkit"},{value:"none",label:"None (API tests only)"}],initialValue:"chromium"});s.isCancel(g)&&(s.cancel("Operation cancelled."),process.exit(0)),g!=="none"?c=g:(t.isApiOnly=!0,t.hasPlaywright=!1)}let a=t.hasAllure;if(!a){let g=await s.confirm({message:"Does your project use Allure reporting?"});s.isCancel(g)&&process.exit(0),a=g}let y=await s.text({message:"Are there any system-level dependencies your tests need? (space separated)",placeholder:"e.g. ffmpeg fonts-liberation"});s.isCancel(y)&&process.exit(0);let m=y?y.split(" ").filter(Boolean):[];s.note(` Base image: ${t.hasPlaywright?`mcr.microsoft.com/playwright/python:v${t.playwrightVersion||b}-jammy`:`python:${t.pythonVersion||"3.11"}-slim`}
71
+ Package mgr: ${t.packageManager}
72
+ Browser: ${c||"none"}
73
+ Allure: ${a?"yes":"no"}
74
+ Extra deps: ${m.length?m.join(", "):"none"}`,"\u{1F4CB} AAC will generate the following setup:");let f=await s.confirm({message:"Proceed with these settings?",initialValue:!0});(s.isCancel(f)||!f)&&(s.cancel("Operation cancelled."),process.exit(0)),l=N({pythonVersion:t.pythonVersion||"3.11",packageManager:t.packageManager,installPlaywright:t.hasPlaywright,playwrightBrowser:c,extraSystemDeps:m}),i=I(t.packageManager)}return[{name:".dockerignore",content:S,mode:420},{name:"entrypoint.sh",content:i,mode:493},{name:"Dockerfile",content:l,mode:420}]}async function Q(e){try{return await(0,P.stat)(e),!0}catch{return!1}}function X(e){return e.replace(/\r\n/g,`
75
+ `)}async function B(e,o){let r=await J(e,o),l=new Set;for(let t of r){let c=(0,$.join)(o,t.name);if(await Q(c)){let a=await s.confirm({message:`File ${d.default.yellow(t.name)} already exists. Overwrite?`});s.isCancel(a)&&(s.cancel("Operation cancelled."),process.exit(0)),a||l.add(t.name)}}if(l.size===r.length){s.log.warn("All files were skipped. No changes were made.");return}let i=[];for(let t of r){if(l.has(t.name))continue;let c=(0,$.join)(o,t.name),a=X(t.content);await(0,P.writeFile)(c,a,{mode:t.mode}),i.push(t.name)}for(let t of i)s.log.success(`Created ${d.default.green(t)}`);s.note([`${d.default.bold("1.")} docker build -t your-username/my-automation-tests:latest .`,`${d.default.bold("2.")} docker push your-username/my-automation-tests:latest`,`${d.default.bold("3.")} Enter this image name in the AAC Dashboard.`].join(`
76
+ `),`${d.default.green("\u2705")} Next steps to connect your project to the AAC`)}var v=require("child_process"),T=require("fs/promises"),U=require("path"),n=k(require("@clack/prompts"),1),u=k(require("picocolors"),1);async function Z(e){try{let o=await(0,T.readFile)((0,U.join)(e,"package.json"),"utf-8"),r=JSON.parse(o);return r.name?r.name.replace(/^@[^/]+\//,""):null}catch{return null}}async function _(e){let o=await n.confirm({message:"Do you have a Docker Hub account?"});if(n.isCancel(o)){n.cancel("Deployment cancelled.");return}o||(n.note(`Create a free account at ${u.default.cyan("https://hub.docker.com")}
77
+ Press Enter when you're ready to continue.`,u.default.yellow("Docker Hub Account Required")),await n.text({message:"Press Enter to continue...",defaultValue:"",placeholder:""}));let r=await n.text({message:"What is your Docker Hub username?",validate:m=>{if(!m.trim())return"Username is required."}});if(n.isCancel(r)){n.cancel("Deployment cancelled.");return}let l=await Z(e),i;if(l){let m=await n.confirm({message:`Detected project name "${u.default.cyan(l)}". Use this for the image?`});if(n.isCancel(m)){n.cancel("Deployment cancelled.");return}if(m)i=l;else{let f=await n.text({message:"Enter the image name:",validate:g=>{if(!g.trim())return"Image name is required."}});if(n.isCancel(f)){n.cancel("Deployment cancelled.");return}i=f.trim()}}else{let m=await n.text({message:"Enter the image name:",validate:f=>{if(!f.trim())return"Image name is required."}});if(n.isCancel(m)){n.cancel("Deployment cancelled.");return}i=m.trim()}let t=`${r.trim()}/${i}:latest`,c=await n.confirm({message:"I need to log you into Docker. Send a login request?"});if(n.isCancel(c)){n.cancel("Deployment cancelled.");return}if(c){n.log.step("Opening Docker login...");try{(0,v.execSync)("docker login",{stdio:"inherit",cwd:e}),n.log.success("Docker login successful.")}catch{n.log.error("Docker login failed. Please try again manually.");return}}let a=await n.confirm({message:`Build multi-platform image ${u.default.cyan(t)} and push to Docker Hub?`});if(n.isCancel(a)||!a){n.log.warn("Build skipped."),n.note([`${u.default.bold("1.")} docker buildx create --name aac-builder --use`,`${u.default.bold("2.")} docker buildx build --platform linux/amd64,linux/arm64 -t ${t} --push .`].join(`
78
+ `),"You can build manually later");return}let y=n.spinner();try{y.start("Setting up Docker Buildx builder..."),(0,v.execSync)("docker buildx create --name aac-builder --use",{stdio:"pipe",cwd:e}),y.stop("Buildx builder ready.")}catch{y.stop("Using existing Buildx builder.")}n.log.step(`Building & pushing ${u.default.cyan(t)}...`);try{(0,v.execSync)(`docker buildx build --platform linux/amd64,linux/arm64 -t ${t} --push .`,{stdio:"inherit",cwd:e}),n.log.success(`Image ${u.default.green(t)} pushed successfully!`),n.note(`Go to the ${u.default.bold("AAC Dashboard")} and enter:
79
+ ${u.default.cyan(t)}`,u.default.green("\u2705 Deployment Complete"))}catch{n.log.error("Docker build failed. Check the output above for details.")}}var C=new M.Command;C.name("aac-cli").description("Agnostic Automation Center CLI \u2014 Prepare any test automation repo for the AAC platform").version("1.1.0");C.command("init").description("Generate AAC integration files and optionally build & push your Docker image").action(async()=>{p.intro(A.default.bgCyan(A.default.black(" AAC CLI ")));let e=await p.select({message:"Select your automation project framework:",options:[{value:"playwright",label:"Playwright (TypeScript/Node.js)"},{value:"pytest",label:"Pytest (Python)"}]});p.isCancel(e)&&(p.cancel("Operation cancelled."),process.exit(0));let o=p.spinner();o.start("Generating AAC integration files..."),await new Promise(i=>setTimeout(i,300)),o.stop("Files ready.");let r=process.cwd();await B(e,r);let l=await p.confirm({message:"Do you want to build and push the image to Docker Hub right now?"});p.isCancel(l)&&(p.cancel("Operation cancelled."),process.exit(0)),l&&await _(r),p.outro(A.default.green("Done!")+" "+A.default.dim("Run `aac-cli init` again anytime."))});C.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keinar/aac-cli",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Agnostic Automation Center CLI — Prepare any test automation repo for the AAC platform",
5
5
  "author": "keinar",
6
6
  "license": "MIT",