-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tabarra:develop' into develop
- Loading branch information
Showing
160 changed files
with
3,296 additions
and
2,248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,40 @@ | ||
import path from 'node:path'; | ||
import fse from 'fs-extra'; | ||
import { canWriteToPath, getPathFiles } from '@lib/fs'; | ||
|
||
|
||
/** | ||
* Check if its possible to create a file in a folder | ||
*/ | ||
const canCreateFile = async (targetPath: string) => { | ||
try { | ||
const filePath = path.join(targetPath, '.empty'); | ||
await fse.outputFile(filePath, '#save_attempt_please_ignore'); | ||
await fse.remove(filePath); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; | ||
//File created up to v7.3.2 | ||
const EMPTY_FILE_NAME = '.empty'; | ||
|
||
|
||
/** | ||
* Perform deployer local target path permission/emptiness checking | ||
* FIXME: timeout to remove folders, or just autoremove them idk | ||
* Perform deployer local target path permission/emptiness checking. | ||
*/ | ||
export const validateTargetPath = async (deployPath: string) => { | ||
if (await fse.pathExists(deployPath)) { | ||
const pathFiles = await fse.readdir(deployPath); | ||
if (pathFiles.some((x) => x !== '.empty')) { | ||
throw new Error('This folder is not empty!'); | ||
} else { | ||
if (await canCreateFile(deployPath)) { | ||
return 'Exists, empty, and writtable!'; | ||
} else { | ||
throw new Error('Path exists, but its not a folder, or its not writtable.'); | ||
} | ||
} | ||
} else { | ||
if (await canCreateFile(deployPath)) { | ||
await fse.remove(deployPath); | ||
return 'Path didn\'t existed, we created one (then deleted it).'; | ||
} else { | ||
throw new Error('Path doesn\'t exist, and we could not create it. Please check parent folder permissions.'); | ||
const canCreateFolder = await canWriteToPath(deployPath); | ||
if(!canCreateFolder) { | ||
throw new Error('Path is not writable due to missing permissions or invalid path.'); | ||
} | ||
try { | ||
const pathFiles = await getPathFiles(deployPath); | ||
if (pathFiles.some((x) => x.name !== EMPTY_FILE_NAME)) { | ||
throw new Error('This folder already exists and is not empty!'); | ||
} | ||
} catch (error) { | ||
if ((error as any).code !== 'ENOENT') throw error; | ||
} | ||
return true as const; | ||
}; | ||
|
||
|
||
/** | ||
* Create a template recipe file | ||
*/ | ||
export const makeTemplateRecipe = (serverName: string, author: string) => `name: ${serverName} | ||
author: ${author} | ||
# This is just a placeholder, please don't run it! | ||
tasks: | ||
- action: waste_time | ||
seconds: 5 | ||
- action: waste_time | ||
seconds: 5 | ||
`; | ||
export const makeTemplateRecipe = (serverName: string, author: string) => [ | ||
`name: ${serverName}`, | ||
`author: ${author}`, | ||
'', | ||
'# This is just a placeholder, please don\'t use it!', | ||
'tasks: ', | ||
' - action: waste_time', | ||
' seconds: 5', | ||
' - action: waste_time', | ||
' seconds: 5', | ||
].join('\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.