@scandipwa/magento-scripts 2.4.5 → 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.
|
@@ -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
|
|
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
|
|
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
|
-
|
|
21
|
-
|
|
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 (!
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
76
|
+
gitRootResult.result,
|
|
77
|
+
currentGitHookPathResult.result.trim(),
|
|
33
78
|
'post-checkout'
|
|
34
79
|
)
|
|
35
80
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 =
|
|
50
|
-
if (isExecutable
|
|
51
|
-
|
|
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
|
-
|
|
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.
|
|
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": "
|
|
62
|
+
"gitHead": "8d5f2908a9e9f3c929625794ec00214de4045b5f"
|
|
63
63
|
}
|