@funish/basis 0.0.2 → 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.
Files changed (45) hide show
  1. package/README.md +85 -50
  2. package/dist/chunks/config.cjs +1 -1
  3. package/dist/chunks/config.mjs +1 -1
  4. package/dist/chunks/git.cjs +1 -1
  5. package/dist/chunks/git.mjs +1 -1
  6. package/dist/chunks/init.cjs +1 -1
  7. package/dist/chunks/init.mjs +1 -1
  8. package/dist/chunks/lint.cjs +1 -1
  9. package/dist/chunks/lint.mjs +1 -1
  10. package/dist/chunks/publish.cjs +1 -1
  11. package/dist/chunks/publish.mjs +1 -1
  12. package/dist/chunks/version.cjs +1 -1
  13. package/dist/chunks/version.mjs +1 -1
  14. package/dist/cli.cjs +1 -1
  15. package/dist/cli.mjs +1 -1
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.d.cts +26 -118
  18. package/dist/index.d.mts +26 -118
  19. package/dist/index.d.ts +26 -118
  20. package/dist/index.mjs +1 -1
  21. package/dist/shared/basis.Bar6V_OJ.cjs +10 -0
  22. package/dist/shared/basis.BzZ6Bs64.mjs +1 -0
  23. package/dist/shared/basis.C-dGsxlD.cjs +1 -0
  24. package/dist/shared/basis.CCjpKO-B.mjs +8 -0
  25. package/dist/shared/basis.CKFXZgQI.mjs +1 -0
  26. package/dist/shared/basis.DADpzLwA.cjs +3 -0
  27. package/dist/shared/basis.DEw91E2d.mjs +1 -0
  28. package/dist/shared/basis.DFb1F94b.mjs +3 -0
  29. package/dist/shared/basis.DVSF1f2D.cjs +8 -0
  30. package/dist/shared/basis.DfY4XEAb.cjs +1 -0
  31. package/dist/shared/basis.Dgo48zAG.cjs +1 -0
  32. package/dist/shared/basis.DzKnyliK.mjs +10 -0
  33. package/package.json +3 -1
  34. package/dist/shared/basis.BglwV-us.mjs +0 -1
  35. package/dist/shared/basis.Bhi6kSAJ.cjs +0 -1
  36. package/dist/shared/basis.BjS41bTE.cjs +0 -1
  37. package/dist/shared/basis.C7U9rUSl.mjs +0 -1
  38. package/dist/shared/basis.CASkqgVR.mjs +0 -1
  39. package/dist/shared/basis.D2srGCU3.cjs +0 -1
  40. package/dist/shared/basis.D3bv4yUV.mjs +0 -3
  41. package/dist/shared/basis.DHqql56x.mjs +0 -10
  42. package/dist/shared/basis.DXBdQ4nF.mjs +0 -1
  43. package/dist/shared/basis.DcyVtmjR.cjs +0 -1
  44. package/dist/shared/basis.FJWRn1Ix.cjs +0 -3
  45. package/dist/shared/basis.QoGvLLsN.cjs +0 -10
package/dist/index.d.mts CHANGED
@@ -1,120 +1,28 @@
1
- import { B as BasisConfig, I as InitOptions, V as VersionOptions, a as VersionUpdateResult, P as PublishOptions, b as PublishResult, C as CommitMessage, G as GitConfig, c as GitConfigData, L as LintConfig } from './shared/basis.BvLeB_5F.mjs';
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 with basis configuration
85
+ * Initialize Git repository
178
86
  */
179
87
  declare function initGitRepo(cwd?: string): Promise<boolean>;
180
88
  /**
@@ -192,26 +100,13 @@ declare function removeGitHooks(cwd?: string, hooksToRemove?: string[], options?
192
100
  * Initialize basis configuration in the current project
193
101
  */
194
102
  declare function init(cwd?: string, options?: InitOptions): Promise<boolean>;
195
- /**
196
- * Preview generated configuration
197
- */
198
- declare function previewBasisConfig(options?: {
199
- enableStagedLinting?: boolean;
200
- enableCommitMsgLinting?: boolean;
201
- customLintPatterns?: string[];
202
- customExcludePatterns?: string[];
203
- }): string;
204
- /**
205
- * Create minimal configuration for quick setup
206
- */
207
- declare function createMinimalConfig(): string;
208
103
 
209
104
  /**
210
105
  * Get staged files (only existing files, not deleted ones)
211
106
  */
212
107
  declare function getStagedFiles(): string[];
213
108
  /**
214
- * Get all project files based on patterns
109
+ * Get all project files based on patterns using fast-glob
215
110
  */
216
111
  declare function getProjectFiles(cwd: string, patterns?: string[], exclude?: string[]): Promise<string[]>;
217
112
  /**
@@ -254,5 +149,18 @@ declare function loadConfig(options?: LoadConfigOptions<BasisConfig>): Promise<c
254
149
  * Check if file or directory exists
255
150
  */
256
151
  declare function fileExists(path: string): Promise<boolean>;
152
+ /**
153
+ * Get package manager specific commands
154
+ */
155
+ declare function getPackageManagerCommands(packageManager: string): {
156
+ outdated: string;
157
+ audit: string;
158
+ } | {
159
+ outdated: string;
160
+ audit: null;
161
+ } | {
162
+ outdated: null;
163
+ audit: null;
164
+ };
257
165
 
258
- export { Basis, BasisConfig, CommitMessage, GitConfig, GitConfigData, InitOptions, LintConfig, PublishOptions, PublishResult, VersionOptions, VersionUpdateResult, createBasis, createMinimalConfig, fileExists, getProjectFiles, getStagedFiles, init, initGitRepo, lintAll, lintCommitMessage, lintDependencies, lintDocs, lintProject, lintStaged, lintStructure, loadConfig, parseCommitMessage, previewBasisConfig, publishPackage, readGitConfig, removeGitHooks, resetGitConfig, setupGit, setupGitConfig, setupGitHooks, updatePackageVersion, validateCommitMessage, writeGitConfig };
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, a as VersionUpdateResult, P as PublishOptions, b as PublishResult, C as CommitMessage, G as GitConfig, c as GitConfigData, L as LintConfig } from './shared/basis.BvLeB_5F.js';
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 with basis configuration
85
+ * Initialize Git repository
178
86
  */
179
87
  declare function initGitRepo(cwd?: string): Promise<boolean>;
180
88
  /**
@@ -192,26 +100,13 @@ declare function removeGitHooks(cwd?: string, hooksToRemove?: string[], options?
192
100
  * Initialize basis configuration in the current project
193
101
  */
194
102
  declare function init(cwd?: string, options?: InitOptions): Promise<boolean>;
195
- /**
196
- * Preview generated configuration
197
- */
198
- declare function previewBasisConfig(options?: {
199
- enableStagedLinting?: boolean;
200
- enableCommitMsgLinting?: boolean;
201
- customLintPatterns?: string[];
202
- customExcludePatterns?: string[];
203
- }): string;
204
- /**
205
- * Create minimal configuration for quick setup
206
- */
207
- declare function createMinimalConfig(): string;
208
103
 
209
104
  /**
210
105
  * Get staged files (only existing files, not deleted ones)
211
106
  */
212
107
  declare function getStagedFiles(): string[];
213
108
  /**
214
- * Get all project files based on patterns
109
+ * Get all project files based on patterns using fast-glob
215
110
  */
216
111
  declare function getProjectFiles(cwd: string, patterns?: string[], exclude?: string[]): Promise<string[]>;
217
112
  /**
@@ -254,5 +149,18 @@ declare function loadConfig(options?: LoadConfigOptions<BasisConfig>): Promise<c
254
149
  * Check if file or directory exists
255
150
  */
256
151
  declare function fileExists(path: string): Promise<boolean>;
152
+ /**
153
+ * Get package manager specific commands
154
+ */
155
+ declare function getPackageManagerCommands(packageManager: string): {
156
+ outdated: string;
157
+ audit: string;
158
+ } | {
159
+ outdated: string;
160
+ audit: null;
161
+ } | {
162
+ outdated: null;
163
+ audit: null;
164
+ };
257
165
 
258
- export { Basis, BasisConfig, CommitMessage, GitConfig, GitConfigData, InitOptions, LintConfig, PublishOptions, PublishResult, VersionOptions, VersionUpdateResult, createBasis, createMinimalConfig, fileExists, getProjectFiles, getStagedFiles, init, initGitRepo, lintAll, lintCommitMessage, lintDependencies, lintDocs, lintProject, lintStaged, lintStructure, loadConfig, parseCommitMessage, previewBasisConfig, publishPackage, readGitConfig, removeGitHooks, resetGitConfig, setupGit, setupGitConfig, setupGitHooks, updatePackageVersion, validateCommitMessage, writeGitConfig };
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{l as r,s as n,a as o,b as c,i as p,r as w,c as u}from"./shared/basis.DHqql56x.mjs";export{p as parseCommitMessage,d as readGitConfig,v as validateCommitMessage,w as writeGitConfig}from"./shared/basis.DHqql56x.mjs";import{i as g}from"./shared/basis.DXBdQ4nF.mjs";export{c as createMinimalConfig,p as previewBasisConfig}from"./shared/basis.DXBdQ4nF.mjs";import{l as h,a as l,b as d,c as m,d as f,e as y}from"./shared/basis.D3bv4yUV.mjs";export{f as getProjectFiles,g as getStagedFiles}from"./shared/basis.D3bv4yUV.mjs";import{p as e}from"./shared/basis.BglwV-us.mjs";import{u as i}from"./shared/basis.CASkqgVR.mjs";import{l as C}from"./shared/basis.C7U9rUSl.mjs";export{f as fileExists}from"./shared/basis.C7U9rUSl.mjs";import"node:child_process";import"node:fs/promises";import"consola";import"ini";import"magicast";import"pathe";import"nypm";import"pkg-types";import"micromatch";import"semver";import"c12";class G{config=null;cwd;constructor(t=process.cwd()){this.cwd=t}async getConfig(){if(!this.config){const{config:t}=await C({cwd:this.cwd});this.config=t}return this.config}async init(t={}){return await g(this.cwd,t)}async lintStaged(){const t=await this.getConfig();return await h(this.cwd,t.lint?.staged)}async lintProject(){const t=await this.getConfig();return await l(this.cwd,t.lint?.project)}async lintDependencies(){const t=await this.getConfig();return await d(this.cwd,t.lint?.dependencies)}async lintStructure(){const t=await this.getConfig();return await m(this.cwd,t.lint?.structure)}async lintDocs(){const t=await this.getConfig();return await f(this.cwd,t.lint?.docs)}async lintAll(){return await y(this.cwd)}async lintCommitMessage(){const t=await this.getConfig();return await r(this.cwd,t.git?.commitMsg)}async setupGitHooks(){const t=await this.getConfig();return await n(this.cwd,t.git?.hooks)}async setupGitConfig(){const t=await this.getConfig();return await o(this.cwd,t.git?.config)}async setupGit(){return await c(this.cwd)}async initGitRepo(){return await p(this.cwd)}async removeGitHooks(t=!1){return await w(this.cwd,void 0,{updateConfig:t})}async resetGitConfig(t=!0,s=!1){return await u(this.cwd,t,{updateConfig:s})}async updateVersion(t={}){return await i(this.cwd,t)}async setVersion(t){return await i(this.cwd,{version:t})}async patchVersion(){return await i(this.cwd,{})}async minorVersion(){return await i(this.cwd,{minor:!0})}async majorVersion(){return await i(this.cwd,{major:!0})}async prereleaseVersion(t){return await i(this.cwd,{prerelease:!0,preid:t})}async publish(t={}){return await e(this.cwd,t)}async publishDryRun(t={}){return await e(this.cwd,{...t,dryRun:!0})}async publishToTag(t,s={}){return await e(this.cwd,{...s,tag:t})}async publishStable(t={}){return await e(this.cwd,{...t,stable:!0})}getCwd(){return this.cwd}setCwd(t){this.cwd=t,this.config=null}async reloadConfig(){return this.config=null,await this.getConfig()}async setup(t={}){return await this.init(t)?await this.setupGit():!1}async release(t={},s={}){if(!await this.lintAll())throw new Error("Lint checks failed. Fix issues before releasing.");const b=await this.updateVersion(t),v=await this.publish(s);return{version:b,publish:v}}}function k(a=process.cwd()){return new G(a)}const x=["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{G as Basis,x as VALID_GIT_HOOKS,k as createBasis,g as init,p as initGitRepo,y as lintAll,r as lintCommitMessage,d as lintDependencies,f as lintDocs,l as lintProject,h as lintStaged,m as lintStructure,C as loadConfig,e as publishPackage,w as removeGitHooks,u as resetGitConfig,c as setupGit,o as setupGitConfig,n as setupGitHooks,i as updatePackageVersion};
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;
@@ -0,0 +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 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;
@@ -0,0 +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: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.2",
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",
@@ -60,6 +60,8 @@
60
60
  "c12": "3.0.4",
61
61
  "citty": "0.1.6",
62
62
  "consola": "3.4.2",
63
+ "defu": "6.1.4",
64
+ "fast-glob": "3.3.3",
63
65
  "ini": "5.0.0",
64
66
  "magicast": "0.3.5",
65
67
  "micromatch": "4.0.8",
@@ -1 +0,0 @@
1
- import{execSync as d}from"node:child_process";import{consola as e}from"consola";import{detectPackageManager as w,runScript as y}from"nypm";import{readPackageJSON as $}from"pkg-types";import h from"semver";import{l as k}from"./basis.C7U9rUSl.mjs";async function b(a,t,o){if(t.checkGitClean&&!o.skipTests)try{if(d("git status --porcelain",{cwd:a,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(i){e.warn("Could not check git status:",i)}if(t.checkTests&&!o.skipTests){e.start("Running tests...");try{t.testCommand?d(t.testCommand,{cwd:a,stdio:"inherit"}):await y("test",{cwd:a,silent:!1}),e.success("Tests passed")}catch(i){throw e.error("Tests failed"),i}}if(t.buildCommand&&!o.skipBuild){e.start("Building package...");try{d(t.buildCommand,{cwd:a,stdio:"inherit"}),e.success("Build completed")}catch(i){throw e.error("Build failed"),i}}}async function T(a,t){if(t.autoGitPush)try{d("git push",{cwd:a}),t.createGitTag&&d("git push --tags",{cwd:a}),e.success("Pushed changes to remote")}catch(o){e.warn("Failed to push changes:",o)}}async function C(a,t={}){const{config:o}=await k({cwd:a}),i=o.publish||{},m=await $(a),{name:n,version:c}=m;if(!n||!c)throw new Error("Missing name or version in package.json");if(!h.valid(c))throw new Error(`Invalid version format in package.json: ${c}`);const p=await w(a),u=p?.command||"npm";await b(a,i,t);let r;if(t.tag)r=t.tag;else if(t.stable||t.latest)r=i.stableTag||"latest";else if(h.prerelease(c)){const s=h.prerelease(c);r=s&&s[0]||i.defaultTag||"edge"}else r=i.stableTag||"latest";e.info(`Publishing ${n}@${c} to tag: ${r}`);const g=["publish","--tag",r,"--access",t.access||i.access||"public"];(t.registry||i.registry)&&g.push("--registry",t.registry||i.registry||""),t.dryRun&&g.push("--dry-run");const f=`${u} ${g.join(" ")}`;e.start("Publishing package...");try{if(d(f,{cwd:a,stdio:"inherit"}),t.dryRun)e.success("Dry run completed successfully");else{e.success(`Published ${n}@${c} to ${r}`);const s=i.defaultTag||"edge";if(r!==s){e.start(`Also publishing to ${s} tag...`);try{let l;p?.name==="yarn"?l=`${u} tag add ${n}@${c} ${s}`:l=`${u} dist-tag add ${n}@${c} ${s}`,d(l,{cwd:a,stdio:"inherit"}),e.success(`Also published ${n}@${c} to ${s}`)}catch(l){e.warn(`Failed to add ${s} tag:`,l)}}await T(a,i)}return{packageName:n,version:c,publishTag:r,dryRun:t.dryRun||!1}}catch(s){throw e.error("Failed to publish package:",s),s}}export{C as p};
@@ -1 +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.DcyVtmjR.cjs");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const g__default=_interopDefaultCompat(g);async function k(e,t,n){if(t.checkGitClean&&!n.skipTests)try{if(node_child_process.execSync("git status --porcelain",{cwd:e,encoding:"utf8"}).trim())throw new Error("Working directory is not clean. Commit your changes first.")}catch(s){consola.consola.warn("Could not check git status:",s)}if(t.checkTests&&!n.skipTests){consola.consola.start("Running tests...");try{t.testCommand?node_child_process.execSync(t.testCommand,{cwd:e,stdio:"inherit"}):await nypm.runScript("test",{cwd:e,silent:!1}),consola.consola.success("Tests passed")}catch(s){throw consola.consola.error("Tests failed"),s}}if(t.buildCommand&&!n.skipBuild){consola.consola.start("Building package...");try{node_child_process.execSync(t.buildCommand,{cwd:e,stdio:"inherit"}),consola.consola.success("Build completed")}catch(s){throw consola.consola.error("Build failed"),s}}}async function C(e,t){if(t.autoGitPush)try{node_child_process.execSync("git push",{cwd:e}),t.createGitTag&&node_child_process.execSync("git push --tags",{cwd:e}),consola.consola.success("Pushed changes to remote")}catch(n){consola.consola.warn("Failed to push changes:",n)}}async function publishPackage(e,t={}){const{config:n}=await utils.loadConfig({cwd:e}),s=n.publish||{},p=await pkgTypes.readPackageJSON(e),{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 d=await nypm.detectPackageManager(e),l=d?.command||"npm";await k(e,s,t);let o;if(t.tag)o=t.tag;else if(t.stable||t.latest)o=s.stableTag||"latest";else if(g__default.prerelease(c)){const a=g__default.prerelease(c);o=a&&a[0]||s.defaultTag||"edge"}else o=s.stableTag||"latest";consola.consola.info(`Publishing ${i}@${c} to tag: ${o}`);const u=["publish","--tag",o,"--access",t.access||s.access||"public"];(t.registry||s.registry)&&u.push("--registry",t.registry||s.registry||""),t.dryRun&&u.push("--dry-run");const h=`${l} ${u.join(" ")}`;consola.consola.start("Publishing package...");try{if(node_child_process.execSync(h,{cwd:e,stdio:"inherit"}),t.dryRun)consola.consola.success("Dry run completed successfully");else{consola.consola.success(`Published ${i}@${c} to ${o}`);const a=s.defaultTag||"edge";if(o!==a){consola.consola.start(`Also publishing to ${a} tag...`);try{let r;d?.name==="yarn"?r=`${l} tag add ${i}@${c} ${a}`:r=`${l} dist-tag add ${i}@${c} ${a}`,node_child_process.execSync(r,{cwd:e,stdio:"inherit"}),consola.consola.success(`Also published ${i}@${c} to ${a}`)}catch(r){consola.consola.warn(`Failed to add ${a} tag:`,r)}}await C(e,s)}return{packageName:i,version:c,publishTag:o,dryRun:t.dryRun||!1}}catch(a){throw consola.consola.error("Failed to publish package:",a),a}}exports.publishPackage=publishPackage;
@@ -1 +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.DcyVtmjR.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 +0,0 @@
1
- import{access as t}from"node:fs/promises";import{loadConfig as o}from"c12";import{defaultConfig as s}from"../config.mjs";async function f(a={}){return await o({name:"basis",cwd:process.cwd(),...a,defaults:{...s,...a.defaults}})}async function r(a){try{return await t(a),!0}catch{return!1}}export{r as f,f as l};
@@ -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.C7U9rUSl.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};