ant-design/tests/dekko/lib.test.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

const $ = require('dekko');
2018-12-23 17:45:31 +08:00
const chalk = require('chalk');
const path = require('path');
function getFileName(filePath) {
return filePath.slice(filePath.lastIndexOf(path.sep) + 1);
}
$('lib')
.isDirectory()
.hasFile('index.js')
.hasFile('index.d.ts');
$('lib/*')
2019-07-18 15:13:23 +08:00
.filter(
filename =>
!filename.endsWith('index.js') &&
!filename.endsWith('index.d.ts') &&
!filename.endsWith('.map'),
)
.isDirectory()
.filter(
filename =>
!filename.endsWith('style') && !filename.endsWith('_util') && !filename.endsWith('locale'),
)
.hasFile('index.js')
.hasFile('index.d.ts')
.hasDirectory('style');
$('lib/*/style')
.hasFile('css.js')
.hasFile('index.js');
// locale
const filterLocaleFile = filePath => {
const fileName = getFileName(filePath);
return (
!fileName.endsWith('index.js') &&
!fileName.endsWith('.d.ts') &&
!fileName.endsWith('.map') &&
!fileName.endsWith('style') &&
!fileName.includes('-') &&
!fileName.endsWith('LocaleReceiver.js')
);
};
const localeFiles = $('lib/locale/*').filter(filterLocaleFile);
const localeProviderFiles = $('lib/locale-provider/*').filter(filterLocaleFile);
function compare(originFiles, targetFiles, targetPath) {
originFiles.assert(
`not exist in '${targetPath}'. Please use 'scripts/generateLegacyLocale.js' to refresh locale files.`,
filePath => {
const fileName = getFileName(filePath);
return targetFiles.filenames.some(targetFilePath => getFileName(targetFilePath) === fileName);
},
);
}
compare(localeFiles, localeProviderFiles, '/locale-provider');
compare(localeProviderFiles, localeFiles, '/locale');
2016-12-11 14:01:14 +08:00
// eslint-disable-next-line
2018-12-23 17:45:31 +08:00
console.log(chalk.green('✨ `lib` directory is valid.'));