Browse Source
* chore: compile es only
* chore: update package.json
* chore: code clean
* chore: code clean
* chore: update workflow
* chore: update workflow
* chore: update less src
* chore: replace lib with es
* chore: recover less
* Revert "chore: replace lib with es"
This reverts commit 41b8bf1938
.
* chore: update dist less
* test: fix
pull/36381/head
MadCcc
2 years ago
committed by
GitHub
7 changed files with 52 additions and 146 deletions
@ -1,62 +1,46 @@ |
|||||
/* eslint-disable import/no-unresolved,no-console */ |
/* eslint-disable import/no-unresolved,no-console,global-require,import/no-dynamic-require */ |
||||
|
|
||||
const chalk = require('chalk'); |
const chalk = require('chalk'); |
||||
const React = require('react'); |
const React = require('react'); |
||||
const ReactDOMServer = require('react-dom/server'); |
const ReactDOMServer = require('react-dom/server'); |
||||
const fs = require('fs-extra'); |
const fs = require('fs-extra'); |
||||
const antd = require('../lib'); |
const glob = require('glob'); |
||||
const { statistic } = require('../lib/theme/util/statistic'); |
const path = require('path'); |
||||
const useMessageStyle = require('../lib/message/style/index').default; |
const { statistic } = require('../components/theme/util/statistic'); |
||||
const useNotificationStyle = require('../lib/notification/style/index').default; |
|
||||
|
|
||||
console.log(chalk.green(`🔥 Collecting token statistics...`)); |
console.log(chalk.green(`🔥 Collecting token statistics...`)); |
||||
// Automatic rendering
|
|
||||
Object.entries(antd).forEach(([key, component]) => { |
|
||||
if ( |
|
||||
/[A-Z]/.test(key.charAt(0)) && |
|
||||
key !== 'Form' && |
|
||||
key !== 'Dropdown' && |
|
||||
key !== 'Grid' && |
|
||||
key !== 'ConfigProvider' |
|
||||
) { |
|
||||
ReactDOMServer.renderToString(React.createElement(component)); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
const EmptyElement = React.createElement('div'); |
const EmptyElement = React.createElement('div'); |
||||
|
|
||||
// Dropdown
|
const styleFiles = glob.sync( |
||||
ReactDOMServer.renderToString( |
path.join( |
||||
React.createElement(antd.Dropdown, { overlay: EmptyElement }, EmptyElement), |
process.cwd(), |
||||
|
'components/!(version|config-provider|icon|locale-provider|auto-complete|col|row|page-header|comment|time-picker|)/style/index.tsx', |
||||
|
), |
||||
); |
); |
||||
|
styleFiles.forEach(file => { |
||||
// Form
|
console.log(file); |
||||
ReactDOMServer.renderToString(React.createElement(antd.Form, undefined, EmptyElement)); |
let useStyle = () => {}; |
||||
|
if (file.includes('grid')) { |
||||
// message
|
const { useColStyle, useRowStyle } = require(file); |
||||
const Message = () => { |
useStyle = () => { |
||||
useMessageStyle('message'); |
useRowStyle(); |
||||
return EmptyElement; |
useColStyle(); |
||||
}; |
}; |
||||
ReactDOMServer.renderToString(React.createElement(Message)); |
} else { |
||||
|
useStyle = require(file).default; |
||||
// Notification
|
} |
||||
const Notification = () => { |
const Component = () => { |
||||
useNotificationStyle('notification'); |
useStyle('file'); |
||||
return EmptyElement; |
return EmptyElement; |
||||
}; |
}; |
||||
ReactDOMServer.renderToString(React.createElement(Notification)); |
ReactDOMServer.renderToString(React.createElement(Component)); |
||||
|
}); |
||||
|
|
||||
(async () => { |
(async () => { |
||||
const libPath = `${process.cwd()}/lib/theme/util/statistic.js`; |
const tokenPath = `${process.cwd()}/components/version/token.tsx`; |
||||
const libContent = await fs.readFile(libPath, 'utf8'); |
const content = `export default ${JSON.stringify(statistic, null, 2)}`; |
||||
const newLibContent = `${libContent}\nexports._statistic_build_ = ${JSON.stringify(statistic)}`; |
await fs.writeFile(tokenPath, content, 'utf8'); |
||||
await fs.writeFile(libPath, newLibContent, 'utf8'); |
|
||||
|
|
||||
const esPath = `${process.cwd()}/es/theme/util/statistic.js`; |
|
||||
const esContent = await fs.readFile(esPath, 'utf8'); |
|
||||
const newEsContent = `${esContent}\n_statistic_build_ = ${JSON.stringify(statistic)}`; |
|
||||
await fs.writeFile(esPath, newEsContent, 'utf8'); |
|
||||
|
|
||||
console.log(chalk.green(`✅ Collecting token statistics done.`)); |
console.log(chalk.green(`✅ Collecting token statistics done.`)); |
||||
})(); |
})(); |
||||
|
@ -1,65 +0,0 @@ |
|||||
const $ = require('dekko'); |
|
||||
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/style').isDirectory().hasFile('index.css').hasFile('default.css'); |
|
||||
|
|
||||
$('lib/*') |
|
||||
.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('theme') && |
|
||||
!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') && |
|
||||
!fileName.endsWith('context.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'); |
|
||||
|
|
||||
// eslint-disable-next-line no-console
|
|
||||
console.log(chalk.green('✨ `lib` directory is valid.')); |
|
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"extends": "./tsconfig.json", |
||||
|
"compilerOptions": { |
||||
|
"module": "CommonJS", |
||||
|
"types": ["node"] |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue