@funish/basis 0.1.1 → 0.1.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.
- package/README.md +4 -4
- package/dist/chunks/git.cjs +1 -1
- package/dist/chunks/git.mjs +1 -1
- package/dist/chunks/init.cjs +1 -1
- package/dist/chunks/init.mjs +1 -1
- package/dist/chunks/lint.cjs +1 -1
- package/dist/chunks/lint.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{basis.C4FYR2wo.mjs → basis.5if__eE1.mjs} +1 -1
- package/dist/shared/basis.CGkMo_WB.cjs +3 -0
- package/dist/shared/basis.Cc1QkX4i.mjs +3 -0
- package/dist/shared/basis.CyWSd-ys.mjs +10 -0
- package/dist/shared/{basis.DuZo2uz1.cjs → basis.GHY7v-ns.cjs} +4 -4
- package/dist/shared/{basis.1-2-e6uu.cjs → basis.iEUClefn.cjs} +1 -1
- package/package.json +2 -2
- package/dist/shared/basis.BDhrNAQD.mjs +0 -10
- package/dist/shared/basis.BMtlh4_u.mjs +0 -3
- package/dist/shared/basis.CckwE9Ed.cjs +0 -3
package/README.md
CHANGED
|
@@ -275,8 +275,8 @@ export default defineBasisConfig({
|
|
|
275
275
|
// See: https://github.com/funish/basis/tree/main/packages/basis#configuration
|
|
276
276
|
git: {
|
|
277
277
|
hooks: {
|
|
278
|
-
"pre-commit": "
|
|
279
|
-
"commit-msg": "
|
|
278
|
+
"pre-commit": "pnpmbasis lint --staged", // Auto-adapts to your package manager
|
|
279
|
+
"commit-msg": "pnpmbasis git --lint-commit",
|
|
280
280
|
},
|
|
281
281
|
},
|
|
282
282
|
});
|
|
@@ -347,8 +347,8 @@ export default defineBasisConfig({
|
|
|
347
347
|
git: {
|
|
348
348
|
// Hook commands
|
|
349
349
|
hooks: {
|
|
350
|
-
"pre-commit": "
|
|
351
|
-
"commit-msg": "
|
|
350
|
+
"pre-commit": "pnpmbasis lint --staged",
|
|
351
|
+
"commit-msg": "pnpmbasis git --lint-commit",
|
|
352
352
|
},
|
|
353
353
|
|
|
354
354
|
// Commit message validation
|
package/dist/chunks/git.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const citty=require("citty"),consola=require("consola"),git$1=require("../shared/basis.
|
|
1
|
+
"use strict";const citty=require("citty"),consola=require("consola"),git$1=require("../shared/basis.GHY7v-ns.cjs");require("node:child_process"),require("node:fs/promises"),require("c12/update"),require("defu"),require("ini"),require("pathe"),require("../shared/basis.D3fInv-P.cjs"),require("c12"),require("../config.cjs");const git=citty.defineCommand({meta:{name:"git",description:"Git configuration and hooks management"},subCommands:{setup:citty.defineCommand({meta:{name:"setup",description:"Setup Git configuration and hooks"},async run(){const e=process.cwd();await git$1.setupGit(e)||process.exit(1)}}),config:citty.defineCommand({meta:{name:"config",description:"Setup Git configuration only"},async run(){const e=process.cwd();await git$1.setupGitConfig(e)||(consola.consola.error("Git configuration failed"),process.exit(1))}}),hooks:citty.defineCommand({meta:{name:"hooks",description:"Setup Git hooks only"},async run(){const e=process.cwd();await git$1.setupGitHooks(e)||(consola.consola.error("Git hooks setup failed"),process.exit(1))}}),remove:citty.defineCommand({meta:{name:"remove",description:"Remove Git hooks"},args:{hooks:{type:"positional",description:"Specific hook names to remove (optional)",required:!1},"update-config":{type:"boolean",description:"Also remove hooks configuration from basis.config.ts",default:!1}},async run({args:e}){const o=process.cwd(),i=e.hooks&&typeof e.hooks=="string"?[e.hooks]:Array.isArray(e.hooks)?e.hooks.filter(s=>typeof s=="string"):void 0,t=typeof e["update-config"]=="boolean"?e["update-config"]:!1;await git$1.removeGitHooks(o,i,{updateConfig:t})||(consola.consola.error("Git hooks removal failed"),process.exit(1))}}),reset:citty.defineCommand({meta:{name:"reset",description:"Reset Git configuration (keeps user info by default)"},args:{"keep-user":{type:"boolean",description:"Keep user information (name, email)",default:!0},"update-config":{type:"boolean",description:"Also remove git config from basis.config.ts",default:!1}},async run({args:e}){const o=process.cwd(),i=typeof e["keep-user"]=="boolean"?e["keep-user"]:!0,t=typeof e["update-config"]=="boolean"?e["update-config"]:!1;await git$1.resetGitConfig(o,i,{updateConfig:t})||(consola.consola.error("Git configuration reset failed"),process.exit(1))}}),init:citty.defineCommand({meta:{name:"init",description:"Initialize Git repository with basis configuration"},async run(){const e=process.cwd();await git$1.initGitRepo(e)||(consola.consola.error("Git initialization failed"),process.exit(1))}}),"lint-commit":citty.defineCommand({meta:{name:"lint-commit",description:"Validate commit message"},async run(){const e=process.cwd();await git$1.lintCommitMessage(e)||(consola.consola.error("Commit message validation failed"),process.exit(1))}})},async run(){}});exports.git=git;
|
package/dist/chunks/git.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as e}from"citty";import{consola as i}from"consola";import{l as r,i as c,b as p,d as m,c as f,a as d,s as u}from"../shared/basis.
|
|
1
|
+
import{defineCommand as e}from"citty";import{consola as i}from"consola";import{l as r,i as c,b as p,d as m,c as f,a as d,s as u}from"../shared/basis.CyWSd-ys.mjs";import"node:child_process";import"node:fs/promises";import"c12/update";import"defu";import"ini";import"pathe";import"../shared/basis.BrlVPuDi.mjs";import"c12";import"../config.mjs";const l=e({meta:{name:"git",description:"Git configuration and hooks management"},subCommands:{setup:e({meta:{name:"setup",description:"Setup Git configuration and hooks"},async run(){const o=process.cwd();await u(o)||process.exit(1)}}),config:e({meta:{name:"config",description:"Setup Git configuration only"},async run(){const o=process.cwd();await d(o)||(i.error("Git configuration failed"),process.exit(1))}}),hooks:e({meta:{name:"hooks",description:"Setup Git hooks only"},async run(){const o=process.cwd();await f(o)||(i.error("Git hooks setup failed"),process.exit(1))}}),remove:e({meta:{name:"remove",description:"Remove Git hooks"},args:{hooks:{type:"positional",description:"Specific hook names to remove (optional)",required:!1},"update-config":{type:"boolean",description:"Also remove hooks configuration from basis.config.ts",default:!1}},async run({args:o}){const t=process.cwd(),s=o.hooks&&typeof o.hooks=="string"?[o.hooks]:Array.isArray(o.hooks)?o.hooks.filter(n=>typeof n=="string"):void 0,a=typeof o["update-config"]=="boolean"?o["update-config"]:!1;await m(t,s,{updateConfig:a})||(i.error("Git hooks removal failed"),process.exit(1))}}),reset:e({meta:{name:"reset",description:"Reset Git configuration (keeps user info by default)"},args:{"keep-user":{type:"boolean",description:"Keep user information (name, email)",default:!0},"update-config":{type:"boolean",description:"Also remove git config from basis.config.ts",default:!1}},async run({args:o}){const t=process.cwd(),s=typeof o["keep-user"]=="boolean"?o["keep-user"]:!0,a=typeof o["update-config"]=="boolean"?o["update-config"]:!1;await p(t,s,{updateConfig:a})||(i.error("Git configuration reset failed"),process.exit(1))}}),init:e({meta:{name:"init",description:"Initialize Git repository with basis configuration"},async run(){const o=process.cwd();await c(o)||(i.error("Git initialization failed"),process.exit(1))}}),"lint-commit":e({meta:{name:"lint-commit",description:"Validate commit message"},async run(){const o=process.cwd();await r(o)||(i.error("Commit message validation failed"),process.exit(1))}})},async run(){}});export{l as git};
|
package/dist/chunks/init.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const citty=require("citty"),consola=require("consola"),init$1=require("../shared/basis.
|
|
1
|
+
"use strict";const citty=require("citty"),consola=require("consola"),init$1=require("../shared/basis.iEUClefn.cjs");require("c12/update"),require("magicast"),require("nypm"),require("pathe"),require("pkg-types"),require("../shared/basis.D3fInv-P.cjs"),require("node:fs/promises"),require("c12"),require("../config.cjs"),require("../shared/basis.GHY7v-ns.cjs"),require("node:child_process"),require("defu"),require("ini");const init=citty.defineCommand({meta:{name:"init",description:"Initialize basis configuration"},args:{force:{type:"boolean",alias:"f",description:"Overwrite existing configuration"},"skip-git-check":{type:"boolean",description:"Skip git directory check"},"skip-install":{type:"boolean",description:"Skip dependency installation"}},async run({args:e}){try{await init$1.init(process.cwd(),{force:e.force,skipGitCheck:e["skip-git-check"],skipInstall:e["skip-install"]})}catch(i){consola.consola.error("Init failed:",i),process.exit(1)}}});exports.default=init;
|
package/dist/chunks/init.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as o}from"citty";import{consola as r}from"consola";import{i as e}from"../shared/basis.
|
|
1
|
+
import{defineCommand as o}from"citty";import{consola as r}from"consola";import{i as e}from"../shared/basis.5if__eE1.mjs";import"c12/update";import"magicast";import"nypm";import"pathe";import"pkg-types";import"../shared/basis.BrlVPuDi.mjs";import"node:fs/promises";import"c12";import"../config.mjs";import"../shared/basis.CyWSd-ys.mjs";import"node:child_process";import"defu";import"ini";const p=o({meta:{name:"init",description:"Initialize basis configuration"},args:{force:{type:"boolean",alias:"f",description:"Overwrite existing configuration"},"skip-git-check":{type:"boolean",description:"Skip git directory check"},"skip-install":{type:"boolean",description:"Skip dependency installation"}},async run({args:i}){try{await e(process.cwd(),{force:i.force,skipGitCheck:i["skip-git-check"],skipInstall:i["skip-install"]})}catch(t){r.error("Init failed:",t),process.exit(1)}}});export{p as default};
|
package/dist/chunks/lint.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const citty=require("citty"),consola=require("consola"),lint$1=require("../shared/basis.
|
|
1
|
+
"use strict";const citty=require("citty"),consola=require("consola"),lint$1=require("../shared/basis.CGkMo_WB.cjs");require("node:child_process"),require("node:fs/promises"),require("fast-glob"),require("micromatch"),require("nypm"),require("pathe"),require("pkg-types"),require("../shared/basis.D3fInv-P.cjs"),require("c12"),require("../config.cjs");const lint=citty.defineCommand({meta:{name:"lint",description:"Run comprehensive project linting and quality checks"},args:{staged:{type:"boolean",description:"Lint only staged files using configured commands",default:!1},project:{type:"boolean",description:"Run project-wide lint commands",default:!1},deps:{type:"boolean",description:"Check dependencies (outdated, security, blocked packages)",default:!1},structure:{type:"boolean",description:"Check project structure (required files/dirs, naming conventions)",default:!1},docs:{type:"boolean",description:"Check documentation (README, CHANGELOG)",default:!1},all:{type:"boolean",description:"Run all lint checks",default:!1},fix:{type:"boolean",description:"Automatically fix issues where possible",default:!1}},async run({args:e}){const t=process.cwd();let i=!0;if(!e.staged&&!e.project&&!e.deps&&!e.structure&&!e.docs&&!e.all&&(e.staged=!0),e.all)i=await lint$1.lintAll(t,e.fix);else{const s=[];e.staged&&s.push(()=>lint$1.lintStaged(t)),e.project&&s.push(()=>lint$1.lintProject(t)),e.deps&&s.push(()=>lint$1.lintDependencies(t,void 0,e.fix)),e.structure&&s.push(()=>lint$1.lintStructure(t,void 0,e.fix)),e.docs&&s.push(()=>lint$1.lintDocs(t,void 0,e.fix));for(const o of s)await o()||(i=!1)}i||(consola.consola.error("Some lint checks failed"),process.exit(1))}});exports.lint=lint;
|
package/dist/chunks/lint.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as a}from"citty";import{consola as n}from"consola";import{l as r,b as l,c,d as p,e as d,f as u}from"../shared/basis.
|
|
1
|
+
import{defineCommand as a}from"citty";import{consola as n}from"consola";import{l as r,b as l,c,d as p,e as d,f as u}from"../shared/basis.Cc1QkX4i.mjs";import"node:child_process";import"node:fs/promises";import"fast-glob";import"micromatch";import"nypm";import"pathe";import"pkg-types";import"../shared/basis.BrlVPuDi.mjs";import"c12";import"../config.mjs";const f=a({meta:{name:"lint",description:"Run comprehensive project linting and quality checks"},args:{staged:{type:"boolean",description:"Lint only staged files using configured commands",default:!1},project:{type:"boolean",description:"Run project-wide lint commands",default:!1},deps:{type:"boolean",description:"Check dependencies (outdated, security, blocked packages)",default:!1},structure:{type:"boolean",description:"Check project structure (required files/dirs, naming conventions)",default:!1},docs:{type:"boolean",description:"Check documentation (README, CHANGELOG)",default:!1},all:{type:"boolean",description:"Run all lint checks",default:!1},fix:{type:"boolean",description:"Automatically fix issues where possible",default:!1}},async run({args:t}){const e=process.cwd();let i=!0;if(!t.staged&&!t.project&&!t.deps&&!t.structure&&!t.docs&&!t.all&&(t.staged=!0),t.all)i=await r(e,t.fix);else{const o=[];t.staged&&o.push(()=>l(e)),t.project&&o.push(()=>c(e)),t.deps&&o.push(()=>p(e,void 0,t.fix)),t.structure&&o.push(()=>d(e,void 0,t.fix)),t.docs&&o.push(()=>u(e,void 0,t.fix));for(const s of o)await s()||(i=!1)}i||(n.error("Some lint checks failed"),process.exit(1))}});export{f as lint};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const config=require("./config.cjs"),git=require("./shared/basis.
|
|
1
|
+
"use strict";const config=require("./config.cjs"),git=require("./shared/basis.GHY7v-ns.cjs"),init=require("./shared/basis.iEUClefn.cjs"),lint=require("./shared/basis.CGkMo_WB.cjs"),publish=require("./shared/basis.Bz4YLlJG.cjs"),version=require("./shared/basis.Bqr6BGbD.cjs"),utils=require("./shared/basis.D3fInv-P.cjs");require("node:child_process"),require("node:fs/promises"),require("c12/update"),require("consola"),require("defu"),require("ini"),require("pathe"),require("magicast"),require("nypm"),require("pkg-types"),require("fast-glob"),require("micromatch"),require("semver"),require("c12");class Basis{config=null;cwd;constructor(e=process.cwd()){this.cwd=e}getCwd(){return this.cwd}setCwd(e){this.cwd=e,this.config=null}async getConfig(){if(!this.config){const{config:e}=await utils.loadConfig({cwd:this.cwd});this.config=e}return this.config}async reloadConfig(){return this.config=null,await this.getConfig()}async setup(e={}){return await init.init(this.cwd,e)?await git.setupGit(this.cwd):!1}async release(e={},s={}){if(!await lint.lintAll(this.cwd))throw new Error("Lint checks failed. Fix issues before releasing.");const i=await version.updatePackageVersion(this.cwd,e),r=await publish.publishPackage(this.cwd,s);return{version:i,publish:r}}}function createBasis(t=process.cwd()){return new Basis(t)}const 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"];exports.defaultConfig=config.defaultConfig,exports.defineBasisConfig=config.defineBasisConfig,exports.initGitRepo=git.initGitRepo,exports.lintCommitMessage=git.lintCommitMessage,exports.parseCommitMessage=git.parseCommitMessage,exports.readGitConfig=git.readGitConfig,exports.removeGitHooks=git.removeGitHooks,exports.resetGitConfig=git.resetGitConfig,exports.setupGit=git.setupGit,exports.setupGitConfig=git.setupGitConfig,exports.setupGitHooks=git.setupGitHooks,exports.validateCommitMessage=git.validateCommitMessage,exports.writeGitConfig=git.writeGitConfig,exports.init=init.init,exports.getProjectFiles=lint.getProjectFiles,exports.getStagedFiles=lint.getStagedFiles,exports.lintAll=lint.lintAll,exports.lintDependencies=lint.lintDependencies,exports.lintDocs=lint.lintDocs,exports.lintProject=lint.lintProject,exports.lintStaged=lint.lintStaged,exports.lintStructure=lint.lintStructure,exports.publishPackage=publish.publishPackage,exports.updatePackageVersion=version.updatePackageVersion,exports.fileExists=utils.fileExists,exports.getPackageManagerCommands=utils.getPackageManagerCommands,exports.loadConfig=utils.loadConfig,exports.Basis=Basis,exports.VALID_GIT_HOOKS=VALID_GIT_HOOKS,exports.createBasis=createBasis;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{defaultConfig,defineBasisConfig}from"./config.mjs";import{s as e}from"./shared/basis.
|
|
1
|
+
export{defaultConfig,defineBasisConfig}from"./config.mjs";import{s as e}from"./shared/basis.CyWSd-ys.mjs";export{i as initGitRepo,l as lintCommitMessage,p as parseCommitMessage,r as readGitConfig,d as removeGitHooks,b as resetGitConfig,a as setupGitConfig,c as setupGitHooks,v as validateCommitMessage,w as writeGitConfig}from"./shared/basis.CyWSd-ys.mjs";import{i as s}from"./shared/basis.5if__eE1.mjs";import{l as o}from"./shared/basis.Cc1QkX4i.mjs";export{a as getProjectFiles,g as getStagedFiles,d as lintDependencies,f as lintDocs,c as lintProject,b as lintStaged,e as lintStructure}from"./shared/basis.Cc1QkX4i.mjs";import{p as a}from"./shared/basis.CYJFGkEy.mjs";import{u as r}from"./shared/basis.4m3-erzm.mjs";import{l as p}from"./shared/basis.BrlVPuDi.mjs";export{f as fileExists,g as getPackageManagerCommands}from"./shared/basis.BrlVPuDi.mjs";import"node:child_process";import"node:fs/promises";import"c12/update";import"consola";import"defu";import"ini";import"pathe";import"magicast";import"nypm";import"pkg-types";import"fast-glob";import"micromatch";import"semver";import"c12";class c{config=null;cwd;constructor(t=process.cwd()){this.cwd=t}getCwd(){return this.cwd}setCwd(t){this.cwd=t,this.config=null}async getConfig(){if(!this.config){const{config:t}=await p({cwd:this.cwd});this.config=t}return this.config}async reloadConfig(){return this.config=null,await this.getConfig()}async setup(t={}){return await s(this.cwd,t)?await e(this.cwd):!1}async release(t={},n={}){if(!await o(this.cwd))throw new Error("Lint checks failed. Fix issues before releasing.");const m=await r(this.cwd,t),g=await a(this.cwd,n);return{version:m,publish:g}}}function f(i=process.cwd()){return new c(i)}const l=["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"];export{c as Basis,l as VALID_GIT_HOOKS,f as createBasis,s as init,o as lintAll,p as loadConfig,a as publishPackage,e as setupGit,r as updatePackageVersion};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{updateConfig as S}from"c12/update";import{consola as i}from"consola";import{parseModule as z,generateCode as B}from"magicast";import{detectPackageManager as v,addDevDependency as F}from"nypm";import{resolve as c}from"pathe";import{findWorkspaceDir as P,readPackageJSON as C,writePackageJSON as D}from"pkg-types";import{f as p,g as I}from"./basis.BrlVPuDi.mjs";import{i as J,s as M}from"./basis.
|
|
1
|
+
import{updateConfig as S}from"c12/update";import{consola as i}from"consola";import{parseModule as z,generateCode as B}from"magicast";import{detectPackageManager as v,addDevDependency as F}from"nypm";import{resolve as c}from"pathe";import{findWorkspaceDir as P,readPackageJSON as C,writePackageJSON as D}from"pkg-types";import{f as p,g as I}from"./basis.BrlVPuDi.mjs";import{i as J,s as M}from"./basis.CyWSd-ys.mjs";const j={ts:{ext:"ts",label:"TypeScript"},mjs:{ext:"mjs",label:"ES Module"},cjs:{ext:"cjs",label:"CommonJS"}};function N(t,l="npm"){const n=z(t==="cjs"?`const { defineBasisConfig } = require("@funish/basis");
|
|
2
2
|
|
|
3
3
|
module.exports = defineBasisConfig({});`:`import { defineBasisConfig } from "@funish/basis";
|
|
4
4
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";const node_child_process=require("node:child_process"),promises=require("node:fs/promises"),consola=require("consola"),P=require("fast-glob"),$=require("micromatch"),nypm=require("nypm"),pathe=require("pathe"),pkgTypes=require("pkg-types"),utils=require("./basis.D3fInv-P.cjs");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const P__default=_interopDefaultCompat(P),$__default=_interopDefaultCompat($);function getStagedFiles(){try{const t=node_child_process.execSync("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
|
|
2
|
+
`).filter(Boolean),i=node_child_process.execSync("git diff --cached --name-only --diff-filter=D",{encoding:"utf8"}),o=new Set(i.trim().split(`
|
|
3
|
+
`).filter(Boolean));return t.filter(s=>!o.has(s))}catch{return[]}}async function getProjectFiles(t,i=["**/*"],o=["node_modules/**","dist/**","build/**",".git/**"]){try{return await P__default(i,{cwd:t,ignore:o,onlyFiles:!0,dot:!1,absolute:!1})}catch(s){return consola.consola.warn("Failed to scan project files:",s),[]}}async function lintStaged(t=process.cwd(),i){const{config:o}=await utils.loadConfig({cwd:t,overrides:i?{lint:{staged:i}}:void 0}),s=o.lint?.staged||{},e=getStagedFiles();if(e.length===0)return!0;if(Object.keys(s).length===0)return consola.consola.warn("No staged lint configuration found. Add lint.staged section to your basis.config.ts"),!0;let r=!1;const n=new Set;for(const[a,u]of Object.entries(s)){const f=e.filter(c=>!n.has(c)&&$__default.isMatch(c.split("/").pop()||c,a));if(f.length!==0){consola.consola.start(`Running staged lint for pattern: ${a}`);try{node_child_process.execSync(u,{stdio:"inherit",cwd:t});const c=[];for(const l of f)await utils.fileExists(pathe.resolve(t,l))&&c.push(l);c.length>0&&node_child_process.execSync(`git add ${c.join(" ")}`,{stdio:"inherit",cwd:t}),f.forEach(l=>n.add(l))}catch(c){r=!0,consola.consola.error(`Lint pattern '${a}' failed. Please fix the issues and try again:`,c)}}}return!r}async function lintProject(t=process.cwd(),i){const{config:o}=await utils.loadConfig({cwd:t,overrides:i?{lint:{project:i}}:void 0}),s=o.lint?.project||{};if(Object.keys(s).length===0)return consola.consola.warn("No project lint configuration found. Add lint.project section to your basis.config.ts"),!0;consola.consola.start("Running project-wide linting...");let e=!1;for(const[r,n]of Object.entries(s)){consola.consola.start(`Running project lint: ${r}`);try{node_child_process.execSync(n,{stdio:"inherit",cwd:t})}catch(a){e=!0,consola.consola.error(`Project lint pattern '${r}' failed. Please fix the issues and try again:`,a)}}return!e}async function lintDependencies(t=process.cwd(),i,o=!1){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{lint:{dependencies:i}}:void 0}),e=s.lint?.dependencies||{},r=s.lint?.fix?.dependencies||{};let n=!1;try{const a=await pkgTypes.readPackageJSON(t),u={...a.dependencies,...a.devDependencies},f=(await nypm.detectPackageManager(t))?.name||"npm",c=utils.getPackageManagerCommands(f);if(consola.consola.start("Checking dependencies..."),e.blockedPackages&&e.blockedPackages.length>0){const l=Object.keys(u).filter(d=>e.blockedPackages?.includes(d));if(l.length>0)if(o&&r.removeBlocked&&c.remove){consola.consola.start(`Removing blocked packages: ${l.join(", ")}`);try{for(const d of l)node_child_process.execSync(`${c.remove} ${d}`,{cwd:t,stdio:"inherit"});consola.consola.success(`Removed ${l.length} blocked packages`)}catch(d){consola.consola.error("Failed to remove blocked packages:",d),n=!0}}else consola.consola.error(`Blocked packages found: ${l.join(", ")}. Please remove these packages from your dependencies.`),n=!0}if(e.checkOutdated)if(c.outdated)try{node_child_process.execSync(c.outdated,{cwd:t,stdio:"pipe"})}catch(l){if(o&&r.updateOutdated&&c.update){consola.consola.start("Updating outdated dependencies...");try{node_child_process.execSync(c.update,{cwd:t,stdio:"inherit"}),consola.consola.success("Dependencies updated")}catch(d){consola.consola.error("Failed to update dependencies:",d),n=!0}}else consola.consola.warn("Some dependencies are outdated:",l)}else consola.consola.warn(`Outdated check not available for ${f}`);if(e.checkSecurity)if(c.audit)try{node_child_process.execSync(c.audit,{cwd:t,stdio:"pipe"})}catch(l){if(o&&r.fixSecurity&&c.auditFix){consola.consola.start("Fixing security vulnerabilities...");try{node_child_process.execSync(c.auditFix,{cwd:t,stdio:"inherit"}),consola.consola.success("Security fixes applied")}catch(d){consola.consola.error("Failed to fix security issues:",d),n=!0}}else consola.consola.error("Security vulnerabilities detected:",l),n=!0}else consola.consola.warn(`Security audit not available for ${f}`);if(e.allowedLicenses&&e.allowedLicenses.length>0){const{hasIssues:l,invalidLicenses:d}=await S(t,e.allowedLicenses);l&&(consola.consola.error("Packages with invalid licenses found:"),d.forEach(p=>consola.consola.error(` ${p}`)),n=!0)}}catch(a){consola.consola.error("Failed to check dependencies:",a),n=!0}return!n}async function v(t,i,o=!1){if(i.length===0)return!0;const s=(await Promise.all(i.map(async e=>({file:e,exists:await utils.fileExists(pathe.resolve(t,e))})))).filter(e=>!e.exists);if(s.length>0)if(o){consola.consola.start(`Creating missing files: ${s.map(e=>e.file).join(", ")}`);try{for(const{file:e}of s)await promises.writeFile(pathe.resolve(t,e),"","utf8");consola.consola.success(`Created ${s.length} missing files`)}catch(e){return consola.consola.error("Failed to create missing files:",e),!1}}else return s.forEach(({file:e})=>{consola.consola.error(`Required file missing: ${e}`)}),!1;return!0}async function R(t,i,o=!1){if(i.length===0)return!0;const s=(await Promise.all(i.map(async e=>({dir:e,exists:await utils.fileExists(pathe.resolve(t,e))})))).filter(e=>!e.exists);if(s.length>0)if(o){consola.consola.start(`Creating missing directories: ${s.map(e=>e.dir).join(", ")}`);try{for(const{dir:e}of s)await promises.mkdir(pathe.resolve(t,e),{recursive:!0});consola.consola.success(`Created ${s.length} missing directories`)}catch(e){return consola.consola.error("Failed to create missing directories:",e),!1}}else return s.forEach(({dir:e})=>{consola.consola.error(`Required directory missing: ${e}`)}),!1;return!0}async function D(t,i,o){const s=new RegExp(o),e=(await getProjectFiles(t,[i])).filter(r=>{const n=r.split("/").pop()||"";return!s.test(n)});return e.length>0?(consola.consola.error(`Files with invalid naming in ${i}: ${e.slice(0,3).join(", ")}${e.length>3?"...":""}`),!1):!0}async function L(t,i,o){const s=new RegExp(o),e=new Set,r=(await getProjectFiles(t,[i.replace(/\/\*\*?$/,"")])).filter(async n=>{const a=pathe.resolve(t,n);try{return(await import("node:fs/promises").then(u=>u.stat(a))).isDirectory()}catch{return!1}});for(const n of await Promise.all(r))if(n){const a=n.split("/").pop()||"";s.test(a)||e.add(n)}return e.size>0?(consola.consola.error(`Directories with invalid naming in ${i}: ${Array.from(e).slice(0,3).join(", ")}`),!1):!0}async function A(t,i){let o=!1;for(const s of i){const{path:e,files:r,directories:n,description:a}=s;consola.consola.start(`Checking naming rule: ${a||e}`),r&&(await D(t,e,r)||(o=!0)),n&&(await L(t,e,n)||(o=!0))}return!o}async function lintStructure(t=process.cwd(),i,o=!1){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{lint:{structure:i}}:void 0}),e=s.lint?.structure||{},r=s.lint?.fix?.structure||{};let n=!1;return consola.consola.start("Checking project structure..."),e.requiredFiles&&(await v(t,e.requiredFiles,o&&r.createMissingFiles)||(n=!0)),e.requiredDirs&&(await R(t,e.requiredDirs,o&&r.createMissingDirs)||(n=!0)),e.naming&&e.naming.length>0&&(await A(t,e.naming)||(n=!0)),!n}async function lintDocs(t=process.cwd(),i,o=!1){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{lint:{docs:i}}:void 0}),e=s.lint?.docs||{},r=s.lint?.fix?.docs||{};let n=!1;consola.consola.start("Checking documentation...");const a=[];e.checkReadme&&a.push({type:"README",files:["README.md","README.rst","README.txt","readme.md"],required:!0,fixEnabled:o&&(r.generateReadme??!1),createFile:"README.md"}),e.checkChangelog&&a.push({type:"CHANGELOG",files:["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"],required:!0,fixEnabled:o&&(r.generateChangelog??!1),createFile:"CHANGELOG.md"});for(const{type:u,files:f,required:c,fixEnabled:l,createFile:d}of a){const p=(await Promise.all(f.map(g=>utils.fileExists(pathe.resolve(t,g))))).some(g=>g);if(c&&!p)if(l&&d){consola.consola.start(`Creating ${d}...`);try{await promises.writeFile(pathe.resolve(t,d),"","utf8"),consola.consola.success(`Created ${d}`)}catch(g){consola.consola.error(`Failed to create ${d}:`,g),n=!0}}else consola.consola.error(`No ${u} file found`),n=!0}return!n}async function lintAll(t=process.cwd(),i=!1){const{config:o}=await utils.loadConfig({cwd:t}),s=o.lint||{};consola.consola.start("Running comprehensive project lint...");const e=(await Promise.allSettled([lintProject(t,s.project),lintDependencies(t,s.dependencies,i),lintStructure(t,s.structure,i),lintDocs(t,s.docs,i)])).filter(r=>r.status==="rejected"||r.status==="fulfilled"&&!r.value);return e.length===0?!0:(consola.consola.error(`${e.length} lint check(s) failed`),!1)}async function S(t,i){try{const o=await P__default(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:t,onlyFiles:!0,absolute:!0}),s=[],e=new Set;for(const r of o)try{const n=await pkgTypes.readPackageJSON(r);if(!n.name||e.has(n.name))continue;if(e.add(n.name),n.license){const a=Array.isArray(n.license)?n.license.join(", "):n.license;i.some(u=>a.includes(u))||s.push(`${n.name}: ${a}`)}}catch{}return{hasIssues:s.length>0,invalidLicenses:s}}catch(o){return consola.consola.warn("Failed to check licenses:",o),{hasIssues:!1,invalidLicenses:[]}}}exports.getProjectFiles=getProjectFiles,exports.getStagedFiles=getStagedFiles,exports.lintAll=lintAll,exports.lintDependencies=lintDependencies,exports.lintDocs=lintDocs,exports.lintProject=lintProject,exports.lintStaged=lintStaged,exports.lintStructure=lintStructure;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{execSync as u}from"node:child_process";import{writeFile as v,mkdir as C}from"node:fs/promises";import{consola as i}from"consola";import j from"fast-glob";import S from"micromatch";import{detectPackageManager as A}from"nypm";import{resolve as m}from"pathe";import{readPackageJSON as b}from"pkg-types";import{l as h,f as y,g as D}from"./basis.BrlVPuDi.mjs";function x(){try{const t=u("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
|
|
2
|
+
`).filter(Boolean),n=u("git diff --cached --name-only --diff-filter=D",{encoding:"utf8"}),a=new Set(n.trim().split(`
|
|
3
|
+
`).filter(Boolean));return t.filter(r=>!a.has(r))}catch{return[]}}async function $(t,n=["**/*"],a=["node_modules/**","dist/**","build/**",".git/**"]){try{return await j(n,{cwd:t,ignore:a,onlyFiles:!0,dot:!1,absolute:!1})}catch(r){return i.warn("Failed to scan project files:",r),[]}}async function O(t=process.cwd(),n){const{config:a}=await h({cwd:t,overrides:n?{lint:{staged:n}}:void 0}),r=a.lint?.staged||{},e=x();if(e.length===0)return!0;if(Object.keys(r).length===0)return i.warn("No staged lint configuration found. Add lint.staged section to your basis.config.ts"),!0;let c=!1;const s=new Set;for(const[o,g]of Object.entries(r)){const p=e.filter(l=>!s.has(l)&&S.isMatch(l.split("/").pop()||l,o));if(p.length!==0){i.start(`Running staged lint for pattern: ${o}`);try{u(g,{stdio:"inherit",cwd:t});const l=[];for(const d of p)await y(m(t,d))&&l.push(d);l.length>0&&u(`git add ${l.join(" ")}`,{stdio:"inherit",cwd:t}),p.forEach(d=>s.add(d))}catch(l){c=!0,i.error(`Lint pattern '${o}' failed. Please fix the issues and try again:`,l)}}}return!c}async function E(t=process.cwd(),n){const{config:a}=await h({cwd:t,overrides:n?{lint:{project:n}}:void 0}),r=a.lint?.project||{};if(Object.keys(r).length===0)return i.warn("No project lint configuration found. Add lint.project section to your basis.config.ts"),!0;i.start("Running project-wide linting...");let e=!1;for(const[c,s]of Object.entries(r)){i.start(`Running project lint: ${c}`);try{u(s,{stdio:"inherit",cwd:t})}catch(o){e=!0,i.error(`Project lint pattern '${c}' failed. Please fix the issues and try again:`,o)}}return!e}async function F(t=process.cwd(),n,a=!1){const{config:r}=await h({cwd:t,overrides:n?{lint:{dependencies:n}}:void 0}),e=r.lint?.dependencies||{},c=r.lint?.fix?.dependencies||{};let s=!1;try{const o=await b(t),g={...o.dependencies,...o.devDependencies},p=(await A(t))?.name||"npm",l=D(p);if(i.start("Checking dependencies..."),e.blockedPackages&&e.blockedPackages.length>0){const d=Object.keys(g).filter(f=>e.blockedPackages?.includes(f));if(d.length>0)if(a&&c.removeBlocked&&l.remove){i.start(`Removing blocked packages: ${d.join(", ")}`);try{for(const f of d)u(`${l.remove} ${f}`,{cwd:t,stdio:"inherit"});i.success(`Removed ${d.length} blocked packages`)}catch(f){i.error("Failed to remove blocked packages:",f),s=!0}}else i.error(`Blocked packages found: ${d.join(", ")}. Please remove these packages from your dependencies.`),s=!0}if(e.checkOutdated)if(l.outdated)try{u(l.outdated,{cwd:t,stdio:"pipe"})}catch(d){if(a&&c.updateOutdated&&l.update){i.start("Updating outdated dependencies...");try{u(l.update,{cwd:t,stdio:"inherit"}),i.success("Dependencies updated")}catch(f){i.error("Failed to update dependencies:",f),s=!0}}else i.warn("Some dependencies are outdated:",d)}else i.warn(`Outdated check not available for ${p}`);if(e.checkSecurity)if(l.audit)try{u(l.audit,{cwd:t,stdio:"pipe"})}catch(d){if(a&&c.fixSecurity&&l.auditFix){i.start("Fixing security vulnerabilities...");try{u(l.auditFix,{cwd:t,stdio:"inherit"}),i.success("Security fixes applied")}catch(f){i.error("Failed to fix security issues:",f),s=!0}}else i.error("Security vulnerabilities detected:",d),s=!0}else i.warn(`Security audit not available for ${p}`);if(e.allowedLicenses&&e.allowedLicenses.length>0){const{hasIssues:d,invalidLicenses:f}=await B(t,e.allowedLicenses);d&&(i.error("Packages with invalid licenses found:"),f.forEach(k=>i.error(` ${k}`)),s=!0)}}catch(o){i.error("Failed to check dependencies:",o),s=!0}return!s}async function L(t,n,a=!1){if(n.length===0)return!0;const r=(await Promise.all(n.map(async e=>({file:e,exists:await y(m(t,e))})))).filter(e=>!e.exists);if(r.length>0)if(a){i.start(`Creating missing files: ${r.map(e=>e.file).join(", ")}`);try{for(const{file:e}of r)await v(m(t,e),"","utf8");i.success(`Created ${r.length} missing files`)}catch(e){return i.error("Failed to create missing files:",e),!1}}else return r.forEach(({file:e})=>{i.error(`Required file missing: ${e}`)}),!1;return!0}async function M(t,n,a=!1){if(n.length===0)return!0;const r=(await Promise.all(n.map(async e=>({dir:e,exists:await y(m(t,e))})))).filter(e=>!e.exists);if(r.length>0)if(a){i.start(`Creating missing directories: ${r.map(e=>e.dir).join(", ")}`);try{for(const{dir:e}of r)await C(m(t,e),{recursive:!0});i.success(`Created ${r.length} missing directories`)}catch(e){return i.error("Failed to create missing directories:",e),!1}}else return r.forEach(({dir:e})=>{i.error(`Required directory missing: ${e}`)}),!1;return!0}async function q(t,n,a){const r=new RegExp(a),e=(await $(t,[n])).filter(c=>{const s=c.split("/").pop()||"";return!r.test(s)});return e.length>0?(i.error(`Files with invalid naming in ${n}: ${e.slice(0,3).join(", ")}${e.length>3?"...":""}`),!1):!0}async function G(t,n,a){const r=new RegExp(a),e=new Set,c=(await $(t,[n.replace(/\/\*\*?$/,"")])).filter(async s=>{const o=m(t,s);try{return(await import("node:fs/promises").then(g=>g.stat(o))).isDirectory()}catch{return!1}});for(const s of await Promise.all(c))if(s){const o=s.split("/").pop()||"";r.test(o)||e.add(s)}return e.size>0?(i.error(`Directories with invalid naming in ${n}: ${Array.from(e).slice(0,3).join(", ")}`),!1):!0}async function N(t,n){let a=!1;for(const r of n){const{path:e,files:c,directories:s,description:o}=r;i.start(`Checking naming rule: ${o||e}`),c&&(await q(t,e,c)||(a=!0)),s&&(await G(t,e,s)||(a=!0))}return!a}async function P(t=process.cwd(),n,a=!1){const{config:r}=await h({cwd:t,overrides:n?{lint:{structure:n}}:void 0}),e=r.lint?.structure||{},c=r.lint?.fix?.structure||{};let s=!1;return i.start("Checking project structure..."),e.requiredFiles&&(await L(t,e.requiredFiles,a&&c.createMissingFiles)||(s=!0)),e.requiredDirs&&(await M(t,e.requiredDirs,a&&c.createMissingDirs)||(s=!0)),e.naming&&e.naming.length>0&&(await N(t,e.naming)||(s=!0)),!s}async function R(t=process.cwd(),n,a=!1){const{config:r}=await h({cwd:t,overrides:n?{lint:{docs:n}}:void 0}),e=r.lint?.docs||{},c=r.lint?.fix?.docs||{};let s=!1;i.start("Checking documentation...");const o=[];e.checkReadme&&o.push({type:"README",files:["README.md","README.rst","README.txt","readme.md"],required:!0,fixEnabled:a&&(c.generateReadme??!1),createFile:"README.md"}),e.checkChangelog&&o.push({type:"CHANGELOG",files:["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"],required:!0,fixEnabled:a&&(c.generateChangelog??!1),createFile:"CHANGELOG.md"});for(const{type:g,files:p,required:l,fixEnabled:d,createFile:f}of o){const k=(await Promise.all(p.map(w=>y(m(t,w))))).some(w=>w);if(l&&!k)if(d&&f){i.start(`Creating ${f}...`);try{await v(m(t,f),"","utf8"),i.success(`Created ${f}`)}catch(w){i.error(`Failed to create ${f}:`,w),s=!0}}else i.error(`No ${g} file found`),s=!0}return!s}async function H(t=process.cwd(),n=!1){const{config:a}=await h({cwd:t}),r=a.lint||{};i.start("Running comprehensive project lint...");const e=(await Promise.allSettled([E(t,r.project),F(t,r.dependencies,n),P(t,r.structure,n),R(t,r.docs,n)])).filter(c=>c.status==="rejected"||c.status==="fulfilled"&&!c.value);return e.length===0?!0:(i.error(`${e.length} lint check(s) failed`),!1)}async function B(t,n){try{const a=await j(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:t,onlyFiles:!0,absolute:!0}),r=[],e=new Set;for(const c of a)try{const s=await b(c);if(!s.name||e.has(s.name))continue;if(e.add(s.name),s.license){const o=Array.isArray(s.license)?s.license.join(", "):s.license;n.some(g=>o.includes(g))||r.push(`${s.name}: ${o}`)}}catch{}return{hasIssues:r.length>0,invalidLicenses:r}}catch(a){return i.warn("Failed to check licenses:",a),{hasIssues:!1,invalidLicenses:[]}}}export{$ as a,O as b,E as c,F as d,P as e,R as f,x as g,H as l};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{execSync as m}from"node:child_process";import{readFile as y,unlink as M,writeFile as G,copyFile as O}from"node:fs/promises";import{updateConfig as S}from"c12/update";import{consola as s}from"consola";import{defu as x}from"defu";import v from"ini";import{resolve as u}from"pathe";import{l as p,f as d}from"./basis.BrlVPuDi.mjs";function g(){try{return m("git --version",{stdio:"pipe"}),!0}catch{return!1}}async function k(e,r=!1,o=!1){try{return await S({cwd:e,configFile:"basis.config",onUpdate:t=>{t.git&&(r&&t.git.hooks&&delete t.git.hooks,o&&t.git.config&&delete t.git.config,Object.keys(t.git).length===0&&delete t.git)}}),!0}catch{return!1}}const E=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function b(e){const r=e.trim().split(`
|
|
2
|
+
`),o=r[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!o)return null;const[,t,,i,a,n]=o,c=r.slice(1).find(l=>l.trim())?.trim(),f=r.slice(-1)[0]?.trim();return{type:t,scope:i,description:n,body:c,footer:f,isBreaking:!!a||e.includes("BREAKING CHANGE:")}}function $(e,r={}){const o=[],{types:t=E,maxLength:i=72,minLength:a=10,scopeRequired:n=!1,allowedScopes:c=[]}=r,f=b(e);if(!f)return{valid:!1,errors:["Invalid commit format. Expected: type(scope): description"]};t.includes(f.type)||o.push(`Invalid type '${f.type}'. Allowed: ${t.join(", ")}`);const l=e.split(`
|
|
3
|
+
`)[0];return l.length>i&&o.push(`Header too long (${l.length}). Max: ${i}`),l.length<a&&o.push(`Header too short (${l.length}). Min: ${a}`),n&&!f.scope&&o.push("Scope is required"),f.scope&&c.length>0&&!c.includes(f.scope)&&o.push(`Invalid scope '${f.scope}'. Allowed: ${c.join(", ")}`),{valid:o.length===0,errors:o}}async function H(e=process.cwd(),r){if(!g())return s.warn("Git command not available, skipping commit message linting"),!0;const{config:o}=await p({cwd:e,overrides:r?{git:{commitMsg:r}}:void 0}),t=o.git?.commitMsg||{};let i;try{const n=u(".git/COMMIT_EDITMSG");await d(n)?i=(await y(n)).toString("utf8"):i=m("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(n){return s.error("Failed to read commit message:",n),!1}const a=$(i,t);return a.valid?!0:(s.error("Invalid commit message:"),a.errors.forEach(n=>s.error(` ${n}`)),!1)}async function j(e){const r=u(e,".git/config");if(!await d(r))return null;const o=new Date().toISOString().replace(/[:.]/g,"-"),t=u(e,`.git/config.backup.${o}`);try{return await O(r,t),t}catch(i){return s.warn("Failed to create Git config backup:",i),null}}async function w(e=process.cwd()){const r=u(e,".git/config");if(!await d(r))return{};try{const o=await y(r,"utf8");return v.parse(o)}catch(o){return s.warn("Failed to read .git/config:",o),{}}}async function h(e,r=process.cwd()){const o=u(r,".git/config");try{let t=v.stringify(e,{whitespace:!0});t=t.split(`
|
|
4
|
+
`).map(i=>i&&!i.startsWith("[")&&i.includes("=")?` ${i}`:i).join(`
|
|
5
|
+
`),await G(o,t,"utf8")}catch(t){throw s.error("Failed to write .git/config:",t),t}}function A(e,r){if(!r)return!0;for(const[o,t]of Object.entries(r)){if(typeof t!="object"||!t)continue;const i=e[o];if(!i||typeof i!="object")return!1;for(const[a,n]of Object.entries(t))if(n!==void 0&&i[a]!==n)return!1}return!0}async function C(e=process.cwd(),r){if(!g())return s.warn("Git command not available, skipping Git config setup"),!0;const{config:o}=await p({cwd:e,overrides:r?{git:{config:r}}:void 0}),t=o.git?.config||{};if(Object.keys(t).length===0)return!0;try{const i=await w(e);if(A(i,t))return!0;await j(e);const a=x(i,t);return await h(a,e),!0}catch(i){return s.error("Failed to setup Git configuration:",i),!1}}async function z(e=process.cwd(),r=!0,o={}){if(!g())return s.warn("Git command not available, skipping Git config reset"),!0;try{await j(e);const t=await w(e);if(!t||Object.keys(t).length===0)return!0;const i={};if(r&&t.user&&(i.user=t.user),t.core){const a=["repositoryformatversion","filemode","bare","logallrefupdates"],n={};a.forEach(c=>{t.core[c]!==void 0&&(n[c]=t.core[c])}),Object.keys(n).length>0&&(i.core=n)}return await h(i,e),o.updateConfig?await k(e,!1,!0):!0}catch(t){return s.error("Failed to reset Git configuration:",t),!1}}async function F(e=process.cwd(),r){if(!g())return s.warn("Git command not available, skipping Git hooks setup"),!0;const{config:o}=await p({cwd:e,overrides:r?{git:{hooks:r}}:void 0}),t=o.git?.hooks||{},i=u(e,".git/hooks");if(!await d(i))return s.error("Git hooks directory not found. Is this a Git repository?"),!1;let a=!0;for(const[n,c]of Object.entries(t)){const f=u(i,n);try{let l=`#!/bin/sh
|
|
6
|
+
|
|
7
|
+
`;if(typeof c=="string")l+=`${c}
|
|
8
|
+
`;else if(c&&typeof c=="object"&&"commands"in c){const I=c.commands;l+=`${I.join(`
|
|
9
|
+
`)}
|
|
10
|
+
`}await G(f,l,{mode:493})}catch(l){s.error(`Failed to setup ${n} hook:`,l),a=!1}}return a}async function B(e=process.cwd()){if(!g())return s.warn("Git command not available, cannot initialize repository"),!1;try{try{return m("git rev-parse --git-dir",{cwd:e,stdio:"pipe"}),!0}catch{return m("git init",{cwd:e,stdio:"inherit"}),s.success("Initialized Git repository"),!0}}catch(r){return s.error("Failed to initialize Git repository:",r),!1}}async function R(e=process.cwd()){const{config:r}=await p({cwd:e}),o=r.git||{},t=(await Promise.allSettled([C(e,o.config),F(e,o.hooks)])).filter(i=>i.status==="rejected"||i.status==="fulfilled"&&!i.value);return t.length===0?(s.success("Git setup completed successfully!"),!0):(s.error(`${t.length} Git setup step(s) failed`),!1)}async function q(e=process.cwd(),r,o={}){if(!g())return s.warn("Git command not available, skipping Git hooks removal"),!0;const t=u(e,".git/hooks");if(!await d(t))return s.warn("Git hooks directory not found. Is this a Git repository?"),!0;let i=!0,a;if(r&&r.length>0)a=r;else{const{config:n}=await p({cwd:e});a=Object.keys(n.git?.hooks||{})}for(const n of a){const c=u(t,n);if(await d(c))try{await M(c)}catch(f){s.error(`Failed to remove ${n} hook:`,f),i=!1}}if(!r&&o.updateConfig){const n=await k(e,!0,!1);i=i&&n}return i}export{C as a,z as b,F as c,q as d,B as i,H as l,b as p,w as r,R as s,$ as v,h as w};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";const node_child_process=require("node:child_process"),promises=require("node:fs/promises"),update=require("c12/update"),consola=require("consola"),defu=require("defu"),
|
|
1
|
+
"use strict";const node_child_process=require("node:child_process"),promises=require("node:fs/promises"),update=require("c12/update"),consola=require("consola"),defu=require("defu"),G=require("ini"),pathe=require("pathe"),utils=require("./basis.D3fInv-P.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const G__default=_interopDefaultCompat(G);function p(){try{return node_child_process.execSync("git --version",{stdio:"pipe"}),!0}catch{return!1}}async function b(e,i=!1,r=!1){try{return await update.updateConfig({cwd:e,configFile:"basis.config",onUpdate:t=>{t.git&&(i&&t.git.hooks&&delete t.git.hooks,r&&t.git.config&&delete t.git.config,Object.keys(t.git).length===0&&delete t.git)}}),!0}catch{return!1}}const M=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function parseCommitMessage(e){const i=e.trim().split(`
|
|
2
2
|
`),r=i[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!r)return null;const[,t,,o,n,s]=r,c=i.slice(1).find(l=>l.trim())?.trim(),a=i.slice(-1)[0]?.trim();return{type:t,scope:o,description:s,body:c,footer:a,isBreaking:!!n||e.includes("BREAKING CHANGE:")}}function validateCommitMessage(e,i={}){const r=[],{types:t=M,maxLength:o=72,minLength:n=10,scopeRequired:s=!1,allowedScopes:c=[]}=i,a=parseCommitMessage(e);if(!a)return{valid:!1,errors:["Invalid commit format. Expected: type(scope): description"]};t.includes(a.type)||r.push(`Invalid type '${a.type}'. Allowed: ${t.join(", ")}`);const l=e.split(`
|
|
3
|
-
`)[0];return l.length>o&&r.push(`Header too long (${l.length}). Max: ${o}`),l.length<n&&r.push(`Header too short (${l.length}). Min: ${n}`),s&&!a.scope&&r.push("Scope is required"),a.scope&&c.length>0&&!c.includes(a.scope)&&r.push(`Invalid scope '${a.scope}'. Allowed: ${c.join(", ")}`),{valid:r.length===0,errors:r}}async function lintCommitMessage(e=process.cwd(),i){if(!
|
|
3
|
+
`)[0];return l.length>o&&r.push(`Header too long (${l.length}). Max: ${o}`),l.length<n&&r.push(`Header too short (${l.length}). Min: ${n}`),s&&!a.scope&&r.push("Scope is required"),a.scope&&c.length>0&&!c.includes(a.scope)&&r.push(`Invalid scope '${a.scope}'. Allowed: ${c.join(", ")}`),{valid:r.length===0,errors:r}}async function lintCommitMessage(e=process.cwd(),i){if(!p())return consola.consola.warn("Git command not available, skipping commit message linting"),!0;const{config:r}=await utils.loadConfig({cwd:e,overrides:i?{git:{commitMsg:i}}:void 0}),t=r.git?.commitMsg||{};let o;try{const s=pathe.resolve(".git/COMMIT_EDITMSG");await utils.fileExists(s)?o=(await promises.readFile(s)).toString("utf8"):o=node_child_process.execSync("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(s){return consola.consola.error("Failed to read commit message:",s),!1}const n=validateCommitMessage(o,t);return n.valid?!0:(consola.consola.error("Invalid commit message:"),n.errors.forEach(s=>consola.consola.error(` ${s}`)),!1)}async function k(e){const i=pathe.resolve(e,".git/config");if(!await utils.fileExists(i))return null;const r=new Date().toISOString().replace(/[:.]/g,"-"),t=pathe.resolve(e,`.git/config.backup.${r}`);try{return await promises.copyFile(i,t),t}catch(o){return consola.consola.warn("Failed to create Git config backup:",o),null}}async function readGitConfig(e=process.cwd()){const i=pathe.resolve(e,".git/config");if(!await utils.fileExists(i))return{};try{const r=await promises.readFile(i,"utf8");return G__default.parse(r)}catch(r){return consola.consola.warn("Failed to read .git/config:",r),{}}}async function writeGitConfig(e,i=process.cwd()){const r=pathe.resolve(i,".git/config");try{let t=G__default.stringify(e,{whitespace:!0});t=t.split(`
|
|
4
4
|
`).map(o=>o&&!o.startsWith("[")&&o.includes("=")?` ${o}`:o).join(`
|
|
5
|
-
`),await promises.writeFile(r,t,"utf8")}catch(t){throw consola.consola.error("Failed to write .git/config:",t),t}}function S(e,i){if(!i)return!0;for(const[r,t]of Object.entries(i)){if(typeof t!="object"||!t)continue;const o=e[r];if(!o||typeof o!="object")return!1;for(const[n,s]of Object.entries(t))if(s!==void 0&&o[n]!==s)return!1}return!0}async function setupGitConfig(e=process.cwd(),i){const{config:r}=await utils.loadConfig({cwd:e,overrides:i?{git:{config:i}}:void 0}),t=r.git?.config||{};if(Object.keys(t).length===0)return!0;try{const o=await readGitConfig(e);if(S(o,t))return!0;await
|
|
5
|
+
`),await promises.writeFile(r,t,"utf8")}catch(t){throw consola.consola.error("Failed to write .git/config:",t),t}}function S(e,i){if(!i)return!0;for(const[r,t]of Object.entries(i)){if(typeof t!="object"||!t)continue;const o=e[r];if(!o||typeof o!="object")return!1;for(const[n,s]of Object.entries(t))if(s!==void 0&&o[n]!==s)return!1}return!0}async function setupGitConfig(e=process.cwd(),i){if(!p())return consola.consola.warn("Git command not available, skipping Git config setup"),!0;const{config:r}=await utils.loadConfig({cwd:e,overrides:i?{git:{config:i}}:void 0}),t=r.git?.config||{};if(Object.keys(t).length===0)return!0;try{const o=await readGitConfig(e);if(S(o,t))return!0;await k(e);const n=defu.defu(o,t);return await writeGitConfig(n,e),!0}catch(o){return consola.consola.error("Failed to setup Git configuration:",o),!1}}async function resetGitConfig(e=process.cwd(),i=!0,r={}){if(!p())return consola.consola.warn("Git command not available, skipping Git config reset"),!0;try{await k(e);const t=await readGitConfig(e);if(!t||Object.keys(t).length===0)return!0;const o={};if(i&&t.user&&(o.user=t.user),t.core){const n=["repositoryformatversion","filemode","bare","logallrefupdates"],s={};n.forEach(c=>{t.core[c]!==void 0&&(s[c]=t.core[c])}),Object.keys(s).length>0&&(o.core=s)}return await writeGitConfig(o,e),r.updateConfig?await b(e,!1,!0):!0}catch(t){return consola.consola.error("Failed to reset Git configuration:",t),!1}}async function setupGitHooks(e=process.cwd(),i){if(!p())return consola.consola.warn("Git command not available, skipping Git hooks setup"),!0;const{config:r}=await utils.loadConfig({cwd:e,overrides:i?{git:{hooks:i}}:void 0}),t=r.git?.hooks||{},o=pathe.resolve(e,".git/hooks");if(!await utils.fileExists(o))return consola.consola.error("Git hooks directory not found. Is this a Git repository?"),!1;let n=!0;for(const[s,c]of Object.entries(t)){const a=pathe.resolve(o,s);try{let l=`#!/bin/sh
|
|
6
6
|
|
|
7
7
|
`;if(typeof c=="string")l+=`${c}
|
|
8
8
|
`;else if(c&&typeof c=="object"&&"commands"in c){const f=c.commands;l+=`${f.join(`
|
|
9
9
|
`)}
|
|
10
|
-
`}await promises.writeFile(a,l,{mode:493})}catch(l){consola.consola.error(`Failed to setup ${s} hook:`,l),n=!1}}return n}async function initGitRepo(e=process.cwd()){if(!
|
|
10
|
+
`}await promises.writeFile(a,l,{mode:493})}catch(l){consola.consola.error(`Failed to setup ${s} hook:`,l),n=!1}}return n}async function initGitRepo(e=process.cwd()){if(!p())return consola.consola.warn("Git command not available, cannot initialize repository"),!1;try{try{return node_child_process.execSync("git rev-parse --git-dir",{cwd:e,stdio:"pipe"}),!0}catch{return node_child_process.execSync("git init",{cwd:e,stdio:"inherit"}),consola.consola.success("Initialized Git repository"),!0}}catch(i){return consola.consola.error("Failed to initialize Git repository:",i),!1}}async function setupGit(e=process.cwd()){const{config:i}=await utils.loadConfig({cwd:e}),r=i.git||{},t=(await Promise.allSettled([setupGitConfig(e,r.config),setupGitHooks(e,r.hooks)])).filter(o=>o.status==="rejected"||o.status==="fulfilled"&&!o.value);return t.length===0?(consola.consola.success("Git setup completed successfully!"),!0):(consola.consola.error(`${t.length} Git setup step(s) failed`),!1)}async function removeGitHooks(e=process.cwd(),i,r={}){if(!p())return consola.consola.warn("Git command not available, skipping Git hooks removal"),!0;const t=pathe.resolve(e,".git/hooks");if(!await utils.fileExists(t))return consola.consola.warn("Git hooks directory not found. Is this a Git repository?"),!0;let o=!0,n;if(i&&i.length>0)n=i;else{const{config:s}=await utils.loadConfig({cwd:e});n=Object.keys(s.git?.hooks||{})}for(const s of n){const c=pathe.resolve(t,s);if(await utils.fileExists(c))try{await promises.unlink(c)}catch(a){consola.consola.error(`Failed to remove ${s} hook:`,a),o=!1}}if(!i&&r.updateConfig){const s=await b(e,!0,!1);o=o&&s}return o}exports.initGitRepo=initGitRepo,exports.lintCommitMessage=lintCommitMessage,exports.parseCommitMessage=parseCommitMessage,exports.readGitConfig=readGitConfig,exports.removeGitHooks=removeGitHooks,exports.resetGitConfig=resetGitConfig,exports.setupGit=setupGit,exports.setupGitConfig=setupGitConfig,exports.setupGitHooks=setupGitHooks,exports.validateCommitMessage=validateCommitMessage,exports.writeGitConfig=writeGitConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const update=require("c12/update"),consola=require("consola"),magicast=require("magicast"),nypm=require("nypm"),pathe=require("pathe"),pkgTypes=require("pkg-types"),utils=require("./basis.D3fInv-P.cjs"),git=require("./basis.
|
|
1
|
+
"use strict";const update=require("c12/update"),consola=require("consola"),magicast=require("magicast"),nypm=require("nypm"),pathe=require("pathe"),pkgTypes=require("pkg-types"),utils=require("./basis.D3fInv-P.cjs"),git=require("./basis.GHY7v-ns.cjs"),S={ts:{ext:"ts",label:"TypeScript"},mjs:{ext:"mjs",label:"ES Module"},cjs:{ext:"cjs",label:"CommonJS"}};function J(i,r="npm"){const o=magicast.parseModule(i==="cjs"?`const { defineBasisConfig } = require("@funish/basis");
|
|
2
2
|
|
|
3
3
|
module.exports = defineBasisConfig({});`:`import { defineBasisConfig } from "@funish/basis";
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funish/basis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A unified development toolkit with CLI for package management, versioning, publishing, linting, and git hooks management for JavaScript/TypeScript projects.",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"micromatch": "4.0.8",
|
|
68
68
|
"nypm": "0.6.0",
|
|
69
69
|
"pathe": "2.0.3",
|
|
70
|
-
"pkg-types": "2.
|
|
70
|
+
"pkg-types": "2.2.0",
|
|
71
71
|
"semver": "7.7.2"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import{execSync as p}from"node:child_process";import{readFile as h,unlink as M,writeFile as y,copyFile as O}from"node:fs/promises";import{updateConfig as S}from"c12/update";import{consola as a}from"consola";import{defu as x}from"defu";import v from"ini";import{resolve as u}from"pathe";import{l as d,f as g}from"./basis.BrlVPuDi.mjs";function G(){try{return p("git --version",{stdio:"pipe"}),!0}catch{return!1}}async function k(e,o=!1,r=!1){try{return await S({cwd:e,configFile:"basis.config",onUpdate:t=>{t.git&&(o&&t.git.hooks&&delete t.git.hooks,r&&t.git.config&&delete t.git.config,Object.keys(t.git).length===0&&delete t.git)}}),!0}catch{return!1}}const E=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function b(e){const o=e.trim().split(`
|
|
2
|
-
`),r=o[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!r)return null;const[,t,,i,n,s]=r,c=o.slice(1).find(l=>l.trim())?.trim(),f=o.slice(-1)[0]?.trim();return{type:t,scope:i,description:s,body:c,footer:f,isBreaking:!!n||e.includes("BREAKING CHANGE:")}}function $(e,o={}){const r=[],{types:t=E,maxLength:i=72,minLength:n=10,scopeRequired:s=!1,allowedScopes:c=[]}=o,f=b(e);if(!f)return{valid:!1,errors:["Invalid commit format. Expected: type(scope): description"]};t.includes(f.type)||r.push(`Invalid type '${f.type}'. Allowed: ${t.join(", ")}`);const l=e.split(`
|
|
3
|
-
`)[0];return l.length>i&&r.push(`Header too long (${l.length}). Max: ${i}`),l.length<n&&r.push(`Header too short (${l.length}). Min: ${n}`),s&&!f.scope&&r.push("Scope is required"),f.scope&&c.length>0&&!c.includes(f.scope)&&r.push(`Invalid scope '${f.scope}'. Allowed: ${c.join(", ")}`),{valid:r.length===0,errors:r}}async function H(e=process.cwd(),o){if(!G())return a.warn("Git command not available, skipping commit message linting"),!0;const{config:r}=await d({cwd:e,overrides:o?{git:{commitMsg:o}}:void 0}),t=r.git?.commitMsg||{};let i;try{const s=u(".git/COMMIT_EDITMSG");await g(s)?i=(await h(s)).toString("utf8"):i=p("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(s){return a.error("Failed to read commit message:",s),!1}const n=$(i,t);return n.valid?!0:(a.error("Invalid commit message:"),n.errors.forEach(s=>a.error(` ${s}`)),!1)}async function j(e){const o=u(e,".git/config");if(!await g(o))return null;const r=new Date().toISOString().replace(/[:.]/g,"-"),t=u(e,`.git/config.backup.${r}`);try{return await O(o,t),t}catch(i){return a.warn("Failed to create Git config backup:",i),null}}async function m(e=process.cwd()){const o=u(e,".git/config");if(!await g(o))return{};try{const r=await h(o,"utf8");return v.parse(r)}catch(r){return a.warn("Failed to read .git/config:",r),{}}}async function w(e,o=process.cwd()){const r=u(o,".git/config");try{let t=v.stringify(e,{whitespace:!0});t=t.split(`
|
|
4
|
-
`).map(i=>i&&!i.startsWith("[")&&i.includes("=")?` ${i}`:i).join(`
|
|
5
|
-
`),await y(r,t,"utf8")}catch(t){throw a.error("Failed to write .git/config:",t),t}}function A(e,o){if(!o)return!0;for(const[r,t]of Object.entries(o)){if(typeof t!="object"||!t)continue;const i=e[r];if(!i||typeof i!="object")return!1;for(const[n,s]of Object.entries(t))if(s!==void 0&&i[n]!==s)return!1}return!0}async function C(e=process.cwd(),o){const{config:r}=await d({cwd:e,overrides:o?{git:{config:o}}:void 0}),t=r.git?.config||{};if(Object.keys(t).length===0)return!0;try{const i=await m(e);if(A(i,t))return!0;await j(e);const n=x(i,t);return await w(n,e),!0}catch(i){return a.error("Failed to setup Git configuration:",i),!1}}async function z(e=process.cwd(),o=!0,r={}){try{await j(e);const t=await m(e);if(!t||Object.keys(t).length===0)return!0;const i={};if(o&&t.user&&(i.user=t.user),t.core){const n=["repositoryformatversion","filemode","bare","logallrefupdates"],s={};n.forEach(c=>{t.core[c]!==void 0&&(s[c]=t.core[c])}),Object.keys(s).length>0&&(i.core=s)}return await w(i,e),r.updateConfig?await k(e,!1,!0):!0}catch(t){return a.error("Failed to reset Git configuration:",t),!1}}async function F(e=process.cwd(),o){const{config:r}=await d({cwd:e,overrides:o?{git:{hooks:o}}:void 0}),t=r.git?.hooks||{},i=u(e,".git/hooks");if(!await g(i))return a.error("Git hooks directory not found. Is this a Git repository?"),!1;let n=!0;for(const[s,c]of Object.entries(t)){const f=u(i,s);try{let l=`#!/bin/sh
|
|
6
|
-
|
|
7
|
-
`;if(typeof c=="string")l+=`${c}
|
|
8
|
-
`;else if(c&&typeof c=="object"&&"commands"in c){const I=c.commands;l+=`${I.join(`
|
|
9
|
-
`)}
|
|
10
|
-
`}await y(f,l,{mode:493})}catch(l){a.error(`Failed to setup ${s} hook:`,l),n=!1}}return n}async function B(e=process.cwd()){if(!G())return a.warn("Git command not available, cannot initialize repository"),!1;try{try{return p("git rev-parse --git-dir",{cwd:e,stdio:"pipe"}),!0}catch{return p("git init",{cwd:e,stdio:"inherit"}),a.success("Initialized Git repository"),!0}}catch(o){return a.error("Failed to initialize Git repository:",o),!1}}async function R(e=process.cwd()){const{config:o}=await d({cwd:e}),r=o.git||{},t=(await Promise.allSettled([C(e,r.config),F(e,r.hooks)])).filter(i=>i.status==="rejected"||i.status==="fulfilled"&&!i.value);return t.length===0?(a.success("Git setup completed successfully!"),!0):(a.error(`${t.length} Git setup step(s) failed`),!1)}async function q(e=process.cwd(),o,r={}){const t=u(e,".git/hooks");if(!await g(t))return a.warn("Git hooks directory not found. Is this a Git repository?"),!0;let i=!0,n;if(o&&o.length>0)n=o;else{const{config:s}=await d({cwd:e});n=Object.keys(s.git?.hooks||{})}for(const s of n){const c=u(t,s);if(await g(c))try{await M(c)}catch(f){a.error(`Failed to remove ${s} hook:`,f),i=!1}}if(!o&&r.updateConfig){const s=await k(e,!0,!1);i=i&&s}return i}export{C as a,z as b,F as c,q as d,B as i,H as l,b as p,m as r,R as s,$ as v,w};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{execSync as g}from"node:child_process";import{writeFile as v,mkdir as R}from"node:fs/promises";import{consola as i}from"consola";import j from"fast-glob";import S from"micromatch";import{detectPackageManager as A}from"nypm";import{resolve as h}from"pathe";import{readPackageJSON as b}from"pkg-types";import{l as m,f as y,g as D}from"./basis.BrlVPuDi.mjs";function x(){try{const t=g("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
|
|
2
|
-
`).filter(Boolean),n=g("git diff --cached --name-only --diff-filter=D",{encoding:"utf8"}),a=new Set(n.trim().split(`
|
|
3
|
-
`).filter(Boolean));return t.filter(r=>!a.has(r))}catch{return[]}}async function $(t,n=["**/*"],a=["node_modules/**","dist/**","build/**",".git/**"]){try{return await j(n,{cwd:t,ignore:a,onlyFiles:!0,dot:!1,absolute:!1})}catch(r){return i.warn("Failed to scan project files:",r),[]}}async function O(t=process.cwd(),n){const{config:a}=await m({cwd:t,overrides:n?{lint:{staged:n}}:void 0}),r=a.lint?.staged||{},e=x();if(e.length===0)return!0;if(Object.keys(r).length===0)return i.warn("No staged lint configuration found. Add lint.staged section to your basis.config.ts"),!0;let c=!1;const s=new Set;for(const[o,p]of Object.entries(r)){const u=e.filter(d=>!s.has(d)&&S.isMatch(d.split("/").pop()||d,o));if(u.length!==0){i.start(`Linting ${u.length} files: ${o}`);try{const d=`${p} ${u.join(" ")}`;g(d,{stdio:"inherit",cwd:t});const f=[];for(const l of u)await y(h(t,l))&&f.push(l);f.length>0&&g(`git add ${f.join(" ")}`,{stdio:"inherit",cwd:t}),u.forEach(l=>s.add(l))}catch(d){c=!0,i.error(`Lint pattern '${o}' failed. Please fix the issues and try again:`,d)}}}return!c}async function E(t=process.cwd(),n){const{config:a}=await m({cwd:t,overrides:n?{lint:{project:n}}:void 0}),r=a.lint?.project||{};if(Object.keys(r).length===0)return i.warn("No project lint configuration found. Add lint.project section to your basis.config.ts"),!0;i.start("Running project-wide linting...");let e=!1;for(const[c,s]of Object.entries(r)){i.start(`Running project lint: ${c}`);try{g(s,{stdio:"inherit",cwd:t})}catch(o){e=!0,i.error(`Project lint pattern '${c}' failed. Please fix the issues and try again:`,o)}}return!e}async function F(t=process.cwd(),n,a=!1){const{config:r}=await m({cwd:t,overrides:n?{lint:{dependencies:n}}:void 0}),e=r.lint?.dependencies||{},c=r.lint?.fix?.dependencies||{};let s=!1;try{const o=await b(t),p={...o.dependencies,...o.devDependencies},u=(await A(t))?.name||"npm",d=D(u);if(i.start("Checking dependencies..."),e.blockedPackages&&e.blockedPackages.length>0){const f=Object.keys(p).filter(l=>e.blockedPackages?.includes(l));if(f.length>0)if(a&&c.removeBlocked&&d.remove){i.start(`Removing blocked packages: ${f.join(", ")}`);try{for(const l of f)g(`${d.remove} ${l}`,{cwd:t,stdio:"inherit"});i.success(`Removed ${f.length} blocked packages`)}catch(l){i.error("Failed to remove blocked packages:",l),s=!0}}else i.error(`Blocked packages found: ${f.join(", ")}. Please remove these packages from your dependencies.`),s=!0}if(e.checkOutdated)if(d.outdated)try{g(d.outdated,{cwd:t,stdio:"pipe"})}catch(f){if(a&&c.updateOutdated&&d.update){i.start("Updating outdated dependencies...");try{g(d.update,{cwd:t,stdio:"inherit"}),i.success("Dependencies updated")}catch(l){i.error("Failed to update dependencies:",l),s=!0}}else i.warn("Some dependencies are outdated:",f)}else i.warn(`Outdated check not available for ${u}`);if(e.checkSecurity)if(d.audit)try{g(d.audit,{cwd:t,stdio:"pipe"})}catch(f){if(a&&c.fixSecurity&&d.auditFix){i.start("Fixing security vulnerabilities...");try{g(d.auditFix,{cwd:t,stdio:"inherit"}),i.success("Security fixes applied")}catch(l){i.error("Failed to fix security issues:",l),s=!0}}else i.error("Security vulnerabilities detected:",f),s=!0}else i.warn(`Security audit not available for ${u}`);if(e.allowedLicenses&&e.allowedLicenses.length>0){const{hasIssues:f,invalidLicenses:l}=await B(t,e.allowedLicenses);f&&(i.error("Packages with invalid licenses found:"),l.forEach(k=>i.error(` ${k}`)),s=!0)}}catch(o){i.error("Failed to check dependencies:",o),s=!0}return!s}async function L(t,n,a=!1){if(n.length===0)return!0;const r=(await Promise.all(n.map(async e=>({file:e,exists:await y(h(t,e))})))).filter(e=>!e.exists);if(r.length>0)if(a){i.start(`Creating missing files: ${r.map(e=>e.file).join(", ")}`);try{for(const{file:e}of r)await v(h(t,e),"","utf8");i.success(`Created ${r.length} missing files`)}catch(e){return i.error("Failed to create missing files:",e),!1}}else return r.forEach(({file:e})=>{i.error(`Required file missing: ${e}`)}),!1;return!0}async function M(t,n,a=!1){if(n.length===0)return!0;const r=(await Promise.all(n.map(async e=>({dir:e,exists:await y(h(t,e))})))).filter(e=>!e.exists);if(r.length>0)if(a){i.start(`Creating missing directories: ${r.map(e=>e.dir).join(", ")}`);try{for(const{dir:e}of r)await R(h(t,e),{recursive:!0});i.success(`Created ${r.length} missing directories`)}catch(e){return i.error("Failed to create missing directories:",e),!1}}else return r.forEach(({dir:e})=>{i.error(`Required directory missing: ${e}`)}),!1;return!0}async function q(t,n,a){const r=new RegExp(a),e=(await $(t,[n])).filter(c=>{const s=c.split("/").pop()||"";return!r.test(s)});return e.length>0?(i.error(`Files with invalid naming in ${n}: ${e.slice(0,3).join(", ")}${e.length>3?"...":""}`),!1):!0}async function G(t,n,a){const r=new RegExp(a),e=new Set,c=(await $(t,[n.replace(/\/\*\*?$/,"")])).filter(async s=>{const o=h(t,s);try{return(await import("node:fs/promises").then(p=>p.stat(o))).isDirectory()}catch{return!1}});for(const s of await Promise.all(c))if(s){const o=s.split("/").pop()||"";r.test(o)||e.add(s)}return e.size>0?(i.error(`Directories with invalid naming in ${n}: ${Array.from(e).slice(0,3).join(", ")}`),!1):!0}async function N(t,n){let a=!1;for(const r of n){const{path:e,files:c,directories:s,description:o}=r;i.start(`Checking naming rule: ${o||e}`),c&&(await q(t,e,c)||(a=!0)),s&&(await G(t,e,s)||(a=!0))}return!a}async function P(t=process.cwd(),n,a=!1){const{config:r}=await m({cwd:t,overrides:n?{lint:{structure:n}}:void 0}),e=r.lint?.structure||{},c=r.lint?.fix?.structure||{};let s=!1;return i.start("Checking project structure..."),e.requiredFiles&&(await L(t,e.requiredFiles,a&&c.createMissingFiles)||(s=!0)),e.requiredDirs&&(await M(t,e.requiredDirs,a&&c.createMissingDirs)||(s=!0)),e.naming&&e.naming.length>0&&(await N(t,e.naming)||(s=!0)),!s}async function C(t=process.cwd(),n,a=!1){const{config:r}=await m({cwd:t,overrides:n?{lint:{docs:n}}:void 0}),e=r.lint?.docs||{},c=r.lint?.fix?.docs||{};let s=!1;i.start("Checking documentation...");const o=[];e.checkReadme&&o.push({type:"README",files:["README.md","README.rst","README.txt","readme.md"],required:!0,fixEnabled:a&&(c.generateReadme??!1),createFile:"README.md"}),e.checkChangelog&&o.push({type:"CHANGELOG",files:["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"],required:!0,fixEnabled:a&&(c.generateChangelog??!1),createFile:"CHANGELOG.md"});for(const{type:p,files:u,required:d,fixEnabled:f,createFile:l}of o){const k=(await Promise.all(u.map(w=>y(h(t,w))))).some(w=>w);if(d&&!k)if(f&&l){i.start(`Creating ${l}...`);try{await v(h(t,l),"","utf8"),i.success(`Created ${l}`)}catch(w){i.error(`Failed to create ${l}:`,w),s=!0}}else i.error(`No ${p} file found`),s=!0}return!s}async function H(t=process.cwd(),n=!1){const{config:a}=await m({cwd:t}),r=a.lint||{};i.start("Running comprehensive project lint...");const e=(await Promise.allSettled([E(t,r.project),F(t,r.dependencies,n),P(t,r.structure,n),C(t,r.docs,n)])).filter(c=>c.status==="rejected"||c.status==="fulfilled"&&!c.value);return e.length===0?!0:(i.error(`${e.length} lint check(s) failed`),!1)}async function B(t,n){try{const a=await j(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:t,onlyFiles:!0,absolute:!0}),r=[],e=new Set;for(const c of a)try{const s=await b(c);if(!s.name||e.has(s.name))continue;if(e.add(s.name),s.license){const o=Array.isArray(s.license)?s.license.join(", "):s.license;n.some(p=>o.includes(p))||r.push(`${s.name}: ${o}`)}}catch{}return{hasIssues:r.length>0,invalidLicenses:r}}catch(a){return i.warn("Failed to check licenses:",a),{hasIssues:!1,invalidLicenses:[]}}}export{$ as a,O as b,E as c,F as d,P as e,C as f,x as g,H as l};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";const node_child_process=require("node:child_process"),promises=require("node:fs/promises"),consola=require("consola"),P=require("fast-glob"),x=require("micromatch"),nypm=require("nypm"),pathe=require("pathe"),pkgTypes=require("pkg-types"),utils=require("./basis.D3fInv-P.cjs");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const P__default=_interopDefaultCompat(P),x__default=_interopDefaultCompat(x);function getStagedFiles(){try{const t=node_child_process.execSync("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
|
|
2
|
-
`).filter(Boolean),i=node_child_process.execSync("git diff --cached --name-only --diff-filter=D",{encoding:"utf8"}),o=new Set(i.trim().split(`
|
|
3
|
-
`).filter(Boolean));return t.filter(s=>!o.has(s))}catch{return[]}}async function getProjectFiles(t,i=["**/*"],o=["node_modules/**","dist/**","build/**",".git/**"]){try{return await P__default(i,{cwd:t,ignore:o,onlyFiles:!0,dot:!1,absolute:!1})}catch(s){return consola.consola.warn("Failed to scan project files:",s),[]}}async function lintStaged(t=process.cwd(),i){const{config:o}=await utils.loadConfig({cwd:t,overrides:i?{lint:{staged:i}}:void 0}),s=o.lint?.staged||{},e=getStagedFiles();if(e.length===0)return!0;if(Object.keys(s).length===0)return consola.consola.warn("No staged lint configuration found. Add lint.staged section to your basis.config.ts"),!0;let r=!1;const n=new Set;for(const[a,f]of Object.entries(s)){const u=e.filter(l=>!n.has(l)&&x__default.isMatch(l.split("/").pop()||l,a));if(u.length!==0){consola.consola.start(`Linting ${u.length} files: ${a}`);try{const l=`${f} ${u.join(" ")}`;node_child_process.execSync(l,{stdio:"inherit",cwd:t});const d=[];for(const c of u)await utils.fileExists(pathe.resolve(t,c))&&d.push(c);d.length>0&&node_child_process.execSync(`git add ${d.join(" ")}`,{stdio:"inherit",cwd:t}),u.forEach(c=>n.add(c))}catch(l){r=!0,consola.consola.error(`Lint pattern '${a}' failed. Please fix the issues and try again:`,l)}}}return!r}async function lintProject(t=process.cwd(),i){const{config:o}=await utils.loadConfig({cwd:t,overrides:i?{lint:{project:i}}:void 0}),s=o.lint?.project||{};if(Object.keys(s).length===0)return consola.consola.warn("No project lint configuration found. Add lint.project section to your basis.config.ts"),!0;consola.consola.start("Running project-wide linting...");let e=!1;for(const[r,n]of Object.entries(s)){consola.consola.start(`Running project lint: ${r}`);try{node_child_process.execSync(n,{stdio:"inherit",cwd:t})}catch(a){e=!0,consola.consola.error(`Project lint pattern '${r}' failed. Please fix the issues and try again:`,a)}}return!e}async function lintDependencies(t=process.cwd(),i,o=!1){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{lint:{dependencies:i}}:void 0}),e=s.lint?.dependencies||{},r=s.lint?.fix?.dependencies||{};let n=!1;try{const a=await pkgTypes.readPackageJSON(t),f={...a.dependencies,...a.devDependencies},u=(await nypm.detectPackageManager(t))?.name||"npm",l=utils.getPackageManagerCommands(u);if(consola.consola.start("Checking dependencies..."),e.blockedPackages&&e.blockedPackages.length>0){const d=Object.keys(f).filter(c=>e.blockedPackages?.includes(c));if(d.length>0)if(o&&r.removeBlocked&&l.remove){consola.consola.start(`Removing blocked packages: ${d.join(", ")}`);try{for(const c of d)node_child_process.execSync(`${l.remove} ${c}`,{cwd:t,stdio:"inherit"});consola.consola.success(`Removed ${d.length} blocked packages`)}catch(c){consola.consola.error("Failed to remove blocked packages:",c),n=!0}}else consola.consola.error(`Blocked packages found: ${d.join(", ")}. Please remove these packages from your dependencies.`),n=!0}if(e.checkOutdated)if(l.outdated)try{node_child_process.execSync(l.outdated,{cwd:t,stdio:"pipe"})}catch(d){if(o&&r.updateOutdated&&l.update){consola.consola.start("Updating outdated dependencies...");try{node_child_process.execSync(l.update,{cwd:t,stdio:"inherit"}),consola.consola.success("Dependencies updated")}catch(c){consola.consola.error("Failed to update dependencies:",c),n=!0}}else consola.consola.warn("Some dependencies are outdated:",d)}else consola.consola.warn(`Outdated check not available for ${u}`);if(e.checkSecurity)if(l.audit)try{node_child_process.execSync(l.audit,{cwd:t,stdio:"pipe"})}catch(d){if(o&&r.fixSecurity&&l.auditFix){consola.consola.start("Fixing security vulnerabilities...");try{node_child_process.execSync(l.auditFix,{cwd:t,stdio:"inherit"}),consola.consola.success("Security fixes applied")}catch(c){consola.consola.error("Failed to fix security issues:",c),n=!0}}else consola.consola.error("Security vulnerabilities detected:",d),n=!0}else consola.consola.warn(`Security audit not available for ${u}`);if(e.allowedLicenses&&e.allowedLicenses.length>0){const{hasIssues:d,invalidLicenses:c}=await S(t,e.allowedLicenses);d&&(consola.consola.error("Packages with invalid licenses found:"),c.forEach(p=>consola.consola.error(` ${p}`)),n=!0)}}catch(a){consola.consola.error("Failed to check dependencies:",a),n=!0}return!n}async function v(t,i,o=!1){if(i.length===0)return!0;const s=(await Promise.all(i.map(async e=>({file:e,exists:await utils.fileExists(pathe.resolve(t,e))})))).filter(e=>!e.exists);if(s.length>0)if(o){consola.consola.start(`Creating missing files: ${s.map(e=>e.file).join(", ")}`);try{for(const{file:e}of s)await promises.writeFile(pathe.resolve(t,e),"","utf8");consola.consola.success(`Created ${s.length} missing files`)}catch(e){return consola.consola.error("Failed to create missing files:",e),!1}}else return s.forEach(({file:e})=>{consola.consola.error(`Required file missing: ${e}`)}),!1;return!0}async function R(t,i,o=!1){if(i.length===0)return!0;const s=(await Promise.all(i.map(async e=>({dir:e,exists:await utils.fileExists(pathe.resolve(t,e))})))).filter(e=>!e.exists);if(s.length>0)if(o){consola.consola.start(`Creating missing directories: ${s.map(e=>e.dir).join(", ")}`);try{for(const{dir:e}of s)await promises.mkdir(pathe.resolve(t,e),{recursive:!0});consola.consola.success(`Created ${s.length} missing directories`)}catch(e){return consola.consola.error("Failed to create missing directories:",e),!1}}else return s.forEach(({dir:e})=>{consola.consola.error(`Required directory missing: ${e}`)}),!1;return!0}async function D(t,i,o){const s=new RegExp(o),e=(await getProjectFiles(t,[i])).filter(r=>{const n=r.split("/").pop()||"";return!s.test(n)});return e.length>0?(consola.consola.error(`Files with invalid naming in ${i}: ${e.slice(0,3).join(", ")}${e.length>3?"...":""}`),!1):!0}async function L(t,i,o){const s=new RegExp(o),e=new Set,r=(await getProjectFiles(t,[i.replace(/\/\*\*?$/,"")])).filter(async n=>{const a=pathe.resolve(t,n);try{return(await import("node:fs/promises").then(f=>f.stat(a))).isDirectory()}catch{return!1}});for(const n of await Promise.all(r))if(n){const a=n.split("/").pop()||"";s.test(a)||e.add(n)}return e.size>0?(consola.consola.error(`Directories with invalid naming in ${i}: ${Array.from(e).slice(0,3).join(", ")}`),!1):!0}async function A(t,i){let o=!1;for(const s of i){const{path:e,files:r,directories:n,description:a}=s;consola.consola.start(`Checking naming rule: ${a||e}`),r&&(await D(t,e,r)||(o=!0)),n&&(await L(t,e,n)||(o=!0))}return!o}async function lintStructure(t=process.cwd(),i,o=!1){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{lint:{structure:i}}:void 0}),e=s.lint?.structure||{},r=s.lint?.fix?.structure||{};let n=!1;return consola.consola.start("Checking project structure..."),e.requiredFiles&&(await v(t,e.requiredFiles,o&&r.createMissingFiles)||(n=!0)),e.requiredDirs&&(await R(t,e.requiredDirs,o&&r.createMissingDirs)||(n=!0)),e.naming&&e.naming.length>0&&(await A(t,e.naming)||(n=!0)),!n}async function lintDocs(t=process.cwd(),i,o=!1){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{lint:{docs:i}}:void 0}),e=s.lint?.docs||{},r=s.lint?.fix?.docs||{};let n=!1;consola.consola.start("Checking documentation...");const a=[];e.checkReadme&&a.push({type:"README",files:["README.md","README.rst","README.txt","readme.md"],required:!0,fixEnabled:o&&(r.generateReadme??!1),createFile:"README.md"}),e.checkChangelog&&a.push({type:"CHANGELOG",files:["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"],required:!0,fixEnabled:o&&(r.generateChangelog??!1),createFile:"CHANGELOG.md"});for(const{type:f,files:u,required:l,fixEnabled:d,createFile:c}of a){const p=(await Promise.all(u.map(g=>utils.fileExists(pathe.resolve(t,g))))).some(g=>g);if(l&&!p)if(d&&c){consola.consola.start(`Creating ${c}...`);try{await promises.writeFile(pathe.resolve(t,c),"","utf8"),consola.consola.success(`Created ${c}`)}catch(g){consola.consola.error(`Failed to create ${c}:`,g),n=!0}}else consola.consola.error(`No ${f} file found`),n=!0}return!n}async function lintAll(t=process.cwd(),i=!1){const{config:o}=await utils.loadConfig({cwd:t}),s=o.lint||{};consola.consola.start("Running comprehensive project lint...");const e=(await Promise.allSettled([lintProject(t,s.project),lintDependencies(t,s.dependencies,i),lintStructure(t,s.structure,i),lintDocs(t,s.docs,i)])).filter(r=>r.status==="rejected"||r.status==="fulfilled"&&!r.value);return e.length===0?!0:(consola.consola.error(`${e.length} lint check(s) failed`),!1)}async function S(t,i){try{const o=await P__default(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:t,onlyFiles:!0,absolute:!0}),s=[],e=new Set;for(const r of o)try{const n=await pkgTypes.readPackageJSON(r);if(!n.name||e.has(n.name))continue;if(e.add(n.name),n.license){const a=Array.isArray(n.license)?n.license.join(", "):n.license;i.some(f=>a.includes(f))||s.push(`${n.name}: ${a}`)}}catch{}return{hasIssues:s.length>0,invalidLicenses:s}}catch(o){return consola.consola.warn("Failed to check licenses:",o),{hasIssues:!1,invalidLicenses:[]}}}exports.getProjectFiles=getProjectFiles,exports.getStagedFiles=getStagedFiles,exports.lintAll=lintAll,exports.lintDependencies=lintDependencies,exports.lintDocs=lintDocs,exports.lintProject=lintProject,exports.lintStaged=lintStaged,exports.lintStructure=lintStructure;
|