@scandipwa/magento-scripts 2.4.5-alpha.0 → 2.4.6-alpha.0

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.
@@ -25,32 +25,39 @@ if [ -z "$CHANGED_FILES" ]; then
25
25
  exit 0
26
26
  fi
27
27
 
28
+ # Extract the first directory name from changed composer files
29
+ CHANGED_DIR=$(basename "$(git rev-parse --show-toplevel)")
30
+
31
+ # Get branch names from refs
32
+ OLD_BRANCH=$(git name-rev --name-only "$OLD_REF" 2>/dev/null | sed 's/^remotes\///' || echo "$OLD_REF")
33
+ NEW_BRANCH=$(git name-rev --name-only "$NEW_REF" 2>/dev/null | sed 's/^remotes\///' || echo "$NEW_REF")
34
+
28
35
  MESSAGE_TITLE="Composer dependencies changed"
29
- MESSAGE_BODY="Detected changes in:\n$CHANGED_FILES\n\nPlease run: composer install"
36
+ MESSAGE_BODY="Changes detected in: $CHANGED_DIR\nBranch: $OLD_BRANCH → $NEW_BRANCH\n\nPlease run composer install or npm run start"
30
37
 
31
38
  # Cross-platform desktop notification with multiple fallbacks
32
39
  send_notification() {
33
40
  local title="$1"
34
41
  local body="$2"
35
-
42
+
36
43
  # Try Linux notify-send first
37
44
  if command -v notify-send >/dev/null 2>&1; then
38
45
  notify-send -u normal -t 8000 "$title" "$body"
39
46
  return 0
40
47
  fi
41
-
48
+
42
49
  # Try macOS terminal-notifier
43
50
  if command -v terminal-notifier >/dev/null 2>&1; then
44
51
  terminal-notifier -title "$title" -message "$body" -timeout 8
45
52
  return 0
46
53
  fi
47
-
54
+
48
55
  # Try macOS osascript (AppleScript) as fallback
49
56
  if command -v osascript >/dev/null 2>&1; then
50
57
  osascript -e "display notification \"$body\" with title \"$title\""
51
58
  return 0
52
59
  fi
53
-
60
+
54
61
  # Final fallback to stdout
55
62
  echo "$title"
56
63
  echo "$body"
@@ -1,58 +1,112 @@
1
1
  const path = require('path')
2
2
  const fs = require('fs')
3
3
  const UnknownError = require('../../errors/unknown-error')
4
- const setConfigFile = require('../../util/set-config')
5
4
  const { execAsyncSpawn } = require('../../util/exec-async-command')
5
+ const pathExists = require('../../util/path-exists')
6
+
7
+ /**
8
+ * @param {string} p
9
+ */
10
+ function isExec(p) {
11
+ try {
12
+ fs.accessSync(p, fs.constants.X_OK)
13
+ return true
14
+ } catch (e) {
15
+ return false
16
+ }
17
+ }
6
18
 
7
19
  /**
8
20
  * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
9
21
  */
10
22
  const createGitHookNotification = () => ({
11
- title: 'Setting git hook notification',
12
- task: async (ctx) => {
23
+ title: 'Setting Git Hook Notification',
24
+ task: async (ctx, task) => {
13
25
  const gitHookTemplatePath = path.join(
14
26
  ctx.config.baseConfig.templateDir,
15
27
  'git-postcheckout-hook.template'
16
28
  )
17
29
 
18
- const gitRoot = await execAsyncSpawn('git rev-parse --show-toplevel')
30
+ const [gitRootResult, currentGitHookPathResult] = await Promise.all([
31
+ execAsyncSpawn('git rev-parse --show-toplevel', {
32
+ withCode: true
33
+ }),
34
+ execAsyncSpawn(`git config --get core.hooksPath`, {
35
+ withCode: true
36
+ })
37
+ ])
19
38
 
20
- let currentGitHookPath = await execAsyncSpawn(
21
- `git config --get core.hooksPath`
22
- )
39
+ if (currentGitHookPathResult.code !== 0) {
40
+ throw new UnknownError(
41
+ `Unexpected error accrued during git hook notification creation\n\n${currentGitHookPathResult.result}`
42
+ )
43
+ }
44
+
45
+ if (gitRootResult.code !== 0) {
46
+ throw new UnknownError(
47
+ `Unexpected error accrued during git hook notification creation\n\n${gitRootResult.result}`
48
+ )
49
+ }
50
+
51
+ const tasks = []
23
52
 
24
- if (!currentGitHookPath.trim()) {
25
- await execAsyncSpawn(`git config core.hooksPath .git/hooks`)
53
+ if (!currentGitHookPathResult.result.trim()) {
54
+ tasks.push({
55
+ title: 'Setting Git Hook Path',
56
+ task: async () => {
57
+ const { code } = await execAsyncSpawn(
58
+ `git config core.hooksPath .git/hooks`,
59
+ {
60
+ withCode: true
61
+ }
62
+ )
26
63
 
27
- currentGitHookPath = '.git/hooks'
64
+ if (code !== 0) {
65
+ throw new UnknownError(
66
+ `Unexpected error accrued during git hook notification creation\n\n${code}`
67
+ )
68
+ }
69
+
70
+ currentGitHookPathResult.result = '.git/hooks'
71
+ }
72
+ })
28
73
  }
29
74
 
30
75
  const gitHookPath = path.join(
31
- gitRoot,
32
- currentGitHookPath,
76
+ gitRootResult.result,
77
+ currentGitHookPathResult.result.trim(),
33
78
  'post-checkout'
34
79
  )
35
80
 
36
- try {
37
- await setConfigFile({
38
- configPathname: gitHookPath,
39
- template: gitHookTemplatePath,
40
- overwrite: false
81
+ if (!(await pathExists(gitHookPath))) {
82
+ tasks.push({
83
+ title: 'Copying Git Hook Template',
84
+ task: async () => {
85
+ await fs.promises.cp(gitHookTemplatePath, gitHookPath)
86
+ }
41
87
  })
42
- } catch (e) {
43
- throw new UnknownError(
44
- `Unexpected error accrued during git hook notification creation\n\n${e}`
45
- )
46
88
  }
47
89
 
48
90
  // check if gitHookPath is executable
49
- const isExecutable = await fs.promises.stat(gitHookPath)
50
- if (isExecutable.mode & 0o111) {
51
- return
91
+ const isExecutable = isExec(gitHookPath)
92
+ if (!isExecutable) {
93
+ tasks.push({
94
+ title: 'Making Git Hook Executable',
95
+ task: async () => {
96
+ await execAsyncSpawn(`chmod +x ${gitHookPath}`, {
97
+ withCode: true
98
+ })
99
+ }
100
+ })
52
101
  }
53
102
 
54
- await execAsyncSpawn(`chmod +x ${gitHookPath}`)
55
- }
103
+ if (tasks.length > 0) {
104
+ return task.newListr(tasks)
105
+ }
106
+
107
+ task.skip()
108
+ },
109
+ exitOnError: false
56
110
  })
57
111
 
58
112
  module.exports = createGitHookNotification
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "2.4.5-alpha.0",
6
+ "version": "2.4.6-alpha.0",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -59,5 +59,5 @@
59
59
  "@types/node": "^20.14.11",
60
60
  "@types/yargs": "^17.0.32"
61
61
  },
62
- "gitHead": "6d3f49a587a3db183e9f89dc936e8c7357accac3"
62
+ "gitHead": "8d5f2908a9e9f3c929625794ec00214de4045b5f"
63
63
  }