Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(popup): RN #2614

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ console.log(argvs, 'argvs')
// 监视频率 https://www.martin-brennan.com/gulp-watch-high-cpu-usage/
const interval = { interval: 500 }
// 监视文件变化
gulp.task('watch', function () {
gulp.task('watch', () => {
argvs.forEach((argv) => {
gulp.watch(
`src/packages/${argv}/demos/taro/*`,
Expand All @@ -42,6 +42,11 @@ gulp.task('watch', function () {
interval,
gulp.series(`${argv}copyTaro`)
)
gulp.watch(
`src/packages/${argv}/${argv}.rn.tsx`,
interval,
gulp.series(`${argv}copyRN`)
)
})
const watchTasks = []
// eslint-disable-next-line array-callback-return
Expand All @@ -60,14 +65,14 @@ gulp.task('watch', function () {
})
argvs.forEach((argv) => {
const targetBaseUrl = `${process.cwd()}/packages/nutui-taro-demo/nutui-react/packages/${argv}`
gulp.task(`${argv}copyDemo`, function (path) {
gulp.task(`${argv}copyDemo`, (path) => {
console.log(path, 'path')
return gulp
.src(`src/packages/${argv}/demos/taro/*`)
.pipe(gulp.dest(`${targetBaseUrl}/demos/taro/`))
})

gulp.task(`${argv}sass`, function () {
gulp.task(`${argv}sass`, () => {
return gulp
.src([`src/packages/${argv}/${argv}.scss`])
.pipe(
Expand All @@ -94,7 +99,7 @@ argvs.forEach((argv) => {
.pipe(gulp.dest(`src/packages/${argv}/`))
})

gulp.task(`${argv}copyCss`, function () {
gulp.task(`${argv}copyCss`, () => {
return gulp
.src([
`src/packages/${argv}/*.scss`,
Expand All @@ -103,17 +108,23 @@ argvs.forEach((argv) => {
.pipe(gulp.dest(`${targetBaseUrl}/`))
})

gulp.task(`${argv}copyTaroDemo`, function () {
gulp.task(`${argv}copyTaroDemo`, () => {
return gulp
.src(`src/packages/${argv}/demo.taro.tsx`)
.pipe(insert.prepend(`import '../../../styles/demo.scss';\n`))
.pipe(gulp.dest(`${targetBaseUrl}/`))
})

gulp.task(`${argv}copyTaro`, function () {
gulp.task(`${argv}copyTaro`, () => {
return gulp
.src(`src/packages/${argv}/${argv}.taro.tsx`)
.pipe(insert.prepend(`import "./${argv}.harmony.css";\n`))
.pipe(gulp.dest(`${targetBaseUrl}/`))
})
gulp.task(`${argv}copyRN`, () => {
return gulp
.src(`src/packages/${argv}/${argv}.rn.tsx`)
.pipe(insert.prepend(`import "./${argv}.harmony.css";\n`))
.pipe(gulp.dest(`${targetBaseUrl}/`))
})
})
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@swc/core": "^1.4.8",
"@tarojs/components": "^4.0.0-alpha.34",
"@tarojs/plugin-platform-alipay": "^4.0.0-alpha.34",
"@tarojs/plugin-platform-weapp": "^4.0.0-alpha.34",
"@tarojs/react": "^4.0.0-alpha.34",
"@tarojs/taro": "^4.0.0-alpha.34",
"@tarojs/components": "4.0.2",
"@tarojs/plugin-platform-alipay": "4.0.2",
"@tarojs/plugin-platform-weapp": "4.0.2",
"@tarojs/react": "4.0.2",
"@tarojs/taro": "4.0.2",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^16.0.0",
"@types/fs-extra": "^11.0.4",
Expand Down Expand Up @@ -194,6 +194,7 @@
"react-color": "^2.19.3",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.1",
"react-native": "0.72.3",
"react-refresh": "^0.14.0",
"react-router-dom": "^6.22.1",
"react-syntax-highlighter": "^15.5.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/nutui-taro-demo/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ const config = {
'@/utils': path.resolve(__dirname, '../nutui-react/utils'),
'@nutui/nutui-react-taro': path.resolve(
__dirname,
'../nutui-react/packages/nutui.react.taro.ts'
'../nutui-react/packages/nutui.react.rn.ts'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

发现仍在使用旧的 Taro 实现 @nutui/nutui-react-taro

以下文件仍在引入 @nutui/nutui-react-taro,请确保这些引用已更新为新的 React Native 实现,以保持项目的一致性和正确性:

  • src/packages/form/demos/taro/demo7.tsx
  • src/packages/form/demos/taro/demo4.tsx
  • src/packages/form/demos/taro/demo6.tsx
  • src/packages/form/demos/taro/demo5.tsx
  • src/packages/form/demos/taro/demo3.tsx
  • (以及其他相关文件)
🔗 Analysis chain

更新了 @nutui/nutui-react-taro 的别名路径

这个更改将 @nutui/nutui-react-taro 的路径从 Taro 特定实现更改为 React Native 实现。

请确保以下几点:

  1. React Native 版本的实现已经完成并经过测试。
  2. 所有使用 @nutui/nutui-react-taro 的组件都与新的 RN 实现兼容。
  3. 项目文档已更新,反映了这一变化。
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否有任何文件仍在使用旧的 Taro 特定实现
rg --type js --type ts --type tsx "from\s+['\"]\@nutui/nutui-react-taro" -g '!config/*'

Length of output: 204


Script:

#!/bin/bash
# 检查是否有任何文件仍在使用旧的 Taro 特定实现 @nutui/nutui-react-taro
rg --type js --type ts --type tsx "from\s+['\"]@nutui/nutui-react-taro['\"]" -g '!config/*'

Length of output: 125


Script:

#!/bin/bash
# 检查是否有任何文件仍在使用旧的 Taro 特定实现 @nutui/nutui-react-taro
rg "from\s+['\"]@nutui/nutui-react-taro['\"]" -g '*.js' -g '*.ts' -g '*.tsx' -g '!config/*'

Length of output: 58615


Script:

#!/bin/bash
# 检查是否有任何文件仍在使用旧的 Taro 特定实现 @nutui/nutui-react-taro
rg "from\s+['\"]@nutui/nutui-react-taro['\"]" -g '*.js' -g '*.ts' -g '*.tsx' -g '!config/*'

Length of output: 58615

),
'@nutui/icons-react-taro': path.resolve(
__dirname,
'../nutui-react/packages/nutui.react.taro.ts'
'../nutui-react/packages/nutui.react.rn.ts'
),
'@styles': path.resolve(__dirname, '../styles'),
}
Expand Down
57 changes: 18 additions & 39 deletions packages/nutui-taro-demo/scripts/taro/generate-nutui-taro.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var glob = require('glob')
const path = require('path')
const fs = require('fs-extra')
let importStr = ``
let importRNStr = ``
let importMarkdownStr = ``
let importScssStr = `\n`
const packages = []
Expand All @@ -12,14 +13,17 @@ const raws = []

config.nav.map((item) => {
item.packages.forEach((element) => {
let { name, show, type, taro, exportEmpty, exclude, version } = element
let { name, show, type, taro, exportEmpty, exclude, version, rn } = element
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

建议为解构赋值添加默认值

在对 element 进行解构赋值时,rn 属性可能不存在,导致 rnundefined。建议为 rn 设置默认值,确保后续使用安全。

可以应用以下修改:

- let { name, show, type, taro, exportEmpty, exclude, version, rn } = element
+ let { name, show, type, taro, exportEmpty, exclude, version, rn = false } = element
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let { name, show, type, taro, exportEmpty, exclude, version, rn } = element
let { name, show, type, taro, exportEmpty, exclude, version, rn = false } = element

if (exclude) return
if (version !== '3.0.0') return // 不显示的不导出
if (version !== '3.0.0') return

importStr += `import ${name} from '@/packages/${name.toLowerCase()}/index.taro'\n`
importStr += `export * from '@/packages/${name.toLowerCase()}/index.taro'\n`
importRNStr += `import ${name} from '@/packages/${name.toLowerCase()}/index.${rn?'rn':'taro'}'\n`
importRNStr += `export * from '@/packages/${name.toLowerCase()}/index.${rn?'rn':'taro'}'\n`
Comment on lines +22 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

提取重复代码,增强可维护性

importStrimportRNStr 的生成逻辑存在重复,建议提取成函数,减少代码冗余,提高代码的可读性和可维护性。

可以重构为:

function generateImportStrings(name, type) {
  return `import ${name} from '@/packages/${name.toLowerCase()}/index.${type}'\nexport * from '@/packages/${name.toLowerCase()}/index.${type}'\n`;
}

importStr += generateImportStrings(name, 'taro');
importRNStr += generateImportStrings(name, rn ? 'rn' : 'taro');

importScssStr += `import '@/packages/${name.toLowerCase()}/${name.toLowerCase()}.harmony.css'\n`
packages.push(name)

glob
.sync(
path.join(__dirname, `../../nutui-react/packages/${name.toLowerCase()}/`) +
Expand All @@ -41,18 +45,6 @@ config.nav.map((item) => {
})
})

// let fileStrBuild = `${importStr}
// export { ${packages.join(',')} };`

// fs.outputFile(
// path.resolve(__dirname, '../../nutui-react/packages/nutui.react.build.taro.ts'),
// fileStrBuild,
// 'utf8',
// (error) => {
// if (error) throw error
// }
// )

let fileStr = `${importStr}
${importScssStr}
export { ${packages.join(',')} };`
Expand All @@ -65,6 +57,18 @@ fs.outputFile(
}
)

let fileRNStr = `${importRNStr}
${importScssStr}
export { ${packages.join(',')} };`
fs.outputFile(
path.resolve(__dirname, '../../nutui-react/packages/nutui.react.rn.ts'),
fileRNStr,
'utf8',
(error) => {
if (error) throw error
}
)

Comment on lines +60 to +71
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

封装文件输出逻辑,减少代码重复

多个文件的输出逻辑相似,建议封装成通用函数,避免代码重复,提高代码可维护性。

可以考虑如下重构:

function writeOutputFile(filePath, content) {
  fs.outputFile(
    path.resolve(__dirname, filePath),
    content,
    'utf8',
    (error) => {
      if (error) throw error;
    }
  );
}

writeOutputFile('../../nutui-react/packages/nutui.react.taro.ts', fileStr);
writeOutputFile('../../nutui-react/packages/nutui.react.rn.ts', fileRNStr);

let taroScssfileStr = `
${importScssStr}
export default { "NutUI":"NutUI-Taro" };`
Expand All @@ -76,28 +80,3 @@ fs.outputFile(
if (error) throw error
}
)

// fs.outputFile(
// path.resolve(__dirname, '../../nutui-react/packages/nutui.react.scss.ts'),
// importScssStr,
// 'utf8',
// (error) => {
// if (error) throw error
// }
// )

// let mdFileStr = `${importMarkdownStr}
// export const routers = [${mds.map((m) => `'${m}'`)}]
// export const raws = {${raws.join(',')}}
// `

// fs.outputFile(
// path.resolve(__dirname, '../../src/sites/doc/docs.taro.ts'),
// mdFileStr,
// 'utf8',
// (error) => {
// if (error) throw error
// }
// )


Loading