diff --git a/.github/workflows/release-beta.yml b/.github/workflows/release-beta.yml new file mode 100644 index 0000000000..e60387b7e8 --- /dev/null +++ b/.github/workflows/release-beta.yml @@ -0,0 +1,82 @@ +name: Release 3x Beta + +on: +# pull_request: + push: + branches: + - feat_v3.x + workflow_dispatch: + +jobs: + release-3x-beta: + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_CONFIG_PROVENANCE: true + RELEASE_TAG: beta + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 +# ref: ${{ github.event.pull_request.head.sha }} + + - name: Get commit message + run: | + COMMIT_MESSAGE=$(git log --format=%s -n 1) + FILTERED_MESSAGE="${COMMIT_MESSAGE//[^a-zA-Z0-9.()_:, -]/}" + echo "COMMIT_MESSAGE=${FILTERED_MESSAGE}" >> $GITHUB_ENV + - name: Show commit message + run: echo "$COMMIT_MESSAGE" + + - name: Commit message compliance verification + if: | + !startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) || + !contains( env.COMMIT_MESSAGE , '-beta' ) + run: echo "ABORT=true" >> $GITHUB_ENV + + - name: Get Tag message + if: contains( env.COMMIT_MESSAGE , '-beta') + run: echo "RELEASE_TAG=beta" >> $GITHUB_ENV + + - name: Install pnpm + run: npm install -g pnpm@v9 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'pnpm' + + - name: Install dependencies + if: env.ABORT != 'true' + run: pnpm install --no-frozen-lockfile + + - name: Run Build + if: env.ABORT != 'true' + run: | + if ! pnpm build; then + echo "构建 nutui-react 失败" + exit 1 + fi + if ! pnpm build:taro; then + echo "构建 nutui-react-taro 失败" + exit 1 + fi + + - name: Run Release @nutui/nutui-react + if: env.ABORT != 'true' + run: | + cd ./release/h5 || exit 1 + if ! npm publish --tag ${{ env.RELEASE_TAG }}; then + echo "发布 @nutui/nutui-react 失败" + exit 1 + fi + + - name: Run Releases @nutui/nutui-react-taro + if: env.ABORT != 'true' + run: | + cd ./release/taro || exit 1 + if ! npm publish --tag ${{ env.RELEASE_TAG }}; then + echo "发布 @nutui/nutui-react-taro 失败" + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..f2088b3a85 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: Release 3.x + +on: + push: + tags: + - v3.* + workflow_dispatch: + +jobs: + release-3x: + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + NPM_CONFIG_PROVENANCE: true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install pnpm + run: npm install -g pnpm@v9 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --no-frozen-lockfile + + - name: Run Build + if: env.ABORT != 'true' + run: | + if ! pnpm build; then + echo "构建 nutui-react 失败" + exit 1 + fi + if ! pnpm build:taro; then + echo "构建 nutui-react-taro 失败" + exit 1 + fi + + - name: Run Release @nutui/nutui-react + if: env.ABORT != 'true' + run: | + cd ./release/h5 || exit 1 + if ! npm publish --tag ${{ env.RELEASE_TAG }}; then + echo "发布 @nutui/nutui-react 失败" + exit 1 + fi + + - name: Run Releases @nutui/nutui-react-taro + if: env.ABORT != 'true' + run: | + cd ./release/taro || exit 1 + if ! npm publish --tag ${{ env.RELEASE_TAG }}; then + echo "发布 @nutui/nutui-react-taro 失败" + exit 1 + fi diff --git a/.gitignore b/.gitignore index f56e3aa29f..41837b6758 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node_modules .npmrc /dist /dist-demo +/release /libs /jd/upload.js # yarn.lock diff --git a/package.json b/package.json index a587ddfa5f..d03a31592d 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/jdf2e/nutui-react.git" + "url": "git+https://github.com/jdf2e/nutui-react.git" }, "files": [ "dist", @@ -77,9 +77,7 @@ "generate:file:taro:pages": "node scripts/taro/generate-taro-pages.js", "lint": "eslint ./src/packages/*/", "lint:fix": "eslint --fix ./src/packages", - "postpublish": "node scripts/postpublish.js", "prepare": "husky && npm run generate:file && npm run generate:file:taro && npm run generate:file:taro:pages", - "prepublishOnly": "node scripts/prepublish.js", "publish:beta": "npm publish --tag beta", "test": "vitest --coverage", "test:ui": "vitest --ui --coverage", diff --git a/scripts/build-comments-to-dts.mjs b/scripts/build-comments-to-dts.mjs index f944e2a249..ac54b0a62e 100644 --- a/scripts/build-comments-to-dts.mjs +++ b/scripts/build-comments-to-dts.mjs @@ -10,6 +10,7 @@ import { dirname } from 'path' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) +const dist = 'release/h5/dist' /** * 通过 cofnig.json 获取所有组件的数据 @@ -135,7 +136,7 @@ function addComments(dtsPath, propsTable, componentName) { } } -function getDtsPath(key) { +function getDtsPath(key, outDir) { // Tabs.Tabpane -> tabpane let name if (key === 'Tabs.Tabpane') { @@ -143,7 +144,7 @@ function getDtsPath(key) { } else { name = key.toLowerCase().replace('.', '') } - const file = path.join(__dirname, '../dist/es/packages', name, name + '.d.ts') + const file = path.join(__dirname, `../${outDir}/es/packages`, name, name + '.d.ts') return file } @@ -170,14 +171,14 @@ export function codeShift(env) { __dirname, '../src/packages', name.toLowerCase(), - env === 'Taro' ? 'doc.taro.md' : 'doc.md' + env === 'taro' ? 'doc.taro.md' : 'doc.md' ) if (fse.pathExistsSync(componentDocumentPath)) { const tables = extractPropsTable( readComponentDocument(componentDocumentPath) ) Object.keys(tables).forEach((key) => { - const dtsPath = getDtsPath(key) + const dtsPath = getDtsPath(key, env !== 'taro' ? dist : dist.replace('h5', env)) if (fse.pathExistsSync(dtsPath)) { const table = markdownTable2Json(tables[key]) addComments(dtsPath, table, getComponentName(key)) diff --git a/scripts/build-taro.mjs b/scripts/build-taro.mjs index 9391a6fda6..e141dc0f3c 100644 --- a/scripts/build-taro.mjs +++ b/scripts/build-taro.mjs @@ -15,9 +15,11 @@ import { readFileSync } from 'fs' import { relativeFilePath } from './relative-path.mjs' import { codeShift } from './build-comments-to-dts.mjs' import { generate } from './build-theme-typings.mjs' +import packageJson from '../package.json' assert { type: 'json' } const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) +const dist = 'release/taro/dist' const isTypesTaro = (name, type) => { return name.indexOf(type) > -1 @@ -50,8 +52,8 @@ const transform = (file, api, replace) => { if (!path.node.source) return if (!alias) { // 处理这里,文件引入中的相对路径下的types的引入。 - path.node.source.value = (!replace || replace && !isTypesTaro(path.node.source.value, 'types.taro')) - ? path.node.source.value.replace('.taro', '') + path.node.source.value = (!replace || replace && !isTypesTaro(path.node.source.value, 'types.taro')) + ? path.node.source.value.replace('.taro', '') : path.node.source.value return } @@ -112,10 +114,10 @@ async function buildES(p) { const ext = extname(relativePath) const writePath = relativePath.replace(ext, '.js').replace('.taro', '') - await dest(join('dist/es', writePath.replace('../src/', '')), code.code) + await dest(join(`${dist}/es`, writePath.replace('../src/', '')), code.code) } - const files = await glob(['dist/es/packages/**/*.js']) + const files = await glob([`${dist}/es/packages/**/*.js`]) for (const file of files) { const result = transform( { @@ -131,7 +133,7 @@ async function buildES(p) { // 构建 CMD async function buildCJS(p) { - const esFiles = await glob(['dist/es/**/*.js']) + const esFiles = await glob([`${dist}/es/**/*.js`]) for (const path of esFiles) { const code = await swc.transformFileSync(join(__dirname, '../', path), { @@ -154,18 +156,18 @@ async function buildCJS(p) { async function buildDeclaration() { const configPath = join(__dirname, '../tsconfig.taro.json') - const dist = join(__dirname, '../dist/types') + const types = join(__dirname, `../${dist}/types`) await execSync( - `tsc --project ${configPath} --emitDeclarationOnly --declaration --declarationDir ${dist}`, + `tsc --project ${configPath} --emitDeclarationOnly --declaration --declarationDir ${types}`, ) const files = await glob([ - 'dist/types/src/packages/**/*.taro.d.ts', - 'dist/types/src/packages/**/types.d.ts', - 'dist/types/src/packages/**/context.d.ts', - 'dist/types/src/packages/**/utils.d.ts', - 'dist/types/src/locales/*.d.ts', - 'dist/types/src/utils/*.d.ts', + `${dist}/types/src/packages/**/*.taro.d.ts`, + `${dist}/types/src/packages/**/types.d.ts`, + `${dist}/types/src/packages/**/context.d.ts`, + `${dist}/types/src/packages/**/utils.d.ts`, + `${dist}/types/src/locales/*.d.ts`, + `${dist}/types/src/utils/*.d.ts`, ]) for (const file of files) { @@ -174,19 +176,19 @@ async function buildDeclaration() { source: readFileSync(join(__dirname, '../', file), { encoding: 'utf8', }), - path: join(__dirname, '../', file).replace('/dist/types', ''), + path: join(__dirname, '../', file).replace(`/${dist}/types`, ''), }, { jscodeshift: j }, - true + true, ) // 修改文件名,除 types.taro 不改之外,其他都修改。 - let to = file.replace('dist/types/src', '') + let to = file.replace(`${dist}/types/src`, '') to = isTypesTaro(to, 'types.taro') ? to : to.replace('.taro', '') - await dest(join('dist/es', to), result) - await dest(join('dist/cjs', to), result) + await dest(join(`${dist}/es`, to), result) + await dest(join(`${dist}/cjs`, to), result) } - deleteAsync('dist/types') + deleteAsync(`${dist}/types`) } // 构建 UMD @@ -205,6 +207,7 @@ async function buildUMD() { build: { minify: false, emptyOutDir: false, + outDir: dist, rollupOptions: { external: ['react', 'react-dom', '@tarojs/taro', '@tarojs/components'], output: [ @@ -217,7 +220,7 @@ async function buildUMD() { ], }, lib: { - entry: join(__dirname, '../dist/es/packages/nutui.react.build.js'), + entry: join(__dirname, `../${dist}/es/packages/nutui.react.build.js`), }, }, }) @@ -228,7 +231,7 @@ async function buildAllCSS() { async function copyStyles() { await copy( resolve(__dirname, '../src/styles'), - resolve(__dirname, '../dist/styles') + resolve(__dirname, `../${dist}/styles`), ) const content = [ @@ -241,14 +244,15 @@ async function buildAllCSS() { if (projectID) { content[1] = `@import '../variables-${projectID}.scss';` } - const scssFiles = await glob(['dist/es/packages/**/*.scss']) + const scssFiles = await glob([`${dist}/es/packages/**/*.scss`]) scssFiles.forEach((file) => { content.push( - `@import '${relativeFilePath('/dist/style.scss', '/' + file)}';` + `@import '${relativeFilePath(`/${dist}/style.scss`, '/' + file)}';`, ) }) - dest('dist/style.scss', content.join('\n')) + dest(`${dist}/style.scss`, content.join('\n')) } + await copyStyles() await vite.build({ logLevel: 'error', @@ -257,8 +261,9 @@ async function buildAllCSS() { }, build: { emptyOutDir: false, + outDir: dist, lib: { - entry: './dist/style.scss', + entry: `./${dist}/style.scss`, formats: ['es'], name: 'style', fileName: 'style', @@ -278,13 +283,13 @@ async function buildThemeCSS() { rollupOptions: { output: [ { - dir: 'dist/styles/themes', + dir: `${dist}/styles/themes`, assetFileNames: 'default.css', }, ], }, lib: { - entry: './dist/styles/themes/default.scss', + entry: `./${dist}/styles/themes/default.scss`, }, }, }) @@ -294,7 +299,7 @@ async function buildThemeCSS() { async function copyStyles() { await copy( resolve(__dirname, '../src/styles'), - resolve(__dirname, '../dist/styles'), + resolve(__dirname, `../${dist}/styles`), ) let content = [ @@ -310,7 +315,7 @@ async function copyStyles() { ] } - dest('dist/styles/themes/default.scss', content.join('\n')) + dest(`${dist}/styles/themes/default.scss`, content.join('\n')) } // 构建样式 @@ -338,19 +343,19 @@ async function buildCSS(p) { }) const cssPath = relative('src', loadPath) // 写 css 文件 - await dest(join('dist/es', cssPath, 'style/style.css'), code.css) - await dest(join('dist/es', cssPath, 'style/css.js'), `import './style.css'`) + await dest(join(`${dist}/es`, cssPath, 'style/style.css'), code.css) + await dest(join(`${dist}/es`, cssPath, 'style/css.js'), `import './style.css'`) - await dest(join('dist/cjs', cssPath, 'style/style.css'), code.css) + await dest(join(`${dist}/cjs`, cssPath, 'style/style.css'), code.css) await dest( - join('dist/cjs', cssPath, 'style/css.js'), + join(`${dist}/cjs`, cssPath, 'style/css.js'), `import './style.css'`, ) // copy harmonycss if (file.indexOf('countup') === -1) { - await copy(join(__dirname, '../', file.replace('scss', 'harmony.css')), join('dist/cjs', cssPath, 'style/style.harmony.css')) - await copy(join(__dirname, '../', file.replace('scss', 'harmony.css')), join('dist/es', cssPath, 'style/style.harmony.css')) + await copy(join(__dirname, '../', file.replace('scss', 'harmony.css')), join(`${dist}/cjs`, cssPath, 'style/style.harmony.css')) + await copy(join(__dirname, '../', file.replace('scss', 'harmony.css')), join(`${dist}/es`, cssPath, 'style/style.harmony.css')) } // 删除 import @@ -376,8 +381,8 @@ async function buildCSS(p) { ]) .process(button, { from: loadPath, syntax: scss }) .then((result) => { - dest(join('dist/es', cssPath, `style/${base}`), result.css) - dest(join('dist/cjs', cssPath, `style/${base}`), result.css) + dest(join(`${dist}/es`, cssPath, `style/${base}`), result.css) + dest(join(`${dist}/cjs`, cssPath, `style/${base}`), result.css) }) const jsContent = [] @@ -396,17 +401,45 @@ async function buildCSS(p) { jsContent.push(`import './${base}';`) await dest( - join('dist/cjs', cssPath, `style/index.js`), + join(`${dist}/cjs`, cssPath, `style/index.js`), jsContent.join('\n'), ) - await dest(join('dist/es', cssPath, `style/index.js`), jsContent.join('\n')) + await dest(join(`${dist}/es`, cssPath, `style/index.js`), jsContent.join('\n')) } } -console.time('clean dist') -await deleteAsync('dist') -console.timeEnd('clean dist') +function generateReleasePackageJson() { + delete packageJson.dependencies['@nutui/icons-react'] + return JSON.stringify({ + name: '@nutui/nutui-react-taro', + version: packageJson.version, + style: packageJson.style, + main: packageJson.main, + module: packageJson.module, + typings: packageJson.typings, + sideEffects: packageJson.sideEffects, + description: packageJson.description, + keywords: packageJson.keywords, + author: packageJson.author, + license: packageJson.license, + repository: packageJson.repository, + files: packageJson.files, + publishConfig: packageJson.publishConfig, + dependencies: packageJson.dependencies, + peerDependencies: packageJson.peerDependencies, + }) +} +async function copyReleaseFiles() { + const npmPublishDir = dist.replace('dist', '') + await copy(join(__dirname, '../README.md'), join(`${npmPublishDir}/README.md`)) + await copy(join(__dirname, '../CHANGELOG.md'), join(`${npmPublishDir}/CHANGELOG.md`)) + await writeFile(join(__dirname, `../${npmPublishDir}/package.json`), generateReleasePackageJson()) +} + +console.time(`clean ${dist}`) +await deleteAsync(dist) +console.timeEnd(`clean ${dist}`) await generate() @@ -445,12 +478,16 @@ console.timeEnd('Build Declaration') // await exportProps() await deleteAsync([ - 'dist/es/packages/nutui.react.js', - 'dist/es/packages/nutui.react.d.ts', - 'dist/es/packages/nutui.react.scss.d.ts', - 'dist/es/packages/nutui.react.scss.js', + `${dist}/es/packages/nutui.react.js`, + `${dist}/es/packages/nutui.react.d.ts`, + `${dist}/es/packages/nutui.react.scss.d.ts`, + `${dist}/es/packages/nutui.react.scss.js`, ]) console.time('Build JSDoc') -codeShift() +codeShift('taro') console.timeEnd('Build JSDoc') + +console.time('Copy package.json readme.md') +await copyReleaseFiles() +console.timeEnd('Copy package.json readme.md') diff --git a/scripts/build.mjs b/scripts/build.mjs index 7bb0b41170..aed614f99b 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -15,9 +15,11 @@ import { readFileSync } from 'fs' import { relativeFilePath } from './relative-path.mjs' import { codeShift } from './build-comments-to-dts.mjs' import { generate } from './build-theme-typings.mjs' +import packageJson from '../package.json' assert { type: 'json' } const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) +const dist = 'release/h5/dist' // 写文件 async function dest(file, content) { @@ -71,13 +73,13 @@ async function buildES(p) { const ext = extname(relativePath) const writePath = relativePath.replace(ext, '.js') - await dest(join('dist/es', writePath.replace('../src/', '')), code.code) + await dest(join(dist, 'es', writePath.replace('../src/', '')), code.code) } } // 构建 CMD async function buildCJS(p) { - const esFiles = await glob(['dist/es/**/*.js']) + const esFiles = await glob([`${dist}/es/**/*.js`]) for (const path of esFiles) { const code = await swc.transformFileSync(join(__dirname, '../', path), { @@ -100,9 +102,9 @@ async function buildCJS(p) { async function buildDeclaration() { const configPath = join(__dirname, '../tsconfig.h5.json') - const dist = join(__dirname, '../dist/types') + const types = join(__dirname, `../${dist}/types`) await execSync( - `tsc --project ${configPath} --emitDeclarationOnly --declaration --declarationDir ${dist}` + `tsc --project ${configPath} --emitDeclarationOnly --declaration --declarationDir ${types}` ) const transform = (file, api) => { const j = api.jscodeshift.withParser('ts') @@ -120,8 +122,8 @@ async function buildDeclaration() { .toSource() } - const files = await glob(['dist/types/src/**/*.d.ts'], { - ignore: ['dist/types/src/**/*.taro.d.ts'], + const files = await glob([`${dist}/types/src/**/*.d.ts`], { + ignore: [`${dist}/types/src/**/*.taro.d.ts`], }) for (const file of files) { @@ -130,14 +132,14 @@ async function buildDeclaration() { source: readFileSync(join(__dirname, '../', file), { encoding: 'utf8', }), - path: join(__dirname, '../', file).replace('/dist/types', ''), + path: join(__dirname, '../', file).replace(`${dist}/types`, ''), }, { jscodeshift: j } ) - await dest(join('dist/es', file.replace('dist/types/src', '')), result) - await dest(join('dist/cjs', file.replace('dist/types/src', '')), result) + await dest(join(dist, 'es', file.replace(`${dist}/types/src`, '')), result) + await dest(join(dist, 'cjs', file.replace(`${dist}/types/src`, '')), result) } - deleteAsync('dist/types') + deleteAsync(`${dist}/types`) } // 构建 UMD @@ -154,6 +156,7 @@ async function buildUMD(p) { build: { minify: false, emptyOutDir: false, + outDir: dist, rollupOptions: { external: ['react', 'react-dom'], output: [ @@ -166,7 +169,7 @@ async function buildUMD(p) { ], }, lib: { - entry: join(__dirname, '../dist/es/packages/nutui.react.build.js'), + entry: join(__dirname, `../${dist}/es/packages/nutui.react.build.js`), }, }, }) @@ -177,7 +180,7 @@ async function buildAllCSS() { async function copyStyles() { await copy( resolve(__dirname, '../src/styles'), - resolve(__dirname, '../dist/styles') + resolve(__dirname, `../${dist}/styles`) ) const content = [ @@ -190,13 +193,13 @@ async function buildAllCSS() { if (projectID) { content[1] = `@import '../variables-${projectID}.scss';` } - const scssFiles = await glob(['dist/es/packages/**/*.scss']) + const scssFiles = await glob([`${dist}/es/packages/**/*.scss`]) scssFiles.forEach((file) => { content.push( - `@import '${relativeFilePath('/dist/style.scss', '/' + file)}';` + `@import '${relativeFilePath(`/${dist}/style.scss`, '/' + file)}';` ) }) - dest('dist/style.scss', content.join('\n')) + dest(`${dist}/style.scss`, content.join('\n')) } await copyStyles() await vite.build({ @@ -206,8 +209,9 @@ async function buildAllCSS() { }, build: { emptyOutDir: false, + outDir: dist, lib: { - entry: './dist/style.scss', + entry: `./${dist}/style.scss`, formats: ['es'], name: 'style', fileName: 'style', @@ -227,13 +231,13 @@ async function buildThemeCSS() { rollupOptions: { output: [ { - dir: 'dist/styles/themes', + dir: `${dist}/styles/themes`, assetFileNames: 'default.css', }, ], }, lib: { - entry: './dist/styles/themes/default.scss', + entry: `./${dist}/styles/themes/default.scss`, }, }, }) @@ -243,7 +247,7 @@ async function buildThemeCSS() { async function copyStyles() { await copy( resolve(__dirname, '../src/styles'), - resolve(__dirname, '../dist/styles') + resolve(__dirname, `../${dist}/styles`) ) let content = [ @@ -259,7 +263,7 @@ async function copyStyles() { ] } - dest('dist/styles/themes/default.scss', content.join('\n')) + dest(`${dist}/styles/themes/default.scss`, content.join('\n')) } // 构建样式 @@ -287,12 +291,12 @@ async function buildCSS(p) { }) const cssPath = relative('src', loadPath) // 写 css 文件 - await dest(join('dist/es', cssPath, 'style/style.css'), code.css) - await dest(join('dist/es', cssPath, 'style/css.js'), `import './style.css'`) + await dest(join(`${dist}/es`, cssPath, 'style/style.css'), code.css) + await dest(join(`${dist}/es`, cssPath, 'style/css.js'), `import './style.css'`) - await dest(join('dist/cjs', cssPath, 'style/style.css'), code.css) + await dest(join(`${dist}/cjs`, cssPath, 'style/style.css'), code.css) await dest( - join('dist/cjs', cssPath, 'style/css.js'), + join(`${dist}/cjs`, cssPath, 'style/css.js'), `import './style.css'` ) @@ -319,8 +323,8 @@ async function buildCSS(p) { ]) .process(button, { from: loadPath, syntax: scss }) .then((result) => { - dest(join('dist/es', cssPath, `style/${base}`), result.css) - dest(join('dist/cjs', cssPath, `style/${base}`), result.css) + dest(join(`${dist}/es`, cssPath, `style/${base}`), result.css) + dest(join(`${dist}/cjs`, cssPath, `style/${base}`), result.css) }) const jsContent = [] @@ -339,16 +343,43 @@ async function buildCSS(p) { jsContent.push(`import './${base}';`) await dest( - join('dist/cjs', cssPath, `style/index.js`), + join(`${dist}/cjs`, cssPath, `style/index.js`), jsContent.join('\n') ) - await dest(join('dist/es', cssPath, `style/index.js`), jsContent.join('\n')) + await dest(join(`${dist}/es`, cssPath, `style/index.js`), jsContent.join('\n')) } } +function generateReleasePackageJson() { + delete packageJson.dependencies['@nutui/icons-react-taro'] + return JSON.stringify({ + name: '@nutui/nutui-react', + version: packageJson.version, + style: packageJson.style, + main: packageJson.main, + module: packageJson.module, + typings: packageJson.typings, + sideEffects: packageJson.sideEffects, + description: packageJson.description, + keywords: packageJson.keywords, + author: packageJson.author, + license: packageJson.license, + repository: packageJson.repository, + files: packageJson.files, + publishConfig: packageJson.publishConfig, + dependencies: packageJson.dependencies, + peerDependencies: packageJson.peerDependencies, + }) +} +async function copyReleaseFiles() { + const npmPublishDir = dist.replace('dist', '') + await copy(join(__dirname, '../README.md'), join(`${npmPublishDir}/README.md`)) + await copy(join(__dirname, '../CHANGELOG.md'), join(`${npmPublishDir}/CHANGELOG.md`)) + await writeFile(join(__dirname, `../${npmPublishDir}/package.json`), generateReleasePackageJson()) +} -console.time('clean dist') -await deleteAsync('dist') -console.timeEnd('clean dist') +console.time(`clean ${dist}`) +await deleteAsync(dist) +console.timeEnd(`clean ${dist}`) await generate() @@ -384,15 +415,17 @@ console.time('Build Declaration') await buildDeclaration() console.timeEnd('Build Declaration') -// await exportProps() - await deleteAsync([ - 'dist/es/packages/nutui.react.js', - 'dist/es/packages/nutui.react.d.ts', - 'dist/es/packages/nutui.react.scss.d.ts', - 'dist/es/packages/nutui.react.scss.js', + `${dist}/es/packages/nutui.react.js`, + `${dist}/es/packages/nutui.react.d.ts`, + `${dist}/es/packages/nutui.react.scss.d.ts`, + `${dist}/es/packages/nutui.react.scss.js`, ]) console.time('Build JSDoc') -codeShift() +codeShift('h5') console.timeEnd('Build JSDoc') + +console.time('Copy package.json readme.md') +await copyReleaseFiles() +console.timeEnd('Copy package.json readme.md') \ No newline at end of file diff --git a/scripts/postpublish.js b/scripts/postpublish.js deleted file mode 100644 index ab821667d4..0000000000 --- a/scripts/postpublish.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 用于在 prepublish 之后,恢复 package.json - * */ -const path = require('path') -const fsExtra = require('fs-extra') - -fsExtra.copySync( - path.join(process.cwd(), '.cache/package.json.bk'), - path.join(process.cwd(), 'package.json'), - { overwrite: true } -) - -fsExtra.removeSync(path.join(process.cwd(), '.cache/package.json.bk')) diff --git a/scripts/prepublish.js b/scripts/prepublish.js deleted file mode 100644 index 4b8b2459e6..0000000000 --- a/scripts/prepublish.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 用于发布之前纠正 H5 和 Taro 版本的依赖 - * */ -const path = require('path') -const fsExtra = require('fs-extra') -const packageData = require('../package.json') - -const cachePath = path.join(process.cwd(), '.cache/') -if (!fsExtra.ensureDirSync(cachePath)) { - fsExtra.mkdirpSync(cachePath) -} - -fsExtra.copySync( - path.join(process.cwd(), 'package.json'), - path.join(cachePath, 'package.json.bk'), - { overwrite: true } -) - -if (packageData.name.indexOf('-taro') > -1) { - delete packageData.dependencies['@nutui/icons-react'] -} else { - delete packageData.dependencies['@nutui/icons-react-taro'] -} - -delete packageData.devDependencies -packageData.scripts = {} - -packageData.scripts['postpublish'] = 'node scripts/postpublish.js' - -fsExtra.writeJsonSync(path.join(process.cwd(), 'package.json'), packageData, { - spaces: 2, -})