@wyxos/zephyr 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.mjs +49 -6
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -20,6 +20,33 @@ const logSuccess = (message = '') => console.log(chalk.green(message))
|
|
|
20
20
|
const logWarning = (message = '') => console.warn(chalk.yellow(message))
|
|
21
21
|
const logError = (message = '') => console.error(chalk.red(message))
|
|
22
22
|
|
|
23
|
+
let logFilePath = null
|
|
24
|
+
|
|
25
|
+
async function getLogFilePath(rootDir) {
|
|
26
|
+
if (logFilePath) {
|
|
27
|
+
return logFilePath
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const configDir = getProjectConfigDir(rootDir)
|
|
31
|
+
await ensureDirectory(configDir)
|
|
32
|
+
|
|
33
|
+
const now = new Date()
|
|
34
|
+
const dateStr = now.toISOString().replace(/:/g, '-').replace(/\..+/, '')
|
|
35
|
+
logFilePath = path.join(configDir, `${dateStr}.log`)
|
|
36
|
+
|
|
37
|
+
return logFilePath
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function writeToLogFile(rootDir, message) {
|
|
41
|
+
const logPath = await getLogFilePath(rootDir)
|
|
42
|
+
const timestamp = new Date().toISOString()
|
|
43
|
+
await fs.appendFile(logPath, `${timestamp} - ${message}\n`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function closeLogFile() {
|
|
47
|
+
logFilePath = null
|
|
48
|
+
}
|
|
49
|
+
|
|
23
50
|
const createSshClient = () => {
|
|
24
51
|
if (typeof globalThis !== 'undefined' && globalThis.__zephyrSSHFactory) {
|
|
25
52
|
return globalThis.__zephyrSSHFactory()
|
|
@@ -795,15 +822,23 @@ async function runRemoteTasks(config, options = {}) {
|
|
|
795
822
|
|
|
796
823
|
const result = await ssh.execCommand(wrappedCommand, execOptions)
|
|
797
824
|
|
|
798
|
-
|
|
799
|
-
|
|
825
|
+
// Log all output to file
|
|
826
|
+
if (result.stdout && result.stdout.trim()) {
|
|
827
|
+
await writeToLogFile(rootDir, `[${label}] STDOUT:\n${result.stdout.trim()}`)
|
|
800
828
|
}
|
|
801
829
|
|
|
802
830
|
if (result.stderr && result.stderr.trim()) {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
831
|
+
await writeToLogFile(rootDir, `[${label}] STDERR:\n${result.stderr.trim()}`)
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// Only show errors in terminal
|
|
835
|
+
if (result.code !== 0) {
|
|
836
|
+
if (result.stdout && result.stdout.trim()) {
|
|
837
|
+
logError(`\n[${label}] Output:\n${result.stdout.trim()}`)
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
if (result.stderr && result.stderr.trim()) {
|
|
841
|
+
logError(`\n[${label}] Error:\n${result.stderr.trim()}`)
|
|
807
842
|
}
|
|
808
843
|
}
|
|
809
844
|
|
|
@@ -1022,9 +1057,17 @@ async function runRemoteTasks(config, options = {}) {
|
|
|
1022
1057
|
}
|
|
1023
1058
|
|
|
1024
1059
|
logSuccess('\nDeployment commands completed successfully.')
|
|
1060
|
+
|
|
1061
|
+
const logPath = await getLogFilePath(rootDir)
|
|
1062
|
+
logSuccess(`\nAll task output has been logged to: ${logPath}`)
|
|
1025
1063
|
} catch (error) {
|
|
1064
|
+
const logPath = logFilePath || await getLogFilePath(rootDir).catch(() => null)
|
|
1065
|
+
if (logPath) {
|
|
1066
|
+
logError(`\nTask output has been logged to: ${logPath}`)
|
|
1067
|
+
}
|
|
1026
1068
|
throw new Error(`Deployment failed: ${error.message}`)
|
|
1027
1069
|
} finally {
|
|
1070
|
+
await closeLogFile()
|
|
1028
1071
|
ssh.dispose()
|
|
1029
1072
|
}
|
|
1030
1073
|
}
|