mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 11:24:35 +00:00
40 lines
1010 B
TypeScript
40 lines
1010 B
TypeScript
import axios from 'axios'
|
|
import Downloader from 'nodejs-file-downloader'
|
|
import { createFile, listFilesInFolder } from '@sasjs/utils'
|
|
|
|
import { sasJSCoreMacros, sasJSCoreMacrosInfo } from '../src/utils/file'
|
|
|
|
export const downloadMacros = async () => {
|
|
const url =
|
|
'https://api.github.com/repos/yabwon/SAS_PACKAGES/contents/SPF/Macros'
|
|
|
|
console.info(`Downloading macros from ${url}`)
|
|
|
|
await axios
|
|
.get(url)
|
|
.then(async (res) => {
|
|
await downloadFiles(res.data)
|
|
})
|
|
.catch((err) => {
|
|
throw new Error(err)
|
|
})
|
|
}
|
|
|
|
const downloadFiles = async function (fileList: any) {
|
|
for (const file of fileList) {
|
|
const downloader = new Downloader({
|
|
url: file.download_url,
|
|
directory: sasJSCoreMacros,
|
|
fileName: file.path.replace(/^SPF\/Macros/, ''),
|
|
cloneFiles: false
|
|
})
|
|
await downloader.download()
|
|
}
|
|
|
|
const fileNames = await listFilesInFolder(sasJSCoreMacros)
|
|
|
|
await createFile(sasJSCoreMacrosInfo, fileNames.join('\n'))
|
|
}
|
|
|
|
downloadMacros()
|