MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / copyIfExists

Function copyIfExists

src/lib/yargs-transition-temp.ts:38–75  ·  view source on GitHub ↗
(
		options: {
			filename: string
			oldDir: string
			newDir: string
			description?: string // when omitted, user is not notified (omit for CLI-managed files)
			verboseLogging: boolean
		},
)

Source from the content-addressed store, hash-verified

36}
37
38export const copyIfExists = async (
39 options: {
40 filename: string
41 oldDir: string
42 newDir: string
43 description?: string // when omitted, user is not notified (omit for CLI-managed files)
44 verboseLogging: boolean
45 },
46): Promise<void> => {
47 const { filename, oldDir, newDir, description, verboseLogging } = options
48 if (oldDir === newDir) {
49 // in some situations, the directory might not change
50 if (verboseLogging) {
51 console.error(`old and new directories (${oldDir}) are the same for ${filename}`)
52 }
53 return
54 }
55 const oldFilename = join(oldDir, filename)
56 const newFilename = join(newDir, filename)
57 const oldExists = await isFile(oldFilename)
58 const newExists = await isFile(newFilename)
59 if (oldExists && !newExists) {
60 if (verboseLogging) {
61 console.error(`found old file ${filename} in ${oldDir}; copying to ${newDir}`)
62 }
63 await ensureDir(newDir)
64 await copyFile(oldFilename, newFilename)
65 if (description) {
66 console.warn(`found old ${description} file ${oldFilename} and copied it to ${newFilename}\n` +
67 `from version 2.0, the CLI will use ${newFilename} for ${description}`)
68 }
69 } else if (verboseLogging) {
70 console.error(
71 `not copying ${filename} from ${oldDir} to ${newDir}; ` +
72 `oldExists=${oldExists}; newExists=${newExists}`,
73 )
74 }
75}

Calls 2

isFileFunction · 0.85
ensureDirFunction · 0.85

Tested by

no test coverage detected