2020-08-06 19:17:38 +00:00
|
|
|
import {
|
|
|
|
readDirSync,
|
|
|
|
isPathExistsSync
|
2020-09-23 13:47:24 +00:00
|
|
|
} from "../generic/filesystem";
|
|
|
|
import { CheckStepInterface, ActionInterface } from "../generic/interface";
|
2020-08-06 19:17:38 +00:00
|
|
|
import {
|
2020-10-19 22:51:47 +00:00
|
|
|
allChains,
|
2021-02-26 11:39:39 +00:00
|
|
|
dappsPath,
|
2020-08-06 19:17:38 +00:00
|
|
|
getChainLogoPath,
|
2021-02-08 09:28:04 +00:00
|
|
|
getChainAssetInfoPath,
|
2020-08-06 19:17:38 +00:00
|
|
|
getChainAssetsPath,
|
|
|
|
getChainAssetPath,
|
2020-09-16 13:32:23 +00:00
|
|
|
getChainAssetLogoPath,
|
2020-08-06 19:17:38 +00:00
|
|
|
assetFolderAllowedFiles,
|
|
|
|
getChainFolderFilesList,
|
|
|
|
chainFolderAllowedFiles,
|
|
|
|
rootDirAllowedFiles
|
2020-09-23 13:47:24 +00:00
|
|
|
} from "../generic/repo-structure";
|
|
|
|
import { isLogoOK } from "../generic/image";
|
|
|
|
import { isLowerCase } from "../generic/types";
|
2021-07-08 15:40:16 +00:00
|
|
|
import { readJsonFile } from "../generic/json";
|
2020-08-06 19:17:38 +00:00
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
|
|
|
|
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-18 14:39:31 +00:00
|
|
|
const 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-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
2020-10-19 22:51:47 +00:00
|
|
|
allChains.forEach(chain => {
|
2020-08-06 19:17:38 +00:00
|
|
|
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-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
2020-10-19 22:51:47 +00:00
|
|
|
await bluebird.each(allChains, async (chain) => {
|
2020-08-06 19:17:38 +00:00
|
|
|
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
|
|
|
{
|
2021-02-08 09:28:04 +00:00
|
|
|
getName: () => { return "Asset folders contain logo and info"},
|
2020-09-16 13:32:23 +00:00
|
|
|
check: async () => {
|
2020-09-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
2021-02-08 09:28:04 +00:00
|
|
|
const warnings: string[] = [];
|
2020-10-19 22:51:47 +00:00
|
|
|
allChains.forEach(chain => {
|
2020-09-16 13:32:23 +00:00
|
|
|
const assetsPath = getChainAssetsPath(chain);
|
|
|
|
if (isPathExistsSync(assetsPath)) {
|
|
|
|
readDirSync(assetsPath).forEach(address => {
|
|
|
|
const logoFullPath = getChainAssetLogoPath(chain, address);
|
2021-07-08 15:40:16 +00:00
|
|
|
const logoExists = isPathExistsSync(logoFullPath);
|
2021-02-08 09:28:04 +00:00
|
|
|
const infoFullPath = getChainAssetInfoPath(chain, address);
|
2021-07-08 15:40:16 +00:00
|
|
|
const infoExists = isPathExistsSync(infoFullPath);
|
|
|
|
// Assets should have a logo and an info file. Exceptions:
|
|
|
|
// - status=spam tokens may have no logo
|
|
|
|
// - on some chains some valid tokens have no info (should be fixed)
|
|
|
|
if (!infoExists || !logoExists) {
|
|
|
|
if (!infoExists && logoExists) {
|
|
|
|
const msg = `Missing info file for asset '${chain}/${address}' -- ${infoFullPath}`;
|
|
|
|
// enforce that info must be present (with some exceptions)
|
2021-07-13 15:39:58 +00:00
|
|
|
if (chain === 'classic' || chain === 'poa' || chain === 'terra') {
|
2021-07-08 15:40:16 +00:00
|
|
|
//console.log(msg);
|
|
|
|
warnings.push(msg);
|
|
|
|
} else {
|
|
|
|
console.log(msg);
|
|
|
|
errors.push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!logoExists && infoExists) {
|
|
|
|
const info: unknown = readJsonFile(infoFullPath);
|
|
|
|
if (!info['status'] || info['status'] !== 'spam') {
|
|
|
|
const msg = `Missing logo file for non-spam asset '${chain}/${address}' -- ${logoFullPath}`;
|
|
|
|
console.log(msg);
|
|
|
|
errors.push(msg);
|
|
|
|
}
|
2021-05-20 10:10:48 +00:00
|
|
|
}
|
2021-02-08 09:28:04 +00:00
|
|
|
}
|
2021-02-26 11:39:39 +00:00
|
|
|
});
|
2020-09-16 13:32:23 +00:00
|
|
|
}
|
|
|
|
});
|
2021-02-08 09:28:04 +00:00
|
|
|
return [errors, warnings];
|
2020-09-16 13:32:23 +00:00
|
|
|
}
|
|
|
|
},
|
2020-09-18 14:43:43 +00:00
|
|
|
/*
|
2020-09-16 13:32:23 +00:00
|
|
|
{
|
|
|
|
getName: () => { return "Asset folders contain info.json"},
|
|
|
|
check: async () => {
|
2020-09-18 14:39:31 +00:00
|
|
|
const warnings: string[] = [];
|
2020-10-19 22:51:47 +00:00
|
|
|
allChains.forEach(chain => {
|
2020-09-16 13:32:23 +00:00
|
|
|
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}`);
|
|
|
|
}
|
2021-02-26 11:39:39 +00:00
|
|
|
});
|
2020-09-16 13:32:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return [[], warnings];
|
|
|
|
}
|
|
|
|
},
|
2020-09-18 14:43:43 +00:00
|
|
|
*/
|
2020-08-06 19:17:38 +00:00
|
|
|
{
|
|
|
|
getName: () => { return "Asset folders contain only predefined set of files"},
|
|
|
|
check: async () => {
|
2020-09-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
2020-10-19 22:51:47 +00:00
|
|
|
allChains.forEach(chain => {
|
2020-08-06 19:17:38 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2021-02-26 11:39:39 +00:00
|
|
|
});
|
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
|
|
|
}
|
2021-02-26 11:39:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
getName: () => { return "Dapps folders contain only .png files, with all lowercase names"},
|
|
|
|
check: async () => {
|
|
|
|
const errors: string[] = [];
|
|
|
|
if (isPathExistsSync(dappsPath)) {
|
|
|
|
readDirSync(dappsPath).forEach(filename => {
|
|
|
|
if (!filename.endsWith('.png')) {
|
|
|
|
errors.push(`File '${filename}' has invalid extension; ${dappsPath}`);
|
|
|
|
}
|
|
|
|
if (filename.toLowerCase() != filename) {
|
|
|
|
errors.push(`File '${filename}' is not all-lowercase; ${dappsPath}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return [errors, []];
|
|
|
|
}
|
2020-09-16 13:32:23 +00:00
|
|
|
}
|
2020-08-06 19:17:38 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|