2020-08-06 19:17:38 +00:00
|
|
|
import {
|
|
|
|
readDirSync,
|
|
|
|
isPathExistsSync
|
|
|
|
} from "../common/filesystem";
|
|
|
|
import { CheckStepInterface, ActionInterface } from "./interface";
|
|
|
|
import {
|
|
|
|
chainsPath,
|
|
|
|
getChainLogoPath,
|
|
|
|
getChainAssetsPath,
|
|
|
|
getChainAssetPath,
|
2020-09-16 13:32:23 +00:00
|
|
|
getChainAssetLogoPath,
|
|
|
|
getChainAssetInfoPath,
|
2020-08-06 19:17:38 +00:00
|
|
|
assetFolderAllowedFiles,
|
|
|
|
getChainFolderFilesList,
|
|
|
|
chainFolderAllowedFiles,
|
|
|
|
rootDirAllowedFiles
|
|
|
|
} from "../common/repo-structure";
|
|
|
|
import { isLogoOK } from "../common/image";
|
|
|
|
import { isLowerCase } from "../common/types";
|
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
|
|
|
|
const foundChains = readDirSync(chainsPath)
|
|
|
|
|
|
|
|
export class FoldersFiles implements ActionInterface {
|
|
|
|
getName(): string { return "Folders and Files"; }
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getSanityChecks(): CheckStepInterface[] {
|
2020-08-06 19:17:38 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
getName: () => { return "Repository root dir"},
|
|
|
|
check: async () => {
|
2020-09-16 12:52:10 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
const dirActualFiles = readDirSync(".");
|
|
|
|
dirActualFiles.forEach(file => {
|
|
|
|
if (!(rootDirAllowedFiles.indexOf(file) >= 0)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`File "${file}" should not be in root or added to predifined list`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errors, []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
getName: () => { return "Chain folders are lowercase, contain only predefined list of files"},
|
|
|
|
check: async () => {
|
2020-09-16 12:52:10 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
foundChains.forEach(chain => {
|
|
|
|
if (!isLowerCase(chain)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Chain folder must be in lowercase "${chain}"`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
getChainFolderFilesList(chain).forEach(file => {
|
|
|
|
if (!(chainFolderAllowedFiles.indexOf(file) >= 0)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`File '${file}' not allowed in chain folder: ${chain}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errors, []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
getName: () => { return "Chain folders have logo, and correct size"},
|
|
|
|
check: async () => {
|
2020-09-16 12:52:10 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(foundChains, async (chain) => {
|
|
|
|
const chainLogoPath = getChainLogoPath(chain);
|
|
|
|
if (!isPathExistsSync(chainLogoPath)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`File missing at path "${chainLogoPath}"`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
const [isOk, error1] = await isLogoOK(chainLogoPath);
|
|
|
|
if (!isOk) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(error1);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errors, []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
},
|
2020-09-16 13:32:23 +00:00
|
|
|
{
|
|
|
|
getName: () => { return "Asset folders contain logo"},
|
|
|
|
check: async () => {
|
|
|
|
var errors: string[] = [];
|
|
|
|
foundChains.forEach(chain => {
|
|
|
|
const assetsPath = getChainAssetsPath(chain);
|
|
|
|
if (isPathExistsSync(assetsPath)) {
|
|
|
|
readDirSync(assetsPath).forEach(address => {
|
|
|
|
const logoFullPath = getChainAssetLogoPath(chain, address);
|
|
|
|
if (!isPathExistsSync(logoFullPath)) {
|
|
|
|
errors.push(`Missing logo file for asset '${chain}/${address}' -- ${logoFullPath}`);
|
|
|
|
}
|
|
|
|
}) ;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return [errors, []];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
getName: () => { return "Asset folders contain info.json"},
|
|
|
|
check: async () => {
|
|
|
|
var warnings: string[] = [];
|
|
|
|
foundChains.forEach(chain => {
|
|
|
|
const assetsPath = getChainAssetsPath(chain);
|
|
|
|
if (isPathExistsSync(assetsPath)) {
|
|
|
|
readDirSync(assetsPath).forEach(address => {
|
|
|
|
const infoFullPath = getChainAssetInfoPath(chain, address);
|
|
|
|
if (!isPathExistsSync(infoFullPath)) {
|
|
|
|
warnings.push(`Missing info file for asset '${chain}/${address}' -- ${infoFullPath}`);
|
|
|
|
}
|
|
|
|
}) ;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return [[], warnings];
|
|
|
|
}
|
|
|
|
},
|
2020-08-06 19:17:38 +00:00
|
|
|
{
|
|
|
|
getName: () => { return "Asset folders contain only predefined set of files"},
|
|
|
|
check: async () => {
|
2020-09-16 12:52:10 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
foundChains.forEach(chain => {
|
|
|
|
const assetsPath = getChainAssetsPath(chain);
|
|
|
|
if (isPathExistsSync(assetsPath)) {
|
|
|
|
readDirSync(assetsPath).forEach(address => {
|
2020-09-16 13:32:23 +00:00
|
|
|
const assetFiles = getChainAssetPath(chain, address);
|
2020-08-06 19:17:38 +00:00
|
|
|
readDirSync(assetFiles).forEach(assetFolderFile => {
|
|
|
|
if (!(assetFolderAllowedFiles.indexOf(assetFolderFile) >= 0)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`File '${assetFolderFile}' not allowed at this path: ${assetsPath}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}) ;
|
|
|
|
}
|
|
|
|
});
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errors, []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
2020-09-16 13:32:23 +00:00
|
|
|
}
|
2020-08-06 19:17:38 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getConsistencyChecks = null;
|
|
|
|
|
|
|
|
sanityFix = null;
|
|
|
|
|
|
|
|
consistencyFix = null;
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
update = null;
|
|
|
|
}
|