🌳
pt0/deployF/ptDeployActions/diffCoreAI.mts
1import { styleText } from 'node:util'
10export const runDiffCore = async ({colorOutput, diffcmd = 'git diff', logLimit, rangeless}: {colorOutput?: (s: string) => Promise<string>, diffcmd?: string, logLimit?: number, rangeless?: boolean} = {}) => {
11 const appConfig = getAppCfg()
12 const {pathsA} = await getRakeEpsPaths({defaultEpScope: epScopes.dockerjs})
14 const diffResult = await appDeployDiff({
15 ...appConfig,
16 filterPathList: pathsA,
17 diffcmd,
18 logLimit,
19 rangeless,
20 })
21 let {stdout, isNameOnly} = diffResult
22 const {existingGitSha, newGitSha, lastDeployCommitsAgo, lastDeployDurAgo} = diffResult
24 if (diffcmd === 'git log') {
25 const deployedSha = appConfig.existingGitSha
26 if (deployedSha) {
27 const lines = stdout.split('\n')
28 const deployedIdx = lines.findIndex(l => {
29 const stripped = l.replace(/\x1b\[[0-9;]*m/g, '')
30 const shaOnLine = stripped.split(' ')[0]
31 return deployedSha.startsWith(shaOnLine) && shaOnLine.length >= 7
32 })
33 if (deployedIdx >= 0) {
34 lines.splice(deployedIdx, 0, `──── [deployed: ${deployedSha.slice(0, 7)}] ────`)
35 stdout = lines.join('\n')
36 }
37 }
38 }
40 if (isNameOnly && colorOutput) {
41 const coloredStdout = await colorOutput(stdout)
42 console.log(coloredStdout)
43 } else {
44 console.log(stdout)
45 }
47 if (diffcmd !== 'git log') await getHowImports()
48 if (existingGitSha) betLog('appDeployDiff', {existingGitSha, newGitSha, lastDeployCommitsAgo, lastDeployDurAgo})
49 printEpScopeHint({defaultEpScope: epScopes.dockerjs})
52export const diff = async () => {
53 await runDiffCore()
55diff.needsLazyDocker = true
56diff.cliSchema = scopeCli
57diff.cliAcceptsPositional = true
58diff.cliDescript = {
59 cliDefaultOpt: epScopes.dockerjs,
60 cliOptA: getEpScopeOptA,
61 cliSupportsEpScopes: true,
62 cliExplain: `git diff from ${styleText('yellow', 'deployed sha')} to ${styleText('green', 'HEAD')}`