anl 26.322.0 → 26.322.1

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.
@@ -59,36 +59,29 @@ fi
59
59
  run_commitlint() {
60
60
  local msg_file="$1"
61
61
  local repo_root="$2"
62
+ local -a cmd
62
63
 
63
64
  # 切换到仓库根目录
64
65
  cd "$repo_root" || exit 1
65
-
66
- # 按优先级尝试不同的执行方式
66
+
67
+ # 只选择一种可用执行方式,避免同一错误重复输出多次
67
68
  if command -v pnpm >/dev/null 2>&1 && [ -f "pnpm-lock.yaml" ]; then
68
- # 优先使用 pnpm(如果存在 pnpm-lock.yaml)
69
- pnpm exec commitlint --edit "$msg_file" 2>/dev/null && return 0
70
- fi
71
-
72
- if command -v yarn >/dev/null 2>&1 && [ -f "yarn.lock" ]; then
73
- # 使用 yarn(如果存在 yarn.lock)
74
- yarn commitlint --edit "$msg_file" 2>/dev/null && return 0
75
- fi
76
-
77
- if command -v npm >/dev/null 2>&1 && [ -f "package-lock.json" ]; then
78
- # 使用 npm(如果存在 package-lock.json)
79
- npm exec commitlint --edit "$msg_file" 2>/dev/null && return 0
69
+ cmd=(pnpm exec commitlint --edit "$msg_file")
70
+ elif command -v yarn >/dev/null 2>&1 && [ -f "yarn.lock" ]; then
71
+ cmd=(yarn commitlint --edit "$msg_file")
72
+ elif command -v npm >/dev/null 2>&1 && [ -f "package-lock.json" ]; then
73
+ cmd=(npm exec commitlint --edit "$msg_file")
74
+ elif command -v npx >/dev/null 2>&1; then
75
+ cmd=(npx --no-install commitlint --edit "$msg_file")
76
+ elif [ -x "node_modules/.bin/commitlint" ]; then
77
+ cmd=(node_modules/.bin/commitlint --edit "$msg_file")
78
+ else
79
+ echo "错误:无法找到可用的 commitlint 执行方式,请先安装依赖后再提交。"
80
+ return 1
80
81
  fi
81
-
82
- # 回退到 npx(通用方案)
83
- npx --no-install commitlint --edit "$msg_file" 2>/dev/null && return 0
84
-
85
- # 最后的回退方案:直接使用 node_modules 中的二进制文件
86
- if [ -f "node_modules/.bin/commitlint" ]; then
87
- node_modules/.bin/commitlint --edit "$msg_file" 2>/dev/null && return 0
88
- fi
89
-
90
- echo "警告:无法找到可用的 commitlint 执行方式,已跳过校验"
91
- return 0
82
+
83
+ "${cmd[@]}"
84
+ return $?
92
85
  }
93
86
 
94
87
  # 执行 commitlint 检查
@@ -0,0 +1,40 @@
1
+ #!/bin/sh
2
+
3
+ # 在提交前执行暂存文件检查和自动修复
4
+ REPO_ROOT=$(git rev-parse --show-toplevel)
5
+
6
+ run_lint_staged() {
7
+ local repo_root="$1"
8
+
9
+ cd "$repo_root" || exit 1
10
+
11
+ if command -v pnpm >/dev/null 2>&1 && [ -f "pnpm-lock.yaml" ]; then
12
+ pnpm exec lint-staged
13
+ return $?
14
+ fi
15
+
16
+ if command -v yarn >/dev/null 2>&1 && [ -f "yarn.lock" ]; then
17
+ yarn lint-staged
18
+ return $?
19
+ fi
20
+
21
+ if command -v npm >/dev/null 2>&1 && [ -f "package-lock.json" ]; then
22
+ npm exec lint-staged
23
+ return $?
24
+ fi
25
+
26
+ if [ -x "node_modules/.bin/lint-staged" ]; then
27
+ node_modules/.bin/lint-staged
28
+ return $?
29
+ fi
30
+
31
+ if command -v npx >/dev/null 2>&1; then
32
+ npx --no-install lint-staged
33
+ return $?
34
+ fi
35
+
36
+ echo "错误:无法找到可用的 lint-staged 执行方式,请先安装依赖后再提交。"
37
+ return 1
38
+ }
39
+
40
+ run_lint_staged "$REPO_ROOT"
@@ -1,3 +1,5 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/index.cjs`),n=require(`./utils.cjs`);let r=require(`child_process`),i=require(`fs`);i=e.__toESM(i);let a=require(`path`);a=e.__toESM(a);const o=async()=>{let e=__dirname,o=process.cwd(),s=a.default.join(e,`.gitscripts`),c=a.default.join(o,`.gitscripts`);await n.pathExists(s)?(await n.copyDirectoryRecursive(s,c),t.log.success(`.gitscripts create done.`)):t.log.error(`source directory ${s} does not exist`);for(let r of[`.gitconfig`,`.commit-type.cjs`]){let i=a.default.join(e,r),s=a.default.join(o,r);await n.pathExists(i)?await n.copyFileIfMissing(i,s):t.log.error(`source file ${i} does not exist`)}try{i.default.chmodSync(a.default.join(c,`random-branch.sh`),493),t.log.success(`random-branch.sh Raise power`)}catch(e){console.log(e),t.log.error(`Set .githooks/commit-msg executable permission failed: ${e instanceof Error?e.message:String(e)}`)}try{(0,r.execSync)(`git config --local include.path ../.gitconfig`,{stdio:`ignore`}),t.log.success(`.gitconfig git set`)}catch(e){console.log(e),t.log.error(`Execute git config --local include.path ../.gitconfig failed, please execute the command manually`)}},s=async()=>{let e=a.default.join(__dirname,`.githooks`),o=process.cwd(),s=a.default.join(o,`.githooks`);if(!await n.pathExists(e)){t.log.error(`source directory ${e} does not exist`);return}await n.copyDirectoryRecursive(e,s),t.log.success(`.githooks create done.`);try{i.default.chmodSync(a.default.join(s,`commit-msg`),493),t.log.success(`commit-msg raise power done.`)}catch(e){console.log(e),t.log.error(`Set .githooks/commit-msg executable permission failed: ${e instanceof Error?e.message:String(e)}`)}try{(0,r.execSync)(`git config core.hooksPath .githooks`,{stdio:`ignore`}),t.log.success(`git set .githooks done.`)}catch(e){console.log(e),t.log.error(`Execute [git config core.hooksPath .githooks] failed, please execute the command manually`)}},c=async()=>{let e=__dirname,r=process.cwd(),i=a.default.join(e,`.gitattributes`),o=a.default.join(r,`.gitattributes`);if(!await n.pathExists(i)){t.log.error(`source file ${i} does not exist`);return}await n.copyFileIfMissing(i,o)},l=async(e=[])=>{e.includes(`gitflow`)&&await o(),e.includes(`commitSubject`)&&await s(),e.includes(`customGitCommand`)&&await c(),console.log(`
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/index.cjs`),n=require(`./utils.cjs`);let r=require(`child_process`),i=require(`fs`);i=e.__toESM(i);let a=require(`path`);a=e.__toESM(a);const o=e=>{try{return(0,r.execSync)(`git rev-parse --is-inside-work-tree`,{cwd:e,stdio:`ignore`}),!0}catch{return!1}},s=(e,n,i)=>{try{return(0,r.execFileSync)(`git`,e,{cwd:n,stdio:`ignore`}),!0}catch(e){return console.log(e),t.log.error(i),!1}},c=e=>{let t=process.platform===`win32`?`where`:`command -v`;try{return(0,r.execSync)(`${t} ${e}`,{stdio:`ignore`}),!0}catch{return!1}},l=e=>i.default.existsSync(a.default.join(e,`pnpm-lock.yaml`))?`pnpm`:i.default.existsSync(a.default.join(e,`yarn.lock`))?`yarn`:`npm`,u=e=>{let t=`@commitlint/cli @commitlint/config-conventional lint-staged`;return e===`pnpm`?`pnpm add -D ${t}`:e===`yarn`?`yarn add -D ${t}`:`npm install -D ${t}`},d=(e,n)=>{let r=[];if(e.includes(`gitflow`)&&!c(`jq`)&&(r.push(`Missing dependency: jq (required by git nb branch generator).`),r.push(`Quick fix (macOS): brew install jq`)),e.includes(`commitSubject`)){let e=i.default.existsSync(a.default.join(n,`node_modules`,`.bin`,process.platform===`win32`?`commitlint.cmd`:`commitlint`))||c(`commitlint`),t=i.default.existsSync(a.default.join(n,`node_modules`,`.bin`,process.platform===`win32`?`lint-staged.cmd`:`lint-staged`))||c(`lint-staged`);if(!e||!t){let e=l(n);r.push(`Missing dependencies for hooks: commitlint and/or lint-staged.`),r.push(`Quick fix (${e}): ${u(e)}`)}}if(r.length>0){console.log(`
2
+ `);for(let e of r)t.log.warning(e);console.log(`
3
+ `)}},f=async(e,r)=>{let i=a.default.join(e,`.commit-type.cjs`),o=a.default.join(r,`.commit-type.cjs`);if(!await n.pathExists(i)){t.log.error(`source file ${i} does not exist`);return}await n.copyFileIfMissing(i,o)},p=async()=>{let e=__dirname,r=process.cwd(),o=a.default.join(e,`.gitscripts`),c=a.default.join(r,`.gitscripts`);await n.pathExists(o)?(await n.copyDirectoryRecursive(o,c),t.log.success(`.gitscripts create done.`)):t.log.error(`source directory ${o} does not exist`);for(let i of[`.gitconfig`]){let o=a.default.join(e,i),s=a.default.join(r,i);await n.pathExists(o)?await n.copyFileIfMissing(o,s):t.log.error(`source file ${o} does not exist`)}await f(e,r);try{i.default.chmodSync(a.default.join(c,`random-branch.sh`),493),t.log.success(`random-branch.sh Raise power`)}catch(e){console.log(e),t.log.error(`Set .gitscripts/random-branch.sh executable permission failed: ${e instanceof Error?e.message:String(e)}`)}let l=a.default.resolve(r,`.gitconfig`);s([`config`,`--local`,`--replace-all`,`include.path`,l],r,`Execute [git config --local --replace-all include.path ${l}] failed, please execute the command manually`)&&t.log.success(`.gitconfig git set`)},m=async()=>{let e=a.default.join(__dirname,`.githooks`),r=process.cwd(),o=a.default.join(r,`.githooks`);if(!await n.pathExists(e)){t.log.error(`source directory ${e} does not exist`);return}await n.copyDirectoryRecursive(e,o,!0),t.log.success(`.githooks create done.`),await f(__dirname,r);try{i.default.chmodSync(a.default.join(o,`commit-msg`),493),i.default.chmodSync(a.default.join(o,`pre-commit`),493),t.log.success(`commit-msg/pre-commit raise power done.`)}catch(e){console.log(e),t.log.error(`Set .githooks hooks executable permission failed: ${e instanceof Error?e.message:String(e)}`)}s([`config`,`--local`,`--replace-all`,`core.hooksPath`,`.githooks`],r,`Execute [git config --local --replace-all core.hooksPath .githooks] failed, please execute the command manually`)&&t.log.success(`git set .githooks done.`)},h=async()=>{let e=__dirname,r=process.cwd(),i=a.default.join(e,`.gitattributes`),o=a.default.join(r,`.gitattributes`);if(!await n.pathExists(i)){t.log.error(`source file ${i} does not exist`);return}await n.copyFileIfMissing(i,o)},g=async(e=[])=>{if(e.length===0){t.log.warning(`No Git feature selected, nothing to initialize.`);return}let n=process.cwd();if((e.includes(`gitflow`)||e.includes(`commitSubject`))&&!o(n)){t.log.error(`Current directory is not a Git repository. Please run this command in a Git project.`);return}d(e,n),e.includes(`gitflow`)&&await p(),e.includes(`commitSubject`)&&await m(),e.includes(`customGitCommand`)&&await h(),e.includes(`gitflow`)&&(console.log(`
2
4
  `),t.log.warning(`please run [git nb] command to create a new branch.`),console.log(`
3
- `)};exports.gitHandle=l;
5
+ `))};exports.gitHandle=g;
@@ -1 +1 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/index.cjs`);let n=require(`fs`);n=e.__toESM(n);let r=require(`path`);r=e.__toESM(r);const i=async e=>{await n.default.promises.mkdir(e,{recursive:!0})},a=async e=>{try{return await n.default.promises.access(e),!0}catch{return!1}},o=async(e,o)=>{if(await a(o)){t.log.info(`${r.default.basename(o)} Already exists, skip generation.`);return}await i(r.default.dirname(o)),await n.default.promises.copyFile(e,o),t.log.success(`${r.default.basename(o)} create done.`)},s=async(e,t)=>{if(!(await n.default.promises.stat(e)).isDirectory())throw Error(`${e} is not a directory`);await i(t);let a=await n.default.promises.readdir(e,{withFileTypes:!0});for(let n of a){let i=r.default.join(e,n.name),a=r.default.join(t,n.name);n.isDirectory()?await s(i,a):n.isFile()&&await o(i,a)}};exports.copyDirectoryRecursive=s,exports.copyFileIfMissing=o,exports.pathExists=a;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/index.cjs`);let n=require(`fs`);n=e.__toESM(n);let r=require(`path`);r=e.__toESM(r);const i=async e=>{await n.default.promises.mkdir(e,{recursive:!0})},a=async e=>{try{return await n.default.promises.access(e),!0}catch{return!1}},o=async(e,o)=>{if(await a(o)){t.log.info(`${r.default.basename(o)} Already exists, skip generation.`);return}await i(r.default.dirname(o)),await n.default.promises.copyFile(e,o),t.log.success(`${r.default.basename(o)} create done.`)},s=async(e,o,s=!1)=>{let c=await a(o);if(c&&!s){t.log.info(`${r.default.basename(o)} Already exists, skip generation.`);return}await i(r.default.dirname(o)),await n.default.promises.copyFile(e,o),t.log.success(`${r.default.basename(o)} ${c?`update done.`:`create done.`}`)},c=async(e,t,a=!1)=>{if(!(await n.default.promises.stat(e)).isDirectory())throw Error(`${e} is not a directory`);await i(t);let o=await n.default.promises.readdir(e,{withFileTypes:!0});for(let n of o){let i=r.default.join(e,n.name),o=r.default.join(t,n.name);n.isDirectory()?await c(i,o,a):n.isFile()&&await s(i,o,a)}};exports.copyDirectoryRecursive=c,exports.copyFileIfMissing=o,exports.pathExists=a;
package/lib/package.cjs CHANGED
@@ -1 +1 @@
1
- var e=`26.322.0`;Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return e}});
1
+ var e=`26.322.1`;Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return e}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anl",
3
- "version": "26.322.0",
3
+ "version": "26.322.1",
4
4
  "description": "FE command line tool",
5
5
  "main": "bin/an-cli.js",
6
6
  "publishConfig": {