Skip to content

Commit

Permalink
chore(script): 简化开发环境启动逻辑 (#1264)
Browse files Browse the repository at this point in the history
* chore(scriptt): 简化开发环境启动逻辑

* chore(script): 调整 taro demo 生成逻辑
  • Loading branch information
eiinu authored Jul 28, 2023
1 parent 8eca985 commit 672c262
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 39 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"add": "node scripts/create-component-mode.js",
"add": "node scripts/create-component-mode.js && npm run prepare",
"generate:file": "node scripts/generate-nutui.js",
"generate:themes": "node scripts/generate-themes.js",
"generate:themes-dev": "node scripts/generate-themes-dev.js",
"checked": "npm run generate:file && tsc --project ./tsconfig.h5.json",
"dev": "npm run checked && vite --open --force",
"dev:jmapp": "npm run checked && VITE_APP_PROJECT_ID=jmapp vite --open --force",
"dev": "vite --open --force",
"dev:jmapp": "VITE_APP_PROJECT_ID=jmapp vite --open --force",
"dev:theme": "npm run generate:themes-dev && npm run checked && vite --force --config vite.config.theme.ts",
"replace:scss": "node scripts/replace-scss-alias.js",
"build:loader-style": "node scripts/generate-loader-style.js",
Expand All @@ -66,15 +66,15 @@
"lint": "eslint ./src/packages",
"lint:fix": "eslint --fix ./src/packages",
"publish:beta": "npm publish --tag beta",
"prepare": "husky install",
"prepare": "husky install && npm run generate:file && npm run generate:file:taro && npm run generate:file:taro:pages",
"test": "jest",
"generate:file:taro": "node scripts/taro/generate-nutui-taro.js",
"checked:taro": "npm run generate:file:taro && tsc --project ./tsconfig.taro.json",
"generate:file:taro:pages": "node scripts/taro/generate-taro-pages.js",
"dev:taro:weapp": "npm run checked:taro && npm run generate:file:taro:pages && cd ./src/sites/mobile-taro && npm run dev:weapp",
"dev:taro:jd": "npm run checked:taro && npm run generate:file:taro:pages && cd ./src/sites/mobile-taro && npm run dev:jd",
"dev:taro:h5": "npm run checked:taro && npm run generate:file:taro:pages && cd ./src/sites/mobile-taro && npm run dev:h5",
"dev:taro:weapp:jmapp": "npm run checked:taro && VITE_APP_PROJECT_ID=jmapp npm run generate:file:taro:pages && cd ./src/sites/mobile-taro && npm run dev:weapp:jmapp",
"dev:taro:weapp": "cd ./src/sites/mobile-taro && npm run dev:weapp",
"dev:taro:jd": "cd ./src/sites/mobile-taro && npm run dev:jd",
"dev:taro:h5": "cd ./src/sites/mobile-taro && npm run dev:h5",
"dev:taro:weapp:jmapp": "cd ./src/sites/mobile-taro && npm run dev:weapp:jmapp",
"build:taro": "npm run checked:taro && node scripts/create-theme-typings.js && vite build --config vite.config.build.taro.ts && npm run build:taro:es && npm run build:css && npm run build:loader-style && npm run build:component:css && npm run build:locales && TARO=1 node scripts/add-comments-to-dts.js",
"build:taro:es": "vite build --config vite.config.build.disperse.taro.ts",
"build:taro:jmapp": "npm run checked:taro && VITE_APP_PROJECT_ID=jmapp node scripts/create-theme-typings.js && vite build --config vite.config.build.taro.ts && npm run build:taro:es && VITE_APP_PROJECT_ID=jmapp npm run build:css && VITE_APP_PROJECT_ID=jmapp npm run build:loader-style && VITE_APP_PROJECT_ID=jmapp npm run build:component:css && npm run build:locales && TARO=1 node scripts/add-comments-to-dts.js",
Expand Down
47 changes: 16 additions & 31 deletions scripts/taro/generate-taro-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,22 @@ const createIndexConfig = (enName, package) => {
resolve(`生成index.config.ts文件成功`)
})

// 拷贝demo
const fileDemoPath = path.resolve(dirPath, `index.tsx`)
let demoPath = `src/packages/${nameLc}/demo.taro.tsx`
fse.readFile(demoPath, (err, data) => {
if (!err) {
let fileString = data.toString()
const lines = fileString.split('\n')
const reg =
/import{1,}[\w\s\S]+(\'@\/packages\/nutui\.react\.taro\'){1,}/g
let fileStrArr = fileString.match(reg)
fileStrArr = fileStrArr[0].split('import')
// let importScssStr = ''
// for (let i = 0, lens = fileStrArr.length; i < lens; i++) {
// if (fileStrArr[i].indexOf('@/packages/nutui.react.taro') != -1) {
// let str = fileStrArr[i]
// str = str.substring(str.indexOf('{') + 1, str.indexOf('}'))
// let strs = str.split(',')
// strs.forEach((namestr) => {
// namestr = namestr.trim()
// namestr &&
// (importScssStr += `import '@/packages/${namestr.toLowerCase()}/${namestr.toLowerCase()}.scss';\n`)
// })
// }
// }
// lines.splice(1, 0, importScssStr)
fileString = lines.join('\n')
fsExtra.outputFile(fileDemoPath, fileString, 'utf8', (error) => {
if (error) console.log('Error', error)
// console.log(`文件写入成功`)
})
}
// 生成 demo
const demoContent = `import Demo from '@/packages/${nameLc}/demo.taro';
export default Demo;`
const demoDirPath = path.join(
__dirname,
`../../src/sites/mobile-taro/src/${enName}/pages/${nameLc}`
)
const demoFilePath = path.join(demoDirPath, `index.tsx`)
if (!fs.existsSync(demoDirPath)) {
fs.mkdirSync(demoDirPath, { recursive: true }, (err) => {
console.log('mkdir error', err)
})
}
fs.writeFile(demoFilePath, demoContent, (err) => {
if (err) { throw err }
resolve(`生成 index.tsx 文件成功`)
})
}
})
Expand Down

0 comments on commit 672c262

Please sign in to comment.