@funish/basis 0.0.1 → 0.0.3

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 (58) hide show
  1. package/README.md +120 -31
  2. package/dist/chunks/config.cjs +1 -1
  3. package/dist/chunks/config.mjs +1 -1
  4. package/dist/chunks/git.cjs +1 -0
  5. package/dist/chunks/git.mjs +1 -0
  6. package/dist/chunks/init.cjs +1 -1
  7. package/dist/chunks/init.mjs +1 -1
  8. package/dist/chunks/lint.cjs +1 -1
  9. package/dist/chunks/lint.mjs +1 -1
  10. package/dist/chunks/publish.cjs +1 -1
  11. package/dist/chunks/publish.mjs +1 -1
  12. package/dist/chunks/version.cjs +1 -1
  13. package/dist/chunks/version.mjs +1 -1
  14. package/dist/cli.cjs +1 -1
  15. package/dist/cli.mjs +1 -1
  16. package/dist/config.cjs +1 -1
  17. package/dist/config.d.cts +1 -1
  18. package/dist/config.d.mts +1 -1
  19. package/dist/config.d.ts +1 -1
  20. package/dist/config.mjs +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.cts +188 -25
  23. package/dist/index.d.mts +188 -25
  24. package/dist/index.d.ts +188 -25
  25. package/dist/index.mjs +1 -1
  26. package/dist/shared/basis.0WCUjjhy.mjs +1 -0
  27. package/dist/shared/basis.1ZgFrMJb.mjs +7 -0
  28. package/dist/shared/basis.B4p52ive.cjs +1 -0
  29. package/dist/shared/basis.BEOfVK6U.cjs +3 -0
  30. package/dist/shared/basis.BJhSbOyA.cjs +1 -0
  31. package/dist/shared/basis.BvLeB_5F.d.cts +253 -0
  32. package/dist/shared/basis.BvLeB_5F.d.mts +253 -0
  33. package/dist/shared/basis.BvLeB_5F.d.ts +253 -0
  34. package/dist/shared/basis.C8S2dWvt.cjs +7 -0
  35. package/dist/shared/basis.CHVACS4W.cjs +1 -0
  36. package/dist/shared/basis.CkZpidFZ.mjs +1 -0
  37. package/dist/shared/basis.DcC8NBqt.mjs +3 -0
  38. package/dist/shared/basis.DzMHJtq5.mjs +10 -0
  39. package/dist/shared/basis.plLH3j3N.mjs +1 -0
  40. package/dist/shared/basis.sOTOmfHG.cjs +10 -0
  41. package/package.json +7 -3
  42. package/dist/chunks/githooks.cjs +0 -1
  43. package/dist/chunks/githooks.mjs +0 -1
  44. package/dist/shared/basis.ByJ8R9TE.cjs +0 -1
  45. package/dist/shared/basis.C0E7mwQ6.mjs +0 -1
  46. package/dist/shared/basis.C5wlo6IO.mjs +0 -1
  47. package/dist/shared/basis.CBZIV3-V.mjs +0 -19
  48. package/dist/shared/basis.CSSuyvpq.cjs +0 -1
  49. package/dist/shared/basis.CgpyxNW3.cjs +0 -1
  50. package/dist/shared/basis.D57HxVvD.cjs +0 -4
  51. package/dist/shared/basis.DeKfEQsQ.cjs +0 -5
  52. package/dist/shared/basis.DweCjqFb.cjs +0 -19
  53. package/dist/shared/basis.O4so-uuj.mjs +0 -5
  54. package/dist/shared/basis.dc3ybBoz.mjs +0 -1
  55. package/dist/shared/basis.iRZ1Ylu8.d.cts +0 -127
  56. package/dist/shared/basis.iRZ1Ylu8.d.mts +0 -127
  57. package/dist/shared/basis.iRZ1Ylu8.d.ts +0 -127
  58. package/dist/shared/basis.rDVxD7qf.mjs +0 -4
@@ -1 +0,0 @@
1
- "use strict";const node_child_process=require("node:child_process"),consola=require("consola"),pkgTypes=require("pkg-types"),m=require("semver"),utils=require("./basis.CSSuyvpq.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const m__default=_interopDefaultCompat(m);async function updatePackageVersion(e,o={}){const{config:u}=await utils.loadConfig({cwd:e}),n=u.version||{},c=await pkgTypes.readPackageJSON(e),t=c.version;if(!t)throw new Error("No version found in package.json");const s=o.version?m__default.valid(o.version)?o.version:(()=>{throw new Error(`Invalid version format: ${o.version}`)})():(()=>{if(!m__default.valid(t))throw new Error(`Invalid current version format: ${t}`);const r=o.preid||n.prereleaseId||"edge",a=o.major?"major":o.minor?"minor":o.prerelease?"prerelease":"patch",d=o.prerelease?m__default.inc(t,a,r):m__default.inc(t,a);if(!d)throw new Error("Failed to calculate new version");return d})();consola.consola.info(`Updating version: ${t} \u2192 ${s}`),await pkgTypes.writePackageJSON(e,{...c,version:s});const i={oldVersion:t,newVersion:s};if(n.autoCommit){const r=o.message||n.commitMessage?.replace("{version}",s)||`chore: release v${s}`;try{node_child_process.execSync("git add package.json",{cwd:e}),node_child_process.execSync(`git commit -m "${r}"`,{cwd:e}),consola.consola.success(`Committed version update: ${r}`)}catch(a){consola.consola.warn("Failed to commit changes:",a)}}if(n.autoTag){const r=`${n.tagPrefix||"v"}${s}`;try{node_child_process.execSync(`git tag ${r}`,{cwd:e}),consola.consola.success(`Created git tag: ${r}`),i.tagName=r}catch(a){consola.consola.warn("Failed to create git tag:",a)}}if(n.autoPush)try{node_child_process.execSync("git push",{cwd:e}),n.autoTag&&node_child_process.execSync("git push --tags",{cwd:e}),consola.consola.success("Pushed changes to remote")}catch(r){consola.consola.warn("Failed to push changes:",r)}return i}exports.updatePackageVersion=updatePackageVersion;
@@ -1 +0,0 @@
1
- import{loadConfig as o}from"c12";import{defaultConfig as f}from"../config.mjs";async function i(a={}){return await o({name:"basis",cwd:process.cwd(),...a,defaults:{...f,...a.defaults}})}export{i as l};
@@ -1 +0,0 @@
1
- import{execSync as c}from"node:child_process";import{consola as i}from"consola";import{readPackageJSON as p,writePackageJSON as l}from"pkg-types";import m from"semver";import{l as v}from"./basis.C0E7mwQ6.mjs";async function f(o,r={}){const{config:w}=await v({cwd:o}),t=w.version||{},g=await p(o),a=g.version;if(!a)throw new Error("No version found in package.json");const n=r.version?m.valid(r.version)?r.version:(()=>{throw new Error(`Invalid version format: ${r.version}`)})():(()=>{if(!m.valid(a))throw new Error(`Invalid current version format: ${a}`);const e=r.preid||t.prereleaseId||"edge",s=r.major?"major":r.minor?"minor":r.prerelease?"prerelease":"patch",u=r.prerelease?m.inc(a,s,e):m.inc(a,s);if(!u)throw new Error("Failed to calculate new version");return u})();i.info(`Updating version: ${a} \u2192 ${n}`),await l(o,{...g,version:n});const d={oldVersion:a,newVersion:n};if(t.autoCommit){const e=r.message||t.commitMessage?.replace("{version}",n)||`chore: release v${n}`;try{c("git add package.json",{cwd:o}),c(`git commit -m "${e}"`,{cwd:o}),i.success(`Committed version update: ${e}`)}catch(s){i.warn("Failed to commit changes:",s)}}if(t.autoTag){const e=`${t.tagPrefix||"v"}${n}`;try{c(`git tag ${e}`,{cwd:o}),i.success(`Created git tag: ${e}`),d.tagName=e}catch(s){i.warn("Failed to create git tag:",s)}}if(t.autoPush)try{c("git push",{cwd:o}),t.autoTag&&c("git push --tags",{cwd:o}),i.success("Pushed changes to remote")}catch(e){i.warn("Failed to push changes:",e)}return d}export{f as u};
@@ -1,19 +0,0 @@
1
- import{existsSync as c,writeFileSync as m}from"node:fs";import{consola as e}from"consola";import{detectPackageManager as u,addDevDependency as g,installDependencies as k}from"nypm";import{resolve as n}from"pathe";import{readPackageJSON as w,writePackageJSON as y}from"pkg-types";const b=`import { defineBasisConfig } from "@funish/basis";
2
-
3
- export default defineBasisConfig({
4
- lint: {
5
- staged: {
6
- },
7
- commitMsg: {
8
- // types: ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"],
9
- // maxLength: 72,
10
- // minLength: 10,
11
- },
12
- },
13
-
14
- hooks: {
15
- // "pre-commit": "basis lint --staged",
16
- // "commit-msg": "basis lint --commit-msg",
17
- },
18
- });
19
- `;async function h(t=process.cwd(),p={}){const{force:l=!1,skipGitCheck:d=!1,skipInstall:a=!1}=p;e.start("Initializing basis configuration...");const r=n(t,"basis.config.ts");if(c(r)&&!l)return e.error("basis.config.ts already exists. Use --force to overwrite."),!1;if(!d&&!c(n(t,".git"))&&(e.warn("No .git directory found. Git hooks will not work properly."),!await e.prompt("Continue anyway?",{type:"confirm",initial:!1})))return e.info("Initialization cancelled."),!1;const o=(await u(t))?.name||"npm";e.info(`Detected package manager: ${o}`),m(r,b,"utf-8"),e.success("Created basis.config.ts");try{const s=await w(t),f=!!(s.workspaces||c(n(t,"pnpm-workspace.yaml")));a?!s.devDependencies?.["@funish/basis"]&&!s.dependencies?.["@funish/basis"]&&(s.devDependencies=s.devDependencies||{},s.devDependencies["@funish/basis"]="latest",e.info("Added @funish/basis to devDependencies")):(await g("@funish/basis",{cwd:t,silent:!1,workspace:f}),e.success("Added @funish/basis to devDependencies"));const i="basis hooks install";s.scripts=s.scripts||{},o==="pnpm"?s.scripts.postinstall?s.scripts.postinstall.includes(i)||(s.scripts.postinstall=`${s.scripts.postinstall} && ${i}`):s.scripts.postinstall=i:o==="yarn"?s.scripts.prepare?s.scripts.prepare.includes(i)||(s.scripts.prepare=`${s.scripts.prepare} && ${i}`):s.scripts.prepare=i:s.scripts.postinstall?s.scripts.postinstall.includes(i)||(s.scripts.postinstall=`${s.scripts.postinstall} && ${i}`):s.scripts.postinstall=i,await y(n(t,"package.json"),s),e.success(`Updated package.json scripts${a?" and dependencies":""}`),a?(e.info("Skipped dependency installation"),e.info("Run your package manager's install command to complete setup")):(e.start("Installing dependencies..."),await k({cwd:t,silent:!1}),e.success("Dependencies installed successfully"))}catch(s){return e.error("Failed to setup dependencies:",s),!1}return e.success("Basis initialization completed!"),e.info("You can now:"),e.info(" - Edit basis.config.ts to customize your configuration"),e.info(" - Run `basis hooks install` to install git hooks"),!0}export{h as i};
@@ -1 +0,0 @@
1
- "use strict";const c12=require("c12"),config=require("../config.cjs");async function loadConfig(c={}){return await c12.loadConfig({name:"basis",cwd:process.cwd(),...c,defaults:{...config.defaultConfig,...c.defaults}})}exports.loadConfig=loadConfig;
@@ -1 +0,0 @@
1
- "use strict";const node_child_process=require("node:child_process"),consola=require("consola"),nypm=require("nypm"),pkgTypes=require("pkg-types"),m=require("semver"),utils=require("./basis.CSSuyvpq.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const m__default=_interopDefaultCompat(m);async function k(e,t,n){if(t.checkGitClean&&!n.skipTests)try{if(node_child_process.execSync("git status --porcelain",{cwd:e,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(s){consola.consola.warn("Could not check git status:",s)}if(t.checkTests&&!n.skipTests){consola.consola.start("Running tests...");try{t.testCommand?node_child_process.execSync(t.testCommand,{cwd:e,stdio:"inherit"}):await nypm.runScript("test",{cwd:e,silent:!1}),consola.consola.success("Tests passed")}catch(s){throw consola.consola.error("Tests failed"),s}}if(t.buildCommand&&!n.skipBuild){consola.consola.start("Building package...");try{node_child_process.execSync(t.buildCommand,{cwd:e,stdio:"inherit"}),consola.consola.success("Build completed")}catch(s){throw consola.consola.error("Build failed"),s}}}async function C(e,t){if(t.autoGitPush)try{node_child_process.execSync("git push",{cwd:e}),t.createGitTag&&node_child_process.execSync("git push --tags",{cwd:e}),consola.consola.success("Pushed changes to remote")}catch(n){consola.consola.warn("Failed to push changes:",n)}}async function publishPackage(e,t={}){const{config:n}=await utils.loadConfig({cwd:e}),s=n.publish||{},g=await pkgTypes.readPackageJSON(e),{name:i,version:c}=g;if(!i||!c)throw new Error("Missing name or version in package.json");if(!m__default.valid(c))throw new Error(`Invalid version format in package.json: ${c}`);const d=await nypm.detectPackageManager(e),l=d?.command||"npm";await k(e,s,t);let o;if(t.tag)o=t.tag;else if(t.stable||t.latest)o=s.stableTag||"latest";else if(m__default.prerelease(c)){const a=m__default.prerelease(c);o=a&&a[0]||s.defaultTag||"edge"}else o=s.stableTag||"latest";consola.consola.info(`Publishing ${i}@${c} to tag: ${o}`);const u=["publish","--tag",o,"--access",t.access||s.access||"public"];(t.registry||s.registry)&&u.push("--registry",t.registry||s.registry||""),t.dryRun&&u.push("--dry-run");const p=`${l} ${u.join(" ")}`;consola.consola.start("Publishing package...");try{if(node_child_process.execSync(p,{cwd:e,stdio:"inherit"}),t.dryRun)consola.consola.success("Dry run completed successfully");else{consola.consola.success(`Published ${i}@${c} to ${o}`);const a=s.defaultTag||"edge";if(o!==a){consola.consola.start(`Also publishing to ${a} tag...`);try{let r;d?.name==="yarn"?r=`${l} tag add ${i}@${c} ${a}`:r=`${l} dist-tag add ${i}@${c} ${a}`,node_child_process.execSync(r,{cwd:e,stdio:"inherit"}),consola.consola.success(`Also published ${i}@${c} to ${a}`)}catch(r){consola.consola.warn(`Failed to add ${a} tag:`,r)}}await C(e,s)}return{packageName:i,version:c,publishTag:o,dryRun:t.dryRun||!1}}catch(a){throw consola.consola.error("Failed to publish package:",a),a}}exports.publishPackage=publishPackage;
@@ -1,4 +0,0 @@
1
- "use strict";const node_child_process=require("node:child_process"),node_fs=require("node:fs"),consola=require("consola"),y=require("micromatch"),pathe=require("pathe"),utils=require("./basis.CSSuyvpq.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const y__default=_interopDefaultCompat(y),M=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function parseCommitMessage(e){const i=e.trim().split(`
2
- `),t=i[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!t)return null;const[,l,,n,c,o]=t,a=i.slice(1).find(s=>s.trim())?.trim(),r=i.slice(-1)[0]?.trim();return{type:l,scope:n,description:o,body:a,footer:r,isBreaking:!!c||e.includes("BREAKING CHANGE:")}}function validateCommitMessage(e,i={}){const t=[],{types:l=M,maxLength:n=72,minLength:c=10,scopeRequired:o=!1,allowedScopes:a=[]}=i,r=parseCommitMessage(e);if(!r)return{valid:!1,errors:["Invalid commit format. Expected: type(scope): description"]};l.includes(r.type)||t.push(`Invalid type '${r.type}'. Allowed: ${l.join(", ")}`);const s=e.split(`
3
- `)[0];return s.length>n&&t.push(`Header too long (${s.length}). Max: ${n}`),s.length<c&&t.push(`Header too short (${s.length}). Min: ${c}`),o&&!r.scope&&t.push("Scope is required"),r.scope&&a.length>0&&!a.includes(r.scope)&&t.push(`Invalid scope '${r.scope}'. Allowed: ${a.join(", ")}`),{valid:t.length===0,errors:t}}function getStagedFiles(){try{return node_child_process.execSync("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
4
- `).filter(Boolean)}catch{return[]}}async function lintStaged(e=process.cwd(),i){const{config:t}=await utils.loadConfig({cwd:e,overrides:i?{lint:{staged:i}}:void 0}),l=t.lint?.staged||{},n=getStagedFiles();if(n.length===0)return consola.consola.info("No staged files to lint"),!0;if(Object.keys(l).length===0)return consola.consola.warn("No staged lint configuration found"),!0;let c=!1;const o=new Set;for(const[a,r]of Object.entries(l)){const s=n.filter(d=>!o.has(d)&&y__default.isMatch(d.split("/").pop()||d,a));if(s.length!==0){consola.consola.start(`Linting ${s.length} files: ${a}`);try{const d=`${r} ${s.join(" ")}`;node_child_process.execSync(d,{stdio:"inherit",cwd:e}),node_child_process.execSync(`git add ${s.join(" ")}`,{stdio:"inherit",cwd:e}),s.forEach(u=>o.add(u)),consola.consola.success(`\u2713 ${a}`)}catch(d){c=!0,consola.consola.error(`\u2717 ${a} failed:`,d)}}}return!c}async function lintCommitMessage(e=process.cwd(),i){const{config:t}=await utils.loadConfig({cwd:e,overrides:i?{lint:{commitMsg:i}}:void 0}),l=t.lint?.commitMsg||{};let n;try{const o=pathe.resolve(".git/COMMIT_EDITMSG");node_fs.existsSync(o)?n=node_fs.readFileSync(o,"utf8"):n=node_child_process.execSync("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(o){return consola.consola.error("\u2717 Failed to read commit message:",o),!1}const c=validateCommitMessage(n,l);return c.valid?(consola.consola.success("\u2713 Commit message is valid"),!0):(consola.consola.error("\u2717 Invalid commit message:"),c.errors.forEach(o=>consola.consola.error(` ${o}`)),!1)}exports.getStagedFiles=getStagedFiles,exports.lintCommitMessage=lintCommitMessage,exports.lintStaged=lintStaged,exports.parseCommitMessage=parseCommitMessage,exports.validateCommitMessage=validateCommitMessage;
@@ -1,5 +0,0 @@
1
- "use strict";const node_child_process=require("node:child_process"),promises=require("node:fs/promises"),consola=require("consola"),pathe=require("pathe"),utils=require("./basis.CSSuyvpq.cjs"),VALID_GIT_HOOKS=["applypatch-msg","pre-applypatch","post-applypatch","pre-commit","pre-merge-commit","prepare-commit-msg","commit-msg","post-commit","pre-rebase","post-checkout","post-merge","pre-push","pre-receive","update","proc-receive","post-receive","post-update","reference-transaction","push-to-checkout","pre-auto-gc","post-rewrite","sendemail-validate","fsmonitor-watchman","p4-changelist","p4-prepare-changelist","p4-post-changelist","p4-pre-submit","post-index-change"];async function y(){try{return node_child_process.execSync("git --version",{stdio:"ignore"}),!0}catch{return!1}}async function b(o){try{return await promises.access(pathe.join(o,".git")),!0}catch{return!1}}async function j(o){try{node_child_process.execSync("git init",{cwd:o,stdio:"inherit"}),consola.consola.success("Initialized git repository")}catch(i){throw consola.consola.error("Failed to initialize git repository:",i),i}}function w(o){return VALID_GIT_HOOKS.includes(o)}function u(o){const i={},r={autoInitGit:o.autoInitGit,skipGitCheck:o.skipGitCheck,force:o.force};for(const[e,n]of Object.entries(o))e!=="autoInitGit"&&e!=="skipGitCheck"&&e!=="force"&&typeof n=="string"&&(i[e]=n);return{hooks:i,options:r}}function p(o){const i=[];for(const r of Object.keys(o))w(r)||i.push(r);return{valid:i.length===0,invalidHooks:i}}async function installHooks(o=process.cwd(),i){const{config:r}=await utils.loadConfig({cwd:o,overrides:i?{githooks:i}:void 0}),e=r.githooks;if(!e){consola.consola.error("No hooks configuration found");return}const{hooks:n,options:s}=u(e);if(!s.skipGitCheck&&!s.force&&!await y())throw consola.consola.error("Git command not found. Please install git or use --force option."),new Error("Git command not available");if(!await b(o))if(s.autoInitGit)consola.consola.info("Not a git repository, initializing..."),await j(o);else throw consola.consola.error("Not a git repository. Use --auto-init-git option or run 'git init' first."),new Error("Not a git repository");const a=p(n);if(!a.valid)throw consola.consola.error("Invalid hook names found:"),a.invalidHooks.forEach(t=>{consola.consola.error(` \u2717 ${t} (not a valid Git hook)`)}),consola.consola.info("Valid Git hooks:",VALID_GIT_HOOKS.join(", ")),new Error(`Invalid hook names: ${a.invalidHooks.join(", ")}`);if(consola.consola.start("Installing git hooks..."),Object.keys(n).length===0){consola.consola.warn("No hooks configured");return}try{const t=pathe.join(o,".git","hooks");await promises.mkdir(t,{recursive:!0});for(const[c,l]of Object.entries(n)){const h=pathe.join(t,c),f=O(l);await promises.writeFile(h,f,"utf-8"),await promises.chmod(h,493),consola.consola.info(`Installed ${c} hook`)}consola.consola.success(`Installed ${Object.keys(n).length} git hooks`)}catch(t){throw consola.consola.error("Failed to install hooks:",t),t}}async function uninstallHooks(o=process.cwd(),i){const{config:r}=await utils.loadConfig({cwd:o,overrides:i?{githooks:i}:void 0}),e=r.githooks||{},{hooks:n,options:s}=u(e);if(!s.skipGitCheck&&!s.force&&!await y())throw consola.consola.error("Git command not found. Please install git or use --force option."),new Error("Git command not available");if(!await b(o)&&!s.force)throw consola.consola.error("Not a git repository."),new Error("Not a git repository");const a=p(n);if(!a.valid)throw consola.consola.error("Invalid hook names found:"),a.invalidHooks.forEach(t=>{consola.consola.error(` \u2717 ${t} (not a valid Git hook)`)}),new Error(`Invalid hook names: ${a.invalidHooks.join(", ")}`);consola.consola.start("Uninstalling git hooks...");try{const t=pathe.join(o,".git","hooks");for(const c of Object.keys(n)){const l=pathe.join(t,c);try{await promises.writeFile(l,"","utf-8"),consola.consola.info(`Uninstalled ${c} hook`)}catch{}}consola.consola.success("Git hooks uninstalled")}catch(t){throw consola.consola.error("Failed to uninstall hooks:",t),t}}async function listHooks(o=process.cwd(),i){const{config:r}=await utils.loadConfig({cwd:o,overrides:i?{githooks:i}:void 0}),e=r.githooks||{},{hooks:n,options:s}=u(e);if(consola.consola.info("Configured git hooks:"),Object.keys(n).length===0){consola.consola.info("No hooks configured");return}(s.autoInitGit||s.skipGitCheck||s.force)&&(consola.consola.info("Options:"),s.autoInitGit&&consola.consola.info(" \u2022 Auto-init git: enabled"),s.skipGitCheck&&consola.consola.info(" \u2022 Skip git check: enabled"),s.force&&consola.consola.info(" \u2022 Force: enabled"));const a=p(n);a.valid||(consola.consola.warn("Warning: Found invalid hook names:"),a.invalidHooks.forEach(t=>{consola.consola.warn(` \u26A0 ${t} (not a valid Git hook)`)}));for(const[t,c]of Object.entries(n)){const l=w(t)?"\u2713":"\u26A0";consola.consola.info(` ${l} ${t}: ${c}`)}}function O(o){return`#!/bin/sh
2
- # Generated by @funish/basis
3
-
4
- ${o}
5
- `}exports.VALID_GIT_HOOKS=VALID_GIT_HOOKS,exports.installHooks=installHooks,exports.listHooks=listHooks,exports.uninstallHooks=uninstallHooks;
@@ -1,19 +0,0 @@
1
- "use strict";const node_fs=require("node:fs"),consola=require("consola"),nypm=require("nypm"),pathe=require("pathe"),pkgTypes=require("pkg-types"),b=`import { defineBasisConfig } from "@funish/basis";
2
-
3
- export default defineBasisConfig({
4
- lint: {
5
- staged: {
6
- },
7
- commitMsg: {
8
- // types: ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"],
9
- // maxLength: 72,
10
- // minLength: 10,
11
- },
12
- },
13
-
14
- hooks: {
15
- // "pre-commit": "basis lint --staged",
16
- // "commit-msg": "basis lint --commit-msg",
17
- },
18
- });
19
- `;async function init(i=process.cwd(),a={}){const{force:c=!1,skipGitCheck:r=!1,skipInstall:n=!1}=a;consola.consola.start("Initializing basis configuration...");const o=pathe.resolve(i,"basis.config.ts");if(node_fs.existsSync(o)&&!c)return consola.consola.error("basis.config.ts already exists. Use --force to overwrite."),!1;if(!r&&!node_fs.existsSync(pathe.resolve(i,".git"))&&(consola.consola.warn("No .git directory found. Git hooks will not work properly."),!await consola.consola.prompt("Continue anyway?",{type:"confirm",initial:!1})))return consola.consola.info("Initialization cancelled."),!1;const t=(await nypm.detectPackageManager(i))?.name||"npm";consola.consola.info(`Detected package manager: ${t}`),node_fs.writeFileSync(o,b,"utf-8"),consola.consola.success("Created basis.config.ts");try{const s=await pkgTypes.readPackageJSON(i),l=!!(s.workspaces||node_fs.existsSync(pathe.resolve(i,"pnpm-workspace.yaml")));n?!s.devDependencies?.["@funish/basis"]&&!s.dependencies?.["@funish/basis"]&&(s.devDependencies=s.devDependencies||{},s.devDependencies["@funish/basis"]="latest",consola.consola.info("Added @funish/basis to devDependencies")):(await nypm.addDevDependency("@funish/basis",{cwd:i,silent:!1,workspace:l}),consola.consola.success("Added @funish/basis to devDependencies"));const e="basis hooks install";s.scripts=s.scripts||{},t==="pnpm"?s.scripts.postinstall?s.scripts.postinstall.includes(e)||(s.scripts.postinstall=`${s.scripts.postinstall} && ${e}`):s.scripts.postinstall=e:t==="yarn"?s.scripts.prepare?s.scripts.prepare.includes(e)||(s.scripts.prepare=`${s.scripts.prepare} && ${e}`):s.scripts.prepare=e:s.scripts.postinstall?s.scripts.postinstall.includes(e)||(s.scripts.postinstall=`${s.scripts.postinstall} && ${e}`):s.scripts.postinstall=e,await pkgTypes.writePackageJSON(pathe.resolve(i,"package.json"),s),consola.consola.success(`Updated package.json scripts${n?" and dependencies":""}`),n?(consola.consola.info("Skipped dependency installation"),consola.consola.info("Run your package manager's install command to complete setup")):(consola.consola.start("Installing dependencies..."),await nypm.installDependencies({cwd:i,silent:!1}),consola.consola.success("Dependencies installed successfully"))}catch(s){return consola.consola.error("Failed to setup dependencies:",s),!1}return consola.consola.success("Basis initialization completed!"),consola.consola.info("You can now:"),consola.consola.info(" - Edit basis.config.ts to customize your configuration"),consola.consola.info(" - Run `basis hooks install` to install git hooks"),!0}exports.init=init;
@@ -1,5 +0,0 @@
1
- import{execSync as m}from"node:child_process";import{writeFile as w,mkdir as I,chmod as j,access as O}from"node:fs/promises";import{consola as o}from"consola";import{join as h}from"pathe";import{l as p}from"./basis.C0E7mwQ6.mjs";const u=["applypatch-msg","pre-applypatch","post-applypatch","pre-commit","pre-merge-commit","prepare-commit-msg","commit-msg","post-commit","pre-rebase","post-checkout","post-merge","pre-push","pre-receive","update","proc-receive","post-receive","post-update","reference-transaction","push-to-checkout","pre-auto-gc","post-rewrite","sendemail-validate","fsmonitor-watchman","p4-changelist","p4-prepare-changelist","p4-post-changelist","p4-pre-submit","post-index-change"];async function v(){try{return m("git --version",{stdio:"ignore"}),!0}catch{return!1}}async function y(t){try{return await O(h(t,".git")),!0}catch{return!1}}async function $(t){try{m("git init",{cwd:t,stdio:"inherit"}),o.success("Initialized git repository")}catch(n){throw o.error("Failed to initialize git repository:",n),n}}function G(t){return u.includes(t)}function d(t){const n={},a={autoInitGit:t.autoInitGit,skipGitCheck:t.skipGitCheck,force:t.force};for(const[s,r]of Object.entries(t))s!=="autoInitGit"&&s!=="skipGitCheck"&&s!=="force"&&typeof r=="string"&&(n[s]=r);return{hooks:n,options:a}}function k(t){const n=[];for(const a of Object.keys(t))G(a)||n.push(a);return{valid:n.length===0,invalidHooks:n}}async function H(t=process.cwd(),n){const{config:a}=await p({cwd:t,overrides:n?{githooks:n}:void 0}),s=a.githooks;if(!s){o.error("No hooks configuration found");return}const{hooks:r,options:e}=d(s);if(!e.skipGitCheck&&!e.force&&!await v())throw o.error("Git command not found. Please install git or use --force option."),new Error("Git command not available");if(!await y(t))if(e.autoInitGit)o.info("Not a git repository, initializing..."),await $(t);else throw o.error("Not a git repository. Use --auto-init-git option or run 'git init' first."),new Error("Not a git repository");const c=k(r);if(!c.valid)throw o.error("Invalid hook names found:"),c.invalidHooks.forEach(i=>{o.error(` \u2717 ${i} (not a valid Git hook)`)}),o.info("Valid Git hooks:",u.join(", ")),new Error(`Invalid hook names: ${c.invalidHooks.join(", ")}`);if(o.start("Installing git hooks..."),Object.keys(r).length===0){o.warn("No hooks configured");return}try{const i=h(t,".git","hooks");await I(i,{recursive:!0});for(const[f,l]of Object.entries(r)){const g=h(i,f),b=N(l);await w(g,b,"utf-8"),await j(g,493),o.info(`Installed ${f} hook`)}o.success(`Installed ${Object.keys(r).length} git hooks`)}catch(i){throw o.error("Failed to install hooks:",i),i}}async function C(t=process.cwd(),n){const{config:a}=await p({cwd:t,overrides:n?{githooks:n}:void 0}),s=a.githooks||{},{hooks:r,options:e}=d(s);if(!e.skipGitCheck&&!e.force&&!await v())throw o.error("Git command not found. Please install git or use --force option."),new Error("Git command not available");if(!await y(t)&&!e.force)throw o.error("Not a git repository."),new Error("Not a git repository");const c=k(r);if(!c.valid)throw o.error("Invalid hook names found:"),c.invalidHooks.forEach(i=>{o.error(` \u2717 ${i} (not a valid Git hook)`)}),new Error(`Invalid hook names: ${c.invalidHooks.join(", ")}`);o.start("Uninstalling git hooks...");try{const i=h(t,".git","hooks");for(const f of Object.keys(r)){const l=h(i,f);try{await w(l,"","utf-8"),o.info(`Uninstalled ${f} hook`)}catch{}}o.success("Git hooks uninstalled")}catch(i){throw o.error("Failed to uninstall hooks:",i),i}}async function E(t=process.cwd(),n){const{config:a}=await p({cwd:t,overrides:n?{githooks:n}:void 0}),s=a.githooks||{},{hooks:r,options:e}=d(s);if(o.info("Configured git hooks:"),Object.keys(r).length===0){o.info("No hooks configured");return}(e.autoInitGit||e.skipGitCheck||e.force)&&(o.info("Options:"),e.autoInitGit&&o.info(" \u2022 Auto-init git: enabled"),e.skipGitCheck&&o.info(" \u2022 Skip git check: enabled"),e.force&&o.info(" \u2022 Force: enabled"));const c=k(r);c.valid||(o.warn("Warning: Found invalid hook names:"),c.invalidHooks.forEach(i=>{o.warn(` \u26A0 ${i} (not a valid Git hook)`)}));for(const[i,f]of Object.entries(r)){const l=G(i)?"\u2713":"\u26A0";o.info(` ${l} ${i}: ${f}`)}}function N(t){return`#!/bin/sh
2
- # Generated by @funish/basis
3
-
4
- ${t}
5
- `}export{u as V,H as i,E as l,C as u};
@@ -1 +0,0 @@
1
- import{execSync as d}from"node:child_process";import{consola as e}from"consola";import{detectPackageManager as w,runScript as y}from"nypm";import{readPackageJSON as $}from"pkg-types";import h from"semver";import{l as k}from"./basis.C0E7mwQ6.mjs";async function b(a,t,o){if(t.checkGitClean&&!o.skipTests)try{if(d("git status --porcelain",{cwd:a,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(i){e.warn("Could not check git status:",i)}if(t.checkTests&&!o.skipTests){e.start("Running tests...");try{t.testCommand?d(t.testCommand,{cwd:a,stdio:"inherit"}):await y("test",{cwd:a,silent:!1}),e.success("Tests passed")}catch(i){throw e.error("Tests failed"),i}}if(t.buildCommand&&!o.skipBuild){e.start("Building package...");try{d(t.buildCommand,{cwd:a,stdio:"inherit"}),e.success("Build completed")}catch(i){throw e.error("Build failed"),i}}}async function T(a,t){if(t.autoGitPush)try{d("git push",{cwd:a}),t.createGitTag&&d("git push --tags",{cwd:a}),e.success("Pushed changes to remote")}catch(o){e.warn("Failed to push changes:",o)}}async function C(a,t={}){const{config:o}=await k({cwd:a}),i=o.publish||{},m=await $(a),{name:n,version:c}=m;if(!n||!c)throw new Error("Missing name or version in package.json");if(!h.valid(c))throw new Error(`Invalid version format in package.json: ${c}`);const p=await w(a),u=p?.command||"npm";await b(a,i,t);let r;if(t.tag)r=t.tag;else if(t.stable||t.latest)r=i.stableTag||"latest";else if(h.prerelease(c)){const s=h.prerelease(c);r=s&&s[0]||i.defaultTag||"edge"}else r=i.stableTag||"latest";e.info(`Publishing ${n}@${c} to tag: ${r}`);const g=["publish","--tag",r,"--access",t.access||i.access||"public"];(t.registry||i.registry)&&g.push("--registry",t.registry||i.registry||""),t.dryRun&&g.push("--dry-run");const f=`${u} ${g.join(" ")}`;e.start("Publishing package...");try{if(d(f,{cwd:a,stdio:"inherit"}),t.dryRun)e.success("Dry run completed successfully");else{e.success(`Published ${n}@${c} to ${r}`);const s=i.defaultTag||"edge";if(r!==s){e.start(`Also publishing to ${s} tag...`);try{let l;p?.name==="yarn"?l=`${u} tag add ${n}@${c} ${s}`:l=`${u} dist-tag add ${n}@${c} ${s}`,d(l,{cwd:a,stdio:"inherit"}),e.success(`Also published ${n}@${c} to ${s}`)}catch(l){e.warn(`Failed to add ${s} tag:`,l)}}await T(a,i)}return{packageName:n,version:c,publishTag:r,dryRun:t.dryRun||!1}}catch(s){throw e.error("Failed to publish package:",s),s}}export{C as p};
@@ -1,127 +0,0 @@
1
- interface BasisConfig {
2
- lint?: LintConfig;
3
- githooks?: GitHooksConfig;
4
- packageManager?: PackageManagerConfig;
5
- version?: VersionConfig;
6
- publish?: PublishConfig;
7
- }
8
- interface LintConfig {
9
- staged?: Record<string, string>;
10
- commitMsg?: {
11
- types?: string[];
12
- maxLength?: number;
13
- minLength?: number;
14
- scopeRequired?: boolean;
15
- allowedScopes?: string[];
16
- };
17
- }
18
- declare const VALID_GIT_HOOKS: readonly ["applypatch-msg", "pre-applypatch", "post-applypatch", "pre-commit", "pre-merge-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-rebase", "post-checkout", "post-merge", "pre-push", "pre-receive", "update", "proc-receive", "post-receive", "post-update", "reference-transaction", "push-to-checkout", "pre-auto-gc", "post-rewrite", "sendemail-validate", "fsmonitor-watchman", "p4-changelist", "p4-prepare-changelist", "p4-post-changelist", "p4-pre-submit", "post-index-change"];
19
- type ValidGitHook = (typeof VALID_GIT_HOOKS)[number];
20
- interface GitHooksConfig extends Partial<Record<ValidGitHook, string>> {
21
- /** Whether to automatically initialize git repository if not found */
22
- autoInitGit?: boolean;
23
- /** Whether to skip git command availability check */
24
- skipGitCheck?: boolean;
25
- /** Force operation even if git is not available */
26
- force?: boolean;
27
- }
28
- interface PackageManagerConfig {
29
- /** Preferred package manager (aligned with nypm support) */
30
- preferred?: "npm" | "yarn" | "pnpm" | "bun" | "deno";
31
- /** Auto-detect package manager from project */
32
- autoDetect?: boolean;
33
- /** NPM registry URL */
34
- registry?: string;
35
- }
36
- interface VersionConfig {
37
- /** Git tag prefix */
38
- tagPrefix?: string;
39
- /** Auto commit version changes */
40
- autoCommit?: boolean;
41
- /** Auto create git tag */
42
- autoTag?: boolean;
43
- /** Auto push changes to remote */
44
- autoPush?: boolean;
45
- /** Prerelease identifier (alpha, beta, rc) */
46
- prereleaseId?: string;
47
- /** Commit message template */
48
- commitMessage?: string;
49
- }
50
- interface PublishConfig {
51
- /** NPM registry URL */
52
- registry?: string;
53
- /** Package access level */
54
- access?: "public" | "private";
55
- /** Default publish tag (for non-stable releases) */
56
- defaultTag?: string;
57
- /** Stable release tag */
58
- stableTag?: string;
59
- /** Build command before publish */
60
- buildCommand?: string;
61
- /** Test command before publish */
62
- testCommand?: string;
63
- /** Check git working directory is clean */
64
- checkGitClean?: boolean;
65
- /** Run tests before publish */
66
- checkTests?: boolean;
67
- /** Auto push git changes after publish */
68
- autoGitPush?: boolean;
69
- /** Create git tag after publish */
70
- createGitTag?: boolean;
71
- }
72
- interface CommitMessage {
73
- type: string;
74
- scope?: string;
75
- description: string;
76
- body?: string;
77
- footer?: string;
78
- isBreaking: boolean;
79
- }
80
- interface InitOptions {
81
- force?: boolean;
82
- skipGitCheck?: boolean;
83
- skipInstall?: boolean;
84
- }
85
- interface VersionOptions {
86
- version?: string;
87
- preid?: string;
88
- prerelease?: boolean;
89
- major?: boolean;
90
- minor?: boolean;
91
- patch?: boolean;
92
- tag?: string;
93
- message?: string;
94
- }
95
- interface PublishOptions {
96
- tag?: string;
97
- stable?: boolean;
98
- latest?: boolean;
99
- dryRun?: boolean;
100
- access?: "public" | "private";
101
- registry?: string;
102
- skipBuild?: boolean;
103
- skipTests?: boolean;
104
- }
105
- interface VersionUpdateResult {
106
- oldVersion: string;
107
- newVersion: string;
108
- tagName?: string;
109
- }
110
- interface PublishResult {
111
- packageName: string;
112
- version: string;
113
- publishTag: string;
114
- dryRun: boolean;
115
- }
116
-
117
- /**
118
- * Define a Basis configuration
119
- */
120
- declare function defineBasisConfig(config: BasisConfig): BasisConfig;
121
- /**
122
- * Default configuration
123
- */
124
- declare const defaultConfig: BasisConfig;
125
-
126
- export { defaultConfig as c, defineBasisConfig as d, VALID_GIT_HOOKS as e };
127
- export type { BasisConfig as B, CommitMessage as C, GitHooksConfig as G, InitOptions as I, LintConfig as L, PublishOptions as P, VersionOptions as V, PublishResult as a, VersionUpdateResult as b, ValidGitHook as f, PackageManagerConfig as g, VersionConfig as h, PublishConfig as i };
@@ -1,127 +0,0 @@
1
- interface BasisConfig {
2
- lint?: LintConfig;
3
- githooks?: GitHooksConfig;
4
- packageManager?: PackageManagerConfig;
5
- version?: VersionConfig;
6
- publish?: PublishConfig;
7
- }
8
- interface LintConfig {
9
- staged?: Record<string, string>;
10
- commitMsg?: {
11
- types?: string[];
12
- maxLength?: number;
13
- minLength?: number;
14
- scopeRequired?: boolean;
15
- allowedScopes?: string[];
16
- };
17
- }
18
- declare const VALID_GIT_HOOKS: readonly ["applypatch-msg", "pre-applypatch", "post-applypatch", "pre-commit", "pre-merge-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-rebase", "post-checkout", "post-merge", "pre-push", "pre-receive", "update", "proc-receive", "post-receive", "post-update", "reference-transaction", "push-to-checkout", "pre-auto-gc", "post-rewrite", "sendemail-validate", "fsmonitor-watchman", "p4-changelist", "p4-prepare-changelist", "p4-post-changelist", "p4-pre-submit", "post-index-change"];
19
- type ValidGitHook = (typeof VALID_GIT_HOOKS)[number];
20
- interface GitHooksConfig extends Partial<Record<ValidGitHook, string>> {
21
- /** Whether to automatically initialize git repository if not found */
22
- autoInitGit?: boolean;
23
- /** Whether to skip git command availability check */
24
- skipGitCheck?: boolean;
25
- /** Force operation even if git is not available */
26
- force?: boolean;
27
- }
28
- interface PackageManagerConfig {
29
- /** Preferred package manager (aligned with nypm support) */
30
- preferred?: "npm" | "yarn" | "pnpm" | "bun" | "deno";
31
- /** Auto-detect package manager from project */
32
- autoDetect?: boolean;
33
- /** NPM registry URL */
34
- registry?: string;
35
- }
36
- interface VersionConfig {
37
- /** Git tag prefix */
38
- tagPrefix?: string;
39
- /** Auto commit version changes */
40
- autoCommit?: boolean;
41
- /** Auto create git tag */
42
- autoTag?: boolean;
43
- /** Auto push changes to remote */
44
- autoPush?: boolean;
45
- /** Prerelease identifier (alpha, beta, rc) */
46
- prereleaseId?: string;
47
- /** Commit message template */
48
- commitMessage?: string;
49
- }
50
- interface PublishConfig {
51
- /** NPM registry URL */
52
- registry?: string;
53
- /** Package access level */
54
- access?: "public" | "private";
55
- /** Default publish tag (for non-stable releases) */
56
- defaultTag?: string;
57
- /** Stable release tag */
58
- stableTag?: string;
59
- /** Build command before publish */
60
- buildCommand?: string;
61
- /** Test command before publish */
62
- testCommand?: string;
63
- /** Check git working directory is clean */
64
- checkGitClean?: boolean;
65
- /** Run tests before publish */
66
- checkTests?: boolean;
67
- /** Auto push git changes after publish */
68
- autoGitPush?: boolean;
69
- /** Create git tag after publish */
70
- createGitTag?: boolean;
71
- }
72
- interface CommitMessage {
73
- type: string;
74
- scope?: string;
75
- description: string;
76
- body?: string;
77
- footer?: string;
78
- isBreaking: boolean;
79
- }
80
- interface InitOptions {
81
- force?: boolean;
82
- skipGitCheck?: boolean;
83
- skipInstall?: boolean;
84
- }
85
- interface VersionOptions {
86
- version?: string;
87
- preid?: string;
88
- prerelease?: boolean;
89
- major?: boolean;
90
- minor?: boolean;
91
- patch?: boolean;
92
- tag?: string;
93
- message?: string;
94
- }
95
- interface PublishOptions {
96
- tag?: string;
97
- stable?: boolean;
98
- latest?: boolean;
99
- dryRun?: boolean;
100
- access?: "public" | "private";
101
- registry?: string;
102
- skipBuild?: boolean;
103
- skipTests?: boolean;
104
- }
105
- interface VersionUpdateResult {
106
- oldVersion: string;
107
- newVersion: string;
108
- tagName?: string;
109
- }
110
- interface PublishResult {
111
- packageName: string;
112
- version: string;
113
- publishTag: string;
114
- dryRun: boolean;
115
- }
116
-
117
- /**
118
- * Define a Basis configuration
119
- */
120
- declare function defineBasisConfig(config: BasisConfig): BasisConfig;
121
- /**
122
- * Default configuration
123
- */
124
- declare const defaultConfig: BasisConfig;
125
-
126
- export { defaultConfig as c, defineBasisConfig as d, VALID_GIT_HOOKS as e };
127
- export type { BasisConfig as B, CommitMessage as C, GitHooksConfig as G, InitOptions as I, LintConfig as L, PublishOptions as P, VersionOptions as V, PublishResult as a, VersionUpdateResult as b, ValidGitHook as f, PackageManagerConfig as g, VersionConfig as h, PublishConfig as i };
@@ -1,127 +0,0 @@
1
- interface BasisConfig {
2
- lint?: LintConfig;
3
- githooks?: GitHooksConfig;
4
- packageManager?: PackageManagerConfig;
5
- version?: VersionConfig;
6
- publish?: PublishConfig;
7
- }
8
- interface LintConfig {
9
- staged?: Record<string, string>;
10
- commitMsg?: {
11
- types?: string[];
12
- maxLength?: number;
13
- minLength?: number;
14
- scopeRequired?: boolean;
15
- allowedScopes?: string[];
16
- };
17
- }
18
- declare const VALID_GIT_HOOKS: readonly ["applypatch-msg", "pre-applypatch", "post-applypatch", "pre-commit", "pre-merge-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-rebase", "post-checkout", "post-merge", "pre-push", "pre-receive", "update", "proc-receive", "post-receive", "post-update", "reference-transaction", "push-to-checkout", "pre-auto-gc", "post-rewrite", "sendemail-validate", "fsmonitor-watchman", "p4-changelist", "p4-prepare-changelist", "p4-post-changelist", "p4-pre-submit", "post-index-change"];
19
- type ValidGitHook = (typeof VALID_GIT_HOOKS)[number];
20
- interface GitHooksConfig extends Partial<Record<ValidGitHook, string>> {
21
- /** Whether to automatically initialize git repository if not found */
22
- autoInitGit?: boolean;
23
- /** Whether to skip git command availability check */
24
- skipGitCheck?: boolean;
25
- /** Force operation even if git is not available */
26
- force?: boolean;
27
- }
28
- interface PackageManagerConfig {
29
- /** Preferred package manager (aligned with nypm support) */
30
- preferred?: "npm" | "yarn" | "pnpm" | "bun" | "deno";
31
- /** Auto-detect package manager from project */
32
- autoDetect?: boolean;
33
- /** NPM registry URL */
34
- registry?: string;
35
- }
36
- interface VersionConfig {
37
- /** Git tag prefix */
38
- tagPrefix?: string;
39
- /** Auto commit version changes */
40
- autoCommit?: boolean;
41
- /** Auto create git tag */
42
- autoTag?: boolean;
43
- /** Auto push changes to remote */
44
- autoPush?: boolean;
45
- /** Prerelease identifier (alpha, beta, rc) */
46
- prereleaseId?: string;
47
- /** Commit message template */
48
- commitMessage?: string;
49
- }
50
- interface PublishConfig {
51
- /** NPM registry URL */
52
- registry?: string;
53
- /** Package access level */
54
- access?: "public" | "private";
55
- /** Default publish tag (for non-stable releases) */
56
- defaultTag?: string;
57
- /** Stable release tag */
58
- stableTag?: string;
59
- /** Build command before publish */
60
- buildCommand?: string;
61
- /** Test command before publish */
62
- testCommand?: string;
63
- /** Check git working directory is clean */
64
- checkGitClean?: boolean;
65
- /** Run tests before publish */
66
- checkTests?: boolean;
67
- /** Auto push git changes after publish */
68
- autoGitPush?: boolean;
69
- /** Create git tag after publish */
70
- createGitTag?: boolean;
71
- }
72
- interface CommitMessage {
73
- type: string;
74
- scope?: string;
75
- description: string;
76
- body?: string;
77
- footer?: string;
78
- isBreaking: boolean;
79
- }
80
- interface InitOptions {
81
- force?: boolean;
82
- skipGitCheck?: boolean;
83
- skipInstall?: boolean;
84
- }
85
- interface VersionOptions {
86
- version?: string;
87
- preid?: string;
88
- prerelease?: boolean;
89
- major?: boolean;
90
- minor?: boolean;
91
- patch?: boolean;
92
- tag?: string;
93
- message?: string;
94
- }
95
- interface PublishOptions {
96
- tag?: string;
97
- stable?: boolean;
98
- latest?: boolean;
99
- dryRun?: boolean;
100
- access?: "public" | "private";
101
- registry?: string;
102
- skipBuild?: boolean;
103
- skipTests?: boolean;
104
- }
105
- interface VersionUpdateResult {
106
- oldVersion: string;
107
- newVersion: string;
108
- tagName?: string;
109
- }
110
- interface PublishResult {
111
- packageName: string;
112
- version: string;
113
- publishTag: string;
114
- dryRun: boolean;
115
- }
116
-
117
- /**
118
- * Define a Basis configuration
119
- */
120
- declare function defineBasisConfig(config: BasisConfig): BasisConfig;
121
- /**
122
- * Default configuration
123
- */
124
- declare const defaultConfig: BasisConfig;
125
-
126
- export { defaultConfig as c, defineBasisConfig as d, VALID_GIT_HOOKS as e };
127
- export type { BasisConfig as B, CommitMessage as C, GitHooksConfig as G, InitOptions as I, LintConfig as L, PublishOptions as P, VersionOptions as V, PublishResult as a, VersionUpdateResult as b, ValidGitHook as f, PackageManagerConfig as g, VersionConfig as h, PublishConfig as i };
@@ -1,4 +0,0 @@
1
- import{execSync as m}from"node:child_process";import{existsSync as $,readFileSync as v}from"node:fs";import{consola as d}from"consola";import w from"micromatch";import{resolve as M}from"pathe";import{l as u}from"./basis.C0E7mwQ6.mjs";const S=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function p(o){const r=o.trim().split(`
2
- `),t=r[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!t)return null;const[,l,,s,c,e]=t,a=r.slice(1).find(i=>i.trim())?.trim(),n=r.slice(-1)[0]?.trim();return{type:l,scope:s,description:e,body:a,footer:n,isBreaking:!!c||o.includes("BREAKING CHANGE:")}}function g(o,r={}){const t=[],{types:l=S,maxLength:s=72,minLength:c=10,scopeRequired:e=!1,allowedScopes:a=[]}=r,n=p(o);if(!n)return{valid:!1,errors:["Invalid commit format. Expected: type(scope): description"]};l.includes(n.type)||t.push(`Invalid type '${n.type}'. Allowed: ${l.join(", ")}`);const i=o.split(`
3
- `)[0];return i.length>s&&t.push(`Header too long (${i.length}). Max: ${s}`),i.length<c&&t.push(`Header too short (${i.length}). Min: ${c}`),e&&!n.scope&&t.push("Scope is required"),n.scope&&a.length>0&&!a.includes(n.scope)&&t.push(`Invalid scope '${n.scope}'. Allowed: ${a.join(", ")}`),{valid:t.length===0,errors:t}}function h(){try{return m("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
4
- `).filter(Boolean)}catch{return[]}}async function x(o=process.cwd(),r){const{config:t}=await u({cwd:o,overrides:r?{lint:{staged:r}}:void 0}),l=t.lint?.staged||{},s=h();if(s.length===0)return d.info("No staged files to lint"),!0;if(Object.keys(l).length===0)return d.warn("No staged lint configuration found"),!0;let c=!1;const e=new Set;for(const[a,n]of Object.entries(l)){const i=s.filter(f=>!e.has(f)&&w.isMatch(f.split("/").pop()||f,a));if(i.length!==0){d.start(`Linting ${i.length} files: ${a}`);try{const f=`${n} ${i.join(" ")}`;m(f,{stdio:"inherit",cwd:o}),m(`git add ${i.join(" ")}`,{stdio:"inherit",cwd:o}),i.forEach(y=>e.add(y)),d.success(`\u2713 ${a}`)}catch(f){c=!0,d.error(`\u2717 ${a} failed:`,f)}}}return!c}async function C(o=process.cwd(),r){const{config:t}=await u({cwd:o,overrides:r?{lint:{commitMsg:r}}:void 0}),l=t.lint?.commitMsg||{};let s;try{const e=M(".git/COMMIT_EDITMSG");$(e)?s=v(e,"utf8"):s=m("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(e){return d.error("\u2717 Failed to read commit message:",e),!1}const c=g(s,l);return c.valid?(d.success("\u2713 Commit message is valid"),!0):(d.error("\u2717 Invalid commit message:"),c.errors.forEach(e=>d.error(` ${e}`)),!1)}export{C as a,h as g,x as l,p,g as v};