fix or disable linting in fs-helper
There is a bit of a catch-22 bere where the createArchives function should not use .then and .catch in favour of async/await according to the linter, but can't use async/await because it's discouraged to make new promise executor functions async. There is a hacky workaround to make this work, but it seems like it isn't worth making the code more fragmented, so i just disabled the linter for these lines.
This commit is contained in:
+45
-35
@@ -35,43 +35,53 @@ export async function createArchives(
|
|||||||
const zipPath = path.join(archiveTargetPath, `archive.zip`)
|
const zipPath = path.join(archiveTargetPath, `archive.zip`)
|
||||||
const tarPath = path.join(archiveTargetPath, `archive.tar.gz`)
|
const tarPath = path.join(archiveTargetPath, `archive.tar.gz`)
|
||||||
|
|
||||||
return Promise.all([
|
const createZipPromise = new Promise<FileMetadata>((resolve, reject) => {
|
||||||
new Promise<FileMetadata>((resolve, reject) => {
|
const output = fs.createWriteStream(zipPath)
|
||||||
const output = fs.createWriteStream(zipPath)
|
const archive = archiver.create('zip')
|
||||||
const archive = archiver.create('zip')
|
|
||||||
|
|
||||||
output.on('error', (err: Error) => {
|
output.on('error', (err: Error) => {
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
|
||||||
|
|
||||||
archive.on('error', (err: Error) => {
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
output.on('close', () => {
|
|
||||||
resolve(fileMetadata(zipPath))
|
|
||||||
})
|
|
||||||
|
|
||||||
archive.pipe(output)
|
|
||||||
archive.directory(distPath, false)
|
|
||||||
archive.finalize()
|
|
||||||
}),
|
|
||||||
new Promise<FileMetadata>((resolve, reject) => {
|
|
||||||
tar
|
|
||||||
.c(
|
|
||||||
{
|
|
||||||
file: tarPath,
|
|
||||||
C: distPath, // Change to the source directory for relative paths (TODO)
|
|
||||||
gzip: true
|
|
||||||
},
|
|
||||||
['.']
|
|
||||||
)
|
|
||||||
.then(() => {
|
|
||||||
resolve(fileMetadata(tarPath))
|
|
||||||
})
|
|
||||||
.catch((err: Error) => reject(err))
|
|
||||||
})
|
})
|
||||||
]).then(([zipFile, tarFile]) => ({ zipFile, tarFile }))
|
|
||||||
|
archive.on('error', (err: Error) => {
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
output.on('close', () => {
|
||||||
|
resolve(fileMetadata(zipPath))
|
||||||
|
})
|
||||||
|
|
||||||
|
archive.pipe(output)
|
||||||
|
archive.directory(distPath, false)
|
||||||
|
archive.finalize()
|
||||||
|
})
|
||||||
|
|
||||||
|
const createTarPromise = new Promise<FileMetadata>((resolve, reject) => {
|
||||||
|
tar
|
||||||
|
.c(
|
||||||
|
{
|
||||||
|
file: tarPath,
|
||||||
|
C: distPath, // Change to the source directory for relative paths (TODO)
|
||||||
|
gzip: true
|
||||||
|
},
|
||||||
|
['.']
|
||||||
|
)
|
||||||
|
// eslint-disable-next-line github/no-then
|
||||||
|
.catch(err => {
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
|
// eslint-disable-next-line github/no-then
|
||||||
|
.then(() => {
|
||||||
|
resolve(fileMetadata(tarPath))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const [zipFile, tarFile] = await Promise.all([
|
||||||
|
createZipPromise,
|
||||||
|
createTarPromise
|
||||||
|
])
|
||||||
|
|
||||||
|
return { zipFile, tarFile }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDirectory(dirPath: string): boolean {
|
export function isDirectory(dirPath: string): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user