Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions packages/toolkit/scripts/build/copyFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,41 @@ function copy(task: CopyTask): void {
}
}

function copySageMakerSshKiroExtension(): void {
function moveSageMakerSshKiroExtension(): void {
const searchDir = path.resolve(projectRoot, '../../')
const destinationDir = path.resolve(outRoot, '../resources')

fs.mkdirSync(destinationDir, { recursive: true })

const files = fs
.readdirSync(searchDir)
.filter((file) => file.startsWith('sagemaker-ssh-kiro') && file.endsWith('.vsix'))
const isSageMakerSshKiroVsix = (file: string) => file.startsWith('sagemaker-ssh-kiro') && file.endsWith('.vsix')

if (files.length !== 1) {
throw new Error(`Expected 1 sagemaker-ssh-kiro VSIX file but found ${files.length}`)
// Remove all existing sagemaker-ssh-kiro files in the destination directory. This prevents multiple
// sagemaker-ssh-kiro VSIX files being present in the destination if the version number has changed.
const existingFilesInDestination = fs.readdirSync(destinationDir).filter(isSageMakerSshKiroVsix)

for (const file of existingFilesInDestination) {
const filePath = path.join(destinationDir, file)
fs.unlinkSync(filePath)
}

const sourceFiles = fs.readdirSync(searchDir).filter(isSageMakerSshKiroVsix)

if (sourceFiles.length !== 1) {
throw new Error(`Expected 1 sagemaker-ssh-kiro VSIX file but found ${sourceFiles.length}`)
}

const sourceFile = path.join(searchDir, files[0])
const destinationFile = path.join(destinationDir, files[0])
const sourceFile = path.join(searchDir, sourceFiles[0])
const destinationFile = path.join(destinationDir, sourceFiles[0])

fs.copyFileSync(sourceFile, destinationFile)
// Move (rather than copy) the sagemaker-ssh-kiro VSIX file to the toolkit resources directory so it's
// no longer at the top level, since we don't want to release it standalone (it should be embedded only).
fs.renameSync(sourceFile, destinationFile)
}

function main() {
try {
tasks.map(copy)
copySageMakerSshKiroExtension()
moveSageMakerSshKiroExtension()
} catch (error) {
console.error('`copyFiles.ts` failed')
console.error(error)
Expand Down
Loading