-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add css variables content for api docs (#2182)
* fix: resolved some spelling mistake * chore: add css variables content for api docs
- Loading branch information
Showing
121 changed files
with
2,088 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const combine = { | ||
avatar: ['avatar-group', 'avatar'], | ||
cell: ['cell-group', 'cell'], | ||
collapse: ['collapse', 'collapse-panel'], | ||
'dropdown-menu': ['dropdown-menu', 'dropdown-item'], | ||
tag: ['tag', 'check-tag'], | ||
checkbox: ['checkbox-group', 'checkbox'], | ||
indexes: ['indexes', 'indexes-anchor'], | ||
picker: ['picker', 'picker-item'], | ||
radio: ['radio-group', 'radio'], | ||
'side-bar': ['side-bar', 'side-bar-item'], | ||
steps: ['steps', 'step-item'], | ||
swiper: ['swiper', 'swiper-nav'], | ||
tabs: ['tabs', 'tab-panel'], | ||
'tab-bar': ['tab-bar', 'tab-bar-item'], | ||
grid: ['grid', 'grid-item'], | ||
}; | ||
|
||
function resolveCwd(...args) { | ||
args.unshift(process.cwd()); | ||
return path.join(...args); | ||
} | ||
|
||
const COMPONENT_NAME = process.argv[process.argv.indexOf('--NAME') + 1]; // 在 --NAME 后面 | ||
|
||
// eslint-disable-next-line | ||
const matchReg = /(?<=var).*?(?=\;)/g; | ||
|
||
// 使用 v2 文件夹下 _var.less 文件 | ||
const lessPath = []; | ||
if (combine[COMPONENT_NAME]) { | ||
combine[COMPONENT_NAME].forEach((item) => { | ||
lessPath.push(resolveCwd(`src/${item}/${item}.less`)); | ||
}); | ||
} else { | ||
lessPath.push(resolveCwd(`src/${COMPONENT_NAME}/${COMPONENT_NAME}.less`)); | ||
} | ||
|
||
// 追加到文件 | ||
const cssVariableHeadContent = `\n\n### CSS 变量\n组件提供了下列 CSS 变量,可用于自定义样式。\n名称 | 默认值 | 描述 \n-- | -- | --\n`; | ||
const cssVariableHeadContentEn = `\n\n### CSS Variables\nThe component provides the following CSS variables, which can be used to customize styles.\nName | Default Value | Description \n-- | -- | --\n`; | ||
|
||
fs.appendFileSync(resolveCwd(`src/${COMPONENT_NAME}/README.md`), cssVariableHeadContent); | ||
fs.appendFileSync(resolveCwd(`src/${COMPONENT_NAME}/README.en-US.md`), cssVariableHeadContentEn); | ||
|
||
// 读取 less 文件内容 | ||
lessPath.forEach((item) => { | ||
if (fs.existsSync(item)) { | ||
fs.readFile(item, 'utf8', (err, file) => { | ||
if (err) { | ||
console.log('please execute npm run update:css first!', err); | ||
return; | ||
} | ||
const list = file.match(matchReg)?.sort(); | ||
let cssVariableBodyContent = ''; | ||
list?.forEach((item) => { | ||
cssVariableBodyContent += `${item.slice(1, item.indexOf(','))} | ${item.slice( | ||
item.indexOf(',') + 2, | ||
item.length - 1, | ||
)} | - \n`; | ||
}); | ||
fs.appendFileSync(resolveCwd(`src/${COMPONENT_NAME}/README.md`), cssVariableBodyContent); | ||
fs.appendFileSync(resolveCwd(`src/${COMPONENT_NAME}/README.en-US.md`), cssVariableBodyContent); | ||
}); | ||
} | ||
}); |
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
Oops, something went wrong.