@funish/basis 0.0.3 → 0.0.4
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 +31 -39
- package/dist/chunks/config.cjs +1 -1
- package/dist/chunks/config.mjs +1 -1
- 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/chunks/publish.cjs +1 -1
- package/dist/chunks/publish.mjs +1 -1
- package/dist/chunks/version.cjs +1 -1
- package/dist/chunks/version.mjs +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +17 -103
- package/dist/index.d.mts +17 -103
- package/dist/index.d.ts +17 -103
- package/dist/index.mjs +1 -1
- package/dist/shared/basis.Bar6V_OJ.cjs +10 -0
- package/dist/shared/basis.BzZ6Bs64.mjs +1 -0
- package/dist/shared/basis.C-dGsxlD.cjs +1 -0
- package/dist/shared/basis.CCjpKO-B.mjs +8 -0
- package/dist/shared/basis.CKFXZgQI.mjs +1 -0
- package/dist/shared/basis.DADpzLwA.cjs +3 -0
- package/dist/shared/{basis.CkZpidFZ.mjs → basis.DEw91E2d.mjs} +1 -1
- package/dist/shared/basis.DFb1F94b.mjs +3 -0
- package/dist/shared/basis.DVSF1f2D.cjs +8 -0
- package/dist/shared/{basis.BJhSbOyA.cjs → basis.DfY4XEAb.cjs} +1 -1
- package/dist/shared/basis.Dgo48zAG.cjs +1 -0
- package/dist/shared/basis.DzKnyliK.mjs +10 -0
- package/package.json +1 -1
- package/dist/shared/basis.0WCUjjhy.mjs +0 -1
- package/dist/shared/basis.1ZgFrMJb.mjs +0 -7
- package/dist/shared/basis.B4p52ive.cjs +0 -1
- package/dist/shared/basis.BEOfVK6U.cjs +0 -3
- package/dist/shared/basis.C8S2dWvt.cjs +0 -7
- package/dist/shared/basis.CHVACS4W.cjs +0 -1
- package/dist/shared/basis.DcC8NBqt.mjs +0 -3
- package/dist/shared/basis.DzMHJtq5.mjs +0 -10
- package/dist/shared/basis.plLH3j3N.mjs +0 -1
- package/dist/shared/basis.sOTOmfHG.cjs +0 -10
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@funish/basis)
|
|
5
5
|
[](https://www.npmjs.com/package/@funish/basis)
|
|
6
6
|
|
|
7
|
-
> A unified development toolkit with CLI for package management, versioning, publishing, linting, and git hooks management for JavaScript/TypeScript projects
|
|
7
|
+
> A unified development toolkit with CLI for package management, versioning, publishing, linting, and git hooks management for JavaScript/TypeScript projects.
|
|
8
|
+
|
|
9
|
+
**🧑💻 Contributing?** See the [monorepo documentation](https://github.com/funish/basis) for development setup and contribution guidelines.
|
|
8
10
|
|
|
9
11
|
## What is Basis?
|
|
10
12
|
|
|
@@ -432,46 +434,36 @@ basis git hooks # Unified git hooks
|
|
|
432
434
|
## API
|
|
433
435
|
|
|
434
436
|
```ts
|
|
435
|
-
import {
|
|
436
|
-
|
|
437
|
-
|
|
437
|
+
import {
|
|
438
|
+
createBasis,
|
|
439
|
+
defineBasisConfig,
|
|
440
|
+
// Import module functions directly for maximum flexibility
|
|
441
|
+
init,
|
|
442
|
+
setupGit,
|
|
443
|
+
lintAll,
|
|
444
|
+
updatePackageVersion,
|
|
445
|
+
publishPackage,
|
|
446
|
+
} from "@funish/basis";
|
|
447
|
+
|
|
448
|
+
// Programmatic usage with Basis class (for config caching and workflows)
|
|
438
449
|
const basis = createBasis(process.cwd());
|
|
439
450
|
|
|
440
|
-
//
|
|
441
|
-
await basis.
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
await basis.
|
|
446
|
-
await basis.
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
//
|
|
450
|
-
|
|
451
|
-
await
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
await
|
|
455
|
-
await
|
|
456
|
-
|
|
457
|
-
// Linting
|
|
458
|
-
await basis.lintStaged();
|
|
459
|
-
await basis.lintProject();
|
|
460
|
-
await basis.lintDependencies();
|
|
461
|
-
await basis.lintStructure();
|
|
462
|
-
await basis.lintDocs();
|
|
463
|
-
|
|
464
|
-
// Git management
|
|
465
|
-
await basis.setupGit(); // Setup everything
|
|
466
|
-
await basis.setupGitConfig(); // Setup config only
|
|
467
|
-
await basis.setupGitHooks(); // Setup hooks only
|
|
468
|
-
await basis.removeGitHooks(); // Remove hooks (keep config)
|
|
469
|
-
await basis.removeGitHooks(true); // Remove hooks + config file
|
|
470
|
-
await basis.resetGitConfig(); // Reset config (keep user)
|
|
471
|
-
await basis.resetGitConfig(false); // Reset config (remove all)
|
|
472
|
-
await basis.resetGitConfig(true, true); // Reset + remove from config file
|
|
473
|
-
await basis.initGitRepo(); // Initialize repository
|
|
474
|
-
await basis.lintCommitMessage(); // Validate commit message
|
|
451
|
+
// High-level workflows
|
|
452
|
+
await basis.setup({ force: false, skipGitCheck: false, skipInstall: false }); // init + git setup
|
|
453
|
+
await basis.release({ patch: true }, { stable: true }); // lint + version + publish
|
|
454
|
+
|
|
455
|
+
// Configuration management
|
|
456
|
+
const config = await basis.getConfig(); // Cached config loading
|
|
457
|
+
await basis.reloadConfig(); // Force reload
|
|
458
|
+
basis.setCwd("/different/path"); // Change working directory
|
|
459
|
+
|
|
460
|
+
// Or use module functions directly for more control
|
|
461
|
+
const cwd = process.cwd();
|
|
462
|
+
await init(cwd, { force: true });
|
|
463
|
+
await setupGit(cwd);
|
|
464
|
+
await lintAll(cwd);
|
|
465
|
+
await updatePackageVersion(cwd, { patch: true });
|
|
466
|
+
await publishPackage(cwd, { stable: true });
|
|
475
467
|
```
|
|
476
468
|
|
|
477
469
|
## License
|
package/dist/chunks/config.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const citty=require("citty"),consola=require("consola"),utils=require("../shared/basis.
|
|
1
|
+
"use strict";const citty=require("citty"),consola=require("consola"),utils=require("../shared/basis.DfY4XEAb.cjs");require("node:fs/promises"),require("c12"),require("../config.cjs");const config=citty.defineCommand({meta:{name:"config",description:"View current basis configuration"},args:{json:{type:"boolean",description:"Output configuration as JSON"},path:{type:"boolean",description:"Show configuration file path"}},async run({args:e}){try{const s=process.cwd(),{config:o,configFile:t}=await utils.loadConfig({cwd:s});if(e.path){t?consola.consola.info(`Configuration file: ${t}`):(consola.consola.warn("No configuration file found"),consola.consola.info("Run `basis init` to create one"));return}if(Object.keys(o).length===0){consola.consola.warn("No configuration found"),consola.consola.info("Run `basis init` to create a basis.config.ts file");return}if(e.json)consola.consola.log(JSON.stringify(o,null,2));else{if(consola.consola.info("Current basis configuration:"),t&&consola.consola.log(`\u{1F4C1} Config file: ${t}`),o.lint){if(consola.consola.log(""),consola.consola.log("\u{1F4DD} Lint:"),o.lint.staged){consola.consola.log(" Staged files:");for(const[n,i]of Object.entries(o.lint.staged))consola.consola.log(` ${n}: ${i}`)}if(o.lint.project){consola.consola.log(" Project:");for(const[n,i]of Object.entries(o.lint.project))consola.consola.log(` ${n}: ${i}`)}}if(o.git&&(consola.consola.log(""),consola.consola.log("\u{1F527} Git:"),o.git.commitMsg&&(consola.consola.log(" Commit message:"),o.git.commitMsg.types&&consola.consola.log(` Types: ${o.git.commitMsg.types.join(", ")}`),o.git.commitMsg.maxLength&&consola.consola.log(` Max length: ${o.git.commitMsg.maxLength}`),o.git.commitMsg.minLength&&consola.consola.log(` Min length: ${o.git.commitMsg.minLength}`)),o.git.hooks)){consola.consola.log(" Hooks:");for(const[n,i]of Object.entries(o.git.hooks))consola.consola.log(` ${n}: ${i}`)}}}catch(s){consola.consola.error("Failed to load configuration:",s),process.exit(1)}}});exports.default=config;
|
package/dist/chunks/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as r}from"citty";import{consola as o}from"consola";import{l as a}from"../shared/basis.
|
|
1
|
+
import{defineCommand as r}from"citty";import{consola as o}from"consola";import{l as a}from"../shared/basis.DEw91E2d.mjs";import"node:fs/promises";import"c12";import"../config.mjs";const f=r({meta:{name:"config",description:"View current basis configuration"},args:{json:{type:"boolean",description:"Output configuration as JSON"},path:{type:"boolean",description:"Show configuration file path"}},async run({args:s}){try{const g=process.cwd(),{config:i,configFile:e}=await a({cwd:g});if(s.path){e?o.info(`Configuration file: ${e}`):(o.warn("No configuration file found"),o.info("Run `basis init` to create one"));return}if(Object.keys(i).length===0){o.warn("No configuration found"),o.info("Run `basis init` to create a basis.config.ts file");return}if(s.json)o.log(JSON.stringify(i,null,2));else{if(o.info("Current basis configuration:"),e&&o.log(`\u{1F4C1} Config file: ${e}`),i.lint){if(o.log(""),o.log("\u{1F4DD} Lint:"),i.lint.staged){o.log(" Staged files:");for(const[t,n]of Object.entries(i.lint.staged))o.log(` ${t}: ${n}`)}if(i.lint.project){o.log(" Project:");for(const[t,n]of Object.entries(i.lint.project))o.log(` ${t}: ${n}`)}}if(i.git&&(o.log(""),o.log("\u{1F527} Git:"),i.git.commitMsg&&(o.log(" Commit message:"),i.git.commitMsg.types&&o.log(` Types: ${i.git.commitMsg.types.join(", ")}`),i.git.commitMsg.maxLength&&o.log(` Max length: ${i.git.commitMsg.maxLength}`),i.git.commitMsg.minLength&&o.log(` Min length: ${i.git.commitMsg.minLength}`)),i.git.hooks)){o.log(" Hooks:");for(const[t,n]of Object.entries(i.git.hooks))o.log(` ${t}: ${n}`)}}}catch(g){o.error("Failed to load configuration:",g),process.exit(1)}}});export{f as default};
|
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.Bar6V_OJ.cjs");require("node:child_process"),require("node:fs/promises"),require("c12/update"),require("defu"),require("ini"),require("pathe"),require("../shared/basis.DfY4XEAb.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(t=>typeof t=="string"):void 0,s=typeof e["update-config"]=="boolean"?e["update-config"]:!1;await git$1.removeGitHooks(o,i,{updateConfig:s})||(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,s=typeof e["update-config"]=="boolean"?e["update-config"]:!1;await git$1.resetGitConfig(o,i,{updateConfig:s})||(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(){const e=process.cwd();await git$1.setupGit(e)||process.exit(1)}});exports.git=git;
|
package/dist/chunks/git.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as
|
|
1
|
+
import{defineCommand as e}from"citty";import{consola as i}from"consola";import{s as r,l as c,i as p,b as m,d as f,c as d,a as u}from"../shared/basis.DzKnyliK.mjs";import"node:child_process";import"node:fs/promises";import"c12/update";import"defu";import"ini";import"pathe";import"../shared/basis.DEw91E2d.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 r(o)||process.exit(1)}}),config:e({meta:{name:"config",description:"Setup Git configuration only"},async run(){const o=process.cwd();await u(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 d(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 f(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 m(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 p(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 c(o)||(i.error("Commit message validation failed"),process.exit(1))}})},async run(){const o=process.cwd();await r(o)||process.exit(1)}});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.DVSF1f2D.cjs");require("c12/update"),require("magicast"),require("nypm"),require("pathe"),require("pkg-types"),require("../shared/basis.DfY4XEAb.cjs"),require("node:fs/promises"),require("c12"),require("../config.cjs"),require("../shared/basis.Bar6V_OJ.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.CCjpKO-B.mjs";import"c12/update";import"magicast";import"nypm";import"pathe";import"pkg-types";import"../shared/basis.DEw91E2d.mjs";import"node:fs/promises";import"c12";import"../config.mjs";import"../shared/basis.DzKnyliK.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.DADpzLwA.cjs");require("node:child_process"),require("fast-glob"),require("micromatch"),require("nypm"),require("pathe"),require("pkg-types"),require("../shared/basis.DfY4XEAb.cjs"),require("node:fs/promises"),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}},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);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)),e.structure&&s.push(()=>lint$1.lintStructure(t)),e.docs&&s.push(()=>lint$1.lintDocs(t));for(const r of s)await r()||(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 n}from"citty";import{consola as
|
|
1
|
+
import{defineCommand as n}from"citty";import{consola as r}from"consola";import{l as a,b as c,c as l,d as p,e as d,f as u}from"../shared/basis.DFb1F94b.mjs";import"node:child_process";import"fast-glob";import"micromatch";import"nypm";import"pathe";import"pkg-types";import"../shared/basis.DEw91E2d.mjs";import"node:fs/promises";import"c12";import"../config.mjs";const m=n({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}},async run({args:t}){const e=process.cwd();let s=!0;if(!t.staged&&!t.project&&!t.deps&&!t.structure&&!t.docs&&!t.all&&(t.staged=!0),t.all)s=await a(e);else{const o=[];t.staged&&o.push(()=>c(e)),t.project&&o.push(()=>l(e)),t.deps&&o.push(()=>p(e)),t.structure&&o.push(()=>d(e)),t.docs&&o.push(()=>u(e));for(const i of o)await i()||(s=!1)}s||(r.error("Some lint checks failed"),process.exit(1))}});export{m as lint};
|
package/dist/chunks/publish.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const citty=require("citty"),consola=require("consola"),publish$1=require("../shared/basis.
|
|
1
|
+
"use strict";const citty=require("citty"),consola=require("consola"),publish$1=require("../shared/basis.Dgo48zAG.cjs");require("node:child_process"),require("nypm"),require("pkg-types"),require("semver"),require("../shared/basis.DfY4XEAb.cjs"),require("node:fs/promises"),require("c12"),require("../config.cjs");const publish=citty.defineCommand({meta:{name:"publish",description:"Publish package to npm registry"},args:{tag:{type:"string",description:"Specific npm tag to publish to",alias:"t"},stable:{type:"boolean",description:"Publish as stable release (latest tag)",alias:"s"},latest:{type:"boolean",description:"Publish to latest tag",alias:"l"},dryRun:{type:"boolean",description:"Perform a dry run without actually publishing",alias:"d"},access:{type:"string",description:"Package access level (public/private)",alias:"a"},registry:{type:"string",description:"NPM registry URL",alias:"r"},skipBuild:{type:"boolean",description:"Skip build step"},skipTests:{type:"boolean",description:"Skip test step"}},async run({args:e}){try{const i=process.cwd(),t={tag:e.tag,stable:e.stable,latest:e.latest,dryRun:e.dryRun,access:e.access,registry:e.registry,skipBuild:e.skipBuild,skipTests:e.skipTests},s=await publish$1.publishPackage(i,t);s.dryRun?consola.consola.success("Dry run completed successfully"):consola.consola.success(`Published ${s.packageName}@${s.version} to ${s.publishTag}`)}catch(i){consola.consola.error("Failed to publish:",i),process.exit(1)}}});exports.default=publish;
|
package/dist/chunks/publish.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as r}from"citty";import{consola as i}from"consola";import{p}from"../shared/basis.
|
|
1
|
+
import{defineCommand as r}from"citty";import{consola as i}from"consola";import{p}from"../shared/basis.CKFXZgQI.mjs";import"node:child_process";import"nypm";import"pkg-types";import"semver";import"../shared/basis.DEw91E2d.mjs";import"node:fs/promises";import"c12";import"../config.mjs";const o=r({meta:{name:"publish",description:"Publish package to npm registry"},args:{tag:{type:"string",description:"Specific npm tag to publish to",alias:"t"},stable:{type:"boolean",description:"Publish as stable release (latest tag)",alias:"s"},latest:{type:"boolean",description:"Publish to latest tag",alias:"l"},dryRun:{type:"boolean",description:"Perform a dry run without actually publishing",alias:"d"},access:{type:"string",description:"Package access level (public/private)",alias:"a"},registry:{type:"string",description:"NPM registry URL",alias:"r"},skipBuild:{type:"boolean",description:"Skip build step"},skipTests:{type:"boolean",description:"Skip test step"}},async run({args:t}){try{const e=process.cwd(),a={tag:t.tag,stable:t.stable,latest:t.latest,dryRun:t.dryRun,access:t.access,registry:t.registry,skipBuild:t.skipBuild,skipTests:t.skipTests},s=await p(e,a);s.dryRun?i.success("Dry run completed successfully"):i.success(`Published ${s.packageName}@${s.version} to ${s.publishTag}`)}catch(e){i.error("Failed to publish:",e),process.exit(1)}}});export{o as default};
|
package/dist/chunks/version.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const citty=require("citty"),consola=require("consola"),
|
|
1
|
+
"use strict";const citty=require("citty"),consola=require("consola"),n=require("semver"),version$1=require("../shared/basis.C-dGsxlD.cjs");require("node:child_process"),require("pkg-types"),require("../shared/basis.DfY4XEAb.cjs"),require("node:fs/promises"),require("c12"),require("../config.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const n__default=_interopDefaultCompat(n),version=citty.defineCommand({meta:{name:"version",description:"Update package version"},args:{version:{type:"positional",description:"Version to set (patch, minor, major, prerelease, or specific version like 1.2.3)",required:!1},preid:{type:"string",description:"Prerelease identifier (alpha, beta, rc)"},tag:{type:"string",description:"Git tag name"},message:{type:"string",description:"Commit message template",alias:"m"}},async run({args:e}){try{const i=process.cwd(),r=e.version,o={preid:e.preid,message:e.message,tag:e.tag};r&&(["patch","minor","major","prerelease"].includes(r)?o[r]=!0:n__default.valid(r)?o.version=r:(consola.consola.error(`Invalid version argument: ${r}`),consola.consola.info("Valid options: patch, minor, major, prerelease, or specific version (e.g., 1.2.3)"),process.exit(1)));const s=await version$1.updatePackageVersion(i,o);consola.consola.success(`Version updated: ${s.oldVersion} \u2192 ${s.newVersion}`),s.tagName&&consola.consola.info(`Git tag created: ${s.tagName}`)}catch(i){consola.consola.error("Failed to update version:",i),process.exit(1)}}});exports.default=version;
|
package/dist/chunks/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as a}from"citty";import{consola as r}from"consola";import n from"semver";import{u as p}from"../shared/basis.
|
|
1
|
+
import{defineCommand as a}from"citty";import{consola as r}from"consola";import n from"semver";import{u as p}from"../shared/basis.BzZ6Bs64.mjs";import"node:child_process";import"pkg-types";import"../shared/basis.DEw91E2d.mjs";import"node:fs/promises";import"c12";import"../config.mjs";const m=a({meta:{name:"version",description:"Update package version"},args:{version:{type:"positional",description:"Version to set (patch, minor, major, prerelease, or specific version like 1.2.3)",required:!1},preid:{type:"string",description:"Prerelease identifier (alpha, beta, rc)"},tag:{type:"string",description:"Git tag name"},message:{type:"string",description:"Commit message template",alias:"m"}},async run({args:i}){try{const s=process.cwd(),e=i.version,t={preid:i.preid,message:i.message,tag:i.tag};e&&(["patch","minor","major","prerelease"].includes(e)?t[e]=!0:n.valid(e)?t.version=e:(r.error(`Invalid version argument: ${e}`),r.info("Valid options: patch, minor, major, prerelease, or specific version (e.g., 1.2.3)"),process.exit(1)));const o=await p(s,t);r.success(`Version updated: ${o.oldVersion} \u2192 ${o.newVersion}`),o.tagName&&r.info(`Git tag created: ${o.tagName}`)}catch(s){r.error("Failed to update version:",s),process.exit(1)}}});export{m as default};
|
package/dist/cli.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";const citty=require("citty"),consola=require("consola"),pkgTypes=require("pkg-types");async function m(){const e=await pkgTypes.readPackageJSON(),n=citty.defineCommand({meta:{name:"basis",version:e.version||"",description:e.description||""},subCommands:{init:()=>import("./chunks/init.cjs").then(t=>t.default),config:()=>import("./chunks/config.cjs").then(t=>t.default),lint:()=>import("./chunks/lint.cjs").then(t=>t.lint),git:()=>import("./chunks/git.cjs").then(t=>t.git),install:()=>import("./chunks/install.cjs").then(t=>t.default),i:()=>import("./chunks/install.cjs").then(t=>t.default),add:()=>import("./chunks/add.cjs").then(t=>t.default),remove:()=>import("./chunks/remove.cjs").then(t=>t.default),rm:()=>import("./chunks/remove.cjs").then(t=>t.default),uninstall:()=>import("./chunks/remove.cjs").then(t=>t.default),run:()=>import("./chunks/run.cjs").then(t=>t.default),version:()=>import("./chunks/version.cjs").then(t=>t.default),publish:()=>import("./chunks/publish.cjs").then(t=>t.default)}});await citty.runMain(n)}m().catch(consola.consola.error);
|
|
2
|
+
"use strict";const citty=require("citty"),consola=require("consola"),pkgTypes=require("pkg-types");var _documentCurrentScript=typeof document<"u"?document.currentScript:null;async function m(){const e=await pkgTypes.readPackageJSON(typeof document>"u"?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&_documentCurrentScript.tagName.toUpperCase()==="SCRIPT"&&_documentCurrentScript.src||new URL("cli.cjs",document.baseURI).href),n=citty.defineCommand({meta:{name:"basis",version:e.version||"",description:e.description||""},subCommands:{init:()=>import("./chunks/init.cjs").then(t=>t.default),config:()=>import("./chunks/config.cjs").then(t=>t.default),lint:()=>import("./chunks/lint.cjs").then(t=>t.lint),git:()=>import("./chunks/git.cjs").then(t=>t.git),install:()=>import("./chunks/install.cjs").then(t=>t.default),i:()=>import("./chunks/install.cjs").then(t=>t.default),add:()=>import("./chunks/add.cjs").then(t=>t.default),remove:()=>import("./chunks/remove.cjs").then(t=>t.default),rm:()=>import("./chunks/remove.cjs").then(t=>t.default),uninstall:()=>import("./chunks/remove.cjs").then(t=>t.default),run:()=>import("./chunks/run.cjs").then(t=>t.default),version:()=>import("./chunks/version.cjs").then(t=>t.default),publish:()=>import("./chunks/publish.cjs").then(t=>t.default)}});await citty.runMain(n)}m().catch(consola.consola.error);
|
package/dist/cli.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{defineCommand as
|
|
2
|
+
import{defineCommand as n,runMain as o}from"citty";import{consola as r}from"consola";import{readPackageJSON as a}from"pkg-types";async function m(){const i=await a(import.meta.url),e=n({meta:{name:"basis",version:i.version||"",description:i.description||""},subCommands:{init:()=>import("./chunks/init.mjs").then(t=>t.default),config:()=>import("./chunks/config.mjs").then(t=>t.default),lint:()=>import("./chunks/lint.mjs").then(t=>t.lint),git:()=>import("./chunks/git.mjs").then(t=>t.git),install:()=>import("./chunks/install.mjs").then(t=>t.default),i:()=>import("./chunks/install.mjs").then(t=>t.default),add:()=>import("./chunks/add.mjs").then(t=>t.default),remove:()=>import("./chunks/remove.mjs").then(t=>t.default),rm:()=>import("./chunks/remove.mjs").then(t=>t.default),uninstall:()=>import("./chunks/remove.mjs").then(t=>t.default),run:()=>import("./chunks/run.mjs").then(t=>t.default),version:()=>import("./chunks/version.mjs").then(t=>t.default),publish:()=>import("./chunks/publish.mjs").then(t=>t.default)}});await o(e)}m().catch(r.error);
|
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.Bar6V_OJ.cjs"),init=require("./shared/basis.DVSF1f2D.cjs"),lint=require("./shared/basis.DADpzLwA.cjs"),publish=require("./shared/basis.Dgo48zAG.cjs"),version=require("./shared/basis.C-dGsxlD.cjs"),utils=require("./shared/basis.DfY4XEAb.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.d.cts
CHANGED
|
@@ -1,120 +1,28 @@
|
|
|
1
|
-
import { B as BasisConfig, I as InitOptions, V as VersionOptions,
|
|
1
|
+
import { B as BasisConfig, I as InitOptions, V as VersionOptions, P as PublishOptions, a as VersionUpdateResult, b as PublishResult, C as CommitMessage, G as GitConfig, c as GitConfigData, L as LintConfig } from './shared/basis.BvLeB_5F.cjs';
|
|
2
2
|
export { f as CommitMsgConfig, j as GitConfigSection, i as GitConfigValue, k as PackageManagerConfig, m as PublishConfig, g as VALID_GIT_HOOKS, h as ValidGitHook, l as VersionConfig, e as defaultConfig, d as defineBasisConfig } from './shared/basis.BvLeB_5F.cjs';
|
|
3
3
|
import * as c12 from 'c12';
|
|
4
4
|
import { LoadConfigOptions } from 'c12';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Basis core utilities for programmatic usage
|
|
8
|
+
* Only includes methods that provide actual value beyond simple function calls
|
|
9
|
+
*/
|
|
6
10
|
declare class Basis {
|
|
7
11
|
private config;
|
|
8
12
|
private cwd;
|
|
9
13
|
constructor(cwd?: string);
|
|
10
|
-
/**
|
|
11
|
-
* Load configuration from file or cache
|
|
12
|
-
*/
|
|
13
|
-
getConfig(): Promise<BasisConfig>;
|
|
14
|
-
/**
|
|
15
|
-
* Initialize basis configuration in a project
|
|
16
|
-
*/
|
|
17
|
-
init(options?: InitOptions): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Run linting for staged files
|
|
20
|
-
*/
|
|
21
|
-
lintStaged(): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Run linting for entire project
|
|
24
|
-
*/
|
|
25
|
-
lintProject(): Promise<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
* Check project dependencies
|
|
28
|
-
*/
|
|
29
|
-
lintDependencies(): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* Check project structure
|
|
32
|
-
*/
|
|
33
|
-
lintStructure(): Promise<boolean>;
|
|
34
|
-
/**
|
|
35
|
-
* Check project documentation
|
|
36
|
-
*/
|
|
37
|
-
lintDocs(): Promise<boolean>;
|
|
38
|
-
/**
|
|
39
|
-
* Run all lint checks
|
|
40
|
-
*/
|
|
41
|
-
lintAll(): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Validate commit message
|
|
44
|
-
*/
|
|
45
|
-
lintCommitMessage(): Promise<boolean>;
|
|
46
|
-
/**
|
|
47
|
-
* Setup Git hooks
|
|
48
|
-
*/
|
|
49
|
-
setupGitHooks(): Promise<boolean>;
|
|
50
|
-
/**
|
|
51
|
-
* Setup Git configuration
|
|
52
|
-
*/
|
|
53
|
-
setupGitConfig(): Promise<boolean>;
|
|
54
|
-
/**
|
|
55
|
-
* Setup complete Git configuration (hooks + config)
|
|
56
|
-
*/
|
|
57
|
-
setupGit(): Promise<boolean>;
|
|
58
|
-
/**
|
|
59
|
-
* Initialize Git repository with basis configuration
|
|
60
|
-
*/
|
|
61
|
-
initGitRepo(): Promise<boolean>;
|
|
62
|
-
/**
|
|
63
|
-
* Remove Git hooks
|
|
64
|
-
*/
|
|
65
|
-
removeGitHooks(updateConfig?: boolean): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* Reset Git configuration
|
|
68
|
-
*/
|
|
69
|
-
resetGitConfig(keepUser?: boolean, updateConfig?: boolean): Promise<boolean>;
|
|
70
|
-
/**
|
|
71
|
-
* Update package version
|
|
72
|
-
*/
|
|
73
|
-
updateVersion(options?: VersionOptions): Promise<VersionUpdateResult>;
|
|
74
|
-
/**
|
|
75
|
-
* Update to specific version
|
|
76
|
-
*/
|
|
77
|
-
setVersion(version: string): Promise<VersionUpdateResult>;
|
|
78
|
-
/**
|
|
79
|
-
* Increment patch version
|
|
80
|
-
*/
|
|
81
|
-
patchVersion(): Promise<VersionUpdateResult>;
|
|
82
|
-
/**
|
|
83
|
-
* Increment minor version
|
|
84
|
-
*/
|
|
85
|
-
minorVersion(): Promise<VersionUpdateResult>;
|
|
86
|
-
/**
|
|
87
|
-
* Increment major version
|
|
88
|
-
*/
|
|
89
|
-
majorVersion(): Promise<VersionUpdateResult>;
|
|
90
|
-
/**
|
|
91
|
-
* Create prerelease version
|
|
92
|
-
*/
|
|
93
|
-
prereleaseVersion(preid?: string): Promise<VersionUpdateResult>;
|
|
94
|
-
/**
|
|
95
|
-
* Publish package to registry
|
|
96
|
-
*/
|
|
97
|
-
publish(options?: PublishOptions): Promise<PublishResult>;
|
|
98
|
-
/**
|
|
99
|
-
* Publish with dry run
|
|
100
|
-
*/
|
|
101
|
-
publishDryRun(options?: PublishOptions): Promise<PublishResult>;
|
|
102
|
-
/**
|
|
103
|
-
* Publish to specific tag
|
|
104
|
-
*/
|
|
105
|
-
publishToTag(tag: string, options?: PublishOptions): Promise<PublishResult>;
|
|
106
|
-
/**
|
|
107
|
-
* Publish as stable release (latest tag)
|
|
108
|
-
*/
|
|
109
|
-
publishStable(options?: PublishOptions): Promise<PublishResult>;
|
|
110
14
|
/**
|
|
111
15
|
* Get current working directory
|
|
112
16
|
*/
|
|
113
17
|
getCwd(): string;
|
|
114
18
|
/**
|
|
115
|
-
* Set working directory
|
|
19
|
+
* Set working directory and reset cached config
|
|
116
20
|
*/
|
|
117
21
|
setCwd(cwd: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Load configuration from file or cache
|
|
24
|
+
*/
|
|
25
|
+
getConfig(): Promise<BasisConfig>;
|
|
118
26
|
/**
|
|
119
27
|
* Reload configuration from file
|
|
120
28
|
*/
|
|
@@ -174,7 +82,7 @@ declare function resetGitConfig(cwd?: string, keepUser?: boolean, options?: {
|
|
|
174
82
|
*/
|
|
175
83
|
declare function setupGitHooks(cwd?: string, config?: GitConfig["hooks"]): Promise<boolean>;
|
|
176
84
|
/**
|
|
177
|
-
* Initialize Git repository
|
|
85
|
+
* Initialize Git repository
|
|
178
86
|
*/
|
|
179
87
|
declare function initGitRepo(cwd?: string): Promise<boolean>;
|
|
180
88
|
/**
|
|
@@ -247,6 +155,12 @@ declare function fileExists(path: string): Promise<boolean>;
|
|
|
247
155
|
declare function getPackageManagerCommands(packageManager: string): {
|
|
248
156
|
outdated: string;
|
|
249
157
|
audit: string;
|
|
158
|
+
} | {
|
|
159
|
+
outdated: string;
|
|
160
|
+
audit: null;
|
|
161
|
+
} | {
|
|
162
|
+
outdated: null;
|
|
163
|
+
audit: null;
|
|
250
164
|
};
|
|
251
165
|
|
|
252
166
|
export { Basis, BasisConfig, CommitMessage, GitConfig, GitConfigData, InitOptions, LintConfig, PublishOptions, PublishResult, VersionOptions, VersionUpdateResult, createBasis, fileExists, getPackageManagerCommands, getProjectFiles, getStagedFiles, init, initGitRepo, lintAll, lintCommitMessage, lintDependencies, lintDocs, lintProject, lintStaged, lintStructure, loadConfig, parseCommitMessage, publishPackage, readGitConfig, removeGitHooks, resetGitConfig, setupGit, setupGitConfig, setupGitHooks, updatePackageVersion, validateCommitMessage, writeGitConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,120 +1,28 @@
|
|
|
1
|
-
import { B as BasisConfig, I as InitOptions, V as VersionOptions,
|
|
1
|
+
import { B as BasisConfig, I as InitOptions, V as VersionOptions, P as PublishOptions, a as VersionUpdateResult, b as PublishResult, C as CommitMessage, G as GitConfig, c as GitConfigData, L as LintConfig } from './shared/basis.BvLeB_5F.mjs';
|
|
2
2
|
export { f as CommitMsgConfig, j as GitConfigSection, i as GitConfigValue, k as PackageManagerConfig, m as PublishConfig, g as VALID_GIT_HOOKS, h as ValidGitHook, l as VersionConfig, e as defaultConfig, d as defineBasisConfig } from './shared/basis.BvLeB_5F.mjs';
|
|
3
3
|
import * as c12 from 'c12';
|
|
4
4
|
import { LoadConfigOptions } from 'c12';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Basis core utilities for programmatic usage
|
|
8
|
+
* Only includes methods that provide actual value beyond simple function calls
|
|
9
|
+
*/
|
|
6
10
|
declare class Basis {
|
|
7
11
|
private config;
|
|
8
12
|
private cwd;
|
|
9
13
|
constructor(cwd?: string);
|
|
10
|
-
/**
|
|
11
|
-
* Load configuration from file or cache
|
|
12
|
-
*/
|
|
13
|
-
getConfig(): Promise<BasisConfig>;
|
|
14
|
-
/**
|
|
15
|
-
* Initialize basis configuration in a project
|
|
16
|
-
*/
|
|
17
|
-
init(options?: InitOptions): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Run linting for staged files
|
|
20
|
-
*/
|
|
21
|
-
lintStaged(): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Run linting for entire project
|
|
24
|
-
*/
|
|
25
|
-
lintProject(): Promise<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
* Check project dependencies
|
|
28
|
-
*/
|
|
29
|
-
lintDependencies(): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* Check project structure
|
|
32
|
-
*/
|
|
33
|
-
lintStructure(): Promise<boolean>;
|
|
34
|
-
/**
|
|
35
|
-
* Check project documentation
|
|
36
|
-
*/
|
|
37
|
-
lintDocs(): Promise<boolean>;
|
|
38
|
-
/**
|
|
39
|
-
* Run all lint checks
|
|
40
|
-
*/
|
|
41
|
-
lintAll(): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Validate commit message
|
|
44
|
-
*/
|
|
45
|
-
lintCommitMessage(): Promise<boolean>;
|
|
46
|
-
/**
|
|
47
|
-
* Setup Git hooks
|
|
48
|
-
*/
|
|
49
|
-
setupGitHooks(): Promise<boolean>;
|
|
50
|
-
/**
|
|
51
|
-
* Setup Git configuration
|
|
52
|
-
*/
|
|
53
|
-
setupGitConfig(): Promise<boolean>;
|
|
54
|
-
/**
|
|
55
|
-
* Setup complete Git configuration (hooks + config)
|
|
56
|
-
*/
|
|
57
|
-
setupGit(): Promise<boolean>;
|
|
58
|
-
/**
|
|
59
|
-
* Initialize Git repository with basis configuration
|
|
60
|
-
*/
|
|
61
|
-
initGitRepo(): Promise<boolean>;
|
|
62
|
-
/**
|
|
63
|
-
* Remove Git hooks
|
|
64
|
-
*/
|
|
65
|
-
removeGitHooks(updateConfig?: boolean): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* Reset Git configuration
|
|
68
|
-
*/
|
|
69
|
-
resetGitConfig(keepUser?: boolean, updateConfig?: boolean): Promise<boolean>;
|
|
70
|
-
/**
|
|
71
|
-
* Update package version
|
|
72
|
-
*/
|
|
73
|
-
updateVersion(options?: VersionOptions): Promise<VersionUpdateResult>;
|
|
74
|
-
/**
|
|
75
|
-
* Update to specific version
|
|
76
|
-
*/
|
|
77
|
-
setVersion(version: string): Promise<VersionUpdateResult>;
|
|
78
|
-
/**
|
|
79
|
-
* Increment patch version
|
|
80
|
-
*/
|
|
81
|
-
patchVersion(): Promise<VersionUpdateResult>;
|
|
82
|
-
/**
|
|
83
|
-
* Increment minor version
|
|
84
|
-
*/
|
|
85
|
-
minorVersion(): Promise<VersionUpdateResult>;
|
|
86
|
-
/**
|
|
87
|
-
* Increment major version
|
|
88
|
-
*/
|
|
89
|
-
majorVersion(): Promise<VersionUpdateResult>;
|
|
90
|
-
/**
|
|
91
|
-
* Create prerelease version
|
|
92
|
-
*/
|
|
93
|
-
prereleaseVersion(preid?: string): Promise<VersionUpdateResult>;
|
|
94
|
-
/**
|
|
95
|
-
* Publish package to registry
|
|
96
|
-
*/
|
|
97
|
-
publish(options?: PublishOptions): Promise<PublishResult>;
|
|
98
|
-
/**
|
|
99
|
-
* Publish with dry run
|
|
100
|
-
*/
|
|
101
|
-
publishDryRun(options?: PublishOptions): Promise<PublishResult>;
|
|
102
|
-
/**
|
|
103
|
-
* Publish to specific tag
|
|
104
|
-
*/
|
|
105
|
-
publishToTag(tag: string, options?: PublishOptions): Promise<PublishResult>;
|
|
106
|
-
/**
|
|
107
|
-
* Publish as stable release (latest tag)
|
|
108
|
-
*/
|
|
109
|
-
publishStable(options?: PublishOptions): Promise<PublishResult>;
|
|
110
14
|
/**
|
|
111
15
|
* Get current working directory
|
|
112
16
|
*/
|
|
113
17
|
getCwd(): string;
|
|
114
18
|
/**
|
|
115
|
-
* Set working directory
|
|
19
|
+
* Set working directory and reset cached config
|
|
116
20
|
*/
|
|
117
21
|
setCwd(cwd: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Load configuration from file or cache
|
|
24
|
+
*/
|
|
25
|
+
getConfig(): Promise<BasisConfig>;
|
|
118
26
|
/**
|
|
119
27
|
* Reload configuration from file
|
|
120
28
|
*/
|
|
@@ -174,7 +82,7 @@ declare function resetGitConfig(cwd?: string, keepUser?: boolean, options?: {
|
|
|
174
82
|
*/
|
|
175
83
|
declare function setupGitHooks(cwd?: string, config?: GitConfig["hooks"]): Promise<boolean>;
|
|
176
84
|
/**
|
|
177
|
-
* Initialize Git repository
|
|
85
|
+
* Initialize Git repository
|
|
178
86
|
*/
|
|
179
87
|
declare function initGitRepo(cwd?: string): Promise<boolean>;
|
|
180
88
|
/**
|
|
@@ -247,6 +155,12 @@ declare function fileExists(path: string): Promise<boolean>;
|
|
|
247
155
|
declare function getPackageManagerCommands(packageManager: string): {
|
|
248
156
|
outdated: string;
|
|
249
157
|
audit: string;
|
|
158
|
+
} | {
|
|
159
|
+
outdated: string;
|
|
160
|
+
audit: null;
|
|
161
|
+
} | {
|
|
162
|
+
outdated: null;
|
|
163
|
+
audit: null;
|
|
250
164
|
};
|
|
251
165
|
|
|
252
166
|
export { Basis, BasisConfig, CommitMessage, GitConfig, GitConfigData, InitOptions, LintConfig, PublishOptions, PublishResult, VersionOptions, VersionUpdateResult, createBasis, fileExists, getPackageManagerCommands, getProjectFiles, getStagedFiles, init, initGitRepo, lintAll, lintCommitMessage, lintDependencies, lintDocs, lintProject, lintStaged, lintStructure, loadConfig, parseCommitMessage, publishPackage, readGitConfig, removeGitHooks, resetGitConfig, setupGit, setupGitConfig, setupGitHooks, updatePackageVersion, validateCommitMessage, writeGitConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,120 +1,28 @@
|
|
|
1
|
-
import { B as BasisConfig, I as InitOptions, V as VersionOptions,
|
|
1
|
+
import { B as BasisConfig, I as InitOptions, V as VersionOptions, P as PublishOptions, a as VersionUpdateResult, b as PublishResult, C as CommitMessage, G as GitConfig, c as GitConfigData, L as LintConfig } from './shared/basis.BvLeB_5F.js';
|
|
2
2
|
export { f as CommitMsgConfig, j as GitConfigSection, i as GitConfigValue, k as PackageManagerConfig, m as PublishConfig, g as VALID_GIT_HOOKS, h as ValidGitHook, l as VersionConfig, e as defaultConfig, d as defineBasisConfig } from './shared/basis.BvLeB_5F.js';
|
|
3
3
|
import * as c12 from 'c12';
|
|
4
4
|
import { LoadConfigOptions } from 'c12';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Basis core utilities for programmatic usage
|
|
8
|
+
* Only includes methods that provide actual value beyond simple function calls
|
|
9
|
+
*/
|
|
6
10
|
declare class Basis {
|
|
7
11
|
private config;
|
|
8
12
|
private cwd;
|
|
9
13
|
constructor(cwd?: string);
|
|
10
|
-
/**
|
|
11
|
-
* Load configuration from file or cache
|
|
12
|
-
*/
|
|
13
|
-
getConfig(): Promise<BasisConfig>;
|
|
14
|
-
/**
|
|
15
|
-
* Initialize basis configuration in a project
|
|
16
|
-
*/
|
|
17
|
-
init(options?: InitOptions): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Run linting for staged files
|
|
20
|
-
*/
|
|
21
|
-
lintStaged(): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Run linting for entire project
|
|
24
|
-
*/
|
|
25
|
-
lintProject(): Promise<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
* Check project dependencies
|
|
28
|
-
*/
|
|
29
|
-
lintDependencies(): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* Check project structure
|
|
32
|
-
*/
|
|
33
|
-
lintStructure(): Promise<boolean>;
|
|
34
|
-
/**
|
|
35
|
-
* Check project documentation
|
|
36
|
-
*/
|
|
37
|
-
lintDocs(): Promise<boolean>;
|
|
38
|
-
/**
|
|
39
|
-
* Run all lint checks
|
|
40
|
-
*/
|
|
41
|
-
lintAll(): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Validate commit message
|
|
44
|
-
*/
|
|
45
|
-
lintCommitMessage(): Promise<boolean>;
|
|
46
|
-
/**
|
|
47
|
-
* Setup Git hooks
|
|
48
|
-
*/
|
|
49
|
-
setupGitHooks(): Promise<boolean>;
|
|
50
|
-
/**
|
|
51
|
-
* Setup Git configuration
|
|
52
|
-
*/
|
|
53
|
-
setupGitConfig(): Promise<boolean>;
|
|
54
|
-
/**
|
|
55
|
-
* Setup complete Git configuration (hooks + config)
|
|
56
|
-
*/
|
|
57
|
-
setupGit(): Promise<boolean>;
|
|
58
|
-
/**
|
|
59
|
-
* Initialize Git repository with basis configuration
|
|
60
|
-
*/
|
|
61
|
-
initGitRepo(): Promise<boolean>;
|
|
62
|
-
/**
|
|
63
|
-
* Remove Git hooks
|
|
64
|
-
*/
|
|
65
|
-
removeGitHooks(updateConfig?: boolean): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* Reset Git configuration
|
|
68
|
-
*/
|
|
69
|
-
resetGitConfig(keepUser?: boolean, updateConfig?: boolean): Promise<boolean>;
|
|
70
|
-
/**
|
|
71
|
-
* Update package version
|
|
72
|
-
*/
|
|
73
|
-
updateVersion(options?: VersionOptions): Promise<VersionUpdateResult>;
|
|
74
|
-
/**
|
|
75
|
-
* Update to specific version
|
|
76
|
-
*/
|
|
77
|
-
setVersion(version: string): Promise<VersionUpdateResult>;
|
|
78
|
-
/**
|
|
79
|
-
* Increment patch version
|
|
80
|
-
*/
|
|
81
|
-
patchVersion(): Promise<VersionUpdateResult>;
|
|
82
|
-
/**
|
|
83
|
-
* Increment minor version
|
|
84
|
-
*/
|
|
85
|
-
minorVersion(): Promise<VersionUpdateResult>;
|
|
86
|
-
/**
|
|
87
|
-
* Increment major version
|
|
88
|
-
*/
|
|
89
|
-
majorVersion(): Promise<VersionUpdateResult>;
|
|
90
|
-
/**
|
|
91
|
-
* Create prerelease version
|
|
92
|
-
*/
|
|
93
|
-
prereleaseVersion(preid?: string): Promise<VersionUpdateResult>;
|
|
94
|
-
/**
|
|
95
|
-
* Publish package to registry
|
|
96
|
-
*/
|
|
97
|
-
publish(options?: PublishOptions): Promise<PublishResult>;
|
|
98
|
-
/**
|
|
99
|
-
* Publish with dry run
|
|
100
|
-
*/
|
|
101
|
-
publishDryRun(options?: PublishOptions): Promise<PublishResult>;
|
|
102
|
-
/**
|
|
103
|
-
* Publish to specific tag
|
|
104
|
-
*/
|
|
105
|
-
publishToTag(tag: string, options?: PublishOptions): Promise<PublishResult>;
|
|
106
|
-
/**
|
|
107
|
-
* Publish as stable release (latest tag)
|
|
108
|
-
*/
|
|
109
|
-
publishStable(options?: PublishOptions): Promise<PublishResult>;
|
|
110
14
|
/**
|
|
111
15
|
* Get current working directory
|
|
112
16
|
*/
|
|
113
17
|
getCwd(): string;
|
|
114
18
|
/**
|
|
115
|
-
* Set working directory
|
|
19
|
+
* Set working directory and reset cached config
|
|
116
20
|
*/
|
|
117
21
|
setCwd(cwd: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Load configuration from file or cache
|
|
24
|
+
*/
|
|
25
|
+
getConfig(): Promise<BasisConfig>;
|
|
118
26
|
/**
|
|
119
27
|
* Reload configuration from file
|
|
120
28
|
*/
|
|
@@ -174,7 +82,7 @@ declare function resetGitConfig(cwd?: string, keepUser?: boolean, options?: {
|
|
|
174
82
|
*/
|
|
175
83
|
declare function setupGitHooks(cwd?: string, config?: GitConfig["hooks"]): Promise<boolean>;
|
|
176
84
|
/**
|
|
177
|
-
* Initialize Git repository
|
|
85
|
+
* Initialize Git repository
|
|
178
86
|
*/
|
|
179
87
|
declare function initGitRepo(cwd?: string): Promise<boolean>;
|
|
180
88
|
/**
|
|
@@ -247,6 +155,12 @@ declare function fileExists(path: string): Promise<boolean>;
|
|
|
247
155
|
declare function getPackageManagerCommands(packageManager: string): {
|
|
248
156
|
outdated: string;
|
|
249
157
|
audit: string;
|
|
158
|
+
} | {
|
|
159
|
+
outdated: string;
|
|
160
|
+
audit: null;
|
|
161
|
+
} | {
|
|
162
|
+
outdated: null;
|
|
163
|
+
audit: null;
|
|
250
164
|
};
|
|
251
165
|
|
|
252
166
|
export { Basis, BasisConfig, CommitMessage, GitConfig, GitConfigData, InitOptions, LintConfig, PublishOptions, PublishResult, VersionOptions, VersionUpdateResult, createBasis, fileExists, getPackageManagerCommands, getProjectFiles, getStagedFiles, init, initGitRepo, lintAll, lintCommitMessage, lintDependencies, lintDocs, lintProject, lintStaged, lintStructure, loadConfig, parseCommitMessage, publishPackage, readGitConfig, removeGitHooks, resetGitConfig, setupGit, setupGitConfig, setupGitHooks, updatePackageVersion, validateCommitMessage, writeGitConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{defaultConfig,defineBasisConfig}from"./config.mjs";import{
|
|
1
|
+
export{defaultConfig,defineBasisConfig}from"./config.mjs";import{s as e}from"./shared/basis.DzKnyliK.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.DzKnyliK.mjs";import{i as s}from"./shared/basis.CCjpKO-B.mjs";import{l as o}from"./shared/basis.DFb1F94b.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.DFb1F94b.mjs";import{p as a}from"./shared/basis.CKFXZgQI.mjs";import{u as r}from"./shared/basis.BzZ6Bs64.mjs";import{l as p}from"./shared/basis.DEw91E2d.mjs";export{f as fileExists,g as getPackageManagerCommands}from"./shared/basis.DEw91E2d.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,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"),y=require("ini"),pathe=require("pathe"),utils=require("./basis.DfY4XEAb.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const y__default=_interopDefaultCompat(y);async function G(e,i=!1,s=!1){try{return await update.updateConfig({cwd:e,configFile:"basis.config",onUpdate:t=>{t.git&&(i&&t.git.hooks&&delete t.git.hooks,s&&t.git.config&&delete t.git.config,Object.keys(t.git).length===0&&delete t.git)}}),!0}catch{return!1}}const P=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function parseCommitMessage(e){const i=e.trim().split(`
|
|
2
|
+
`),s=i[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!s)return null;const[,t,,o,n,r]=s,c=i.slice(1).find(l=>l.trim())?.trim(),a=i.slice(-1)[0]?.trim();return{type:t,scope:o,description:r,body:c,footer:a,isBreaking:!!n||e.includes("BREAKING CHANGE:")}}function validateCommitMessage(e,i={}){const s=[],{types:t=P,maxLength:o=72,minLength:n=10,scopeRequired:r=!1,allowedScopes:c=[]}=i,a=parseCommitMessage(e);if(!a)return{valid:!1,errors:["Invalid commit format. Expected: type(scope): description"]};t.includes(a.type)||s.push(`Invalid type '${a.type}'. Allowed: ${t.join(", ")}`);const l=e.split(`
|
|
3
|
+
`)[0];return l.length>o&&s.push(`Header too long (${l.length}). Max: ${o}`),l.length<n&&s.push(`Header too short (${l.length}). Min: ${n}`),r&&!a.scope&&s.push("Scope is required"),a.scope&&c.length>0&&!c.includes(a.scope)&&s.push(`Invalid scope '${a.scope}'. Allowed: ${c.join(", ")}`),{valid:s.length===0,errors:s}}async function lintCommitMessage(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{git:{commitMsg:i}}:void 0}),t=s.git?.commitMsg||{};let o;try{const r=pathe.resolve(".git/COMMIT_EDITMSG");await utils.fileExists(r)?o=(await promises.readFile(r)).toString("utf8"):o=node_child_process.execSync("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(r){return consola.consola.error("Failed to read commit message:",r),!1}const n=validateCommitMessage(o,t);return n.valid?!0:(consola.consola.error("Invalid commit message:"),n.errors.forEach(r=>consola.consola.error(` ${r}`)),!1)}async function w(e){const i=pathe.resolve(e,".git/config");if(!await utils.fileExists(i))return null;const s=new Date().toISOString().replace(/[:.]/g,"-"),t=pathe.resolve(e,`.git/config.backup.${s}`);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 s=await promises.readFile(i,"utf8");return y__default.parse(s)}catch(s){return consola.consola.warn("Failed to read .git/config:",s),{}}}async function writeGitConfig(e,i=process.cwd()){const s=pathe.resolve(i,".git/config");try{let t=y__default.stringify(e,{whitespace:!0});t=t.split(`
|
|
4
|
+
`).map(o=>o&&!o.startsWith("[")&&o.includes("=")?` ${o}`:o).join(`
|
|
5
|
+
`),await promises.writeFile(s,t,"utf8")}catch(t){throw consola.consola.error("Failed to write .git/config:",t),t}}function M(e,i){if(!i)return!0;for(const[s,t]of Object.entries(i)){if(typeof t!="object"||!t)continue;const o=e[s];if(!o||typeof o!="object")return!1;for(const[n,r]of Object.entries(t))if(r!==void 0&&o[n]!==r)return!1}return!0}async function setupGitConfig(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{git:{config:i}}:void 0}),t=s.git?.config||{};if(Object.keys(t).length===0)return!0;try{const o=await readGitConfig(e);if(M(o,t))return!0;await w(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,s={}){try{await w(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"],r={};n.forEach(c=>{t.core[c]!==void 0&&(r[c]=t.core[c])}),Object.keys(r).length>0&&(o.core=r)}return await writeGitConfig(o,e),s.updateConfig?await G(e,!1,!0):!0}catch(t){return consola.consola.error("Failed to reset Git configuration:",t),!1}}async function setupGitHooks(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{git:{hooks:i}}:void 0}),t=s.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[r,c]of Object.entries(t)){const a=pathe.resolve(o,r);try{let l=`#!/bin/sh
|
|
6
|
+
|
|
7
|
+
`;if(typeof c=="string")l+=`${c}
|
|
8
|
+
`;else if(c&&typeof c=="object"&&"commands"in c){const f=c.commands;l+=`${f.join(`
|
|
9
|
+
`)}
|
|
10
|
+
`}await promises.writeFile(a,l,{mode:493})}catch(l){consola.consola.error(`Failed to setup ${r} hook:`,l),n=!1}}return n}async function initGitRepo(e=process.cwd()){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}),s=i.git||{},t=(await Promise.allSettled([setupGitConfig(e,s.config),setupGitHooks(e,s.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,s={}){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:r}=await utils.loadConfig({cwd:e});n=Object.keys(r.git?.hooks||{})}for(const r of n){const c=pathe.resolve(t,r);if(await utils.fileExists(c))try{await promises.unlink(c)}catch(a){consola.consola.error(`Failed to remove ${r} hook:`,a),o=!1}}if(!i&&s.updateConfig){const r=await G(e,!0,!1);o=o&&r}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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{execSync as t}from"node:child_process";import{consola as l}from"consola";import{readPackageJSON as d,resolvePackageJSON as w,writePackageJSON as v}from"pkg-types";import s from"semver";import{l as u}from"./basis.DEw91E2d.mjs";function h(e,o,m){if(o.version){if(s.valid(o.version))return o.version;throw new Error(`Invalid version format: ${o.version}. Please use semantic versioning format (e.g., 1.0.0, 2.1.0-alpha.1)`)}if(!s.valid(e))throw new Error(`Invalid current version format: ${e}. Please fix version in package.json to use semantic versioning format (e.g., 1.0.0)`);const r=s.prerelease(e),c=o.preid||(r&&typeof r[0]=="string"?r[0]:null)||m.prereleaseId||"edge";let a;o.major?a="major":o.minor?a="minor":o.prerelease?a=r?"prerelease":"prepatch":a=r?"prerelease":"patch";const i=a==="prerelease"||a.startsWith("pre")?s.inc(e,a,c):s.inc(e,a);if(!i)throw new Error(`Failed to calculate new version from ${e}. Please check your version increment options.`);return i}async function P(e,o={}){const{config:m}=await u({cwd:e}),r=m.version||{},c=await d(e),a=c.version;if(!a)throw new Error("No version found in package.json");const i=h(a,o,r),f=await w(e);await v(f,{...c,version:i});const p={oldVersion:a,newVersion:i};if(r.autoCommit){const n=o.message||r.commitMessage?.replace("{version}",i)||`chore: release v${i}`;try{t("git add package.json",{cwd:e}),t(`git commit -m "${n}"`,{cwd:e})}catch(g){l.warn("Failed to commit changes:",g)}}if(r.autoTag){const n=`${r.tagPrefix||"v"}${i}`;try{t(`git tag ${n}`,{cwd:e}),p.tagName=n}catch(g){l.warn("Failed to create git tag:",g)}}if(r.autoPush)try{t("git push",{cwd:e}),r.autoTag&&t("git push --tags",{cwd:e})}catch(n){l.warn("Failed to push changes:",n)}return p}export{P as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const node_child_process=require("node:child_process"),consola=require("consola"),pkgTypes=require("pkg-types"),n=require("semver"),utils=require("./basis.DfY4XEAb.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const n__default=_interopDefaultCompat(n);function P(e,a,c){if(a.version){if(n__default.valid(a.version))return a.version;throw new Error(`Invalid version format: ${a.version}. Please use semantic versioning format (e.g., 1.0.0, 2.1.0-alpha.1)`)}if(!n__default.valid(e))throw new Error(`Invalid current version format: ${e}. Please fix version in package.json to use semantic versioning format (e.g., 1.0.0)`);const r=n__default.prerelease(e),t=a.preid||(r&&typeof r[0]=="string"?r[0]:null)||c.prereleaseId||"edge";let o;a.major?o="major":a.minor?o="minor":a.prerelease?o=r?"prerelease":"prepatch":o=r?"prerelease":"patch";const i=o==="prerelease"||o.startsWith("pre")?n__default.inc(e,o,t):n__default.inc(e,o);if(!i)throw new Error(`Failed to calculate new version from ${e}. Please check your version increment options.`);return i}async function updatePackageVersion(e,a={}){const{config:c}=await utils.loadConfig({cwd:e}),r=c.version||{},t=await pkgTypes.readPackageJSON(e),o=t.version;if(!o)throw new Error("No version found in package.json");const i=P(o,a,r),u=await pkgTypes.resolvePackageJSON(e);await pkgTypes.writePackageJSON(u,{...t,version:i});const g={oldVersion:o,newVersion:i};if(r.autoCommit){const s=a.message||r.commitMessage?.replace("{version}",i)||`chore: release v${i}`;try{node_child_process.execSync("git add package.json",{cwd:e}),node_child_process.execSync(`git commit -m "${s}"`,{cwd:e})}catch(l){consola.consola.warn("Failed to commit changes:",l)}}if(r.autoTag){const s=`${r.tagPrefix||"v"}${i}`;try{node_child_process.execSync(`git tag ${s}`,{cwd:e}),g.tagName=s}catch(l){consola.consola.warn("Failed to create git tag:",l)}}if(r.autoPush)try{node_child_process.execSync("git push",{cwd:e}),r.autoTag&&node_child_process.execSync("git push --tags",{cwd:e})}catch(s){consola.consola.warn("Failed to push changes:",s)}return g}exports.updatePackageVersion=updatePackageVersion;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{updateConfig as S}from"c12/update";import{consola as t}from"consola";import{parseModule as $,generateCode as B}from"magicast";import{addDevDependency as z,detectPackageManager as v}from"nypm";import{resolve as r}from"pathe";import{findWorkspaceDir as D,readPackageJSON as k,writePackageJSON as F}from"pkg-types";import{f as c}from"./basis.DEw91E2d.mjs";import{i as I,s as J}from"./basis.DzKnyliK.mjs";const j={ts:{ext:"ts",label:"TypeScript"},mjs:{ext:"mjs",label:"ES Module"},cjs:{ext:"cjs",label:"CommonJS"}};function M(i){const o=$(i==="cjs"?`const { defineBasisConfig } = require("@funish/basis");
|
|
2
|
+
|
|
3
|
+
module.exports = defineBasisConfig({});`:`import { defineBasisConfig } from "@funish/basis";
|
|
4
|
+
|
|
5
|
+
export default defineBasisConfig({});`),l={lint:{staged:{},project:{}},git:{hooks:{},autoSetup:!0},packageManager:{autoDetect:!0}},n=o.exports.default.$args[0];return Object.assign(n,l),n.$ast.leadingComments=[{type:"Block",value:`
|
|
6
|
+
Configure your project here
|
|
7
|
+
See: https://github.com/funish/basis/tree/main/packages/basis#configuration
|
|
8
|
+
`}],B(o).code}async function N(i){if(await c(r(i,"tsconfig.json")))return"ts";try{if((await k(i)).type==="module")return"mjs"}catch{}return"ts"}async function O(i=process.cwd(),o={}){const{force:l=!1,skipGitCheck:n=!1,skipInstall:G=!1}=o;t.start("Initializing basis configuration...");const w=await N(i),y=await t.prompt("Choose config file format:",{type:"select",initial:w,options:Object.entries(j).map(([e,{label:a,ext:f}])=>({value:e,label:`${a} (${f}) ${w===e?"(recommended)":""}`}))}),b=j[y].ext,h=`basis.config.${b}`,C=r(i,h);if(await c(C)&&!l)return t.error(`${h} already exists. Use --force to overwrite.`),!1;let s=!1;if(!n)if(await c(r(i,".git")))s=await t.prompt("Setup Git hooks and configuration?",{type:"confirm",initial:!0});else if(t.info("No Git repository found."),await t.prompt("Initialize Git repository?",{type:"confirm",initial:!0}))try{await I(i)?s=await t.prompt("Setup Git hooks and configuration?",{type:"confirm",initial:!0}):(t.warn("Git initialization failed, skipping Git setup"),s=!1)}catch(e){t.error("Failed to initialize Git repository:",e),t.warn("Skipping Git setup"),s=!1}else t.info("Skipping Git initialization"),s=!1;await S({cwd:i,configFile:"basis.config",createExtension:`.${b}`,onCreate:()=>M(y)});let p=!1;G||(p=await t.prompt("Install @funish/basis dependency now?",{type:"confirm",initial:!0}));const x=await D(i)===i;if(p)try{await z(["@funish/basis"],{workspace:x})}catch(e){t.error("Failed to install @funish/basis:",e),t.info("You can install it manually with: basis add -D @funish/basis")}if(s)try{const e=r(i,"package.json");if(await c(e)){const a=await k(e),f=(await v(i))?.name||"npm",u="basis git setup";a.scripts=a.scripts||{};const m=f==="yarn"?"prepare":"postinstall",d=a.scripts[m];let g=!1;d?d.includes(u)||(a.scripts[m]=`${d} && ${u}`,g=!0):(a.scripts[m]=u,g=!0),g&&await F(e,a)}else t.warn("No package.json found. You'll need to run git setup manually.")}catch(e){t.error("Failed to update package.json:",e),t.warn("You can manually add 'basis git setup' to your postinstall script")}return s&&!p&&(await J(i)||t.warn("Git setup failed, but basis config was created successfully")),t.success("Basis initialization completed!"),!0}export{O as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{execSync as o}from"node:child_process";import{consola as s}from"consola";import{detectPackageManager as y,runScript as h}from"nypm";import{readPackageJSON as k}from"pkg-types";import m from"semver";import{l as b}from"./basis.DEw91E2d.mjs";function $(t,a,r){if(a.tag)return a.tag;if(a.stable||a.latest)return r.stableTag||"latest";if(m.prerelease(t)){const i=m.prerelease(t);return i&&i[0]||r.defaultTag||"edge"}return r.stableTag||"latest"}async function C(t,a,r){if(a.checkGitClean&&!r.skipTests)try{if(o("git status --porcelain",{cwd:t,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(i){s.warn("Could not check git status:",i)}if(a.checkTests&&!r.skipTests){s.start("Running tests...");try{a.testCommand?o(a.testCommand,{cwd:t,stdio:"inherit"}):await h("test",{cwd:t,silent:!1})}catch(i){throw s.error("Tests failed"),i}}if(a.buildCommand&&!r.skipBuild){s.start("Building package...");try{a.buildCommand.includes(" ")?o(a.buildCommand,{cwd:t,stdio:"inherit"}):await h(a.buildCommand,{cwd:t,silent:!1})}catch(i){throw s.error("Build failed"),i}}}async function T(t,a){if(a.autoGitPush)try{o("git push",{cwd:t}),a.createGitTag&&o("git push --tags",{cwd:t})}catch(r){s.warn("Failed to push changes:",r)}}async function v(t,a={}){const{config:r}=await b({cwd:t}),i=r.publish||{},f=await k(t),{name:d,version:n}=f;if(!d||!n)throw new Error("Missing name or version in package.json. Please ensure your package.json contains valid 'name' and 'version' fields.");if(!m.valid(n))throw new Error(`Invalid version format in package.json: ${n}. Please use semantic versioning format (e.g., 1.0.0, 2.1.0-alpha.1)`);const p=await y(t),l=p?.command||"npm";await C(t,i,a);const g=$(n,a,i),u=["publish","--tag",g,"--access",a.access||i.access||"public"];(a.registry||i.registry)&&u.push("--registry",a.registry||i.registry||""),a.dryRun&&u.push("--dry-run");const w=`${l} ${u.join(" ")}`;s.start("Publishing package...");try{if(o(w,{cwd:t,stdio:"inherit"}),!a.dryRun){const e=i.defaultTag||"edge";if(g!==e){s.start(`Also publishing to ${e} tag...`);try{let c;p?.name==="yarn"?c=`${l} tag add ${d}@${n} ${e}`:c=`${l} dist-tag add ${d}@${n} ${e}`,o(c,{cwd:t,stdio:"inherit"})}catch(c){s.warn(`Failed to add ${e} tag:`,c)}}await T(t,i)}return{packageName:d,version:n,publishTag:g,dryRun:a.dryRun||!1}}catch(e){throw s.error("Failed to publish package:",e),e}}export{v as p};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";const node_child_process=require("node:child_process"),consola=require("consola"),y=require("fast-glob"),w=require("micromatch"),nypm=require("nypm"),pathe=require("pathe"),pkgTypes=require("pkg-types"),utils=require("./basis.DfY4XEAb.cjs");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const y__default=_interopDefaultCompat(y),w__default=_interopDefaultCompat(w);function getStagedFiles(){try{const t=node_child_process.execSync("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
|
|
2
|
+
`).filter(Boolean),s=node_child_process.execSync("git diff --cached --name-only --diff-filter=D",{encoding:"utf8"}),o=new Set(s.trim().split(`
|
|
3
|
+
`).filter(Boolean));return t.filter(e=>!o.has(e))}catch{return[]}}async function getProjectFiles(t,s=["**/*"],o=["node_modules/**","dist/**","build/**",".git/**"]){try{return await y__default(s,{cwd:t,ignore:o,onlyFiles:!0,dot:!1,absolute:!1})}catch(e){return consola.consola.warn("Failed to scan project files:",e),[]}}async function lintStaged(t=process.cwd(),s){const{config:o}=await utils.loadConfig({cwd:t,overrides:s?{lint:{staged:s}}:void 0}),e=o.lint?.staged||{},n=getStagedFiles();if(n.length===0)return!0;if(Object.keys(e).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 i=new Set;for(const[c,d]of Object.entries(e)){const a=n.filter(l=>!i.has(l)&&w__default.isMatch(l.split("/").pop()||l,c));if(a.length!==0){consola.consola.start(`Linting ${a.length} files: ${c}`);try{const l=`${d} ${a.join(" ")}`;node_child_process.execSync(l,{stdio:"inherit",cwd:t});const u=[];for(const f of a)await utils.fileExists(pathe.resolve(t,f))&&u.push(f);u.length>0&&node_child_process.execSync(`git add ${u.join(" ")}`,{stdio:"inherit",cwd:t}),a.forEach(f=>i.add(f))}catch(l){r=!0,consola.consola.error(`Lint pattern '${c}' failed. Please fix the issues and try again:`,l)}}}return!r}async function lintProject(t=process.cwd(),s){const{config:o}=await utils.loadConfig({cwd:t,overrides:s?{lint:{project:s}}:void 0}),e=o.lint?.project||{};if(Object.keys(e).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 n=!1;for(const[r,i]of Object.entries(e)){consola.consola.start(`Running project lint: ${r}`);try{node_child_process.execSync(i,{stdio:"inherit",cwd:t})}catch(c){n=!0,consola.consola.error(`Project lint pattern '${r}' failed. Please fix the issues and try again:`,c)}}return!n}async function lintDependencies(t=process.cwd(),s){const{config:o}=await utils.loadConfig({cwd:t,overrides:s?{lint:{dependencies:s}}:void 0}),e=o.lint?.dependencies||{};let n=!1;try{const r=await pkgTypes.readPackageJSON(t),i={...r.dependencies,...r.devDependencies},c=(await nypm.detectPackageManager(t))?.name||"npm",d=utils.getPackageManagerCommands(c);if(consola.consola.start("Checking dependencies..."),e.blockedPackages&&e.blockedPackages.length>0){const a=Object.keys(i).filter(l=>e.blockedPackages?.includes(l));a.length>0&&(consola.consola.error(`Blocked packages found: ${a.join(", ")}. Please remove these packages from your dependencies.`),n=!0)}if(e.checkOutdated)if(d.outdated)try{node_child_process.execSync(d.outdated,{cwd:t,stdio:"pipe"})}catch(a){consola.consola.warn("Some dependencies are outdated:",a)}else consola.consola.warn(`Outdated check not available for ${c}`);if(e.checkSecurity)if(d.audit)try{node_child_process.execSync(d.audit,{cwd:t,stdio:"pipe"})}catch(a){consola.consola.error("Security vulnerabilities detected:",a),n=!0}else consola.consola.warn(`Security audit not available for ${c}`);if(e.allowedLicenses&&e.allowedLicenses.length>0){const{hasIssues:a,invalidLicenses:l}=await E(t,e.allowedLicenses);a&&(consola.consola.error("Packages with invalid licenses found:"),l.forEach(u=>consola.consola.error(` ${u}`)),n=!0)}}catch(r){consola.consola.error("Failed to check dependencies:",r),n=!0}return!n}async function j(t,s){if(s.length===0)return!0;const o=(await Promise.all(s.map(async e=>({file:e,exists:await utils.fileExists(pathe.resolve(t,e))})))).filter(e=>!e.exists);return o.length>0?(o.forEach(({file:e})=>{consola.consola.error(`Required file missing: ${e}`)}),!1):!0}async function $(t,s){if(s.length===0)return!0;const o=(await Promise.all(s.map(async e=>({dir:e,exists:await utils.fileExists(pathe.resolve(t,e))})))).filter(e=>!e.exists);return o.length>0?(o.forEach(({dir:e})=>{consola.consola.error(`Required directory missing: ${e}`)}),!1):!0}async function x(t,s,o){const e=new RegExp(o),n=(await getProjectFiles(t,[s])).filter(r=>{const i=r.split("/").pop()||"";return!e.test(i)});return n.length>0?(consola.consola.error(`Files with invalid naming in ${s}: ${n.slice(0,3).join(", ")}${n.length>3?"...":""}`),!1):!0}async function F(t,s,o){const e=new RegExp(o),n=new Set,r=(await getProjectFiles(t,[s.replace(/\/\*\*?$/,"")])).filter(async i=>{const c=pathe.resolve(t,i);try{return(await import("node:fs/promises").then(d=>d.stat(c))).isDirectory()}catch{return!1}});for(const i of await Promise.all(r))if(i){const c=i.split("/").pop()||"";e.test(c)||n.add(i)}return n.size>0?(consola.consola.error(`Directories with invalid naming in ${s}: ${Array.from(n).slice(0,3).join(", ")}`),!1):!0}async function v(t,s){let o=!1;for(const e of s){const{path:n,files:r,directories:i,description:c}=e;consola.consola.start(`Checking naming rule: ${c||n}`),r&&(await x(t,n,r)||(o=!0)),i&&(await F(t,n,i)||(o=!0))}return!o}async function lintStructure(t=process.cwd(),s){const{config:o}=await utils.loadConfig({cwd:t,overrides:s?{lint:{structure:s}}:void 0}),e=o.lint?.structure||{};let n=!1;return consola.consola.start("Checking project structure..."),e.requiredFiles&&(await j(t,e.requiredFiles)||(n=!0)),e.requiredDirs&&(await $(t,e.requiredDirs)||(n=!0)),e.naming&&e.naming.length>0&&(await v(t,e.naming)||(n=!0)),!n}async function lintDocs(t=process.cwd(),s){const{config:o}=await utils.loadConfig({cwd:t,overrides:s?{lint:{docs:s}}:void 0}),e=o.lint?.docs||{};let n=!1;consola.consola.start("Checking documentation...");const r=[];e.checkReadme!==!1&&r.push({type:"README",files:["README.md","README.rst","README.txt","readme.md"],required:!0}),e.checkChangelog&&r.push({type:"CHANGELOG",files:["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"],required:!0});for(const{type:i,files:c,required:d}of r){const a=(await Promise.all(c.map(l=>utils.fileExists(pathe.resolve(t,l))))).some(l=>l);d&&!a&&(consola.consola.error(`No ${i} file found`),n=!0)}return!n}async function lintAll(t=process.cwd()){const{config:s}=await utils.loadConfig({cwd:t}),o=s.lint||{};consola.consola.start("Running comprehensive project lint...");const e=(await Promise.allSettled([lintProject(t,o.project),lintDependencies(t,o.dependencies),lintStructure(t,o.structure),lintDocs(t,o.docs)])).filter(n=>n.status==="rejected"||n.status==="fulfilled"&&!n.value);return e.length===0?!0:(consola.consola.error(`${e.length} lint check(s) failed`),!1)}async function E(t,s){try{const o=await y__default(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:t,onlyFiles:!0,absolute:!0}),e=[],n=new Set;for(const r of o)try{const i=await pkgTypes.readPackageJSON(r);if(!i.name||n.has(i.name))continue;if(n.add(i.name),i.license){const c=Array.isArray(i.license)?i.license.join(", "):i.license;s.some(d=>c.includes(d))||e.push(`${i.name}: ${c}`)}}catch{}return{hasIssues:e.length>0,invalidLicenses:e}}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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{access as t}from"node:fs/promises";import{loadConfig as e}from"c12";import{defaultConfig as d}from"../config.mjs";async function
|
|
1
|
+
import{access as t}from"node:fs/promises";import{loadConfig as e}from"c12";import{defaultConfig as d}from"../config.mjs";async function n(a={}){return await e({name:"basis",cwd:process.cwd(),...a,defaults:{...d,...a.defaults}})}async function u(a){try{return await t(a),!0}catch{return!1}}function o(a){switch(a){case"yarn":return{outdated:"yarn outdated --json",audit:"yarn audit --level moderate"};case"pnpm":return{outdated:"pnpm outdated --format table",audit:"pnpm audit --audit-level moderate"};case"bun":return{outdated:"bun outdated",audit:null};case"deno":return{outdated:null,audit:null};default:return{outdated:"npm outdated --json",audit:"npm audit --audit-level moderate"}}}export{u as f,o as g,n as l};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{execSync as f}from"node:child_process";import{consola as a}from"consola";import k from"fast-glob";import S from"micromatch";import{detectPackageManager as x}from"nypm";import{resolve as h}from"pathe";import{readPackageJSON as j}from"pkg-types";import{l as g,f as m,g as A}from"./basis.DEw91E2d.mjs";function $(){try{const t=f("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
|
|
2
|
+
`).filter(Boolean),r=f("git diff --cached --name-only --diff-filter=D",{encoding:"utf8"}),i=new Set(r.trim().split(`
|
|
3
|
+
`).filter(Boolean));return t.filter(e=>!i.has(e))}catch{return[]}}async function y(t,r=["**/*"],i=["node_modules/**","dist/**","build/**",".git/**"]){try{return await k(r,{cwd:t,ignore:i,onlyFiles:!0,dot:!1,absolute:!1})}catch(e){return a.warn("Failed to scan project files:",e),[]}}async function R(t=process.cwd(),r){const{config:i}=await g({cwd:t,overrides:r?{lint:{staged:r}}:void 0}),e=i.lint?.staged||{},n=$();if(n.length===0)return!0;if(Object.keys(e).length===0)return a.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,u]of Object.entries(e)){const l=n.filter(d=>!s.has(d)&&S.isMatch(d.split("/").pop()||d,o));if(l.length!==0){a.start(`Linting ${l.length} files: ${o}`);try{const d=`${u} ${l.join(" ")}`;f(d,{stdio:"inherit",cwd:t});const p=[];for(const w of l)await m(h(t,w))&&p.push(w);p.length>0&&f(`git add ${p.join(" ")}`,{stdio:"inherit",cwd:t}),l.forEach(w=>s.add(w))}catch(d){c=!0,a.error(`Lint pattern '${o}' failed. Please fix the issues and try again:`,d)}}}return!c}async function v(t=process.cwd(),r){const{config:i}=await g({cwd:t,overrides:r?{lint:{project:r}}:void 0}),e=i.lint?.project||{};if(Object.keys(e).length===0)return a.warn("No project lint configuration found. Add lint.project section to your basis.config.ts"),!0;a.start("Running project-wide linting...");let n=!1;for(const[c,s]of Object.entries(e)){a.start(`Running project lint: ${c}`);try{f(s,{stdio:"inherit",cwd:t})}catch(o){n=!0,a.error(`Project lint pattern '${c}' failed. Please fix the issues and try again:`,o)}}return!n}async function E(t=process.cwd(),r){const{config:i}=await g({cwd:t,overrides:r?{lint:{dependencies:r}}:void 0}),e=i.lint?.dependencies||{};let n=!1;try{const c=await j(t),s={...c.dependencies,...c.devDependencies},o=(await x(t))?.name||"npm",u=A(o);if(a.start("Checking dependencies..."),e.blockedPackages&&e.blockedPackages.length>0){const l=Object.keys(s).filter(d=>e.blockedPackages?.includes(d));l.length>0&&(a.error(`Blocked packages found: ${l.join(", ")}. Please remove these packages from your dependencies.`),n=!0)}if(e.checkOutdated)if(u.outdated)try{f(u.outdated,{cwd:t,stdio:"pipe"})}catch(l){a.warn("Some dependencies are outdated:",l)}else a.warn(`Outdated check not available for ${o}`);if(e.checkSecurity)if(u.audit)try{f(u.audit,{cwd:t,stdio:"pipe"})}catch(l){a.error("Security vulnerabilities detected:",l),n=!0}else a.warn(`Security audit not available for ${o}`);if(e.allowedLicenses&&e.allowedLicenses.length>0){const{hasIssues:l,invalidLicenses:d}=await M(t,e.allowedLicenses);l&&(a.error("Packages with invalid licenses found:"),d.forEach(p=>a.error(` ${p}`)),n=!0)}}catch(c){a.error("Failed to check dependencies:",c),n=!0}return!n}async function D(t,r){if(r.length===0)return!0;const i=(await Promise.all(r.map(async e=>({file:e,exists:await m(h(t,e))})))).filter(e=>!e.exists);return i.length>0?(i.forEach(({file:e})=>{a.error(`Required file missing: ${e}`)}),!1):!0}async function O(t,r){if(r.length===0)return!0;const i=(await Promise.all(r.map(async e=>({dir:e,exists:await m(h(t,e))})))).filter(e=>!e.exists);return i.length>0?(i.forEach(({dir:e})=>{a.error(`Required directory missing: ${e}`)}),!1):!0}async function F(t,r,i){const e=new RegExp(i),n=(await y(t,[r])).filter(c=>{const s=c.split("/").pop()||"";return!e.test(s)});return n.length>0?(a.error(`Files with invalid naming in ${r}: ${n.slice(0,3).join(", ")}${n.length>3?"...":""}`),!1):!0}async function L(t,r,i){const e=new RegExp(i),n=new Set,c=(await y(t,[r.replace(/\/\*\*?$/,"")])).filter(async s=>{const o=h(t,s);try{return(await import("node:fs/promises").then(u=>u.stat(o))).isDirectory()}catch{return!1}});for(const s of await Promise.all(c))if(s){const o=s.split("/").pop()||"";e.test(o)||n.add(s)}return n.size>0?(a.error(`Directories with invalid naming in ${r}: ${Array.from(n).slice(0,3).join(", ")}`),!1):!0}async function C(t,r){let i=!1;for(const e of r){const{path:n,files:c,directories:s,description:o}=e;a.start(`Checking naming rule: ${o||n}`),c&&(await F(t,n,c)||(i=!0)),s&&(await L(t,n,s)||(i=!0))}return!i}async function P(t=process.cwd(),r){const{config:i}=await g({cwd:t,overrides:r?{lint:{structure:r}}:void 0}),e=i.lint?.structure||{};let n=!1;return a.start("Checking project structure..."),e.requiredFiles&&(await D(t,e.requiredFiles)||(n=!0)),e.requiredDirs&&(await O(t,e.requiredDirs)||(n=!0)),e.naming&&e.naming.length>0&&(await C(t,e.naming)||(n=!0)),!n}async function b(t=process.cwd(),r){const{config:i}=await g({cwd:t,overrides:r?{lint:{docs:r}}:void 0}),e=i.lint?.docs||{};let n=!1;a.start("Checking documentation...");const c=[];e.checkReadme!==!1&&c.push({type:"README",files:["README.md","README.rst","README.txt","readme.md"],required:!0}),e.checkChangelog&&c.push({type:"CHANGELOG",files:["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"],required:!0});for(const{type:s,files:o,required:u}of c){const l=(await Promise.all(o.map(d=>m(h(t,d))))).some(d=>d);u&&!l&&(a.error(`No ${s} file found`),n=!0)}return!n}async function q(t=process.cwd()){const{config:r}=await g({cwd:t}),i=r.lint||{};a.start("Running comprehensive project lint...");const e=(await Promise.allSettled([v(t,i.project),E(t,i.dependencies),P(t,i.structure),b(t,i.docs)])).filter(n=>n.status==="rejected"||n.status==="fulfilled"&&!n.value);return e.length===0?!0:(a.error(`${e.length} lint check(s) failed`),!1)}async function M(t,r){try{const i=await k(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:t,onlyFiles:!0,absolute:!0}),e=[],n=new Set;for(const c of i)try{const s=await j(c);if(!s.name||n.has(s.name))continue;if(n.add(s.name),s.license){const o=Array.isArray(s.license)?s.license.join(", "):s.license;r.some(u=>o.includes(u))||e.push(`${s.name}: ${o}`)}}catch{}return{hasIssues:e.length>0,invalidLicenses:e}}catch(i){return a.warn("Failed to check licenses:",i),{hasIssues:!1,invalidLicenses:[]}}}export{y as a,R as b,v as c,E as d,P as e,b as f,$ as g,q as l};
|
|
@@ -0,0 +1,8 @@
|
|
|
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.DfY4XEAb.cjs"),git=require("./basis.Bar6V_OJ.cjs"),G={ts:{ext:"ts",label:"TypeScript"},mjs:{ext:"mjs",label:"ES Module"},cjs:{ext:"cjs",label:"CommonJS"}};function B(t){const s=magicast.parseModule(t==="cjs"?`const { defineBasisConfig } = require("@funish/basis");
|
|
2
|
+
|
|
3
|
+
module.exports = defineBasisConfig({});`:`import { defineBasisConfig } from "@funish/basis";
|
|
4
|
+
|
|
5
|
+
export default defineBasisConfig({});`),n={lint:{staged:{},project:{}},git:{hooks:{},autoSetup:!0},packageManager:{autoDetect:!0}},o=s.exports.default.$args[0];return Object.assign(o,n),o.$ast.leadingComments=[{type:"Block",value:`
|
|
6
|
+
Configure your project here
|
|
7
|
+
See: https://github.com/funish/basis/tree/main/packages/basis#configuration
|
|
8
|
+
`}],magicast.generateCode(s).code}async function J(t){if(await utils.fileExists(pathe.resolve(t,"tsconfig.json")))return"ts";try{if((await pkgTypes.readPackageJSON(t)).type==="module")return"mjs"}catch{}return"ts"}async function init(t=process.cwd(),s={}){const{force:n=!1,skipGitCheck:o=!1,skipInstall:y=!1}=s;consola.consola.start("Initializing basis configuration...");const d=await J(t),g=await consola.consola.prompt("Choose config file format:",{type:"select",initial:d,options:Object.entries(G).map(([e,{label:i,ext:c}])=>({value:e,label:`${i} (${c}) ${d===e?"(recommended)":""}`}))}),m=G[g].ext,w=`basis.config.${m}`,b=pathe.resolve(t,w);if(await utils.fileExists(b)&&!n)return consola.consola.error(`${w} already exists. Use --force to overwrite.`),!1;let a=!1;if(!o)if(await utils.fileExists(pathe.resolve(t,".git")))a=await consola.consola.prompt("Setup Git hooks and configuration?",{type:"confirm",initial:!0});else if(consola.consola.info("No Git repository found."),await consola.consola.prompt("Initialize Git repository?",{type:"confirm",initial:!0}))try{await git.initGitRepo(t)?a=await consola.consola.prompt("Setup Git hooks and configuration?",{type:"confirm",initial:!0}):(consola.consola.warn("Git initialization failed, skipping Git setup"),a=!1)}catch(e){consola.consola.error("Failed to initialize Git repository:",e),consola.consola.warn("Skipping Git setup"),a=!1}else consola.consola.info("Skipping Git initialization"),a=!1;await update.updateConfig({cwd:t,configFile:"basis.config",createExtension:`.${m}`,onCreate:()=>B(g)});let r=!1;y||(r=await consola.consola.prompt("Install @funish/basis dependency now?",{type:"confirm",initial:!0}));const k=await pkgTypes.findWorkspaceDir(t)===t;if(r)try{await nypm.addDevDependency(["@funish/basis"],{workspace:k})}catch(e){consola.consola.error("Failed to install @funish/basis:",e),consola.consola.info("You can install it manually with: basis add -D @funish/basis")}if(a)try{const e=pathe.resolve(t,"package.json");if(await utils.fileExists(e)){const i=await pkgTypes.readPackageJSON(e),c=(await nypm.detectPackageManager(t))?.name||"npm",l="basis git setup";i.scripts=i.scripts||{};const p=c==="yarn"?"prepare":"postinstall",u=i.scripts[p];let f=!1;u?u.includes(l)||(i.scripts[p]=`${u} && ${l}`,f=!0):(i.scripts[p]=l,f=!0),f&&await pkgTypes.writePackageJSON(e,i)}else consola.consola.warn("No package.json found. You'll need to run git setup manually.")}catch(e){consola.consola.error("Failed to update package.json:",e),consola.consola.warn("You can manually add 'basis git setup' to your postinstall script")}return a&&!r&&(await git.setupGit(t)||consola.consola.warn("Git setup failed, but basis config was created successfully")),consola.consola.success("Basis initialization completed!"),!0}exports.init=init;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const promises=require("node:fs/promises"),c12=require("c12"),config=require("../config.cjs");async function loadConfig(e={}){return await c12.loadConfig({name:"basis",cwd:process.cwd(),...e,defaults:{...config.defaultConfig,...e.defaults}})}async function fileExists(e){try{return await promises.access(e),!0}catch{return!1}}function getPackageManagerCommands(e){switch(e){case"yarn":return{outdated:"yarn outdated --json",audit:"yarn audit --level moderate"};case"pnpm":return{outdated:"pnpm outdated --format table",audit:"pnpm audit --audit-level moderate"};case"bun":return{outdated:"bun outdated",audit:"
|
|
1
|
+
"use strict";const promises=require("node:fs/promises"),c12=require("c12"),config=require("../config.cjs");async function loadConfig(e={}){return await c12.loadConfig({name:"basis",cwd:process.cwd(),...e,defaults:{...config.defaultConfig,...e.defaults}})}async function fileExists(e){try{return await promises.access(e),!0}catch{return!1}}function getPackageManagerCommands(e){switch(e){case"yarn":return{outdated:"yarn outdated --json",audit:"yarn audit --level moderate"};case"pnpm":return{outdated:"pnpm outdated --format table",audit:"pnpm audit --audit-level moderate"};case"bun":return{outdated:"bun outdated",audit:null};case"deno":return{outdated:null,audit:null};default:return{outdated:"npm outdated --json",audit:"npm audit --audit-level moderate"}}}exports.fileExists=fileExists,exports.getPackageManagerCommands=getPackageManagerCommands,exports.loadConfig=loadConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const node_child_process=require("node:child_process"),consola=require("consola"),nypm=require("nypm"),pkgTypes=require("pkg-types"),n=require("semver"),utils=require("./basis.DfY4XEAb.cjs");function _interopDefaultCompat(a){return a&&typeof a=="object"&&"default"in a?a.default:a}const n__default=_interopDefaultCompat(n);function C(a,e,s){if(e.tag)return e.tag;if(e.stable||e.latest)return s.stableTag||"latest";if(n__default.prerelease(a)){const t=n__default.prerelease(a);return t&&t[0]||s.defaultTag||"edge"}return s.stableTag||"latest"}async function T(a,e,s){if(e.checkGitClean&&!s.skipTests)try{if(node_child_process.execSync("git status --porcelain",{cwd:a,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(t){consola.consola.warn("Could not check git status:",t)}if(e.checkTests&&!s.skipTests){consola.consola.start("Running tests...");try{e.testCommand?node_child_process.execSync(e.testCommand,{cwd:a,stdio:"inherit"}):await nypm.runScript("test",{cwd:a,silent:!1})}catch(t){throw consola.consola.error("Tests failed"),t}}if(e.buildCommand&&!s.skipBuild){consola.consola.start("Building package...");try{e.buildCommand.includes(" ")?node_child_process.execSync(e.buildCommand,{cwd:a,stdio:"inherit"}):await nypm.runScript(e.buildCommand,{cwd:a,silent:!1})}catch(t){throw consola.consola.error("Build failed"),t}}}async function $(a,e){if(e.autoGitPush)try{node_child_process.execSync("git push",{cwd:a}),e.createGitTag&&node_child_process.execSync("git push --tags",{cwd:a})}catch(s){consola.consola.warn("Failed to push changes:",s)}}async function publishPackage(a,e={}){const{config:s}=await utils.loadConfig({cwd:a}),t=s.publish||{},p=await pkgTypes.readPackageJSON(a),{name:o,version:r}=p;if(!o||!r)throw new Error("Missing name or version in package.json. Please ensure your package.json contains valid 'name' and 'version' fields.");if(!n__default.valid(r))throw new Error(`Invalid version format in package.json: ${r}. Please use semantic versioning format (e.g., 1.0.0, 2.1.0-alpha.1)`);const g=await nypm.detectPackageManager(a),d=g?.command||"npm";await T(a,t,e);const l=C(r,e,t),u=["publish","--tag",l,"--access",e.access||t.access||"public"];(e.registry||t.registry)&&u.push("--registry",e.registry||t.registry||""),e.dryRun&&u.push("--dry-run");const h=`${d} ${u.join(" ")}`;consola.consola.start("Publishing package...");try{if(node_child_process.execSync(h,{cwd:a,stdio:"inherit"}),!e.dryRun){const i=t.defaultTag||"edge";if(l!==i){consola.consola.start(`Also publishing to ${i} tag...`);try{let c;g?.name==="yarn"?c=`${d} tag add ${o}@${r} ${i}`:c=`${d} dist-tag add ${o}@${r} ${i}`,node_child_process.execSync(c,{cwd:a,stdio:"inherit"})}catch(c){consola.consola.warn(`Failed to add ${i} tag:`,c)}}await $(a,t)}return{packageName:o,version:r,publishTag:l,dryRun:e.dryRun||!1}}catch(i){throw consola.consola.error("Failed to publish package:",i),i}}exports.publishPackage=publishPackage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{execSync as p}from"node:child_process";import{readFile as m,unlink as I,writeFile as y,copyFile as M}from"node:fs/promises";import{updateConfig as O}from"c12/update";import{consola as a}from"consola";import{defu as S}from"defu";import v from"ini";import{resolve as u}from"pathe";import{l as g,f as d}from"./basis.DEw91E2d.mjs";async function k(e,i=!1,r=!1){try{return await O({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 x=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function G(e){const i=e.trim().split(`
|
|
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(),f=i.slice(-1)[0]?.trim();return{type:t,scope:o,description:s,body:c,footer:f,isBreaking:!!n||e.includes("BREAKING CHANGE:")}}function b(e,i={}){const r=[],{types:t=x,maxLength:o=72,minLength:n=10,scopeRequired:s=!1,allowedScopes:c=[]}=i,f=G(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>o&&r.push(`Header too long (${l.length}). Max: ${o}`),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 E(e=process.cwd(),i){const{config:r}=await g({cwd:e,overrides:i?{git:{commitMsg:i}}:void 0}),t=r.git?.commitMsg||{};let o;try{const s=u(".git/COMMIT_EDITMSG");await d(s)?o=(await m(s)).toString("utf8"):o=p("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(s){return a.error("Failed to read commit message:",s),!1}const n=b(o,t);return n.valid?!0:(a.error("Invalid commit message:"),n.errors.forEach(s=>a.error(` ${s}`)),!1)}async function $(e){const i=u(e,".git/config");if(!await d(i))return null;const r=new Date().toISOString().replace(/[:.]/g,"-"),t=u(e,`.git/config.backup.${r}`);try{return await M(i,t),t}catch(o){return a.warn("Failed to create Git config backup:",o),null}}async function w(e=process.cwd()){const i=u(e,".git/config");if(!await d(i))return{};try{const r=await m(i,"utf8");return v.parse(r)}catch(r){return a.warn("Failed to read .git/config:",r),{}}}async function h(e,i=process.cwd()){const r=u(i,".git/config");try{let t=v.stringify(e,{whitespace:!0});t=t.split(`
|
|
4
|
+
`).map(o=>o&&!o.startsWith("[")&&o.includes("=")?` ${o}`:o).join(`
|
|
5
|
+
`),await y(r,t,"utf8")}catch(t){throw a.error("Failed to write .git/config:",t),t}}function H(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 j(e=process.cwd(),i){const{config:r}=await g({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 w(e);if(H(o,t))return!0;await $(e);const n=S(o,t);return await h(n,e),!0}catch(o){return a.error("Failed to setup Git configuration:",o),!1}}async function A(e=process.cwd(),i=!0,r={}){try{await $(e);const t=await w(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 h(o,e),r.updateConfig?await k(e,!1,!0):!0}catch(t){return a.error("Failed to reset Git configuration:",t),!1}}async function C(e=process.cwd(),i){const{config:r}=await g({cwd:e,overrides:i?{git:{hooks:i}}:void 0}),t=r.git?.hooks||{},o=u(e,".git/hooks");if(!await d(o))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(o,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 F=c.commands;l+=`${F.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()){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(i){return a.error("Failed to initialize Git repository:",i),!1}}async function R(e=process.cwd()){const{config:i}=await g({cwd:e}),r=i.git||{},t=(await Promise.allSettled([j(e,r.config),C(e,r.hooks)])).filter(o=>o.status==="rejected"||o.status==="fulfilled"&&!o.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(),i,r={}){const t=u(e,".git/hooks");if(!await d(t))return a.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 g({cwd:e});n=Object.keys(s.git?.hooks||{})}for(const s of n){const c=u(t,s);if(await d(c))try{await I(c)}catch(f){a.error(`Failed to remove ${s} hook:`,f),o=!1}}if(!i&&r.updateConfig){const s=await k(e,!0,!1);o=o&&s}return o}export{j as a,A as b,C as c,q as d,B as i,E as l,G as p,w as r,R as s,b as v,h as w};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funish/basis",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{execSync as g}from"node:child_process";import{consola as s}from"consola";import{readPackageJSON as v,resolvePackageJSON as f,writePackageJSON as h}from"pkg-types";import m from"semver";import{l as $}from"./basis.CkZpidFZ.mjs";async function P(r,o={}){const{config:u}=await $({cwd:r}),i=u.version||{},d=await v(r),t=d.version;if(!t)throw new Error("No version found in package.json");const n=o.version?m.valid(o.version)?o.version:(()=>{throw new Error(`Invalid version format: ${o.version}`)})():(()=>{if(!m.valid(t))throw new Error(`Invalid current version format: ${t}`);const e=m.prerelease(t),c=o.preid||(e&&typeof e[0]=="string"?e[0]:null)||i.prereleaseId||"edge";let a;o.major?a="major":o.minor?a="minor":o.prerelease?a=e?"prerelease":"prepatch":a=e?"prerelease":"patch";const l=a==="prerelease"||a.startsWith("pre")?m.inc(t,a,c):m.inc(t,a);if(!l)throw new Error("Failed to calculate new version");return l})();s.info(`Updating version: ${t} \u2192 ${n}`);const w=await f(r);await h(w,{...d,version:n});const p={oldVersion:t,newVersion:n};if(i.autoCommit){const e=o.message||i.commitMessage?.replace("{version}",n)||`chore: release v${n}`;try{g("git add package.json",{cwd:r}),g(`git commit -m "${e}"`,{cwd:r}),s.success(`Committed version update: ${e}`)}catch(c){s.warn("Failed to commit changes:",c)}}if(i.autoTag){const e=`${i.tagPrefix||"v"}${n}`;try{g(`git tag ${e}`,{cwd:r}),s.success(`Created git tag: ${e}`),p.tagName=e}catch(c){s.warn("Failed to create git tag:",c)}}if(i.autoPush)try{g("git push",{cwd:r}),i.autoTag&&g("git push --tags",{cwd:r}),s.success("Pushed changes to remote")}catch(e){s.warn("Failed to push changes:",e)}return p}export{P as u};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{updateConfig as k}from"c12/update";import{consola as s}from"consola";import{parseModule as C,builders as b,generateCode as j}from"magicast";import{detectPackageManager as x,addDevDependency as v,installDependencies as D}from"nypm";import{resolve as c}from"pathe";import{readPackageJSON as w,writePackageJSON as B}from"pkg-types";import{f as l}from"./basis.CkZpidFZ.mjs";import{b as S}from"./basis.DzMHJtq5.mjs";const n={ts:{ext:"ts",label:"TypeScript"},mjs:{ext:"mjs",label:"ES Module"},cjs:{ext:"cjs",label:"CommonJS"}};function G(i){const t=C("");if(i==="cjs"){t.imports.$prepend({from:"@funish/basis",imported:"defineBasisConfig",local:"defineBasisConfig"}),t.exports.default=b.functionCall("defineBasisConfig",{});const o=t.exports.default.$args[0];o.$ast.leadingComments=[{type:"Block",value:`
|
|
2
|
-
Configure your project here
|
|
3
|
-
See: https://github.com/funish/basis/tree/main/packages/basis#configuration
|
|
4
|
-
`}]}else{t.imports.$prepend({from:"@funish/basis",imported:"defineBasisConfig",local:"defineBasisConfig"}),t.exports.default=b.functionCall("defineBasisConfig",{});const o=t.exports.default.$args[0];o.$ast.leadingComments=[{type:"Block",value:`
|
|
5
|
-
Configure your project here
|
|
6
|
-
See: https://github.com/funish/basis/tree/main/packages/basis#configuration
|
|
7
|
-
`}]}return j(t).code}async function z(i){if(await l(c(i,"tsconfig.json")))return"ts";try{if((await w(i)).type==="module")return"mjs"}catch{}return"ts"}async function E(i=process.cwd(),t={}){const{force:o=!1,skipGitCheck:$=!1,skipInstall:f=!1}=t;s.start("Initializing basis configuration...");const p=await z(i),m=await s.prompt("Choose config file format:",{type:"select",initial:p,options:[{value:"ts",label:`${n.ts.label} (${n.ts.ext}) ${p==="ts"?"(recommended)":""}`},{value:"mjs",label:`${n.mjs.label} (${n.mjs.ext}) ${p==="mjs"?"(recommended)":""}`},{value:"cjs",label:`${n.cjs.label} (${n.cjs.ext}) ${p==="cjs"?"(recommended)":""}`}]}),g=n[m].ext,r=`basis.config.${g}`,y=c(i,r);if(await l(y)&&!o)return s.error(`${r} already exists. Use --force to overwrite.`),!1;let d=!1;if(!$){if(await l(c(i,".git")))d=await s.prompt("Setup Git hooks and configuration?",{type:"confirm",initial:!0});else if(s.warn("No .git directory found. Git hooks will not work properly."),!await s.prompt("Continue anyway?",{type:"confirm",initial:!1}))return s.info("Initialization cancelled."),!1}const u=(await x(i))?.name||"npm";s.info(`Detected package manager: ${u}`),await k({cwd:i,configFile:"basis.config",createExtension:g,onCreate:()=>(s.info(`Creating ${r}...`),G(m))}),s.success(`Created ${r}`);try{const e=await w(i),h=!!(e.workspaces||await l(c(i,"pnpm-workspace.yaml")));f?!e.devDependencies?.["@funish/basis"]&&!e.dependencies?.["@funish/basis"]&&(e.devDependencies=e.devDependencies||{},e.devDependencies["@funish/basis"]="latest",s.info("Added @funish/basis to devDependencies")):(await v("@funish/basis",{cwd:i,silent:!1,workspace:h}),s.success("Added @funish/basis to devDependencies"));const a="basis git --setup";e.scripts=e.scripts||{},u==="pnpm"?e.scripts.postinstall?e.scripts.postinstall.includes(a)||(e.scripts.postinstall=`${e.scripts.postinstall} && ${a}`):e.scripts.postinstall=a:u==="yarn"?e.scripts.prepare?e.scripts.prepare.includes(a)||(e.scripts.prepare=`${e.scripts.prepare} && ${a}`):e.scripts.prepare=a:e.scripts.postinstall?e.scripts.postinstall.includes(a)||(e.scripts.postinstall=`${e.scripts.postinstall} && ${a}`):e.scripts.postinstall=a,await B(c(i,"package.json"),e),s.success(`Updated package.json scripts${f?" and dependencies":""}`),f?(s.info("Skipped dependency installation"),s.info("Run your package manager's install command to complete setup")):(s.start("Installing dependencies..."),await D({cwd:i,silent:!1}),s.success("Dependencies installed successfully"))}catch(e){return s.error("Failed to setup dependencies:",e),!1}return d&&(s.start("Setting up Git hooks and configuration..."),await S(i)?s.success("Git setup completed!"):s.warn("Git setup failed, but basis config was created successfully")),s.success("Basis initialization completed!"),s.info("You can now:"),s.info(` - Edit ${r} to customize your configuration`),d||s.info(" - Run `basis git --setup` to install git hooks"),!0}export{E as i};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const node_child_process=require("node:child_process"),consola=require("consola"),nypm=require("nypm"),pkgTypes=require("pkg-types"),g=require("semver"),utils=require("./basis.BJhSbOyA.cjs");function _interopDefaultCompat(a){return a&&typeof a=="object"&&"default"in a?a.default:a}const g__default=_interopDefaultCompat(g);async function k(a,e,o){if(e.checkGitClean&&!o.skipTests)try{if(node_child_process.execSync("git status --porcelain",{cwd:a,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(s){consola.consola.warn("Could not check git status:",s)}if(e.checkTests&&!o.skipTests){consola.consola.start("Running tests...");try{e.testCommand?node_child_process.execSync(e.testCommand,{cwd:a,stdio:"inherit"}):await nypm.runScript("test",{cwd:a,silent:!1}),consola.consola.success("Tests passed")}catch(s){throw consola.consola.error("Tests failed"),s}}if(e.buildCommand&&!o.skipBuild){consola.consola.start("Building package...");try{e.buildCommand.includes(" ")?node_child_process.execSync(e.buildCommand,{cwd:a,stdio:"inherit"}):await nypm.runScript(e.buildCommand,{cwd:a,silent:!1}),consola.consola.success("Build completed")}catch(s){throw consola.consola.error("Build failed"),s}}}async function C(a,e){if(e.autoGitPush)try{node_child_process.execSync("git push",{cwd:a}),e.createGitTag&&node_child_process.execSync("git push --tags",{cwd:a}),consola.consola.success("Pushed changes to remote")}catch(o){consola.consola.warn("Failed to push changes:",o)}}async function publishPackage(a,e={}){const{config:o}=await utils.loadConfig({cwd:a}),s=o.publish||{},p=await pkgTypes.readPackageJSON(a),{name:i,version:c}=p;if(!i||!c)throw new Error("Missing name or version in package.json");if(!g__default.valid(c))throw new Error(`Invalid version format in package.json: ${c}`);const u=await nypm.detectPackageManager(a),l=u?.command||"npm";await k(a,s,e);let n;if(e.tag)n=e.tag;else if(e.stable||e.latest)n=s.stableTag||"latest";else if(g__default.prerelease(c)){const t=g__default.prerelease(c);n=t&&t[0]||s.defaultTag||"edge"}else n=s.stableTag||"latest";consola.consola.info(`Publishing ${i}@${c} to tag: ${n}`);const d=["publish","--tag",n,"--access",e.access||s.access||"public"];(e.registry||s.registry)&&d.push("--registry",e.registry||s.registry||""),e.dryRun&&d.push("--dry-run");const h=`${l} ${d.join(" ")}`;consola.consola.start("Publishing package...");try{if(node_child_process.execSync(h,{cwd:a,stdio:"inherit"}),e.dryRun)consola.consola.success("Dry run completed successfully");else{consola.consola.success(`Published ${i}@${c} to ${n}`);const t=s.defaultTag||"edge";if(n!==t){consola.consola.start(`Also publishing to ${t} tag...`);try{let r;u?.name==="yarn"?r=`${l} tag add ${i}@${c} ${t}`:r=`${l} dist-tag add ${i}@${c} ${t}`,node_child_process.execSync(r,{cwd:a,stdio:"inherit"}),consola.consola.success(`Also published ${i}@${c} to ${t}`)}catch(r){consola.consola.warn(`Failed to add ${t} tag:`,r)}}await C(a,s)}return{packageName:i,version:c,publishTag:n,dryRun:e.dryRun||!1}}catch(t){throw consola.consola.error("Failed to publish package:",t),t}}exports.publishPackage=publishPackage;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";const node_child_process=require("node:child_process"),consola=require("consola"),P=require("fast-glob"),$=require("micromatch"),nypm=require("nypm"),pathe=require("pathe"),pkgTypes=require("pkg-types"),utils=require("./basis.BJhSbOyA.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const P__default=_interopDefaultCompat(P),$__default=_interopDefaultCompat($);function getStagedFiles(){try{const e=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"}),s=new Set(i.trim().split(`
|
|
3
|
-
`).filter(Boolean));return e.filter(n=>!s.has(n))}catch{return[]}}async function getProjectFiles(e,i=["**/*"],s=["node_modules/**","dist/**","build/**",".git/**"]){try{return await P__default(i,{cwd:e,ignore:s,onlyFiles:!0,dot:!1,absolute:!1})}catch(n){return consola.consola.warn("Failed to scan project files:",n),[]}}async function lintStaged(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{lint:{staged:i}}:void 0}),n=s.lint?.staged||{},c=getStagedFiles();if(c.length===0)return consola.consola.info("No staged files to lint"),!0;if(Object.keys(n).length===0)return consola.consola.warn("No staged lint configuration found"),!0;let o=!1;const t=new Set;for(const[d,u]of Object.entries(n)){const r=c.filter(l=>!t.has(l)&&$__default.isMatch(l.split("/").pop()||l,d));if(r.length!==0){consola.consola.start(`Linting ${r.length} files: ${d}`);try{const l=`${u} ${r.join(" ")}`;node_child_process.execSync(l,{stdio:"inherit",cwd:e});const f=[];for(const a of r)await utils.fileExists(pathe.resolve(e,a))&&f.push(a);f.length>0&&node_child_process.execSync(`git add ${f.join(" ")}`,{stdio:"inherit",cwd:e}),r.forEach(a=>t.add(a)),consola.consola.success(`${d}`)}catch(l){o=!0,consola.consola.error(`${d} failed:`,l)}}}return!o}async function lintProject(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{lint:{project:i}}:void 0}),n=s.lint?.project||{};if(Object.keys(n).length===0)return consola.consola.warn("No project lint configuration found"),!0;consola.consola.start("Running project-wide linting...");let c=!1;for(const[o,t]of Object.entries(n)){consola.consola.start(`Running project lint: ${o}`);try{node_child_process.execSync(t,{stdio:"inherit",cwd:e}),consola.consola.success(`${o}`)}catch(d){c=!0,consola.consola.error(`${o} failed:`,d)}}return!c}async function lintDependencies(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{lint:{dependencies:i}}:void 0}),n=s.lint?.dependencies||{};let c=!1;try{const o=await pkgTypes.readPackageJSON(e),t={...o.dependencies,...o.devDependencies},d=(await nypm.detectPackageManager(e))?.name||"npm",u=utils.getPackageManagerCommands(d);if(consola.consola.start("Checking dependencies..."),n.blockedPackages&&n.blockedPackages.length>0){const r=Object.keys(t).filter(l=>n.blockedPackages?.includes(l));r.length>0?(consola.consola.error(`Blocked packages found: ${r.join(", ")}`),c=!0):consola.consola.success("No blocked packages found")}if(n.checkOutdated)try{node_child_process.execSync(u.outdated,{cwd:e,stdio:"pipe"}),consola.consola.success("All dependencies are up to date")}catch(r){consola.consola.warn("\u26A0 Some dependencies are outdated:",r)}if(n.checkSecurity)try{node_child_process.execSync(u.audit,{cwd:e,stdio:"pipe"}),consola.consola.success("No security vulnerabilities found")}catch(r){consola.consola.error("Security vulnerabilities detected:",r),c=!0}n.allowedLicenses&&n.allowedLicenses.length>0&&consola.consola.info("\u{1F4DD} License checking requires manual review or additional tooling")}catch(o){consola.consola.error("Failed to check dependencies:",o),c=!0}return!c}async function lintStructure(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{lint:{structure:i}}:void 0}),n=s.lint?.structure||{};let c=!1;if(consola.consola.start("Checking project structure..."),n.requiredFiles)for(const o of n.requiredFiles){const t=pathe.resolve(e,o);await utils.fileExists(t)?consola.consola.success(`Required file found: ${o}`):(consola.consola.error(`Required file missing: ${o}`),c=!0)}if(n.requiredDirs)for(const o of n.requiredDirs){const t=pathe.resolve(e,o);await utils.fileExists(t)?consola.consola.success(`Required directory found: ${o}`):(consola.consola.error(`Required directory missing: ${o}`),c=!0)}if(n.naming&&n.naming.length>0)for(const o of n.naming){const{path:t,files:d,directories:u,description:r}=o;consola.consola.start(`Checking naming rule: ${r||t}`);const l=await getProjectFiles(e,[t]);if(d){const f=new RegExp(d),a=l.filter(p=>{const g=p.split("/").pop()||"";return!f.test(g)});a.length>0?(consola.consola.error(`Files with invalid naming in ${t}: ${a.slice(0,3).join(", ")}${a.length>3?"...":""}`),c=!0):l.length>0&&consola.consola.success(`All files in ${t} follow naming convention`)}if(u){const f=new RegExp(u),a=new Set;l.forEach(g=>{const h=g.split("/");h.pop(),h.forEach(w=>a.add(w))});const p=Array.from(a).filter(g=>!f.test(g));p.length>0?(consola.consola.error(`Directories with invalid naming in ${t}: ${p.slice(0,3).join(", ")}`),c=!0):a.size>0&&consola.consola.success(`All directories in ${t} follow naming convention`)}}return!c}async function lintDocs(e=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:e,overrides:i?{lint:{docs:i}}:void 0}),n=s.lint?.docs||{};let c=!1;if(consola.consola.start("Checking documentation..."),n.checkReadme!==!1){const o=["README.md","README.rst","README.txt","readme.md"];(await Promise.all(o.map(t=>utils.fileExists(pathe.resolve(e,t))))).some(t=>t)?consola.consola.success("README file found"):(consola.consola.error("No README file found"),c=!0)}if(n.checkChangelog){const o=["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"];(await Promise.all(o.map(t=>utils.fileExists(pathe.resolve(e,t))))).some(t=>t)?consola.consola.success("CHANGELOG file found"):(consola.consola.error("No CHANGELOG file found"),c=!0)}return!c}async function lintAll(e=process.cwd()){const{config:i}=await utils.loadConfig({cwd:e}),s=i.lint||{};consola.consola.start("Running comprehensive project lint...");const n=(await Promise.allSettled([lintProject(e,s.project),lintDependencies(e,s.dependencies),lintStructure(e,s.structure),lintDocs(e,s.docs)])).filter(c=>c.status==="rejected"||c.status==="fulfilled"&&!c.value);return n.length===0?(consola.consola.success("All lint checks passed!"),!0):(consola.consola.error(`${n.length} lint check(s) failed`),!1)}exports.getProjectFiles=getProjectFiles,exports.getStagedFiles=getStagedFiles,exports.lintAll=lintAll,exports.lintDependencies=lintDependencies,exports.lintDocs=lintDocs,exports.lintProject=lintProject,exports.lintStaged=lintStaged,exports.lintStructure=lintStructure;
|
|
@@ -1,7 +0,0 @@
|
|
|
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.BJhSbOyA.cjs"),git=require("./basis.sOTOmfHG.cjs"),o={ts:{ext:"ts",label:"TypeScript"},mjs:{ext:"mjs",label:"ES Module"},cjs:{ext:"cjs",label:"CommonJS"}};function D(e){const i=magicast.parseModule("");if(e==="cjs"){i.imports.$prepend({from:"@funish/basis",imported:"defineBasisConfig",local:"defineBasisConfig"}),i.exports.default=magicast.builders.functionCall("defineBasisConfig",{});const t=i.exports.default.$args[0];t.$ast.leadingComments=[{type:"Block",value:`
|
|
2
|
-
Configure your project here
|
|
3
|
-
See: https://github.com/funish/basis/tree/main/packages/basis#configuration
|
|
4
|
-
`}]}else{i.imports.$prepend({from:"@funish/basis",imported:"defineBasisConfig",local:"defineBasisConfig"}),i.exports.default=magicast.builders.functionCall("defineBasisConfig",{});const t=i.exports.default.$args[0];t.$ast.leadingComments=[{type:"Block",value:`
|
|
5
|
-
Configure your project here
|
|
6
|
-
See: https://github.com/funish/basis/tree/main/packages/basis#configuration
|
|
7
|
-
`}]}return magicast.generateCode(i).code}async function B(e){if(await utils.fileExists(pathe.resolve(e,"tsconfig.json")))return"ts";try{if((await pkgTypes.readPackageJSON(e)).type==="module")return"mjs"}catch{}return"ts"}async function init(e=process.cwd(),i={}){const{force:t=!1,skipGitCheck:f=!1,skipInstall:l=!1}=i;consola.consola.start("Initializing basis configuration...");const c=await B(e),d=await consola.consola.prompt("Choose config file format:",{type:"select",initial:c,options:[{value:"ts",label:`${o.ts.label} (${o.ts.ext}) ${c==="ts"?"(recommended)":""}`},{value:"mjs",label:`${o.mjs.label} (${o.mjs.ext}) ${c==="mjs"?"(recommended)":""}`},{value:"cjs",label:`${o.cjs.label} (${o.cjs.ext}) ${c==="cjs"?"(recommended)":""}`}]}),u=o[d].ext,n=`basis.config.${u}`,g=pathe.resolve(e,n);if(await utils.fileExists(g)&&!t)return consola.consola.error(`${n} already exists. Use --force to overwrite.`),!1;let r=!1;if(!f){if(await utils.fileExists(pathe.resolve(e,".git")))r=await consola.consola.prompt("Setup Git hooks and configuration?",{type:"confirm",initial:!0});else if(consola.consola.warn("No .git directory found. Git hooks will not work properly."),!await consola.consola.prompt("Continue anyway?",{type:"confirm",initial:!1}))return consola.consola.info("Initialization cancelled."),!1}const p=(await nypm.detectPackageManager(e))?.name||"npm";consola.consola.info(`Detected package manager: ${p}`),await update.updateConfig({cwd:e,configFile:"basis.config",createExtension:u,onCreate:()=>(consola.consola.info(`Creating ${n}...`),D(d))}),consola.consola.success(`Created ${n}`);try{const s=await pkgTypes.readPackageJSON(e),m=!!(s.workspaces||await utils.fileExists(pathe.resolve(e,"pnpm-workspace.yaml")));l?!s.devDependencies?.["@funish/basis"]&&!s.dependencies?.["@funish/basis"]&&(s.devDependencies=s.devDependencies||{},s.devDependencies["@funish/basis"]="latest",consola.consola.info("Added @funish/basis to devDependencies")):(await nypm.addDevDependency("@funish/basis",{cwd:e,silent:!1,workspace:m}),consola.consola.success("Added @funish/basis to devDependencies"));const a="basis git --setup";s.scripts=s.scripts||{},p==="pnpm"?s.scripts.postinstall?s.scripts.postinstall.includes(a)||(s.scripts.postinstall=`${s.scripts.postinstall} && ${a}`):s.scripts.postinstall=a:p==="yarn"?s.scripts.prepare?s.scripts.prepare.includes(a)||(s.scripts.prepare=`${s.scripts.prepare} && ${a}`):s.scripts.prepare=a:s.scripts.postinstall?s.scripts.postinstall.includes(a)||(s.scripts.postinstall=`${s.scripts.postinstall} && ${a}`):s.scripts.postinstall=a,await pkgTypes.writePackageJSON(pathe.resolve(e,"package.json"),s),consola.consola.success(`Updated package.json scripts${l?" and dependencies":""}`),l?(consola.consola.info("Skipped dependency installation"),consola.consola.info("Run your package manager's install command to complete setup")):(consola.consola.start("Installing dependencies..."),await nypm.installDependencies({cwd:e,silent:!1}),consola.consola.success("Dependencies installed successfully"))}catch(s){return consola.consola.error("Failed to setup dependencies:",s),!1}return r&&(consola.consola.start("Setting up Git hooks and configuration..."),await git.setupGit(e)?consola.consola.success("Git setup completed!"):consola.consola.warn("Git setup failed, but basis config was created successfully")),consola.consola.success("Basis initialization completed!"),consola.consola.info("You can now:"),consola.consola.info(` - Edit ${n} to customize your configuration`),r||consola.consola.info(" - Run `basis git --setup` to install git hooks"),!0}exports.init=init;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const node_child_process=require("node:child_process"),consola=require("consola"),pkgTypes=require("pkg-types"),g=require("semver"),utils=require("./basis.BJhSbOyA.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const g__default=_interopDefaultCompat(g);async function updatePackageVersion(e,t={}){const{config:u}=await utils.loadConfig({cwd:e}),r=u.version||{},i=await pkgTypes.readPackageJSON(e),s=i.version;if(!s)throw new Error("No version found in package.json");const c=t.version?g__default.valid(t.version)?t.version:(()=>{throw new Error(`Invalid version format: ${t.version}`)})():(()=>{if(!g__default.valid(s))throw new Error(`Invalid current version format: ${s}`);const o=g__default.prerelease(s),n=t.preid||(o&&typeof o[0]=="string"?o[0]:null)||r.prereleaseId||"edge";let a;t.major?a="major":t.minor?a="minor":t.prerelease?a=o?"prerelease":"prepatch":a=o?"prerelease":"patch";const d=a==="prerelease"||a.startsWith("pre")?g__default.inc(s,a,n):g__default.inc(s,a);if(!d)throw new Error("Failed to calculate new version");return d})();consola.consola.info(`Updating version: ${s} \u2192 ${c}`);const p=await pkgTypes.resolvePackageJSON(e);await pkgTypes.writePackageJSON(p,{...i,version:c});const l={oldVersion:s,newVersion:c};if(r.autoCommit){const o=t.message||r.commitMessage?.replace("{version}",c)||`chore: release v${c}`;try{node_child_process.execSync("git add package.json",{cwd:e}),node_child_process.execSync(`git commit -m "${o}"`,{cwd:e}),consola.consola.success(`Committed version update: ${o}`)}catch(n){consola.consola.warn("Failed to commit changes:",n)}}if(r.autoTag){const o=`${r.tagPrefix||"v"}${c}`;try{node_child_process.execSync(`git tag ${o}`,{cwd:e}),consola.consola.success(`Created git tag: ${o}`),l.tagName=o}catch(n){consola.consola.warn("Failed to create git tag:",n)}}if(r.autoPush)try{node_child_process.execSync("git push",{cwd:e}),r.autoTag&&node_child_process.execSync("git push --tags",{cwd:e}),consola.consola.success("Pushed changes to remote")}catch(o){consola.consola.warn("Failed to push changes:",o)}return l}exports.updatePackageVersion=updatePackageVersion;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{execSync as p}from"node:child_process";import{consola as e}from"consola";import S from"fast-glob";import N from"micromatch";import{detectPackageManager as O}from"nypm";import{resolve as w}from"pathe";import{readPackageJSON as P}from"pkg-types";import{l as h,f as k,g as C}from"./basis.CkZpidFZ.mjs";function j(){try{const t=p("git diff --cached --name-only",{encoding:"utf8"}).trim().split(`
|
|
2
|
-
`).filter(Boolean),o=p("git diff --cached --name-only --diff-filter=D",{encoding:"utf8"}),s=new Set(o.trim().split(`
|
|
3
|
-
`).filter(Boolean));return t.filter(i=>!s.has(i))}catch{return[]}}async function v(t,o=["**/*"],s=["node_modules/**","dist/**","build/**",".git/**"]){try{return await S(o,{cwd:t,ignore:s,onlyFiles:!0,dot:!1,absolute:!1})}catch(i){return e.warn("Failed to scan project files:",i),[]}}async function q(t=process.cwd(),o){const{config:s}=await h({cwd:t,overrides:o?{lint:{staged:o}}:void 0}),i=s.lint?.staged||{},c=j();if(c.length===0)return e.info("No staged files to lint"),!0;if(Object.keys(i).length===0)return e.warn("No staged lint configuration found"),!0;let n=!1;const r=new Set;for(const[f,u]of Object.entries(i)){const a=c.filter(l=>!r.has(l)&&N.isMatch(l.split("/").pop()||l,f));if(a.length!==0){e.start(`Linting ${a.length} files: ${f}`);try{const l=`${u} ${a.join(" ")}`;p(l,{stdio:"inherit",cwd:t});const g=[];for(const d of a)await k(w(t,d))&&g.push(d);g.length>0&&p(`git add ${g.join(" ")}`,{stdio:"inherit",cwd:t}),a.forEach(d=>r.add(d)),e.success(`${f}`)}catch(l){n=!0,e.error(`${f} failed:`,l)}}}return!n}async function E(t=process.cwd(),o){const{config:s}=await h({cwd:t,overrides:o?{lint:{project:o}}:void 0}),i=s.lint?.project||{};if(Object.keys(i).length===0)return e.warn("No project lint configuration found"),!0;e.start("Running project-wide linting...");let c=!1;for(const[n,r]of Object.entries(i)){e.start(`Running project lint: ${n}`);try{p(r,{stdio:"inherit",cwd:t}),e.success(`${n}`)}catch(f){c=!0,e.error(`${n} failed:`,f)}}return!c}async function A(t=process.cwd(),o){const{config:s}=await h({cwd:t,overrides:o?{lint:{dependencies:o}}:void 0}),i=s.lint?.dependencies||{};let c=!1;try{const n=await P(t),r={...n.dependencies,...n.devDependencies},f=(await O(t))?.name||"npm",u=C(f);if(e.start("Checking dependencies..."),i.blockedPackages&&i.blockedPackages.length>0){const a=Object.keys(r).filter(l=>i.blockedPackages?.includes(l));a.length>0?(e.error(`Blocked packages found: ${a.join(", ")}`),c=!0):e.success("No blocked packages found")}if(i.checkOutdated)try{p(u.outdated,{cwd:t,stdio:"pipe"}),e.success("All dependencies are up to date")}catch(a){e.warn("\u26A0 Some dependencies are outdated:",a)}if(i.checkSecurity)try{p(u.audit,{cwd:t,stdio:"pipe"}),e.success("No security vulnerabilities found")}catch(a){e.error("Security vulnerabilities detected:",a),c=!0}i.allowedLicenses&&i.allowedLicenses.length>0&&e.info("\u{1F4DD} License checking requires manual review or additional tooling")}catch(n){e.error("Failed to check dependencies:",n),c=!0}return!c}async function R(t=process.cwd(),o){const{config:s}=await h({cwd:t,overrides:o?{lint:{structure:o}}:void 0}),i=s.lint?.structure||{};let c=!1;if(e.start("Checking project structure..."),i.requiredFiles)for(const n of i.requiredFiles){const r=w(t,n);await k(r)?e.success(`Required file found: ${n}`):(e.error(`Required file missing: ${n}`),c=!0)}if(i.requiredDirs)for(const n of i.requiredDirs){const r=w(t,n);await k(r)?e.success(`Required directory found: ${n}`):(e.error(`Required directory missing: ${n}`),c=!0)}if(i.naming&&i.naming.length>0)for(const n of i.naming){const{path:r,files:f,directories:u,description:a}=n;e.start(`Checking naming rule: ${a||r}`);const l=await v(t,[r]);if(f){const g=new RegExp(f),d=l.filter(y=>{const m=y.split("/").pop()||"";return!g.test(m)});d.length>0?(e.error(`Files with invalid naming in ${r}: ${d.slice(0,3).join(", ")}${d.length>3?"...":""}`),c=!0):l.length>0&&e.success(`All files in ${r} follow naming convention`)}if(u){const g=new RegExp(u),d=new Set;l.forEach(m=>{const $=m.split("/");$.pop(),$.forEach(D=>d.add(D))});const y=Array.from(d).filter(m=>!g.test(m));y.length>0?(e.error(`Directories with invalid naming in ${r}: ${y.slice(0,3).join(", ")}`),c=!0):d.size>0&&e.success(`All directories in ${r} follow naming convention`)}}return!c}async function b(t=process.cwd(),o){const{config:s}=await h({cwd:t,overrides:o?{lint:{docs:o}}:void 0}),i=s.lint?.docs||{};let c=!1;if(e.start("Checking documentation..."),i.checkReadme!==!1){const n=["README.md","README.rst","README.txt","readme.md"];(await Promise.all(n.map(r=>k(w(t,r))))).some(r=>r)?e.success("README file found"):(e.error("No README file found"),c=!0)}if(i.checkChangelog){const n=["CHANGELOG.md","CHANGELOG.rst","HISTORY.md","changelog.md"];(await Promise.all(n.map(r=>k(w(t,r))))).some(r=>r)?e.success("CHANGELOG file found"):(e.error("No CHANGELOG file found"),c=!0)}return!c}async function F(t=process.cwd()){const{config:o}=await h({cwd:t}),s=o.lint||{};e.start("Running comprehensive project lint...");const i=(await Promise.allSettled([E(t,s.project),A(t,s.dependencies),R(t,s.structure),b(t,s.docs)])).filter(c=>c.status==="rejected"||c.status==="fulfilled"&&!c.value);return i.length===0?(e.success("All lint checks passed!"),!0):(e.error(`${i.length} lint check(s) failed`),!1)}export{E as a,A as b,R as c,b as d,F as e,v as f,j as g,q as l};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import{execSync as p}from"node:child_process";import{readFile as G,unlink as k,writeFile as v,copyFile as I}from"node:fs/promises";import{updateConfig as x}from"c12/update";import{consola as s}from"consola";import{defu as M}from"defu";import b from"ini";import{resolve as l}from"pathe";import{l as d,f as g}from"./basis.CkZpidFZ.mjs";async function $(i,o=!1,r=!1){try{return await x({cwd:i,configFile:"basis.config",onUpdate:t=>{t.git&&(o&&t.git.hooks&&(delete t.git.hooks,s.success("Removed hooks configuration from basis.config.ts")),r&&t.git.config&&(delete t.git.config,s.success("Removed git config from basis.config.ts")),Object.keys(t.git).length===0&&(delete t.git,s.success("Removed empty git section from basis.config.ts")))}}),!0}catch{return!1}}const S=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function F(i){const o=i.trim().split(`
|
|
2
|
-
`),r=o[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!r)return null;const[,t,,e,c,n]=r,a=o.slice(1).find(u=>u.trim())?.trim(),f=o.slice(-1)[0]?.trim();return{type:t,scope:e,description:n,body:a,footer:f,isBreaking:!!c||i.includes("BREAKING CHANGE:")}}function j(i,o={}){const r=[],{types:t=S,maxLength:e=72,minLength:c=10,scopeRequired:n=!1,allowedScopes:a=[]}=o,f=F(i);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 u=i.split(`
|
|
3
|
-
`)[0];return u.length>e&&r.push(`Header too long (${u.length}). Max: ${e}`),u.length<c&&r.push(`Header too short (${u.length}). Min: ${c}`),n&&!f.scope&&r.push("Scope is required"),f.scope&&a.length>0&&!a.includes(f.scope)&&r.push(`Invalid scope '${f.scope}'. Allowed: ${a.join(", ")}`),{valid:r.length===0,errors:r}}async function E(i=process.cwd(),o){const{config:r}=await d({cwd:i,overrides:o?{git:{commitMsg:o}}:void 0}),t=r.git?.commitMsg||{};let e;try{const n=l(".git/COMMIT_EDITMSG");await g(n)?e=(await G(n)).toString("utf8"):e=p("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(n){return s.error("Failed to read commit message:",n),!1}const c=j(e,t);return c.valid?(s.success("Commit message is valid"),!0):(s.error("Invalid commit message:"),c.errors.forEach(n=>s.error(` ${n}`)),!1)}async function C(i){const o=l(i,".git/config");if(!await g(o))return null;const r=new Date().toISOString().replace(/[:.]/g,"-"),t=l(i,`.git/config.backup.${r}`);try{return await I(o,t),s.info(`\u{1F4C4} Created backup: ${t}`),t}catch(e){return s.warn("Failed to create Git config backup:",e),null}}async function m(i=process.cwd()){const o=l(i,".git/config");if(!await g(o))return s.info("No .git/config found, will create new one"),{};try{const r=await G(o,"utf8"),t=b.parse(r);return s.success(`Read existing Git configuration from ${o}`),t}catch(r){return s.warn("Failed to read .git/config:",r),{}}}async function w(i,o=process.cwd()){const r=l(o,".git/config");try{let t=b.stringify(i,{whitespace:!0});t=t.split(`
|
|
4
|
-
`).map(e=>e&&!e.startsWith("[")&&e.includes("=")?` ${e}`:e).join(`
|
|
5
|
-
`),await v(r,t,"utf8"),s.success(`Git configuration written to ${r}`)}catch(t){throw s.error("Failed to write .git/config:",t),t}}function R(i,o){if(!o)return!0;for(const[r,t]of Object.entries(o)){if(typeof t!="object"||!t)continue;const e=i[r];if(!e||typeof e!="object")return!1;for(const[c,n]of Object.entries(t))if(n!==void 0&&e[c]!==n)return!1}return!0}async function h(i=process.cwd(),o){const{config:r}=await d({cwd:i,overrides:o?{git:{config:o}}:void 0}),t=r.git?.config||{};if(Object.keys(t).length===0)return s.info("No Git configuration settings to apply"),!0;try{const e=await m(i);if(R(e,t))return s.success("Git configuration is already up to date"),!0;const c=await C(i),n=M(e,t);return await w(n,i),s.success("Git configuration setup completed"),c&&s.info(`\u{1F4BE} Original config backed up to: ${c.split("/").pop()}`),!0}catch(e){return s.error("Failed to setup Git configuration:",e),!1}}async function B(i=process.cwd(),o=!0,r={}){try{const t=await C(i),e=await m(i);if(!e||Object.keys(e).length===0)return s.info("No Git configuration found to reset"),!0;const c={};if(o&&e.user&&(c.user=e.user,s.info("\u{1F512} Keeping user configuration (name, email)")),e.core){const n=["repositoryformatversion","filemode","bare","logallrefupdates"],a={};n.forEach(f=>{e.core[f]!==void 0&&(a[f]=e.core[f])}),Object.keys(a).length>0&&(c.core=a,s.info("\u{1F512} Keeping essential core Git settings"))}return await w(c,i),s.success("Git configuration reset completed"),t&&s.info(`\u{1F4BE} Original config backed up to: ${t.split("/").pop()}`),r.updateConfig?await $(i,!1,!0):!0}catch(t){return s.error("Failed to reset Git configuration:",t),!1}}async function y(i=process.cwd(),o){const{config:r}=await d({cwd:i,overrides:o?{git:{hooks:o}}:void 0}),t=r.git?.hooks||{},e=l(i,".git/hooks");if(!await g(e))return s.error("Git hooks directory not found. Is this a Git repository?"),!1;let c=!0;for(const[n,a]of Object.entries(t)){const f=l(e,n);try{let u=`#!/bin/sh
|
|
6
|
-
|
|
7
|
-
`;if(typeof a=="string")u+=`${a}
|
|
8
|
-
`;else if(a&&typeof a=="object"&&"commands"in a){const O=a.commands;u+=`${O.join(`
|
|
9
|
-
`)}
|
|
10
|
-
`}await v(f,u,{mode:493}),s.success(`Setup ${n} hook`)}catch(u){s.error(`Failed to setup ${n} hook:`,u),c=!1}}return c}async function H(i=process.cwd()){try{try{p("git rev-parse --git-dir",{cwd:i,stdio:"pipe"}),s.info("Git repository already exists")}catch{p("git init",{cwd:i,stdio:"inherit"}),s.success("Initialized Git repository")}const o=await h(i),r=await y(i);return o&&r}catch(o){return s.error("Failed to initialize Git repository:",o),!1}}async function N(i=process.cwd()){const{config:o}=await d({cwd:i}),r=o.git||{};s.start("Setting up Git configuration...");const t=(await Promise.allSettled([h(i,r.config),y(i,r.hooks)])).filter(e=>e.status==="rejected"||e.status==="fulfilled"&&!e.value);return t.length===0?(s.success("Git setup completed successfully!"),!0):(s.error(`${t.length} Git setup step(s) failed`),!1)}async function A(i=process.cwd(),o,r={}){const t=l(i,".git/hooks");if(!await g(t))return s.warn("Git hooks directory not found. Is this a Git repository?"),!0;let e=!0;if(o&&o.length>0)for(const c of o){const n=l(t,c);if(await g(n))try{await k(n),s.success(`Removed ${c} hook`)}catch(a){s.error(`Failed to remove ${c} hook:`,a),e=!1}}else{const{config:c}=await d({cwd:i}),n=c.git?.hooks||{};for(const a of Object.keys(n)){const f=l(t,a);if(await g(f))try{await k(f),s.success(`Removed ${a} hook`)}catch(u){s.error(`Failed to remove ${a} hook:`,u),e=!1}}if(r.updateConfig){const a=await $(i,!0,!1);e=e&&a}}return e}export{h as a,N as b,B as c,m as d,H as i,E as l,F as p,A as r,y as s,j as v,w};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{execSync as d}from"node:child_process";import{consola as a}from"consola";import{detectPackageManager as y,runScript as p}from"nypm";import{readPackageJSON as $}from"pkg-types";import h from"semver";import{l as b}from"./basis.CkZpidFZ.mjs";async function k(e,t,n){if(t.checkGitClean&&!n.skipTests)try{if(d("git status --porcelain",{cwd:e,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(i){a.warn("Could not check git status:",i)}if(t.checkTests&&!n.skipTests){a.start("Running tests...");try{t.testCommand?d(t.testCommand,{cwd:e,stdio:"inherit"}):await p("test",{cwd:e,silent:!1}),a.success("Tests passed")}catch(i){throw a.error("Tests failed"),i}}if(t.buildCommand&&!n.skipBuild){a.start("Building package...");try{t.buildCommand.includes(" ")?d(t.buildCommand,{cwd:e,stdio:"inherit"}):await p(t.buildCommand,{cwd:e,silent:!1}),a.success("Build completed")}catch(i){throw a.error("Build failed"),i}}}async function C(e,t){if(t.autoGitPush)try{d("git push",{cwd:e}),t.createGitTag&&d("git push --tags",{cwd:e}),a.success("Pushed changes to remote")}catch(n){a.warn("Failed to push changes:",n)}}async function T(e,t={}){const{config:n}=await b({cwd:e}),i=n.publish||{},f=await $(e),{name:o,version:r}=f;if(!o||!r)throw new Error("Missing name or version in package.json");if(!h.valid(r))throw new Error(`Invalid version format in package.json: ${r}`);const m=await y(e),u=m?.command||"npm";await k(e,i,t);let c;if(t.tag)c=t.tag;else if(t.stable||t.latest)c=i.stableTag||"latest";else if(h.prerelease(r)){const s=h.prerelease(r);c=s&&s[0]||i.defaultTag||"edge"}else c=i.stableTag||"latest";a.info(`Publishing ${o}@${r} to tag: ${c}`);const g=["publish","--tag",c,"--access",t.access||i.access||"public"];(t.registry||i.registry)&&g.push("--registry",t.registry||i.registry||""),t.dryRun&&g.push("--dry-run");const w=`${u} ${g.join(" ")}`;a.start("Publishing package...");try{if(d(w,{cwd:e,stdio:"inherit"}),t.dryRun)a.success("Dry run completed successfully");else{a.success(`Published ${o}@${r} to ${c}`);const s=i.defaultTag||"edge";if(c!==s){a.start(`Also publishing to ${s} tag...`);try{let l;m?.name==="yarn"?l=`${u} tag add ${o}@${r} ${s}`:l=`${u} dist-tag add ${o}@${r} ${s}`,d(l,{cwd:e,stdio:"inherit"}),a.success(`Also published ${o}@${r} to ${s}`)}catch(l){a.warn(`Failed to add ${s} tag:`,l)}}await C(e,i)}return{packageName:o,version:r,publishTag:c,dryRun:t.dryRun||!1}}catch(s){throw a.error("Failed to publish package:",s),s}}export{T as p};
|
|
@@ -1,10 +0,0 @@
|
|
|
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"),k=require("ini"),pathe=require("pathe"),utils=require("./basis.BJhSbOyA.cjs");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const k__default=_interopDefaultCompat(k);async function G(t,i=!1,s=!1){try{return await update.updateConfig({cwd:t,configFile:"basis.config",onUpdate:e=>{e.git&&(i&&e.git.hooks&&(delete e.git.hooks,consola.consola.success("Removed hooks configuration from basis.config.ts")),s&&e.git.config&&(delete e.git.config,consola.consola.success("Removed git config from basis.config.ts")),Object.keys(e.git).length===0&&(delete e.git,consola.consola.success("Removed empty git section from basis.config.ts")))}}),!0}catch{return!1}}const P=["feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"];function parseCommitMessage(t){const i=t.trim().split(`
|
|
2
|
-
`),s=i[0].match(/^(\w+)(\(([^)]+)\))?(!)?:\s*(.+)$/);if(!s)return null;const[,e,,o,c,n]=s,r=i.slice(1).find(l=>l.trim())?.trim(),a=i.slice(-1)[0]?.trim();return{type:e,scope:o,description:n,body:r,footer:a,isBreaking:!!c||t.includes("BREAKING CHANGE:")}}function validateCommitMessage(t,i={}){const s=[],{types:e=P,maxLength:o=72,minLength:c=10,scopeRequired:n=!1,allowedScopes:r=[]}=i,a=parseCommitMessage(t);if(!a)return{valid:!1,errors:["Invalid commit format. Expected: type(scope): description"]};e.includes(a.type)||s.push(`Invalid type '${a.type}'. Allowed: ${e.join(", ")}`);const l=t.split(`
|
|
3
|
-
`)[0];return l.length>o&&s.push(`Header too long (${l.length}). Max: ${o}`),l.length<c&&s.push(`Header too short (${l.length}). Min: ${c}`),n&&!a.scope&&s.push("Scope is required"),a.scope&&r.length>0&&!r.includes(a.scope)&&s.push(`Invalid scope '${a.scope}'. Allowed: ${r.join(", ")}`),{valid:s.length===0,errors:s}}async function lintCommitMessage(t=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{git:{commitMsg:i}}:void 0}),e=s.git?.commitMsg||{};let o;try{const n=pathe.resolve(".git/COMMIT_EDITMSG");await utils.fileExists(n)?o=(await promises.readFile(n)).toString("utf8"):o=node_child_process.execSync("git log -1 --pretty=%B",{encoding:"utf8"}).trim()}catch(n){return consola.consola.error("Failed to read commit message:",n),!1}const c=validateCommitMessage(o,e);return c.valid?(consola.consola.success("Commit message is valid"),!0):(consola.consola.error("Invalid commit message:"),c.errors.forEach(n=>consola.consola.error(` ${n}`)),!1)}async function b(t){const i=pathe.resolve(t,".git/config");if(!await utils.fileExists(i))return null;const s=new Date().toISOString().replace(/[:.]/g,"-"),e=pathe.resolve(t,`.git/config.backup.${s}`);try{return await promises.copyFile(i,e),consola.consola.info(`\u{1F4C4} Created backup: ${e}`),e}catch(o){return consola.consola.warn("Failed to create Git config backup:",o),null}}async function readGitConfig(t=process.cwd()){const i=pathe.resolve(t,".git/config");if(!await utils.fileExists(i))return consola.consola.info("No .git/config found, will create new one"),{};try{const s=await promises.readFile(i,"utf8"),e=k__default.parse(s);return consola.consola.success(`Read existing Git configuration from ${i}`),e}catch(s){return consola.consola.warn("Failed to read .git/config:",s),{}}}async function writeGitConfig(t,i=process.cwd()){const s=pathe.resolve(i,".git/config");try{let e=k__default.stringify(t,{whitespace:!0});e=e.split(`
|
|
4
|
-
`).map(o=>o&&!o.startsWith("[")&&o.includes("=")?` ${o}`:o).join(`
|
|
5
|
-
`),await promises.writeFile(s,e,"utf8"),consola.consola.success(`Git configuration written to ${s}`)}catch(e){throw consola.consola.error("Failed to write .git/config:",e),e}}function x(t,i){if(!i)return!0;for(const[s,e]of Object.entries(i)){if(typeof e!="object"||!e)continue;const o=t[s];if(!o||typeof o!="object")return!1;for(const[c,n]of Object.entries(e))if(n!==void 0&&o[c]!==n)return!1}return!0}async function setupGitConfig(t=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{git:{config:i}}:void 0}),e=s.git?.config||{};if(Object.keys(e).length===0)return consola.consola.info("No Git configuration settings to apply"),!0;try{const o=await readGitConfig(t);if(x(o,e))return consola.consola.success("Git configuration is already up to date"),!0;const c=await b(t),n=defu.defu(o,e);return await writeGitConfig(n,t),consola.consola.success("Git configuration setup completed"),c&&consola.consola.info(`\u{1F4BE} Original config backed up to: ${c.split("/").pop()}`),!0}catch(o){return consola.consola.error("Failed to setup Git configuration:",o),!1}}async function resetGitConfig(t=process.cwd(),i=!0,s={}){try{const e=await b(t),o=await readGitConfig(t);if(!o||Object.keys(o).length===0)return consola.consola.info("No Git configuration found to reset"),!0;const c={};if(i&&o.user&&(c.user=o.user,consola.consola.info("\u{1F512} Keeping user configuration (name, email)")),o.core){const n=["repositoryformatversion","filemode","bare","logallrefupdates"],r={};n.forEach(a=>{o.core[a]!==void 0&&(r[a]=o.core[a])}),Object.keys(r).length>0&&(c.core=r,consola.consola.info("\u{1F512} Keeping essential core Git settings"))}return await writeGitConfig(c,t),consola.consola.success("Git configuration reset completed"),e&&consola.consola.info(`\u{1F4BE} Original config backed up to: ${e.split("/").pop()}`),s.updateConfig?await G(t,!1,!0):!0}catch(e){return consola.consola.error("Failed to reset Git configuration:",e),!1}}async function setupGitHooks(t=process.cwd(),i){const{config:s}=await utils.loadConfig({cwd:t,overrides:i?{git:{hooks:i}}:void 0}),e=s.git?.hooks||{},o=pathe.resolve(t,".git/hooks");if(!await utils.fileExists(o))return consola.consola.error("Git hooks directory not found. Is this a Git repository?"),!1;let c=!0;for(const[n,r]of Object.entries(e)){const a=pathe.resolve(o,n);try{let l=`#!/bin/sh
|
|
6
|
-
|
|
7
|
-
`;if(typeof r=="string")l+=`${r}
|
|
8
|
-
`;else if(r&&typeof r=="object"&&"commands"in r){const f=r.commands;l+=`${f.join(`
|
|
9
|
-
`)}
|
|
10
|
-
`}await promises.writeFile(a,l,{mode:493}),consola.consola.success(`Setup ${n} hook`)}catch(l){consola.consola.error(`Failed to setup ${n} hook:`,l),c=!1}}return c}async function initGitRepo(t=process.cwd()){try{try{node_child_process.execSync("git rev-parse --git-dir",{cwd:t,stdio:"pipe"}),consola.consola.info("Git repository already exists")}catch{node_child_process.execSync("git init",{cwd:t,stdio:"inherit"}),consola.consola.success("Initialized Git repository")}const i=await setupGitConfig(t),s=await setupGitHooks(t);return i&&s}catch(i){return consola.consola.error("Failed to initialize Git repository:",i),!1}}async function setupGit(t=process.cwd()){const{config:i}=await utils.loadConfig({cwd:t}),s=i.git||{};consola.consola.start("Setting up Git configuration...");const e=(await Promise.allSettled([setupGitConfig(t,s.config),setupGitHooks(t,s.hooks)])).filter(o=>o.status==="rejected"||o.status==="fulfilled"&&!o.value);return e.length===0?(consola.consola.success("Git setup completed successfully!"),!0):(consola.consola.error(`${e.length} Git setup step(s) failed`),!1)}async function removeGitHooks(t=process.cwd(),i,s={}){const e=pathe.resolve(t,".git/hooks");if(!await utils.fileExists(e))return consola.consola.warn("Git hooks directory not found. Is this a Git repository?"),!0;let o=!0;if(i&&i.length>0)for(const c of i){const n=pathe.resolve(e,c);if(await utils.fileExists(n))try{await promises.unlink(n),consola.consola.success(`Removed ${c} hook`)}catch(r){consola.consola.error(`Failed to remove ${c} hook:`,r),o=!1}}else{const{config:c}=await utils.loadConfig({cwd:t}),n=c.git?.hooks||{};for(const r of Object.keys(n)){const a=pathe.resolve(e,r);if(await utils.fileExists(a))try{await promises.unlink(a),consola.consola.success(`Removed ${r} hook`)}catch(l){consola.consola.error(`Failed to remove ${r} hook:`,l),o=!1}}if(s.updateConfig){const r=await G(t,!0,!1);o=o&&r}}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;
|