@funish/basis 0.1.0 → 0.1.2
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/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.CGkMo_WB.cjs +3 -0
- package/dist/shared/basis.Cc1QkX4i.mjs +3 -0
- package/package.json +2 -2
- package/dist/shared/basis.Bd1FyPZU.mjs +0 -3
- package/dist/shared/basis.CRtpAFNR.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/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.DuZo2uz1.cjs"),init=require("./shared/basis.1-2-e6uu.cjs"),lint=require("./shared/basis.
|
|
1
|
+
"use strict";const config=require("./config.cjs"),git=require("./shared/basis.DuZo2uz1.cjs"),init=require("./shared/basis.1-2-e6uu.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.BDhrNAQD.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.BDhrNAQD.mjs";import{i as s}from"./shared/basis.C4FYR2wo.mjs";import{l as o}from"./shared/basis.
|
|
1
|
+
export{defaultConfig,defineBasisConfig}from"./config.mjs";import{s as e}from"./shared/basis.BDhrNAQD.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.BDhrNAQD.mjs";import{i as s}from"./shared/basis.C4FYR2wo.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};
|
|
@@ -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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funish/basis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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,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!==!1&&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!==!1&&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;
|