🌳
pt0/deployF/viteAppF/submoduleTarAI.mts
10import { tsAbsPath } from '../../ptDirF.mts'
11import { execSync } from 'child_process'
13export const submoduleTarPath = async ({submodulePtPath}: {submodulePtPath: string}) => {
14 const submoduleAbsPath = `${ptDir}/${submodulePtPath}`
16 const gitShaInSubmodule = execSync('git rev-parse HEAD', {cwd: submoduleAbsPath, encoding: 'utf8'}).trim()
17 const tarHash = calcReqHash([submodulePtPath, gitShaInSubmodule, '1'])
19 const tarFileName = `submodule-${submodulePtPath.replace(/\//g, '-')}-${tarHash}.tar.gz`
20 const tarFilePtPath = `tmpdockertars/${tarFileName}`
22 if (await fileExists(tsAbsPath(tarFilePtPath))) {
23 if (isVeryVerbose) console.log(chalkGreen('cacheHit submodule tar!'), tarFilePtPath)
24 } else {
25 mkdirParentP(tarFilePtPath)
26 if (isVeryVerbose) console.log(chalkYellow('writing submodule tar..'), tarFilePtPath)
30 '-zcvf', `${ptDir}/${tarFilePtPath}`,
31 '-C', ptDir,
32 '--exclude', 'node_modules',
33 '--exclude', '.git',
34 submodulePtPath,
35 ], {env: {...process.env, GZIP: '-n'}})
36 }
38 const dfCpTarStr = [
39 `# submodule: ${submodulePtPath}`,
40 `ADD ${tarFilePtPath} .`,
41 `#^ ${humanBytes(await fileSizeBytes(tsAbsPath(tarFilePtPath)))}`,
42 ].join("\n") + "\n"
44 const tarSpec = { type: 'submodule', tarPath: tarFilePtPath, submodulePath: submodulePtPath }
46 return {dfCpTarStr, tarSpec}