mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-23 11:59:34 +08:00
fix replaceAll is undefined (#3024)
This commit is contained in:
parent
f4bad47cd5
commit
a3d0d05d82
69
build/build-indices.ts
Normal file
69
build/build-indices.ts
Normal file
@ -0,0 +1,69 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
'use strict'
|
||||
|
||||
import fs from 'fs'
|
||||
import algoliasearch from 'algoliasearch'
|
||||
import { slugify } from 'transliteration'
|
||||
import fg from 'fast-glob'
|
||||
|
||||
const algoliaKey = process.env.ALGOLIA_KEY
|
||||
|
||||
const client = algoliasearch('7DCTSU0WBW', algoliaKey)
|
||||
const langs = {
|
||||
'zh-CN': 'element-zh',
|
||||
'en-US': 'element-en',
|
||||
es: 'element-es',
|
||||
'fr-FR': 'element-fr',
|
||||
jp: 'element-jp',
|
||||
}
|
||||
;['zh-CN', 'en-US', 'es', 'fr-FR', 'jp'].forEach(lang => {
|
||||
const indexName = langs[lang]
|
||||
const index = client.initIndex(indexName)
|
||||
index.clearObjects().then(() => {
|
||||
const files = fg.sync(`website/docs/${lang}/*.md`)
|
||||
let indices = []
|
||||
files.forEach(file => {
|
||||
const regExp = new RegExp(`website\/docs\/${lang}\/(.*).md`)
|
||||
const pathContent = file.match(regExp)
|
||||
const path = pathContent[1]
|
||||
const index = path.lastIndexOf('/')
|
||||
const names = index !== -1 ? path.split('/') : []
|
||||
const component = names.length ? names[names.length - 1] : path
|
||||
const content = fs.readFileSync(file, 'utf8')
|
||||
const matches = content
|
||||
.replace(/:::[\s\S]*?:::/g, '')
|
||||
.replace(/```[\s\S]*?```/g, '')
|
||||
.match(/#{2,4}[^#]*/g)
|
||||
.map(match =>
|
||||
match
|
||||
.replace(/\n+/g, '\n')
|
||||
.split('\n')
|
||||
.filter(part => !!part),
|
||||
)
|
||||
.map(match => {
|
||||
const length = match.length
|
||||
if (length > 2) {
|
||||
const desc = match.slice(1, length).join('')
|
||||
return [match[0], desc]
|
||||
}
|
||||
return match
|
||||
})
|
||||
let i = 0
|
||||
indices = indices.concat(
|
||||
matches.map(match => {
|
||||
const title = match[0].replace(/#{2,4}/, '').trim()
|
||||
const index = { component, title }
|
||||
index.anchor = slugify(title)
|
||||
index.content = (match[1] || title).replace(/<[^>]+>/g, '')
|
||||
index.path = path
|
||||
index.sort = i++
|
||||
return index
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
index.saveObjects(indices, {
|
||||
autoGenerateObjectIDIfNotExist: true,
|
||||
})
|
||||
})
|
||||
})
|
@ -112,9 +112,9 @@ const genVueTypes = async (root, outDir = path.resolve(__dirname, '../dist/types
|
||||
await fs.promises.writeFile(filepath,
|
||||
outputFile
|
||||
.getText()
|
||||
.replaceAll('@element-plus/components', 'element-plus/es')
|
||||
.replaceAll('@element-plus/theme-chalk', 'element-plus/theme-chalk')
|
||||
.replaceAll('@element-plus', 'element-plus/es'),
|
||||
.replace(new RegExp('@element-plus/components', 'g'), 'element-plus/es')
|
||||
.replace(new RegExp('@element-plus/theme-chalk', 'g'), 'element-plus/theme-chalk')
|
||||
.replace(new RegExp('@element-plus', 'g'), 'element-plus/es'),
|
||||
'utf8')
|
||||
console.log(
|
||||
chalk.green(
|
||||
|
@ -47,7 +47,7 @@ const gen = async () => {
|
||||
await fs.promises.writeFile(filepath,
|
||||
outputFile
|
||||
.getText()
|
||||
.replaceAll('@element-plus', '.'),
|
||||
.replace(new RegExp('@element-plus', 'g'), '.'),
|
||||
// .replaceAll('@element-plus/theme-chalk', 'element-plus/theme-chalk'),
|
||||
'utf8')
|
||||
console.log(
|
||||
|
@ -2,12 +2,12 @@ import through2 from 'through2'
|
||||
|
||||
const rewriter = (rewriteTo = '../..') => {
|
||||
return through2.obj(function(file, _, cb) {
|
||||
const compIdentifier = '@element-plus'
|
||||
const compIdentifier = new RegExp('@element-plus', 'g')
|
||||
|
||||
file.contents = Buffer.from(
|
||||
file.contents
|
||||
.toString()
|
||||
.replaceAll(compIdentifier, rewriteTo),
|
||||
.replace(compIdentifier, rewriteTo),
|
||||
)
|
||||
cb(null, file)
|
||||
})
|
||||
|
@ -14,15 +14,15 @@ const tsProject = ts.createProject('tsconfig.json', {
|
||||
|
||||
const rewriter = () => {
|
||||
return through2.obj(function(file, _, cb) {
|
||||
const compIdentifier = '@element-plus/components'
|
||||
const compIdentifier = new RegExp('@element-plus/components', 'g')
|
||||
const compReplacer = '../../../components'
|
||||
const themeIdentifier = '@element-plus/theme-chalk'
|
||||
const themeIdentifier = new RegExp('@element-plus/theme-chalk', 'g')
|
||||
const themeReplacer = '../../../../theme-chalk'
|
||||
file.contents = Buffer.from(
|
||||
file.contents
|
||||
.toString()
|
||||
.replaceAll(compIdentifier, compReplacer)
|
||||
.replaceAll(themeIdentifier, themeReplacer),
|
||||
.replace(compIdentifier, compReplacer)
|
||||
.replace(themeIdentifier, themeReplacer),
|
||||
)
|
||||
cb(null, file)
|
||||
})
|
||||
|
@ -13,7 +13,7 @@
|
||||
"build:esm-bundle": "rollup --config ./build/rollup.config.bundle.js && yarn build:type",
|
||||
"build:locale-umd": "esno ./build/build-locale.ts",
|
||||
"build:helper": "esno build/build-helper.ts",
|
||||
"build:indices": "node build/build-indices.js",
|
||||
"build:indices": "esno build/build-indices.ts",
|
||||
"update:version": "esno build/update-version.ts",
|
||||
"build:comps": "rimraf dist/components && esno build/components.ts",
|
||||
"build:style": "gulp --cwd ./build",
|
||||
|
Loading…
Reference in New Issue
Block a user