@visulima/vis 4.0.2 → 4.1.1
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/CHANGELOG.md +46 -0
- package/README.md +2 -2
- package/dist/bin.js +1 -1
- package/dist/binx.js +1 -1
- package/dist/packem_chunks/catalog.js +1 -1
- package/dist/packem_chunks/cli-exec.js +1 -1
- package/dist/packem_chunks/cli-main.js +155 -155
- package/dist/packem_chunks/git.js +4 -3
- package/dist/packem_chunks/handler2.js +1 -1
- package/dist/packem_chunks/handler28.js +1 -1
- package/dist/packem_chunks/handler3.js +1 -1
- package/dist/packem_chunks/handler39.js +6 -6
- package/dist/packem_chunks/handler40.js +1 -75
- package/dist/packem_chunks/handler56.js +6 -6
- package/dist/packem_chunks/handler59.js +73 -9
- package/dist/packem_chunks/handler6.js +1 -1
- package/dist/packem_chunks/handler60.js +11 -3
- package/dist/packem_chunks/handler61.js +3 -22
- package/dist/packem_chunks/handler62.js +21 -60
- package/dist/packem_chunks/handler63.js +61 -3
- package/dist/packem_chunks/handler64.js +3 -6
- package/dist/packem_chunks/handler65.js +6 -9
- package/dist/packem_chunks/handler72.js +1 -1
- package/dist/packem_chunks/handler78.js +1 -1
- package/dist/packem_chunks/help-command.js +2 -2
- package/dist/packem_chunks/resolveFormatter.js +7 -5
- package/dist/packem_chunks/root-handler.js +1 -0
- package/dist/packem_chunks/version-resolver.js +3 -2
- package/dist/packem_shared/DEFAULT_BREAKING_SECTION-DUAcKVLD.js +1 -0
- package/dist/packem_shared/DEFAULT_CONVENTIONAL_HEADING-D7oNGUcP.js +1 -0
- package/dist/packem_shared/{affected-selection-BdFnUyQZ.js → affected-selection-D3rosWKF.js} +1 -1
- package/dist/packem_shared/{api.d-BPftyU9r.d.ts → api.d-C10vHKJZ.d.ts} +1 -1
- package/dist/packem_shared/{bin-BieNPL6n.js → bin-Bc5j8Cdm.js} +1 -1
- package/dist/packem_shared/buildCompareUrl-BLaukjgu.js +1 -0
- package/dist/packem_shared/conventional-CGiOOEq1.js +4 -0
- package/dist/packem_shared/hasBulletMarker-BX2KwzI5.js +1 -0
- package/dist/packem_shared/{index-BPeT7L7t.js → index-B0ahNAKR.js} +1 -1
- package/dist/packem_shared/{package-version-DqNoc-rP.js → package-version-BhrkMRQ2.js} +1 -1
- package/dist/packem_shared/{project-name-filter-B0y95mKx.js → project-name-filter-jDQpaOkI.js} +1 -1
- package/dist/packem_shared/release-heading-DRpkhETz.js +1 -0
- package/dist/packem_shared/run-D-uVGHQ4.js +10 -0
- package/dist/packem_shared/{vis-user-error-4RgO8nMw.js → vis-user-error-CEc_asoq.js} +1 -1
- package/dist/release/core/changelog/index.d.ts +274 -31
- package/dist/release/core/changelog/index.js +1 -1
- package/dist/release/plugin-sdk.d.ts +2 -2
- package/dist/release/types.d.ts +44 -2
- package/index.js +52 -52
- package/package.json +11 -11
- package/schemas/vis-config.schema.json +19 -1
- package/schemas/vis-release-config.schema.json +19 -1
|
@@ -1,11 +1,75 @@
|
|
|
1
|
-
import{createRequire as
|
|
2
|
-
`)
|
|
1
|
+
import{createRequire as D}from"node:module";import{V as q}from"../packem_shared/vis-user-error-CEc_asoq.js";let W;const L=e=>(W??=D(import.meta.url))(e),R=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,E=e=>{if(typeof R<"u"&&R.versions&&R.versions.node){const[t,n]=R.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return R.getBuiltinModule(e)}return L(e)},{relative:h,join:u,dirname:_}=E("node:path"),{lstat:G}=E("node:fs/promises"),U=new Set(["ENOENT","ENOTDIR"]),$=e=>U.has(e?.code??""),T=async(e,t)=>{const n=e.lstat;try{return(typeof n=="function"?await n.call(e,t):await G(t)).isSymbolicLink()}catch(i){if($(i))return!1;throw i}},v=async(e,t,n)=>{if(await T(e,t))throw new q(`Refusing to write ${t}: it is a symlink, and following it would write somewhere else. Remove or replace the link, then re-run.`);await e.writeFile(t,n)},g=async(e,t)=>{try{return await e.access(t),!0}catch(n){if($(n))return!1;throw n}},Y=async(e,t)=>{try{return(await e.stat(t)).isDirectory()}catch(n){if($(n))return!1;throw n}},b=async(e,t)=>{try{return await e.readFile(t,"utf8")}catch(n){if($(n))return;throw n}},K=e=>{const t=/\n([\t ]+)\S/.exec(e);return t?.[1]!==void 0?t[1]:e.includes(`
|
|
2
|
+
`)?" ":""},V=(e,t)=>{const n=t.includes(`\r
|
|
3
3
|
`)?`\r
|
|
4
4
|
`:`
|
|
5
|
-
`,
|
|
6
|
-
|
|
7
|
-
`),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
`)?c
|
|
11
|
-
|
|
5
|
+
`,i=JSON.stringify(e,void 0,K(t)).replaceAll(`
|
|
6
|
+
`,n);return t.endsWith(`
|
|
7
|
+
`)?`${i}${n}`:i},H=[/defineConfig\s*\(\s*\{/,/export\s+default\s+\{/],X=new Set(["","!","%","&","(","*","+",",","-",":",";","<","=",">","?","[","^","{","|","}","~"]),Z=e=>{const t=Array.from({length:e.length}),n=[];let i="code",r="",o="",a=0;const s=(c,f)=>{const d=e[c];t[c]=f||d===`
|
|
8
|
+
`?d:" ",f&&d.trim()!==""&&(o=d)},l=()=>{s(a,!1),a+1<e.length&&s(a+1,!1),a+=2};for(;a<e.length;){const c=e[a],f=e[a+1];if(i==="code"){c==="/"&&f==="/"?(s(a,!1),s(a+1,!1),a+=2,i="line-comment"):c==="/"&&f==="*"?(s(a,!1),s(a+1,!1),a+=2,i="block-comment"):c==='"'||c==="'"?(r=c,s(a,!0),a+=1,i="string"):c==="`"?(s(a,!1),a+=1,i="template"):c==="/"&&X.has(o)?(s(a,!1),a+=1,i="regex"):n.length>0&&c==="}"&&n.at(-1)===0?(n.pop(),s(a,!1),a+=1,i="template"):(n.length>0&&(c==="{"||c==="}")&&(n[n.length-1]=n.at(-1)+(c==="{"?1:-1)),s(a,!0),a+=1);continue}if(i==="line-comment"){s(a,!1),a+=1,c===`
|
|
9
|
+
`&&(i="code");continue}if(i==="block-comment"){s(a,!1),c==="*"&&f==="/"?(s(a+1,!1),a+=2,i="code"):a+=1;continue}if(i==="string"){if(c==="\\"){l();continue}if(c===r||c===`
|
|
10
|
+
`){s(a,c===r),a+=1,i="code";continue}s(a,!1),a+=1;continue}if(i==="template"){if(c==="\\"){l();continue}s(a,!1),c==="`"?(a+=1,i="code"):c==="$"&&f==="{"?(s(a+1,!1),n.push(0),a+=2,i="code"):a+=1;continue}if(c==="\\"){l();continue}s(a,!1),a+=1,c===`
|
|
11
|
+
`?i="code":i==="regex"&&c==="["?i="regex-class":i==="regex"&&c==="/"?i="code":i==="regex-class"&&c==="]"&&(i="regex")}return t.join("")},j=/[A-Z_$][\w$]*/iy,N=/\s*[:(,}]/y,F=(e,t)=>(N.lastIndex=t,N.test(e)),z=e=>{const t=Z(e);let n;for(const a of H){const s=a.exec(t);if(s!==null){n=s.index+s[0].length;break}}if(n===void 0)return{kind:"no-anchor"};let i=1,r=!1,o=n;for(;o<t.length;){const a=t[o];if(a==="{"){i+=1,o+=1;continue}if(a==="}"){if(i-=1,i===0)return{bodyStart:n,hasReleaseKey:r,kind:"found"};o+=1;continue}if(a==='"'||a==="'"){const l=t.indexOf(a,o+1);if(l===-1)return{kind:"unterminated"};i===1&&e.slice(o+1,l)==="release"&&F(t,l+1)&&(r=!0),o=l+1;continue}j.lastIndex=o;const s=j.exec(t);if(s!==null){const l=o+s[0].length;i===1&&s[0]==="release"&&t[o-1]!=="."&&F(t,l)&&(r=!0),o=l;continue}o+=1}return{kind:"unterminated"}},P=new Set([".releaserc.cjs",".releaserc.js",".releaserc.json"]),Q=5e3,I=async(e,t,n)=>{const i=[];for(const a of P){const s=u(t,a);if(await g(e,s)&&(i.push(s),n))return i}const r=[u(t,"packages"),u(t,"apps")];let o=0;for(;r.length>0&&o<Q;){const a=r.shift();o+=1;let s;try{s=await e.readdir(a)}catch(l){if(!$(l))throw l;continue}for(const l of s){const c=u(a,l);if(P.has(l)){if(i.push(c),n)return i;continue}l==="node_modules"||l.startsWith(".")||await Y(e,c)&&!await T(e,c)&&r.push(c)}}return i},ee=async(e,t)=>(await I(e,t,!0)).length>0,te=(e,t)=>I(e,t,!1),ne=async(e,t)=>{if(!t.endsWith(".json"))return{path:t};const n=await b(e,t);if(n!==void 0)try{const i=JSON.parse(n);return{branches:i.branches,extends:typeof i.extends=="string"?i.extends:void 0,path:t,plugins:Array.isArray(i.plugins)?i.plugins:void 0}}catch{return}},ie=e=>Array.isArray(e)?e.map(t=>{if(typeof t=="string")return{name:t};if(typeof t=="object"&&t!==null&&typeof t.name=="string"){const n=t;return{channel:n.channel,name:n.name,prerelease:n.prerelease}}}).filter(t=>t!==void 0):[],ae=e=>{const t={};for(const n of e){const i={tag:"latest"};typeof n.prerelease=="string"?(i.prerelease=n.prerelease,i.tag=n.prerelease,i.mode="auto-publish"):n.prerelease===!0?(i.prerelease=n.name,i.tag=n.name,i.mode="auto-publish"):(i.tag=n.channel??(n.name==="main"||n.name==="master"?"latest":n.name),i.mode="version-pr"),t[n.name]=i}return t},se=(e,t)=>{const n=Object.entries(e).map(([r,o])=>` ${JSON.stringify(r)}: ${JSON.stringify(o)},`).join(`
|
|
12
|
+
`);return` release: {
|
|
13
|
+
baseBranch: "main",
|
|
14
|
+
${t?" defaultManaged: true,":" defaultManaged: false, // per-package opt-in; --cutover flips this to true"}
|
|
15
|
+
channels: {
|
|
16
|
+
${n}
|
|
17
|
+
},
|
|
18
|
+
publish: {
|
|
19
|
+
packManager: "auto",
|
|
20
|
+
publishStrategy: "npm-publish-tarball",
|
|
21
|
+
publishArgs: ["--provenance"],
|
|
22
|
+
protocolResolution: "pack",
|
|
23
|
+
catalogResolution: "auto",
|
|
24
|
+
cleanPackageJson: true,
|
|
25
|
+
},
|
|
26
|
+
gitUser: { name: "release-bot", email: "release-bot@example.com" },
|
|
27
|
+
},`},J=e=>e.visConfig?[e.visConfig,...e.manifests]:e.manifests,re=async(e,t,n)=>{const i=u(t,"vis.config.ts"),r=await b(e,i);if(r===void 0)return{kind:"write",write:{action:"create",content:`import { defineConfig } from "@visulima/vis/config";
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
${n}
|
|
31
|
+
});
|
|
32
|
+
`,detail:"release block",path:i}};const o=z(r);return o.kind==="no-anchor"?{kind:"skip",skipped:{blocking:!0,path:i,reason:"could not locate `defineConfig({` or `export default {` to inject into; merge the suggested block manually"}}:o.kind==="unterminated"?{kind:"skip",skipped:{blocking:!0,path:i,reason:"its config object is never closed (unbalanced braces); fix the file, or merge the suggested block manually"}}:o.hasReleaseKey?{kind:"skip",skipped:{blocking:!1,path:i,reason:"already has a `release` key; merge the suggested block manually"}}:{kind:"write",write:{action:"update",content:`${r.slice(0,o.bodyStart)}
|
|
33
|
+
${n}
|
|
34
|
+
${r.slice(o.bodyStart)}`,detail:"release block",path:i}}},oe=async(e,t,n,i)=>{const r=[],o=[],a=new Set;for(const s of n){const l=_(s),c=u(l,"package.json"),f=await b(e,c);if(f===void 0)continue;let d;try{d=JSON.parse(f)}catch{r.push(` skipped ${h(t,c)} — invalid JSON.`);continue}const p=h(t,l).replaceAll("\\","/"),w=typeof d.name=="string"?d.name:p;if(i!==void 0){const A=i.find(x=>x===w||x.replaceAll("\\","/").replace(/\/+$/,"")===p);if(A===void 0)continue;a.add(A)}if(d.private===!0){r.push(` skipped ${h(t,c)} — \`private: true\` packages are not published, so they are not opted in.`);continue}const m=d["vis-release"];if(m!==null&&typeof m=="object"&&m.managed===!0)continue;const k=m!==null&&typeof m=="object"?{...m,managed:!0}:{managed:!0};o.push({action:"update",content:V({...d,"vis-release":k},f),detail:"add vis-release.managed = true",path:c})}if(i!==void 0)for(const s of i)a.has(s)||r.push(`--packages: no package with a sibling .releaserc.* matched "${s}".`);return{warnings:r,writes:o}},ce=async(e,t,n,i,{cutover:r,selection:o})=>{const a=r||o!==void 0?await oe(e,t,n,r?void 0:o):{warnings:[],writes:[]},s=await re(e,t,i);return{deletions:r?n:[],manifests:a.writes,skipped:s.kind==="skip"?[s.skipped]:[],visConfig:s.kind==="write"?s.write:void 0,warnings:a.warnings}},le=(e,t,n)=>{for(const i of t.skipped)n.info(`[dry-run] would skip ${h(e,i.path)} — ${i.reason}`);for(const i of J(t))n.info(`[dry-run] would ${i.action} ${h(e,i.path)} (${i.detail})`);for(const i of t.deletions)n.info(`[dry-run] would delete ${h(e,i)}`);t.manifests.length===0&&t.deletions.length===0&&n.info("[dry-run] no package.json or .releaserc.* is touched — pass `--packages <a,b>` to opt packages in, or `--cutover` for all of them.")},fe=async(e,t)=>{for(const n of t.toReversed())try{await(n.previous===void 0?e.rm(n.path,{force:!0}):e.writeFile(n.path,n.previous))}catch{}},de=async(e,t,n,i)=>{for(const o of n.skipped)i.warn(` skipped ${h(t,o.path)} — ${o.reason}.`);const r=[];try{for(const o of J(n))r.push({path:o.path,previous:await b(e,o.path)}),await v(e,o.path,o.content),i.info(` ${o.action==="create"?"wrote":"updated"} ${h(t,o.path)} (${o.detail})`);for(const o of n.deletions)r.push({path:o,previous:await b(e,o)}),await e.rm(o,{force:!0}),i.info(` deleted ${h(t,o)}`)}catch(o){throw i.error(`Migration write failed — rolling back ${r.length} change(s).`),await fe(e,r),o}},ue=()=>process.stdout.isTTY&&process.env.CI!=="true",pe=async(e,t,n)=>{if(e.deletions.length===0||t)return"confirmed";if(!ue())return n.error(`Refusing to delete ${e.deletions.length} .releaserc.* file(s) without confirmation.`),n.error("Re-run with `--yes` to confirm in a non-interactive shell, or with `--dry-run` to preview the run first."),"refused";const i=`Delete ${e.deletions.length} .releaserc.* file(s) and mark ${e.manifests.length} package.json file(s) managed?`;try{const{confirmPrompt:r}=await import("./prompts.js");return await r(i,!1)?"confirmed":"declined"}catch{return"declined"}},he=e=>e.deletions.length===0?[]:e.skipped.filter(t=>t.blocking),me=(e,t,n)=>{n.error("Refusing to run the cutover — the vis release config could not be written:");for(const i of t)n.error(` ${h(e,i.path)} — ${i.reason}`);n.error("Deleting every .releaserc.* now would leave this repo with no release configuration at all."),n.error("Paste the release block above into your config (or remove the file so init can create it), then re-run with `--apply --cutover`.")},O=(e,t,n)=>{if(n.info(""),t?(n.info("Full cutover (--cutover): every detected package is marked `vis-release.managed` and its `.releaserc.*` removed."),n.info("Backfill any missing git tags so already-published detection works.")):(n.info("Migration is per-package opt-in (RFC §17.1). For each package you want to migrate:"),n.info(' 1. Add to its package.json: "vis-release": { "managed": true } (or re-run with `--packages <a,b>`)'),n.info(" 2. Backfill any missing git tags so already-published detection works."),n.info(" 3. Add to multi-semantic-release's --ignore-packages list in your release workflow."),n.info(""),n.info("Existing .releaserc.json files are kept in place during transition."),n.info("Once every package is migrated, re-run with `--apply --cutover` to delete them (Phase 6).")),!e){n.info(`Re-run with \`--apply${t?" --cutover --yes":""}\` to perform the writes automatically.`);return}n.info(""),n.info("Migration writes complete. Follow-up steps you still need to do manually:"),n.info(" - Update your CI workflow: remove `multi-semantic-release` step, add `vis release ci/release` step (see `.github/workflows/vis-release.yml` example in the vis package)"),n.info(" - Run `pnpm install` to drop semantic-release deps once you remove them from root package.json"),n.info(" - Run `vis release doctor` to verify the migration")},ye=async(e,t)=>{let n=[],i=0;for(const a of t){const s=await ne(e,a);s&&(s.branches&&(n=[...n,...ie(s.branches)]),s.plugins?.some(l=>typeof l=="string"&&l.includes("native-addons"))&&(i+=1),s.plugins?.some(l=>Array.isArray(l)&&typeof l[0]=="string"&&l[0].includes("native-addons"))&&(i+=1))}const r=new Set,o=n.filter(a=>r.has(a.name)?!1:(r.add(a.name),!0));return{channels:o.length>0?ae(o):{alpha:{mode:"auto-publish",prerelease:"alpha",tag:"alpha"},main:{mode:"version-pr",tag:"latest"}},nativeAddonCount:i}},we=async(e,t,{apply:n,autoYes:i,cutover:r,dryRun:o,selection:a},s)=>{const l=await te(e,t);if(s.info(`Found ${l.length} .releaserc file(s).`),l.length===0)return;const{channels:c,nativeAddonCount:f}=await ye(e,l),d=se(c,r);s.info(""),s.info("Suggested vis.config.ts release block (paste into your existing config):"),s.info(""),s.info(d),s.info(""),f>0&&(s.info(`Found ${f} package(s) using a NAPI native-addons plugin.`),s.info("These will auto-detect via the `napi` field in package.json — no config needed."),s.info(""));const p=await ce(e,t,l,d,{cutover:r,selection:a});for(const k of p.warnings)s.warn(k);const w=he(p);if(o||!n){if(o&&(s.info("Planned writes:"),le(t,p,s)),w.length>0){s.warn("This cutover would be refused: the vis release config cannot be written, so the .releaserc.* deletions would strip the repo bare.");for(const k of w)s.warn(` ${h(t,k.path)} — ${k.reason}`)}O(!1,r,s);return}if(w.length>0){me(t,w,s),process.exitCode=1;return}const m=await pe(p,i,s);if(m!=="confirmed"){s.info(""),s.info("Cutover cancelled — no migration writes were made."),m==="refused"&&(process.exitCode=1);return}s.info("Applying migration writes (--apply set)…"),await de(e,t,p,s),O(!0,r,s)},ke=async(e,t)=>await g(e,u(t,".changeset"))?"changesets":await g(e,u(t,".bumpy"))?"bumpy":await ee(e,t)?"semantic-release":"fresh",ve=e=>{if(typeof e!="string")return;const t=e.split(",").map(n=>n.trim()).filter(n=>n.length>0);return t.length>0?t:void 0},ge=e=>new Set(e.split(/\r?\n/).map(t=>t.trim()).filter(t=>t.length>0)),M=async(e,t,n,i)=>{const{entries:r,header:o,label:a,path:s}=n,l=await b(e,s),c=l===void 0?void 0:ge(l),f=c===void 0?r:r.filter(d=>!c.has(d.trim()));if(f.length!==0){if(t){i.info(`[dry-run] would add to ${a}:
|
|
35
|
+
${f.map(d=>` ${d}`).join(`
|
|
36
|
+
`)}`);return}if(l===void 0){await v(e,s,`${o}
|
|
37
|
+
${f.join(`
|
|
38
|
+
`)}
|
|
39
|
+
`),i.info(`Created ${a}.`);return}await v(e,s,`${l.replace(/\n*$/,`
|
|
40
|
+
`)}
|
|
41
|
+
${o}
|
|
42
|
+
${f.join(`
|
|
43
|
+
`)}
|
|
44
|
+
`),i.info(`Updated ${a}.`)}},be=async(e,t,n,i)=>{const{upsertAgentSection:r}=await import("./agent-instructions.js"),o=u(t,"AGENTS.md");let a;try{a=await e.readFile(o,"utf8")}catch(c){if(!$(c))throw c;a=void 0}const{changed:s,content:l}=r(a);s?n?i.info(`[dry-run] would ${a?"update":"create"} AGENTS.md with the 'Releasing with vis' section`):(await v(e,o,l),i.info(`${a?"Updated":"Created"} AGENTS.md.`)):i.info("AGENTS.md already up to date.")},$e=e=>{e.info(""),e.info("Next steps:"),e.info(" 1. Add the `release: { ... }` block above to your vis.config.mjs"),e.info(" 2. Author your first change file: vis release add"),e.info(" 3. Preview the plan: vis release status"),e.info(" 4. Apply: vis release version --dry-run")},Fe=async({fs:e,logger:t,options:n,workspaceRoot:i})=>{const r=i??process.cwd(),o=n.dryRun===!0,a=n.cutover===!0,s=n.yes===!0,l=ve(n.packages);let c=n.apply===!0;o&&c&&(t.warn("--apply is ignored because --dry-run is set (dry-run takes precedence)."),c=!1),a&&l!==void 0&&t.warn("--packages is ignored because --cutover opts every detected package in.");let f;n.fromSemanticRelease?f="semantic-release":n.fromChangesets?f="changesets":n.fromBumpy?f="bumpy":n.fresh?f="fresh":f=await ke(e,r),t.info(`Detected source: ${f}`),(a||l!==void 0)&&f!=="semantic-release"&&t.warn("`--cutover` / `--packages` only affect the semantic-release migration path.");const d=o||f==="semantic-release"&&!c;d&&!o&&t.info("Preview only — a semantic-release migration writes nothing without `--apply`."),t.info("");const p=u(r,".vis","release");switch(d?t.info(`[dry-run] would create directory: ${p}`):(await e.mkdir(p,{recursive:!0}),t.info(`Created ${h(r,p)}/`)),await M(e,d,{entries:[".vis/release/.state.json",".vis/release/.lock"],header:"# vis release subsystem",label:".gitignore",path:u(r,".gitignore")},t),n.agent&&await be(e,r,d,t),await M(e,d,{entries:[".vis/release/**"],header:"# vis release change files (author handles false-positive secretlint)",label:".secretlintignore",path:u(r,".secretlintignore")},t),f){case"bumpy":{await xe(e,r,d,t);break}case"changesets":{await Se(e,r,d,t);break}case"semantic-release":{await we(e,r,{apply:c,autoYes:s,cutover:a,dryRun:d,selection:l},t);break}default:Ce(t)}await Re(e,r,d,s,t),await Ae(e,r,d,n,t),$e(t)},B=async(e,t,n,i,r)=>{const o=[];try{for(const c of await e.readdir(n))c.endsWith(".md")&&c!=="README.md"&&o.push(c)}catch(c){if(!$(c))throw c}const a=u(t,".vis","release");let s=0,l=0;for(const c of o){const f=u(n,c),d=u(a,c);if(i){r.info(`[dry-run] would copy ${f} → ${d}`);continue}if(await g(e,d)){r.info(`Skipping existing ${h(t,d)}.`),l+=1;continue}await v(e,d,await e.readFile(f,"utf8")),s+=1}return l>0&&r.info(`Skipped ${l} file(s) that already exist in .vis/release/.`),{found:o.length,preserved:s}},Se=async(e,t,n,i)=>{const r=u(t,".changeset"),o=u(r,"config.json");if(await g(e,u(r,"pre.json"))){i.error("Pre-release mode is active in changesets (.changeset/pre.json exists)."),i.error("Run `changeset pre exit && changeset version` to consume pending changes, then re-run `vis release init`."),process.exitCode=1;return}let a={};try{a=JSON.parse(await e.readFile(o,"utf8"))}catch{i.warn(".changeset/config.json missing or unreadable; using defaults.")}const s={access:a.access==="restricted"?"restricted":"public",baseBranch:typeof a.baseBranch=="string"?a.baseBranch:"main",defaultManaged:!0,fixed:Array.isArray(a.fixed)?a.fixed:[],ignore:Array.isArray(a.ignore)?a.ignore:[],linked:Array.isArray(a.linked)?a.linked:[],privatePackages:a.privatePackages??{tag:!1,version:!1},updateInternalDependencies:a.updateInternalDependencies??"out-of-range"},l=a.changelog,c=typeof l=="string"?l:Array.isArray(l)&&typeof l[0]=="string"?l[0]:void 0;let f;l===!1?f="false":c?.includes("@changesets/changelog-github")?f='"github"':(c?.includes("@changesets/cli"),f='"default"');const{found:d,preserved:p}=await B(e,t,r,n,i);i.info(`Found ${d} pending .changeset/*.md file(s); ${p>0?`copied ${p} to .vis/release/`:"(dry-run — would copy)"}.`),i.info(""),i.info("Suggested vis.config.ts release block:"),i.info(""),i.info(` release: {
|
|
45
|
+
baseBranch: ${JSON.stringify(s.baseBranch)},
|
|
46
|
+
access: ${JSON.stringify(s.access)},
|
|
47
|
+
defaultManaged: ${s.defaultManaged},
|
|
48
|
+
updateInternalDependencies: ${JSON.stringify(s.updateInternalDependencies)},
|
|
49
|
+
fixed: ${JSON.stringify(s.fixed)},
|
|
50
|
+
linked: ${JSON.stringify(s.linked)},
|
|
51
|
+
ignore: ${JSON.stringify(s.ignore)},
|
|
52
|
+
privatePackages: ${JSON.stringify(s.privatePackages)},
|
|
53
|
+
changelog: ${f},
|
|
54
|
+
publish: {
|
|
55
|
+
packManager: "auto",
|
|
56
|
+
publishStrategy: "npm-publish-tarball",
|
|
57
|
+
cleanPackageJson: true,
|
|
58
|
+
},
|
|
59
|
+
},`),i.info(""),i.info("After confirming the config, you can delete `.changeset/` (or run `vis release init --remove-changesets`).")},xe=async(e,t,n,i)=>{const r=u(t,".bumpy"),o=u(r,"_config.json");let a={};try{a=JSON.parse(await e.readFile(o,"utf8"))}catch{i.warn(".bumpy/_config.json missing or unreadable; using defaults.")}const s=JSON.stringify(a,null,4).split(`
|
|
60
|
+
`).map(f=>` ${f}`).join(`
|
|
61
|
+
`),{found:l,preserved:c}=await B(e,t,r,n,i);i.info(`Found ${l} pending .bumpy/*.md file(s); ${c>0?`copied ${c} to .vis/release/`:"(dry-run)"}.`),i.info(""),i.info("Suggested vis.config.ts release block (bumpy config translates 1:1):"),i.info(""),i.info(` release: ${s.trimStart()},`),i.info(""),i.info("After confirming, delete `.bumpy/`.")},Re=async(e,t,n,i,r)=>{const o=u(t,".husky","pre-commit");if(!await g(e,o))return;const a=await b(e,o)??"";if(a.includes("vis release check"))return;const s="vis release check --hook pre-commit --no-fail";if(!await(async()=>{if(!process.stdout.isTTY||process.env.CI==="true")return!1;if(i)return!0;try{const{confirmPrompt:c}=await import("./prompts.js");return await c(`Wire \`${s}\` into your .husky/pre-commit hook?`,!0)}catch{return!1}})()){r.info(""),r.info("Optional: add this line to .husky/pre-commit:"),r.info(` ${s}`);return}if(n){r.info(`[dry-run] would append \`${s}\` to .husky/pre-commit`);return}await v(e,o,`${a.replace(/\n*$/,`
|
|
62
|
+
`)}${s}
|
|
63
|
+
`),r.info("Wired vis release check into .husky/pre-commit.")},Ae=async(e,t,n,i,r)=>{const o=i.workflows===!0,a=i.yes===!0;if(!o&&(!process.stdout.isTTY||process.env.CI==="true"))return;if(!(o||a||await(async()=>{try{const{confirmPrompt:y}=await import("./prompts.js");return await y("Generate CI workflow files for the active provider?",!0)}catch{return!1}})())){r.info(""),r.info("Skipped workflow generation. Re-run with `vis release init --workflows` later.");return}const{detectRemoteProvider:l}=await import("./detect.js"),{generateWorkflowFiles:c}=await import("./workflow-templates.js"),{detectPackageManager:f}=await import("../packem_shared/createAdapter-F7GidOzU.js"),{createShellRunner:d}=await import("./shell-runner.js"),p=d(),w=await l(t,p,void 0),m=await f(t,p),A=i.packageManager??m;let x={};try{const{loadVisConfig:y}=await import("./CONFIG_FILES.js"),S=await y(t);S.release&&(x=S.release)}catch{}const C=c(x,{packageManager:A,provider:w});r.info(""),r.info(`Generating ${C.length} workflow file(s) for ${w}:`);for(const y of C){const S=u(t,y.path);if(await g(e,S)){r.warn(` ${y.path} — already exists, skipping`);continue}if(n){r.info(` ${y.path} — [dry-run] would write ${y.content.length} bytes`);continue}await e.mkdir(_(S),{recursive:!0}),await v(e,S,y.content),r.info(` ${y.path} — wrote ${y.content.length} bytes`)}},Ce=e=>{e.info(""),e.info("Suggested vis.config.ts release block:"),e.info(""),e.info(` release: {
|
|
64
|
+
baseBranch: "main",
|
|
65
|
+
defaultManaged: true,
|
|
66
|
+
channels: {
|
|
67
|
+
main: { tag: "latest", mode: "version-pr" },
|
|
68
|
+
},
|
|
69
|
+
publish: {
|
|
70
|
+
packManager: "auto",
|
|
71
|
+
publishStrategy: "npm-publish-tarball",
|
|
72
|
+
publishArgs: ["--provenance"],
|
|
73
|
+
cleanPackageJson: true,
|
|
74
|
+
},
|
|
75
|
+
},`)};export{Fe as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as q,b as J,p as f,O as G,c as T,d as O}from"./cli-main.js";import{l as H,r as K,t as m,c as Q,k as W,R as c,E as X,m as y,n as P,o as Z,s as _}from"./catalog.js";import{i as ee}from"../packem_shared/index-BjdW45xX.js";import{v as te,r as se,f as re}from"../packem_shared/ai-analysis-DSQQDFU9.js";import{V as ae}from"../packem_shared/vis-user-error-
|
|
1
|
+
import{a as q,b as J,p as f,O as G,c as T,d as O}from"./cli-main.js";import{l as H,r as K,t as m,c as Q,k as W,R as c,E as X,m as y,n as P,o as Z,s as _}from"./catalog.js";import{i as ee}from"../packem_shared/index-BjdW45xX.js";import{v as te,r as se,f as re}from"../packem_shared/ai-analysis-DSQQDFU9.js";import{V as ae}from"../packem_shared/vis-user-error-CEc_asoq.js";import{d as ne}from"../packem_shared/pm-runner-d93_73O6.js";import{s as oe}from"../packem_shared/formatBytes-BHAzNIrn-Bkk_uRS-.js";import{U as ce,V as ie,C as j}from"../packem_shared/vis-update-app-DNeU8RBQ.js";const we=async({argument:$,logger:s,options:e,visConfig:o,workspaceRoot:C})=>{if(!C)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const d=C;if(e.sync&&!e.securityConfig)throw new ae("--sync requires --security-config. Run `vis check --security-config --sync`.");if(e.securityConfig){const t=ne(d);if(q(o??{},t.name),e.sync&&t.name==="pnpm"){const r=J(o??{});if(r.length>0){f.info(`
|
|
2
2
|
Settings that would sync to pnpm-workspace.yaml:`);for(const S of r)f.success(` ${S}`)}else f.info("No security settings to sync.")}else e.sync&&t.name!=="pnpm"&&(f.info(`--sync is only available for pnpm projects. Your project uses ${t.name}.`),f.info("vis enforces security settings at the vis layer for non-pnpm projects."));if(!e.security&&!$?.length)return}const{packageManager:N}=G(d),U=H(d),i=o?.update??{},h=K(d,N,{dev:e.dev,includeInternal:e["include-internal"],peer:e.peer,prod:e.prod});if(h.size===0){s.info("No catalogs found.");return}const k=e.target??i.target??"latest";if(!["latest","minor","patch"].includes(k))throw new Error(`Invalid target "${k}". Use: latest, minor, or patch.`);const D={exclude:[...m(e.exclude),...m(i.exclude)],ignore:m(i.ignore),include:[...m(e.include),...m(i.include),...$],includeLocked:!!e.includeLocked,includePrerelease:e.prerelease||i.prerelease||!1,security:e.security!==!1,target:k};let x=0;for(const t of h.values())x+=t.size;const w=!!process.stdout.isTTY&&!ee;let l;const I=w?(t,r)=>{l?l.rerender(c.createElement(j,{current:t,total:r})):l=O(c.createElement(j,{current:t,total:r}),{interactive:!0,patchConsole:!1})}:(t,r)=>{s.info(`Checking ${String(t)}/${String(r)} dependencies...`)};w||s.info(`Checking ${String(x)} catalog dependencies against npm registry...
|
|
3
3
|
`);const g=new Set;T("socket")&&g.add("socket"),T("depsDev")&&g.add("deps-dev");const v=o?.security?.policies?.score?.minimum,M=Q(o?.security,{disabled:g,minimumScore:v}),{failed:E,outdated:n}=await W(h,D,U,I,d,M,o?.security?.acceptedRisks);if(l&&(l.clear(),l.unmount()),E.length>0&&s.warn(`Failed to fetch: ${E.join(", ")}`),n.length===0){s.info("All catalog dependencies are up to date.");return}const R=e.format??i.format??"table",V=te(e.aiType??"impact"),u=e.ai?await se(n,s,o?.ai,V):void 0;if(w&&R==="table"){const t=new ce(n,u??null),r=o?.tui?.autoExit??!1,S=r===!0?3:typeof r=="number"?r:0;await O(c.createElement(ie,{autoExitSeconds:S,isDryRun:!0,store:t}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit();const B=process.stdout.columns||80;process.stdout.write(`
|
|
4
4
|
`);for(const a of n){const Y=a.vulnerabilities?.length||a.socketReport&&a.socketReport.alerts.length>0,b=!!a.acceptedRisk,z=Y?b?"✓":"⚠":"✓",F=b?"gray":a.updateType==="major"?"red":a.updateType==="minor"?"yellow":"green",p=a.socketReport?.score.overall,L=p===void 0?"":` [${String(Math.round(p*100))}%]`,A=p===void 0?void 0:oe(p);process.stdout.write(`${X(c.createElement(y,null," ",c.createElement(y,{color:F},z),` ${a.packageName} ${a.currentRange} → ${a.newRange}`,c.createElement(y,{dimColor:!0},` ${a.updateType}`),A?c.createElement(y,{color:A},L):null),{columns:B})}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import{createRequire as
|
|
2
|
-
`)
|
|
3
|
-
`)
|
|
1
|
+
import{createRequire as K}from"node:module";import{j as g,F as m,q as v,J as N,X as P,b as j}from"../packem_shared/index.server-sXNQYpsl.js";import{e as h,v as U}from"../packem_shared/index-DHD8wb6Z.js";import{d as F,b as Y}from"./catalog.js";import{d as J}from"../packem_shared/lockfile-DVFySxTS.js";import{p as z,s as X}from"../packem_shared/docker-Dy-X_BuM.js";import{i as ne}from"../packem_shared/index-BjdW45xX.js";import{g as B}from"../packem_shared/formatBytes-BHAzNIrn-Bkk_uRS-.js";import{h as oe}from"../packem_shared/writeFileSync-DJoHk3Ks-CgQ-VNNT.js";import{y as re}from"../packem_shared/isAccessibleSync-DYKTrrvc-CSnBISfV.js";let G;const W=e=>(G??=K(import.meta.url))(e),b=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=e=>{if(typeof b<"u"&&b.versions&&b.versions.node){const[t,n]=b.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return b.getBuiltinModule(e)}return W(e)},{createInterface:O}=y("node:readline"),{spawn:Q}=y("node:child_process"),{createHash:Z}=y("node:crypto"),{existsSync:I,writeFileSync:ee,chmodSync:te}=y("node:fs"),S={aube:{base:["RUN corepack enable"],build:e=>e?`RUN aube run --filter ${e} build`:"RUN aube run build",install:"RUN aube install --frozen-lockfile"},bun:{base:["RUN npm install -g bun"],build:e=>e?`RUN bun run --filter ${e} build`:"RUN bun run build",install:"RUN --mount=type=cache,target=/root/.bun/install/cache bun install --frozen-lockfile"},npm:{base:[],build:e=>e?`RUN npm run build --workspace ${e}`:"RUN npm run build",install:"RUN --mount=type=cache,target=/root/.npm npm ci"},pnpm:{base:["ENV PNPM_HOME=/pnpm","ENV PATH=$PNPM_HOME:$PATH","RUN corepack enable"],build:e=>e?`RUN pnpm --filter ${e} build`:"RUN pnpm build",install:"RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile"},yarn:{base:["RUN corepack enable"],build:e=>e?`RUN yarn workspace ${e} build`:"RUN yarn build",install:"RUN --mount=type=cache,target=/usr/local/share/.cache/yarn yarn install --immutable"}},se=e=>{const{focus:t,manager:n,nodeVersion:r}=e,o=S[n]??S.npm;return["# syntax=docker/dockerfile:1","","# Generated by 'vis docker init'. Before building, scaffold the context:",`# vis docker scaffold${t?` --focus=${t}`:""} --include-sources`,"# then build with BuildKit enabled (DOCKER_BUILDKIT=1).","",`FROM node:${r}-slim AS base`,"WORKDIR /app",...o.base,"","# --- install dependencies from the scaffolded manifests only ---","FROM base AS deps","COPY .vis/docker/workspace/ ./",o.install,"","# --- build the focus project, then drop unfocused workspace projects ---","FROM deps AS build","COPY .vis/docker/sources/ ./",o.build(t),"RUN npx vis docker prune --context=.vis/docker","","# --- minimal runtime image ---",`FROM node:${r}-slim AS runtime`,"WORKDIR /app","ENV NODE_ENV=production","COPY --from=build /app ./","USER node","# TODO: point this at your app's entrypoint",'CMD ["node", "index.js"]',""].join(`
|
|
2
|
+
`)},$="v2.14.0",D=`https://github.com/hadolint/hadolint/releases/download/${$}`,ie={"hadolint-linux-arm64":"331f1d3511b84a4f1e3d18d52fec284723e4019552f4f47b19322a53ce9a40ed","hadolint-linux-x86_64":"6bf226944684f56c84dd014e8b979d27425c0148f61b3bd99bcc6f39e9dc5a47","hadolint-macos-arm64":"3625e2e9f43dcfe7bd38738a5f5520ed50ce39ed28485266e6803dd7bc197b10","hadolint-macos-x86_64":"2b69a853433f1eca522ffb921cd490bd1321424d03331fd8390f93b7fb4a02e9","hadolint-windows-x86_64.exe":"8e0ee174f88edb14f207a68430c7a53c2883ed509cdbde9a3a26fffa140fa5e4"},ae=e=>ie[e],ce=(e=process.platform,t=process.arch)=>{const n=e==="darwin"?"macos":e==="linux"?"linux":e==="win32"?"windows":void 0;if(n===void 0)return;const r=t==="arm64"?"arm64":t==="x64"?"x86_64":void 0;if(n==="windows")return"hadolint-windows-x86_64.exe";if(r!==void 0)return`hadolint-${n}-${r}`},L=e=>h(B(),"hadolint",$,e.endsWith(".exe")?"hadolint.exe":"hadolint"),le=()=>{const e=process.platform==="win32"?"hadolint.exe":"hadolint",t=(process.env.PATH??"").split(process.platform==="win32"?";":":");for(const n of t)if(n!==""&&I(h(n,e)))return e},de=e=>e.trim().split(/\s+/u)[0]??"",E=async e=>{const t=await fetch(e,{redirect:"follow"});if(!t.ok)throw new Error(`download failed (${String(t.status)} ${t.statusText}) for ${e}`);return Buffer.from(await t.arrayBuffer())},ue=async e=>{const t=L(e),n=ae(e),r=await E(`${D}/${e}`),o=Z("sha256").update(r).digest("hex");if(n===void 0){const s=await E(`${D}/${e}.sha256`),i=de(s.toString("utf8")).toLowerCase();if(i==="")throw new Error("hadolint checksum sidecar was empty or unparseable. Refusing to use the download.");if(i!==o)throw new Error(`hadolint checksum mismatch (expected ${i}, got ${o}). Refusing to use the download.`)}else if(n.toLowerCase()!==o)throw new Error(`hadolint checksum mismatch (expected ${n.toLowerCase()}, got ${o}). Refusing to use the download.`);return oe(h(B(),"hadolint",$)),ee(t,r),process.platform!=="win32"&&te(t,493),t},fe=async()=>{const e=O({input:process.stdin,output:process.stderr}),t=await new Promise(n=>{e.question(` Download hadolint ${v($)} now? ${m("[y/N]")} `,r=>{n(r.trim().toLowerCase())})});return e.close(),t==="y"||t==="yes"},pe=async e=>{const{autoInstall:t=!1,log:n}=e,r=le();if(r!==void 0)return r;const o=ce();if(o===void 0){n(`hadolint has no prebuilt binary for ${process.platform}/${process.arch}. Install it manually: https://github.com/hadolint/hadolint`);return}const s=L(o);if(I(s))return s;if(!t){if(!(!!process.stdin.isTTY&&!ne)){n(`hadolint is not installed. Re-run with ${g("--install")} (or install hadolint on PATH) to enable Dockerfile linting.`);return}if(n(`${g("hadolint")} is required to lint Dockerfiles but was not found on your PATH.`),!await fe()){n(`Skipped. Install it yourself or re-run with ${g("--install")}.`);return}}n(`Downloading hadolint ${$} (${o})…`);try{const i=await ue(o);return n(`Installed hadolint to ${m(i)}`),i}catch(i){n(`Failed to download hadolint: ${i.message}`);return}},_=async(e,t,n)=>{if(t.length===0)return[];const r=["--format","json","--no-fail",...n!==void 0&&n!==""?["--config",n]:[],...t],o=await new Promise((i,l)=>{const a=Q(e,r,{stdio:["ignore","pipe","pipe"],windowsHide:!0});let d="",u="";a.stdout?.on("data",c=>{d+=c.toString("utf8")}),a.stderr?.on("data",c=>{u+=c.toString("utf8")}),a.on("error",l),a.on("close",()=>{if(d.trim()===""&&u.trim()!==""){l(new Error(u.trim()));return}i(d)})});if(o.trim()==="")return[];let s;try{s=JSON.parse(o)}catch{throw new Error("Could not parse hadolint JSON output.")}return Array.isArray(s)?s:[]},C=(e,t,n)=>{if(!(!/\bapt-get\b/u.test(e)||!/\binstall\b/u.test(e)||n.test(e)))return e.replace(/\binstall\b/u,`install ${t}`)},k={DL3014:e=>C(e,"-y",/(?:^|\s)(?:-y|--yes|--assume-yes|-qq?)\b/u),DL3015:e=>C(e,"--no-install-recommends",/--no-install-recommends\b/u),DL3020:e=>/^\s*ADD\b/u.test(e)?e.replace(/^(\s*)ADD\b/u,"$1COPY"):void 0,DL3027:e=>/(?:^|\s)apt\s/u.test(e)&&!/\bapt-get\b/u.test(e)?e.replace(/(^|\s)apt(\s)/u,"$1apt-get$2"):void 0},T=new Set(Object.keys(k)),me=(e,t)=>{const n=e.includes(`\r
|
|
3
|
+
`)?`\r
|
|
4
|
+
`:`
|
|
5
|
+
`,r=e.split(/\r?\n/u),o=new Set;let s=0;const i=new Map;for(const l of t){if(!k[l.code])continue;const a=i.get(l.line)??[];a.push(l),i.set(l.line,a)}for(const[l,a]of i){const d=l-1;if(!(d<0||d>=r.length))for(const u of a){const c=k[u.code],f=c?.(r[d]??"");f!==void 0&&f!==r[d]&&(r[d]=f,o.add(u.code),s+=1)}}return{content:s>0?r.join(n):e,fixedCodes:[...o],fixedCount:s}},A={error:0,info:2,style:3,warning:1},he=(e,t)=>{switch(e){case"error":return P(t);case"info":return v(t);case"warning":return j(t);default:return m(t)}},we=(e,t)=>(e.length>0?e:["Dockerfile"]).map(r=>U(r)?r:h(t,r)).filter(r=>re(r)),be=(e,t)=>{const n=[...e].sort((o,s)=>o.file.localeCompare(s.file)||o.line-s.line||o.column-s.column||A[o.level]-A[s.level]);let r="";for(const o of n){o.file!==r&&(r=o.file,t.info(`
|
|
6
|
+
${g(r)}`));const s=m(`${String(o.line)}:${String(o.column)}`),i=he(o.level,o.level.padEnd(7)),l=T.has(o.code)?m(" (fixable)"):"";t.info(` ${s} ${i} ${v(o.code)} ${o.message}${l}`)}},ge=e=>{const t={error:0,info:0,style:0,warning:0};for(const n of e)t[n.level]+=1;return t},$e=async e=>{const{autoInstall:t,configPath:n,cwd:r,files:o,fix:s,fs:i,json:l,logger:a}=e,d=we(o,r);if(d.length===0)return a.error(`No Dockerfile found${o.length>0?` at: ${o.join(", ")}`:` in ${r}`}. Pass a path: vis docker lint <path>`),1;const u=await pe({autoInstall:t,log:p=>{a.info(p)}});if(u===void 0)return 0;let c=await _(u,d,n),f=0;if(s&&c.length>0){for(const p of d){const H=c.filter(V=>V.file===p),q=await i.readFile(p,"utf8"),x=me(q,H);x.fixedCount>0&&(await i.writeFile(p,x.content),f+=x.fixedCount)}f>0&&(c=await _(u,d,n))}if(l)return process.stdout.write(`${JSON.stringify({findings:c,fixed:f},null,2)}
|
|
7
|
+
`),c.some(p=>p.level==="error")?1:0;if(s&&f>0&&a.info(N(`✔ Auto-fixed ${String(f)} issue${f===1?"":"s"}.`)),c.length===0)return a.info(N("✔ No Dockerfile issues found.")),0;be(c,a);const w=ge(c),R=c.filter(p=>T.has(p.code)).length;return a.info(`
|
|
8
|
+
${g(String(c.length))} issue${c.length===1?"":"s"}: ${P(`${String(w.error)} error`)}, ${j(`${String(w.warning)} warning`)}, ${v(`${String(w.info)} info`)}, ${m(`${String(w.style)} style`)}`),!s&&R>0&&a.info(m(`Run 'vis docker lint --fix' to auto-fix ${String(R)} of them.`)),w.error>0?1:0},M=e=>{if(!e)throw new Error("Could not determine workspace root. Run inside a monorepo.");return e},Oe=async({logger:e,options:t,visConfig:n,workspaceRoot:r})=>{const o=M(r),{packageJsons:s,workspace:i}=F(o,n),l=Y(o,i,s),a=(t.focus??"").split(",").map(c=>c.trim()).filter(Boolean);if(a.length===0)throw new Error("Missing --focus. Pass one or more project names, comma-separated.");const d=h(o,t.out??".vis/docker"),{projects:u}=X({focus:a,includeSources:!!t.includeSources,log:c=>{e.info(c)},outDir:d,projectGraph:l,pruneLockfile:t.pruneLockfile,workspace:i,workspaceRoot:o});e.info(`Scaffolded ${u.length} project(s) into ${d}`),e.info(`Focus closure: ${u.toSorted().join(", ")}`)},Pe=async({logger:e,options:t,visConfig:n,workspaceRoot:r})=>{const o=M(r),{workspace:s}=F(o,n),i=h(o,t.context??".vis/docker"),{removed:l}=z({contextRoot:i,workspace:s,workspaceRoot:o});e.info(`Pruned ${l.length} unfocused project(s)`),l.length>0&&e.debug?.(l.join(`
|
|
9
|
+
`))},je=async({argument:e,fs:t,logger:n,options:r,process:o,workspaceRoot:s})=>{const i=await $e({autoInstall:!!r.install,configPath:r.config,cwd:s??o.cwd,files:e.filter(Boolean),fix:!!r.fix,fs:t,json:!!r.json,logger:n});i!==0&&(process.exitCode=i)},ye=async(e,t)=>{try{return await e.access(t),!0}catch{return!1}},ve=async e=>{const t=O({input:process.stdin,output:process.stderr}),n=await new Promise(r=>{t.question(` ${e} already exists. Overwrite? ${m("[y/N]")} `,o=>{r(o.trim().toLowerCase())})});return t.close(),n==="y"||n==="yes"},Ue=async({argument:e,fs:t,logger:n,options:r,process:o,workspaceRoot:s})=>{const i=s??o.cwd,l=e[0]??"Dockerfile",a=U(l)?l:h(i,l),d=J(i)?.manager??"npm",u=(r.focus??"").split(",").map(f=>f.trim()).find(Boolean),c=se({focus:u,manager:d,nodeVersion:r.node??"22"});if(r.dryRun){process.stdout.write(c.endsWith(`
|
|
10
|
+
`)?c:`${c}
|
|
11
|
+
`);return}if(await ye(t,a)&&!r.force){if(!!!process.stdin.isTTY){n.error(`${a} already exists. Re-run with --force to overwrite.`),process.exitCode=1;return}if(!await ve(a)){n.info("Aborted — existing Dockerfile left untouched.");return}}await t.writeFile(a,c),n.info(`Created ${a} (package manager: ${d}).`),n.info(m(`Next: vis docker scaffold${u?` --focus=${u}`:""} --include-sources, then DOCKER_BUILDKIT=1 docker build .`))};export{Ue as initExecute,je as lintExecute,Pe as pruneExecute,Oe as scaffoldExecute};
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import{createRequire as
|
|
2
|
-
`);
|
|
3
|
-
`)}
|
|
4
|
-
${d(`Enter choice (1-${String(r.length)}):`)} `);if(s===""&&n!==void 0)return n;const i=Number.parseInt(s,10);if(Number.isInteger(i)&&i>=1&&i<=r.length)return r[i-1];const a=r.find(c=>c===s);if(a)return a;process.stderr.write(` ${d("Invalid choice. Try again.")}
|
|
5
|
-
`)}},Ee=async(t,e,r,n)=>{process.stderr.write(` ${e} ${d("(comma-separated numbers)")}
|
|
6
|
-
`);for(const[s,i]of r.entries()){const a=y(v(` ${String(s+1)}.`)),c=n.includes(i)?d(" (default)"):"";process.stderr.write(`${a} ${i}${c}
|
|
7
|
-
`)}for(;;){const s=await q(t,`
|
|
8
|
-
${d("Enter choices:")} `);if(s===""&&n.length>0)return n;const i=s.split(",").map(a=>Number.parseInt(a.trim(),10)).filter(a=>Number.isInteger(a)&&a>=1&&a<=r.length);if(i.length>0)return i.map(a=>r[a-1]);process.stderr.write(` ${d("Invalid choice. Try again.")}
|
|
9
|
-
`)}},xe=t=>` ${d(`${t}:`)} `,Ne=(t,e)=>e.prompt??t,Oe=t=>Object.entries(t).sort(([e,r],[n,s])=>{const i=r.order??0,a=s.order??0;return i!==a?i-a:e.localeCompare(n)}),V=(t,e)=>{switch(t.type){case"array":return e.split(",").map(r=>r.trim()).filter(Boolean);case"boolean":return e==="true"||e==="1"||e==="yes"||e==="y";case"enum":return t.multiple?e.split(",").map(r=>r.trim()).filter(Boolean):e;case"number":{const r=Number(e);if(Number.isNaN(r))throw new TypeError(`Expected a number, got "${e}"`);return r}default:return e}},W=(t,e,r)=>{if(e.type==="enum"){const n=Array.isArray(r)?r:[r];for(const s of n)if(typeof s!="string"||!e.values.includes(s))throw new Error(`Variable "${t}" must be one of: ${e.values.join(", ")} (got "${String(s)}")`)}},_e=async t=>{const{defaults:e,interactive:r,overrides:n,variables:s}=t,i={},a=r?ce({input:process.stdin,output:process.stderr}):null;try{for(const[c,o]of Oe(s)){if(Object.hasOwn(n,c)){const m=V(o,n[c]??"");W(c,o,m),i[c]=m;continue}if(e||!r||o.internal){if(o.default!==void 0){W(c,o,o.default),i[c]=o.default;continue}if(o.required)throw new Error(`Required variable "${c}" not provided. Pass --${c}=<value> or remove --defaults.`);continue}const l=Ne(c,o);let u;if(o.type==="boolean")u=await Te(a,l,!!(o.default??!1));else if(o.type==="enum")if(o.multiple){const m=Array.isArray(o.default)?o.default:[];u=await Ee(a,l,o.values,m)}else{const m=typeof o.default=="string"?o.default:void 0;u=await Se(a,l,o.values,m)}else{const m=o.default===void 0?"":` (${String(o.default)})`,T=await q(a,xe(`${l}${m}`));if(T===""&&o.default!==void 0)u=o.default;else if(T===""){if(o.required)throw new Error(`Variable "${c}" is required`);continue}else u=V(o,T)}W(c,o,u),i[c]=u}return i}finally{a?.close()}},Be=["git://","npm://","https://","github:","gitlab:","bitbucket:","sourcehut:"],ke=t=>Be.some(e=>t.startsWith(e)),De=async(t,e={})=>{const r=e.targetDirectory===void 0,n=e.targetDirectory??le(S(ue(),"vis-generate-")),s=()=>{if(r)try{fe(n,{force:!0,recursive:!0})}catch{}};f.info(`Downloading ${t}…`);try{const i=await de(t,{auth:e.auth||process.env.GIGET_AUTH||process.env.GITHUB_TOKEN||process.env.GH_TOKEN||void 0,dir:n,force:!0,preferOffline:e.preferOffline});return{cleanup:s,directory:i.dir}}catch(i){s();const a=i instanceof Error?i.message:String(i);throw f.warn(`Failed to download template: ${a}`),i}},Y=(t,e="")=>{const r=[];for(const[n,s]of Object.entries(t)){const i=e?`${e}/${n}`:n;typeof s=="string"||Buffer.isBuffer(s)?r.push({content:s,path:i}):s&&typeof s=="object"&&r.push(...Y(s,i))}return r},je=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`,Ie=(t,e)=>{if(F(e))throw new Error(`Refusing to write outside destination: template produced absolute path "${e}".`);const r=S(t,e),n=G(t,r);if(n===".."||n.startsWith(`..${oe}`)||F(n))throw new Error(`Refusing to write outside destination: "${e}" resolves to "${r}" which escapes "${t}".`);return r},Re=(t,e)=>{J(K(t)),me(t,e)},qe=(t,e,r=!1)=>{const n=typeof t=="string"?[t]:t.commands,s=typeof t=="string"?r:t.silent??r;for(const i of n){s||f.info(`$ ${i}`);const a=pe(i,{cwd:e,shell:!0,stdio:s?"ignore":"inherit"});if(a.status!==0)return f.warn(`Script failed (exit ${String(a.status)}): ${i}`),!1}return!0},Le=t=>{const e=new Map;for(const r of t){const n=typeof r=="string"?0:r.phase??0,s=e.get(n);s?s.push(r):e.set(n,[r])}return[...e.entries()].sort(([r],[n])=>r-n)},We=async(t,e)=>{const n={builtins:{dest_dir:e.destination,dest_rel_dir:G(e.workspaceRoot,e.destination)||".",working_dir:e.cwd,workspace_root:e.workspaceRoot},options:e.options},s=await t.produce(n),i=s.files?Y(s.files):[],a=s.filesMeta??{},c=[];for(const o of i){const l=Ie(e.destination,o.path);c.push({file:o,meta:a[o.path]??{},target:l})}if(e.dryRun){f.info(`${y(v("Plan"))} ${d("(dry-run, no files written)")}`);for(const o of c){const l=Buffer.isBuffer(o.file.content)?o.file.content.length:Buffer.byteLength(o.file.content,"utf8");process.stderr.write(` ${d("write")} ${o.file.path} ${d(`(${je(l)})`)}
|
|
10
|
-
`)}}else{J(e.destination);let o=0,l=0;for(const u of c){const{file:m,meta:T,target:k}=u,b=_(k),E=e.force||T.force===!0;if(b&&!E){f.warn(`Skipped existing file: ${m.path} (use --force or set frontmatter force: true to overwrite)`),l+=1;continue}Re(k,m.content),o+=1}f.success(`Wrote ${String(o)} file${o===1?"":"s"}${l>0?`, skipped ${String(l)}`:""}`)}if(!e.dryRun&&!e.skipScripts&&s.scripts&&s.scripts.length>0){const o=Le(s.scripts);f.info(`Running ${String(s.scripts.length)} script${s.scripts.length===1?"":"s"} across ${String(o.length)} phase${o.length===1?"":"s"}…`);for(const[,l]of o)if((await Promise.all(l.map(m=>Promise.resolve(qe(m,e.destination))))).includes(!1))throw new Error("Script failed — aborting.")}if(s.suggestions&&s.suggestions.length>0){process.stderr.write(`
|
|
11
|
-
`),f.notice("Next steps:");for(const o of s.suggestions)process.stderr.write(` ${d("•")} ${o}
|
|
12
|
-
`)}},Fe=async t=>{let e;try{e=(await t.load()).about?.description}catch{}return{description:e,name:t.name,path:t.path,source:t.source}},Me=(t,e)=>{const r={default:e.default,name:t,order:e.order,prompt:e.prompt,required:e.required,type:e.type};return e.type==="enum"&&(r.multiple=e.multiple,r.values=e.values),r},Ae=async t=>{const e=await t.load(),r=Object.entries(e.options??{}).sort(([n,s],[i,a])=>{const c=s.order??0,o=a.order??0;return c===o?n.localeCompare(i):c-o}).map(([n,s])=>Me(n,s));return{description:e.about?.description??"",destination:e.destination,name:t.name,path:t.path,source:t.source,variables:r}},Pe=t=>{if(t.length===0){f.info("No templates found."),f.notice("Create one at .vis/templates/<name>.ts (programmatic) or .vis/templates/<name>/ (moon-format with template.yml).");return}f.info("Available templates:");for(const e of t){const r=d(`(${e.source})`);process.stderr.write(` ${y(v(e.name))} ${r}
|
|
13
|
-
`)}},Ce=(t,e)=>{const r={},n=[];for(let s=0;s<t.length;s++){const i=t[s];if(!i.startsWith("--")){n.push(i);continue}const a=i.indexOf("=");if(a===-1){const l=i.slice(2);if(l.startsWith("no-"))r[l.slice(3)]="false";else{r[l]="true";const u=t[s+1];u!==void 0&&!u.startsWith("-")&&e?.(`\`--${l} ${u}\` was read as boolean \`--${l}=true\` and \`${u}\` was ignored. For a string value use \`--${l}=${u}\`.`)}continue}const c=i.slice(2,a),o=i.slice(a+1);r[c]=o}return{overrides:r,remaining:n}},Ue=async t=>{const{createInterface:e}=await import("node:readline"),r=e({input:process.stdin,output:process.stderr});try{process.stderr.write(` ${y(v("vis generate"))} ${d("— pick a template")}
|
|
14
|
-
|
|
15
|
-
`);for(const[n,s]of t.entries()){const i=y(v(` ${String(n+1)}.`));process.stderr.write(`${i} ${s.name} ${d(`(${s.source})`)}
|
|
16
|
-
`)}return new Promise((n,s)=>{r.question(`
|
|
17
|
-
${d(`Enter choice (1-${String(t.length)}):`)} `,i=>{const a=Number.parseInt(i.trim(),10);Number.isInteger(a)&&a>=1&&a<=t.length?n(t[a-1].name):s(new Error("Invalid choice."))})})}finally{r.close()}},Qe=async({argument:t,options:e,rawUnknown:r,visConfig:n,workspaceRoot:s})=>{const i=e.cwd||s||process.cwd(),a=s??i,c=n?.generator,o=Array.isArray(t)?t:t?[t]:[];if(e.list){const p=R({extraDirectories:c?.templates??[],onWarning:h=>{f.warn(h)},workspaceRoot:a});if(e.json){const h=await Promise.all(p.map(w=>Fe(w)));process.stdout.write(`${JSON.stringify(h,null,2)}
|
|
18
|
-
`);return}Pe(p);return}if(e.describe){const p=o[0];if(!p)throw new Error("`--describe` requires a template name. Run `vis generate --list` to see available templates.");const w=R({extraDirectories:c?.templates??[],onWarning:$=>{f.warn($)},workspaceRoot:a}).find($=>$.name===p);if(!w)throw new Error(`Template "${p}" not found. Run \`vis generate --list\` to see available templates.`);const g=await Ae(w);if(e.json){process.stdout.write(`${JSON.stringify(g,null,2)}
|
|
19
|
-
`);return}if(f.info(`Template: ${y(v(g.name))} ${d(`(${g.source})`)}`),g.description&&f.info(g.description),g.destination&&f.info(`Destination: ${d(g.destination)}`),g.variables.length===0)f.info("No variables.");else{f.info("Variables:");for(const $ of g.variables){const j=[$.type];$.required&&j.push("required"),$.default!==void 0&&j.push(`default=${JSON.stringify($.default)}`),$.values&&j.push(`values=${$.values.join("|")}`),process.stderr.write(` ${y(v($.name))} ${d(`(${j.join(", ")})`)}
|
|
20
|
-
`)}}return}let l=[...r??[]];if(l.length===0){const p=process.argv.slice(2),h=p.indexOf("--");h!==-1&&(l=p.slice(h+1))}const u=o.indexOf("--"),m=u===-1?[]:o.slice(u+1),T=u===-1?o:o.slice(0,u),{overrides:k}=Ce([...m,...l],p=>{f.warn(p)});let b,E,D;const N=T[0];let L;if(N&&ke(N)){const p=await De(N,{auth:c?.auth,preferOffline:!!e.preferOffline||c?.preferOffline});L=p.cleanup;try{const w=R({extraDirectories:[p.directory],workspaceRoot:a}).find(g=>g.path.startsWith(p.directory));if(!w)throw new Error(`Downloaded template at ${p.directory} contains no template.yml or *.ts entrypoint.`);b=await w.load(),E=w.name,D=b.destination}catch(h){throw L(),h}}else{const p=R({extraDirectories:c?.templates??[],onWarning:g=>{f.warn(g)},workspaceRoot:a});if(p.length===0)throw new Error("No templates found. Create one at .vis/templates/<name>.ts or .vis/templates/<name>/template.yml.");let h;if(N)h=N;else{if(e.interactive===!1||!process.stdin.isTTY)throw new Error("No template specified. Pass a template name (see `vis generate --list`) or run interactively in a terminal.");h=await Ue(p)}const w=p.find(g=>g.name===h);if(!w)throw new Error(`Template "${h}" not found. Run 'vis generate --list' to see available templates.`);b=await w.load(),E=w.name,D=b.destination}const M=e.to,A=!!e.dryRun,Q=!!e.force,P=!!e.defaults,Z=!!e.skipScripts,ee=e.interactive!==!1&&!!process.stdin.isTTY&&!P;let x;M?x=M:D?x=D:x=".";const C=F(x)?x:ie(i,x);f.info(`Template: ${y(v(E))}`),f.info(`Target: ${d(C)}`),process.stderr.write(`
|
|
21
|
-
`);const te=await _e({defaults:P,interactive:ee,overrides:k,variables:b.options??{}});try{await We(b,{cwd:i,destination:C,dryRun:A,force:Q,options:te,skipScripts:Z,workspaceRoot:a}),A||(process.stderr.write(`
|
|
22
|
-
`),f.success(`Template '${E}' applied.`))}finally{L?.()}};export{Qe as default};
|
|
1
|
+
import{createRequire as H}from"node:module";import{J as A,q as U,j as W,F as E}from"../packem_shared/index.server-sXNQYpsl.js";import{a as P}from"../packem_shared/index-DHD8wb6Z.js";import{Z as I}from"./cli-main.js";import{d as F,f as C,r as Z,a as Q,b as X,s as Y,c as ee,e as te,g as se,h as ie,i as ne,j as re,k as ae,l as oe,m as ce,n as de,o as fe,p as le,q as ue,t as pe}from"../packem_shared/watch-loop-COWvvSbR.js";import{T as h}from"./catalog.js";let J;const D=t=>(J??=H(import.meta.url))(t),k=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=t=>{if(typeof k<"u"&&k.versions&&k.versions.node){const[e,s]=k.versions.node.split(".").map(Number);if(e>22||e===22&&s>=3||e===20&&s>=16)return k.getBuiltinModule(t)}return D(t)},{createHash:_}=G("node:crypto"),ge=t=>t.startsWith("/")||/^[a-z]:[\\/]/i.test(t),q=(t,e)=>ge(e)?e:`${t}/${e}`,me={argsCheck:(t,e)=>O(t,e,"check"),argsFix:(t,e)=>O(t,e,"fix"),bin:()=>["pnpm","exec","dprint"],cacheKey:(t,e)=>{const s=["dprint",t.declaredVersion??"unknown",t.configFile??"no-config",e.quiet?"q":"",...e.extraArgs??[]];return _("sha256").update(s.join("|")).digest("hex").slice(0,16)},detect:(t,e)=>{const s=F(e,h.dprint.packageNames[0]),i=C(t,h.dprint.configFiles);if(!(!s&&!i))return{adapter:"dprint",configFile:i,declared:!!s,declaredVersion:s,root:t}},extensions:["cjs","css","cts","dockerfile","html","js","json","jsonc","jsx","md","mdx","mjs","mts","toml","ts","tsx","yaml","yml"],id:"dprint",kind:"fmt",parse:(t,e)=>{if(t.exitCode===0)return[];const s=[];for(const i of t.stdout.split(/\r?\n/)){const n=i.trim();!n||n.startsWith("[")||n.startsWith("Checked ")||n.startsWith("Error:")||s.push({adapter:"dprint",file:q(e.root,n),fixable:!0,message:"Code style issues would be auto-fixed",severity:"info"})}return s}},O=(t,e,s)=>{const i=s==="fix"?["fmt"]:["check","--list-different"];return e.extraArgs?.length&&i.push(...e.extraArgs),i.push(...t),i},he={argsCheck:(t,e)=>V(t,e,"check"),argsFix:(t,e)=>V(t,e,"fix"),bin:()=>["pnpm","exec","oxfmt"],cacheKey:(t,e)=>{const s=["oxfmt",t.declaredVersion??"unknown",t.configFile??"no-config",e.quiet?"q":"",...e.extraArgs??[]];return _("sha256").update(s.join("|")).digest("hex").slice(0,16)},detect:(t,e)=>{const s=F(e,h.oxfmt.packageNames[0]),i=C(t,h.oxfmt.configFiles);if(!(!s&&!i))return{adapter:"oxfmt",configFile:i,declared:!!s,declaredVersion:s,root:t}},extensions:["cjs","cts","js","json","jsonc","jsx","mjs","mts","ts","tsx"],id:"oxfmt",kind:"fmt",parse:(t,e)=>{if(t.exitCode===0)return[];const s=[];for(const i of t.stdout.split(/\r?\n/)){const n=i.trim();!n||n.startsWith("[")||s.push({adapter:"oxfmt",file:q(e.root,n),fixable:!0,message:"Code style issues would be auto-fixed",severity:"info"})}return s}},V=(t,e,s)=>{const i=s==="fix"?["--write"]:["--list-different"];return e.extraArgs?.length&&i.push(...e.extraArgs),i.push(...t),i},xe={argsCheck:(t,e)=>N(t,e,"check"),argsFix:(t,e)=>N(t,e,"fix"),bin:()=>["pnpm","exec","prettier"],cacheKey:(t,e)=>{const s=["prettier",t.declaredVersion??"unknown",t.configFile??"no-config",e.quiet?"q":"",...e.extraArgs??[]];return _("sha256").update(s.join("|")).digest("hex").slice(0,16)},detect:(t,e)=>{const s=F(e,h.prettier.packageNames[0]),i=C(t,h.prettier.configFiles);if(!(!s&&!i))return{adapter:"prettier",configFile:i,declared:!!s,declaredVersion:s,root:t}},extensions:["cjs","css","cts","html","js","json","jsx","less","md","mdx","mjs","mts","scss","ts","tsx","vue","yaml","yml"],id:"prettier",kind:"fmt",parse:(t,e)=>{if(t.exitCode===0)return[];const s=[];for(const i of t.stdout.split(/\r?\n/)){const n=i.trim();n&&(n.startsWith("[")||s.push({adapter:"prettier",file:q(e.root,n),fixable:!0,message:"Code style issues would be auto-fixed",severity:"info"}))}return s}},N=(t,e,s)=>{const i=s==="fix"?["--write"]:["--list-different"];return e.quiet&&i.push("--log-level","warn"),e.extraArgs?.length&&i.push(...e.extraArgs),i.push(...t),i},ke=[he,se,me,xe,ie,ne],Re=async({logger:t,options:e,visConfig:s,workspaceRoot:i})=>{const n=i??process.cwd(),p=s?.fmt,w=Z(ke,p?.order),L=Q(n,w),x=X(L,w,"fmt").filter(({adapter:l})=>p?.adapters?.[l.id]?.enabled!==!1);if(x.length===0){t.warn("vis fmt: no formatter detected in this workspace (looked for: oxfmt, biome, dprint, prettier, ruff, deno-fmt).");return}const R=l=>{const a=p?.adapters?.[l]?.extraArgs;return a&&a.length>0?[...a]:void 0},v={quiet:e.quiet??!1},$=we(e),b=e.check?"check":"fix";let c;if(e.staged){if(c=Y(n),c===void 0)t.warn("vis fmt: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(c.length===0){t.info(A("✓ fmt: no staged files"));return}}else if(typeof e.since=="string"&&e.since.length>0){if(c=ee(n,e.since),c===void 0)t.warn(`vis fmt: could not resolve --since ${e.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(c.length===0){t.info(A(`✓ fmt: no files changed since ${e.since}`));return}}const K=I(n,void 0,void 0,!0),y=e.format??"human";y==="human"&&e.output!==void 0&&t.warn("vis fmt: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const M=async l=>{const a=$.length>0?$:l,g=[];if(a){const r=re(a,x,p?.extensionOverrides);for(const{adapter:o,presence:d}of x){const f=r.get(o.id);if(!f||f.length===0)continue;const B=R(o.id),T={adapter:o,files:f,presence:d};B&&(T.options={...v,extraArgs:B}),g.push(T)}}else for(const{adapter:r,presence:o}of x){const d=R(r.id),f={adapter:r,files:["."],presence:o};d&&(f.options={...v,extraArgs:d}),g.push(f)}if(g.length===0)return;const z=await ae(g,v,b,{cacheRoot:K}),j=g.map((r,o)=>{const d=z[o],f=r.adapter.parse(d,r.presence);return{adapter:r.adapter,durationMs:d.durationMs,exitCode:d.exitCode,findings:f}}),u=oe(j.map(r=>({adapter:r.adapter.id,durationMs:r.durationMs,exitCode:r.exitCode,findingCount:r.findings.length,findings:r.findings}))),m=y==="human"?void 0:ce({cwd:n,target:e.output});try{switch(y){case"github":{m.write(le({runs:j.map(r=>({findings:r.findings})),workspaceRoot:n}));break}case"json":{m.write(`${JSON.stringify({findings:u.findings,mode:b,runs:u.runs},null,2)}
|
|
2
|
+
`);break}case"junit":{m.write(fe({runs:j.map(r=>({adapter:r.adapter.id,durationMs:r.durationMs,findings:r.findings})),workspaceRoot:n}));break}case"minimal":{je(u.findings,n,m);break}case"sarif":{m.write(de({runs:j.map(r=>({adapter:r.adapter.id,findings:r.findings,presence:g.find(o=>o.adapter.id===r.adapter.id)?.presence})),workspaceRoot:n}));break}default:be(u.findings,n,b,t)}}finally{m?.close()}const S=b==="fix"?u.hadProcessFailure?1:0:ue({...u,maxSeverity:u.findings.length>0?"error":void 0});S!==0&&(process.exitCode=S)};if(e.watch){const l=[...new Set(x.flatMap(({adapter:a})=>a.extensions))];await te({extensions:l,initialFiles:c,label:"fmt",log:a=>{t.info(a)},runCycle:M,workspaceRoot:n});return}await M(c)},we=t=>{const e=t;return[...e._??e.args??[]]},be=(t,e,s,i)=>{if(t.length===0){i.info(A(s==="fix"?"✓ fmt: nothing to change":"✓ fmt: all files already formatted"));return}const n=pe(t),p=s==="fix"?U(W("Formatted:")):W("Would change:");i.info(p);for(const w of n.keys())i.info(` ${E("·")} ${P(e,w)}`);s==="check"&&(i.info(""),i.info(E(`Run \`vis fmt\` to apply changes (${String(n.size)} file${n.size===1?"":"s"}).`)))},je=(t,e,s)=>{for(const i of t)s.write(`${i.adapter} ${P(e,i.file)}
|
|
3
|
+
`)};export{Re as default};
|
|
@@ -1,61 +1,22 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`),
|
|
3
|
-
`)}
|
|
1
|
+
import{createRequire as re}from"node:module";import{F as d,j as y,q as v}from"../packem_shared/index.server-sXNQYpsl.js";import{e as S,m as K,a as G,v as F,b as oe,U as ie}from"../packem_shared/index-DHD8wb6Z.js";import{y as _}from"../packem_shared/isAccessibleSync-DYKTrrvc-CSnBISfV.js";import{L as H}from"./catalog.js";import{d as de}from"../packem_shared/giget-D8Kwb0kD.js";import{p as f}from"./cli-main.js";import{h as J,U as me}from"../packem_shared/writeFileSync-DJoHk3Ks-CgQ-VNNT.js";let se;const ne=t=>(se??=re(import.meta.url))(t),O=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,B=t=>{if(typeof O<"u"&&O.versions&&O.versions.node){const[e,r]=O.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return O.getBuiltinModule(t)}return ne(t)},{fileURLToPath:ae}=B("node:url"),{createInterface:ce}=B("node:readline"),{mkdtempSync:le,rmSync:fe}=B("node:fs"),{tmpdir:ue}=B("node:os"),{spawnSync:pe}=B("node:child_process"),z=[".ts",".mts",".cts",".js",".mjs",".cjs"],he="template.yml",ge=[".d",".test",".spec",".config",".bench",".stories"],we=[".d.ts",".d.mts",".d.cts",".js.map",".mjs.map",".cjs.map",".ts.map"],X=t=>{for(const e of z)if(t.endsWith(e))return t.slice(0,-e.length);return t},$e=t=>{if(we.some(r=>t.endsWith(r))||!z.some(r=>t.endsWith(r)))return!1;const e=X(t);return!ge.some(r=>e.endsWith(r))},U=(t,e)=>{const r=[];if(!_(t))return r;for(const n of H(t,{includeDirs:!1,includeSymlinks:!1,maxDepth:1})){if(!$e(n.name))continue;const s=X(n.name);r.push({load:()=>ve(n.path),name:s,path:n.path,source:e})}return r},I=(t,e)=>{const r=[];if(!_(t))return r;for(const n of H(t,{includeFiles:!1,includeSymlinks:!1,maxDepth:1})){if(n.path===t)continue;const s=S(n.path,he);_(s)&&r.push({load:()=>be(n.path,n.name),name:n.name,path:n.path,source:e})}return r},ye=()=>{try{const t=ae(import.meta.url),e=S(K(t),"..","..","templates");return _(e)?e:void 0}catch{return}},R=t=>{const{extraDirectories:e=[],onWarning:r,workspaceRoot:n}=t,s=[...U(S(n,".vis","templates"),"native"),...I(S(n,".vis","templates"),"moon"),...I(S(n,".moon","templates"),"moon")];for(const c of e)s.push(...I(c,"config")),s.push(...U(c,"config"));const i=ye();i&&s.push(...I(i,"builtin"));const a=new Map;for(const c of s){const o=a.get(c.name);if(!o){a.set(c.name,c);continue}r&&r(`Template "${c.name}" exists in multiple sources — using ${o.source} (${o.path}), ignoring ${c.source} (${c.path}).`)}return[...a.values()].sort((c,o)=>c.name.localeCompare(o.name))},ve=async t=>{const{loadNativeTemplate:e}=await import("./loader2.js");return e(t)},be=async(t,e)=>{const{loadMoonTemplate:r}=await import("./index5.js");return r(t,e)},q=(t,e)=>new Promise(r=>{t.question(e,n=>{r(n.trim())})}),Te=async(t,e,r)=>{const s=await q(t,` ${e} ${d(r?"[Y/n]":"[y/N]")} `);return s===""?r:s.toLowerCase()==="y"||s.toLowerCase()==="yes"},Se=async(t,e,r,n)=>{process.stderr.write(` ${e}
|
|
2
|
+
`);for(const[s,i]of r.entries()){const a=y(v(` ${String(s+1)}.`)),c=i===n?d(" (default)"):"";process.stderr.write(`${a} ${i}${c}
|
|
3
|
+
`)}for(;;){const s=await q(t,`
|
|
4
|
+
${d(`Enter choice (1-${String(r.length)}):`)} `);if(s===""&&n!==void 0)return n;const i=Number.parseInt(s,10);if(Number.isInteger(i)&&i>=1&&i<=r.length)return r[i-1];const a=r.find(c=>c===s);if(a)return a;process.stderr.write(` ${d("Invalid choice. Try again.")}
|
|
5
|
+
`)}},Ee=async(t,e,r,n)=>{process.stderr.write(` ${e} ${d("(comma-separated numbers)")}
|
|
6
|
+
`);for(const[s,i]of r.entries()){const a=y(v(` ${String(s+1)}.`)),c=n.includes(i)?d(" (default)"):"";process.stderr.write(`${a} ${i}${c}
|
|
7
|
+
`)}for(;;){const s=await q(t,`
|
|
8
|
+
${d("Enter choices:")} `);if(s===""&&n.length>0)return n;const i=s.split(",").map(a=>Number.parseInt(a.trim(),10)).filter(a=>Number.isInteger(a)&&a>=1&&a<=r.length);if(i.length>0)return i.map(a=>r[a-1]);process.stderr.write(` ${d("Invalid choice. Try again.")}
|
|
9
|
+
`)}},xe=t=>` ${d(`${t}:`)} `,Ne=(t,e)=>e.prompt??t,Oe=t=>Object.entries(t).sort(([e,r],[n,s])=>{const i=r.order??0,a=s.order??0;return i!==a?i-a:e.localeCompare(n)}),V=(t,e)=>{switch(t.type){case"array":return e.split(",").map(r=>r.trim()).filter(Boolean);case"boolean":return e==="true"||e==="1"||e==="yes"||e==="y";case"enum":return t.multiple?e.split(",").map(r=>r.trim()).filter(Boolean):e;case"number":{const r=Number(e);if(Number.isNaN(r))throw new TypeError(`Expected a number, got "${e}"`);return r}default:return e}},W=(t,e,r)=>{if(e.type==="enum"){const n=Array.isArray(r)?r:[r];for(const s of n)if(typeof s!="string"||!e.values.includes(s))throw new Error(`Variable "${t}" must be one of: ${e.values.join(", ")} (got "${String(s)}")`)}},_e=async t=>{const{defaults:e,interactive:r,overrides:n,variables:s}=t,i={},a=r?ce({input:process.stdin,output:process.stderr}):null;try{for(const[c,o]of Oe(s)){if(Object.hasOwn(n,c)){const m=V(o,n[c]??"");W(c,o,m),i[c]=m;continue}if(e||!r||o.internal){if(o.default!==void 0){W(c,o,o.default),i[c]=o.default;continue}if(o.required)throw new Error(`Required variable "${c}" not provided. Pass --${c}=<value> or remove --defaults.`);continue}const l=Ne(c,o);let u;if(o.type==="boolean")u=await Te(a,l,!!(o.default??!1));else if(o.type==="enum")if(o.multiple){const m=Array.isArray(o.default)?o.default:[];u=await Ee(a,l,o.values,m)}else{const m=typeof o.default=="string"?o.default:void 0;u=await Se(a,l,o.values,m)}else{const m=o.default===void 0?"":` (${String(o.default)})`,T=await q(a,xe(`${l}${m}`));if(T===""&&o.default!==void 0)u=o.default;else if(T===""){if(o.required)throw new Error(`Variable "${c}" is required`);continue}else u=V(o,T)}W(c,o,u),i[c]=u}return i}finally{a?.close()}},Be=["git://","npm://","https://","github:","gitlab:","bitbucket:","sourcehut:"],ke=t=>Be.some(e=>t.startsWith(e)),De=async(t,e={})=>{const r=e.targetDirectory===void 0,n=e.targetDirectory??le(S(ue(),"vis-generate-")),s=()=>{if(r)try{fe(n,{force:!0,recursive:!0})}catch{}};f.info(`Downloading ${t}…`);try{const i=await de(t,{auth:e.auth||process.env.GIGET_AUTH||process.env.GITHUB_TOKEN||process.env.GH_TOKEN||void 0,dir:n,force:!0,preferOffline:e.preferOffline});return{cleanup:s,directory:i.dir}}catch(i){s();const a=i instanceof Error?i.message:String(i);throw f.warn(`Failed to download template: ${a}`),i}},Y=(t,e="")=>{const r=[];for(const[n,s]of Object.entries(t)){const i=e?`${e}/${n}`:n;typeof s=="string"||Buffer.isBuffer(s)?r.push({content:s,path:i}):s&&typeof s=="object"&&r.push(...Y(s,i))}return r},je=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`,Ie=(t,e)=>{if(F(e))throw new Error(`Refusing to write outside destination: template produced absolute path "${e}".`);const r=S(t,e),n=G(t,r);if(n===".."||n.startsWith(`..${oe}`)||F(n))throw new Error(`Refusing to write outside destination: "${e}" resolves to "${r}" which escapes "${t}".`);return r},Re=(t,e)=>{J(K(t)),me(t,e)},qe=(t,e,r=!1)=>{const n=typeof t=="string"?[t]:t.commands,s=typeof t=="string"?r:t.silent??r;for(const i of n){s||f.info(`$ ${i}`);const a=pe(i,{cwd:e,shell:!0,stdio:s?"ignore":"inherit"});if(a.status!==0)return f.warn(`Script failed (exit ${String(a.status)}): ${i}`),!1}return!0},Le=t=>{const e=new Map;for(const r of t){const n=typeof r=="string"?0:r.phase??0,s=e.get(n);s?s.push(r):e.set(n,[r])}return[...e.entries()].sort(([r],[n])=>r-n)},We=async(t,e)=>{const n={builtins:{dest_dir:e.destination,dest_rel_dir:G(e.workspaceRoot,e.destination)||".",working_dir:e.cwd,workspace_root:e.workspaceRoot},options:e.options},s=await t.produce(n),i=s.files?Y(s.files):[],a=s.filesMeta??{},c=[];for(const o of i){const l=Ie(e.destination,o.path);c.push({file:o,meta:a[o.path]??{},target:l})}if(e.dryRun){f.info(`${y(v("Plan"))} ${d("(dry-run, no files written)")}`);for(const o of c){const l=Buffer.isBuffer(o.file.content)?o.file.content.length:Buffer.byteLength(o.file.content,"utf8");process.stderr.write(` ${d("write")} ${o.file.path} ${d(`(${je(l)})`)}
|
|
10
|
+
`)}}else{J(e.destination);let o=0,l=0;for(const u of c){const{file:m,meta:T,target:k}=u,b=_(k),E=e.force||T.force===!0;if(b&&!E){f.warn(`Skipped existing file: ${m.path} (use --force or set frontmatter force: true to overwrite)`),l+=1;continue}Re(k,m.content),o+=1}f.success(`Wrote ${String(o)} file${o===1?"":"s"}${l>0?`, skipped ${String(l)}`:""}`)}if(!e.dryRun&&!e.skipScripts&&s.scripts&&s.scripts.length>0){const o=Le(s.scripts);f.info(`Running ${String(s.scripts.length)} script${s.scripts.length===1?"":"s"} across ${String(o.length)} phase${o.length===1?"":"s"}…`);for(const[,l]of o)if((await Promise.all(l.map(m=>Promise.resolve(qe(m,e.destination))))).includes(!1))throw new Error("Script failed — aborting.")}if(s.suggestions&&s.suggestions.length>0){process.stderr.write(`
|
|
11
|
+
`),f.notice("Next steps:");for(const o of s.suggestions)process.stderr.write(` ${d("•")} ${o}
|
|
12
|
+
`)}},Fe=async t=>{let e;try{e=(await t.load()).about?.description}catch{}return{description:e,name:t.name,path:t.path,source:t.source}},Me=(t,e)=>{const r={default:e.default,name:t,order:e.order,prompt:e.prompt,required:e.required,type:e.type};return e.type==="enum"&&(r.multiple=e.multiple,r.values=e.values),r},Ae=async t=>{const e=await t.load(),r=Object.entries(e.options??{}).sort(([n,s],[i,a])=>{const c=s.order??0,o=a.order??0;return c===o?n.localeCompare(i):c-o}).map(([n,s])=>Me(n,s));return{description:e.about?.description??"",destination:e.destination,name:t.name,path:t.path,source:t.source,variables:r}},Pe=t=>{if(t.length===0){f.info("No templates found."),f.notice("Create one at .vis/templates/<name>.ts (programmatic) or .vis/templates/<name>/ (moon-format with template.yml).");return}f.info("Available templates:");for(const e of t){const r=d(`(${e.source})`);process.stderr.write(` ${y(v(e.name))} ${r}
|
|
13
|
+
`)}},Ce=(t,e)=>{const r={},n=[];for(let s=0;s<t.length;s++){const i=t[s];if(!i.startsWith("--")){n.push(i);continue}const a=i.indexOf("=");if(a===-1){const l=i.slice(2);if(l.startsWith("no-"))r[l.slice(3)]="false";else{r[l]="true";const u=t[s+1];u!==void 0&&!u.startsWith("-")&&e?.(`\`--${l} ${u}\` was read as boolean \`--${l}=true\` and \`${u}\` was ignored. For a string value use \`--${l}=${u}\`.`)}continue}const c=i.slice(2,a),o=i.slice(a+1);r[c]=o}return{overrides:r,remaining:n}},Ue=async t=>{const{createInterface:e}=await import("node:readline"),r=e({input:process.stdin,output:process.stderr});try{process.stderr.write(` ${y(v("vis generate"))} ${d("— pick a template")}
|
|
4
14
|
|
|
5
|
-
`}${
|
|
6
|
-
`
|
|
7
|
-
`),s=t.
|
|
8
|
-
`);return
|
|
9
|
-
name:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
paths:
|
|
14
|
-
${n}
|
|
15
|
-
|
|
16
|
-
permissions:
|
|
17
|
-
contents: read
|
|
18
|
-
pull-requests: read
|
|
19
|
-
|
|
20
|
-
jobs:
|
|
21
|
-
write-guard:
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v4
|
|
25
|
-
with:
|
|
26
|
-
fetch-depth: 0
|
|
27
|
-
- uses: geritol/write-guard@v1
|
|
28
|
-
with:
|
|
29
|
-
codeowners: CODEOWNERS
|
|
30
|
-
paths: |
|
|
31
|
-
${s}
|
|
32
|
-
`},pe=e=>{const n=T(e).map(s=>` - "${s}/*"`).join(`
|
|
33
|
-
`);return`# ${L}
|
|
34
|
-
#
|
|
35
|
-
# SOFT GUARD ONLY — this job does NOT block a merge by itself.
|
|
36
|
-
# It verifies the generated CODEOWNERS is in sync and flags that a
|
|
37
|
-
# restricted path changed. GitLab CI cannot portably gate a merge on
|
|
38
|
-
# code-owner *approval* from a job, so REAL ENFORCEMENT REQUIRES the
|
|
39
|
-
# native GitLab setting:
|
|
40
|
-
# Settings -> Repository -> Protected branches ->
|
|
41
|
-
# "Require approval from Code Owners" (GitLab Premium / Ultimate)
|
|
42
|
-
# https://docs.gitlab.com/ee/user/project/codeowners/
|
|
43
|
-
# Without that setting enabled, this job is advisory only.
|
|
44
|
-
write-guard:
|
|
45
|
-
stage: test
|
|
46
|
-
image: node:22-alpine
|
|
47
|
-
rules:
|
|
48
|
-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
49
|
-
changes:
|
|
50
|
-
${n}
|
|
51
|
-
script:
|
|
52
|
-
- corepack enable
|
|
53
|
-
- pnpm install --frozen-lockfile
|
|
54
|
-
- pnpm vis sync codeowners --check
|
|
55
|
-
- >-
|
|
56
|
-
echo "SOFT GUARD: a restricted path changed. This job does NOT enforce
|
|
57
|
-
code-owner approval. Enable 'Require approval from Code Owners' on the
|
|
58
|
-
protected branch (GitLab Premium/Ultimate) for a real merge gate:
|
|
59
|
-
https://docs.gitlab.com/ee/user/project/codeowners/"
|
|
60
|
-
`},he=e=>e.length===0?[]:[{content:ue(e),path:".github/workflows/write-guard.yml"},{content:pe(e),path:".gitlab/write-guard.gitlab-ci.yml"}],W=new Set(["nested-codeowners","package-json-maintainers","project-json"]),_=(e,t,n)=>{const s=new Set,o=[];for(const i of e??[])for(const c of i.split(",")){const r=c.trim();if(r.length===0)continue;if(n&&!n(r))throw new Error(`Unknown codeowners source: "${r}". Known: ${[...W].join(", ")}.`);const a=r;s.has(a)||(s.add(a),o.push(a))}return o.length>0?o:[...t]},ge=e=>W.has(e),S=["codeowners","package-json-fields"],me=(e,t)=>t.some(n=>x(n,e)),we=async(e,t,n,s,o)=>{const i=Object.entries(s.projects).filter(([,r])=>r.restricted===!0).map(([r,a])=>({name:r,root:a.root??r})),c=he(i);if(c.length===0){t.info("No projects flagged `restricted: true` in project.json. Skipping Write Guard.");return}if(o){let r=!1;for(const a of c){const f=b(n,a.path);let l="";try{l=await e.readFile(f,"utf8")}catch(p){if(p.code!=="ENOENT")throw p}l.trim()!==a.content.trim()&&(t.error(`${a.path} is out of date. Run \`vis sync codeowners --write-guard\` to update it.`),r=!0)}r?process.exitCode=1:t.info(`Write Guard CI is up to date (${c.length} files, ${i.length} restricted projects).`);return}for(const r of c){const a=b(n,r.path);M(G(a)),R(a,r.content),t.info(`Wrote ${r.path}`)}t.info(`Write Guard CI scoped to ${i.length} restricted project${i.length===1?"":"s"}.`)},ye=async({fs:e,logger:t,options:n,visConfig:s,workspaceRoot:o})=>{const i=o,{workspace:c}=U(i,s),r=s?.codeowners;n.writeGuard&&await we(e,t,i,c,n.check);const a=_(n.from,r?.sources??["project-json"],ge),f=n.regenerationCommand??r?.regenerationCommand,l=n.preserveBlock||r?.preserveBlock===!0,p=r?.blockMarker??O,y=n.nestedIncludes??r?.nestedIncludes,g=n.out??"CODEOWNERS",w=[];if(a.includes("nested-codeowners")){const m=await oe(i,y,g);for(const j of m)w.push({...j,source:"nested"})}if(a.includes("package-json-maintainers")){const m=ce(c,i);for(const j of m)w.push({...j,source:"maintainers"})}const u=a.includes("project-json")?N(c,r,w):N({projects:{}},r,w);if(u.length===0){t.info("No `owners` entries found in any source. Nothing to sync.");return}const $=b(i,g);let d="";try{d=await e.readFile($,"utf8")}catch(m){if(m.code!=="ENOENT")throw m}const h={regenerationCommand:f},k=l?Z(d,X(u,p,h),p):Q(u,h);if(n.check){if(d.trim()!==k.trim()){t.error(`${$} is out of date. Run \`vis sync codeowners\` to update it.`),process.exitCode=1;return}t.info(`${$} is up to date.`);return}R($,k),t.info(`Wrote ${u.length} entries to ${$}`)},ke=({logger:e,options:t,visConfig:n,workspaceRoot:s})=>{const o=s,i=n?.editorconfig??!0,c=E(b(o,"package.json"));if(!c){e.error("Could not read root package.json. Nothing to sync."),process.exitCode=1;return}const r=_(t.fields,ie),a=t.ignorePackageName??[],f=t.check,l=(t.format??"human").toLowerCase(),{quiet:p}=t,y=J(o).filter(d=>d!=="."),g=[];let w=0;for(const d of y){const h=b(o,d,"package.json"),k=E(h);if(!k)continue;const m=typeof k.name=="string"?k.name:void 0;if(m!==void 0&&a.length>0&&me(m,a))continue;w+=1;const j=de(c,k,{fields:r});j.length!==0&&g.push({filePath:h,packageJsonPath:I(o,h),packageName:m,pkg:k,pkgChanges:j})}if(!f)for(const d of g)fe(d.pkg,d.pkgChanges),q(d.filePath,d.pkg,{indent:F(d.filePath,{useEditorconfig:i}),overwrite:!0});const u=g.flatMap(d=>d.pkgChanges.map(h=>({after:h.after,before:h.before,field:h.field,packageJsonPath:d.packageJsonPath,packageName:d.packageName}))),$={changes:u,fields:r,kind:"package-json-fields",mode:f?"check":"write",totalChanges:u.length,totalPackages:w};if(l==="json")process.stdout.write(`${JSON.stringify($,null,4)}
|
|
61
|
-
`);else if(u.length===0)e.info(`All ${w} package${w===1?"":"s"} in sync (fields: ${r.join(", ")}).`);else if(f){if(!p)for(const d of u)e.error(`${d.packageJsonPath}: ${d.field} drifts from root`);e.error(`Found ${u.length} field drift${u.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}. Run \`vis sync package-json-fields\` to fix.`)}else{if(!p)for(const d of g)e.info(`${d.packageJsonPath}: synced ${d.pkgChanges.map(h=>h.field).join(", ")}`);e.info(`Synced ${u.length} field${u.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}.`)}f&&u.length>0&&(process.exitCode=1)},Pe=async e=>{const t=e.argument[0];if(!t)throw new Error(`Missing sync kind. Usage: vis sync <kind> (known kinds: ${S.join(", ")})`);if(!e.workspaceRoot)throw new Error("Could not determine workspace root. Run inside a monorepo.");if(t==="codeowners"){await ye(e);return}if(t==="package-json-fields"){ke(e);return}throw new Error(`Unknown sync kind: "${t}". Known kinds: ${S.join(", ")}.`)};export{Pe as default};
|
|
15
|
+
`);for(const[n,s]of t.entries()){const i=y(v(` ${String(n+1)}.`));process.stderr.write(`${i} ${s.name} ${d(`(${s.source})`)}
|
|
16
|
+
`)}return new Promise((n,s)=>{r.question(`
|
|
17
|
+
${d(`Enter choice (1-${String(t.length)}):`)} `,i=>{const a=Number.parseInt(i.trim(),10);Number.isInteger(a)&&a>=1&&a<=t.length?n(t[a-1].name):s(new Error("Invalid choice."))})})}finally{r.close()}},Qe=async({argument:t,options:e,rawUnknown:r,visConfig:n,workspaceRoot:s})=>{const i=e.cwd||s||process.cwd(),a=s??i,c=n?.generator,o=Array.isArray(t)?t:t?[t]:[];if(e.list){const p=R({extraDirectories:c?.templates??[],onWarning:h=>{f.warn(h)},workspaceRoot:a});if(e.json){const h=await Promise.all(p.map(w=>Fe(w)));process.stdout.write(`${JSON.stringify(h,null,2)}
|
|
18
|
+
`);return}Pe(p);return}if(e.describe){const p=o[0];if(!p)throw new Error("`--describe` requires a template name. Run `vis generate --list` to see available templates.");const w=R({extraDirectories:c?.templates??[],onWarning:$=>{f.warn($)},workspaceRoot:a}).find($=>$.name===p);if(!w)throw new Error(`Template "${p}" not found. Run \`vis generate --list\` to see available templates.`);const g=await Ae(w);if(e.json){process.stdout.write(`${JSON.stringify(g,null,2)}
|
|
19
|
+
`);return}if(f.info(`Template: ${y(v(g.name))} ${d(`(${g.source})`)}`),g.description&&f.info(g.description),g.destination&&f.info(`Destination: ${d(g.destination)}`),g.variables.length===0)f.info("No variables.");else{f.info("Variables:");for(const $ of g.variables){const j=[$.type];$.required&&j.push("required"),$.default!==void 0&&j.push(`default=${JSON.stringify($.default)}`),$.values&&j.push(`values=${$.values.join("|")}`),process.stderr.write(` ${y(v($.name))} ${d(`(${j.join(", ")})`)}
|
|
20
|
+
`)}}return}let l=[...r??[]];if(l.length===0){const p=process.argv.slice(2),h=p.indexOf("--");h!==-1&&(l=p.slice(h+1))}const u=o.indexOf("--"),m=u===-1?[]:o.slice(u+1),T=u===-1?o:o.slice(0,u),{overrides:k}=Ce([...m,...l],p=>{f.warn(p)});let b,E,D;const N=T[0];let L;if(N&&ke(N)){const p=await De(N,{auth:c?.auth,preferOffline:!!e.preferOffline||c?.preferOffline});L=p.cleanup;try{const w=R({extraDirectories:[p.directory],workspaceRoot:a}).find(g=>g.path.startsWith(p.directory));if(!w)throw new Error(`Downloaded template at ${p.directory} contains no template.yml or *.ts entrypoint.`);b=await w.load(),E=w.name,D=b.destination}catch(h){throw L(),h}}else{const p=R({extraDirectories:c?.templates??[],onWarning:g=>{f.warn(g)},workspaceRoot:a});if(p.length===0)throw new Error("No templates found. Create one at .vis/templates/<name>.ts or .vis/templates/<name>/template.yml.");let h;if(N)h=N;else{if(e.interactive===!1||!process.stdin.isTTY)throw new Error("No template specified. Pass a template name (see `vis generate --list`) or run interactively in a terminal.");h=await Ue(p)}const w=p.find(g=>g.name===h);if(!w)throw new Error(`Template "${h}" not found. Run 'vis generate --list' to see available templates.`);b=await w.load(),E=w.name,D=b.destination}const M=e.to,A=!!e.dryRun,Q=!!e.force,P=!!e.defaults,Z=!!e.skipScripts,ee=e.interactive!==!1&&!!process.stdin.isTTY&&!P;let x;M?x=M:D?x=D:x=".";const C=F(x)?x:ie(i,x);f.info(`Template: ${y(v(E))}`),f.info(`Target: ${d(C)}`),process.stderr.write(`
|
|
21
|
+
`);const te=await _e({defaults:P,interactive:ee,overrides:k,variables:b.options??{}});try{await We(b,{cwd:i,destination:C,dryRun:A,force:Q,options:te,skipScripts:Z,workspaceRoot:a}),A||(process.stderr.write(`
|
|
22
|
+
`),f.success(`Template '${E}' applied.`))}finally{L?.()}};export{Qe as default};
|