Skip to content

Commit

Permalink
fix: conditional preact build
Browse files Browse the repository at this point in the history
  • Loading branch information
afiiif committed Oct 16, 2023
1 parent 0280d4d commit c5f25d9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Code Quality Check & Publish

on:
push:
branches: [main, alpha, beta]
branches: [main, beta, alpha, experimental]
pull_request:
types: [opened, synchronize]

Expand Down Expand Up @@ -49,7 +49,12 @@ jobs:
publish:
name: Publish to NPM
needs: [lint, type-check, test]
if: github.repository == 'afiiif/floppy-disk' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta')
if: |
github.repository == 'afiiif/floppy-disk'
&& (github.ref == 'refs/heads/main'
|| github.ref == 'refs/heads/beta'
|| github.ref == 'refs/heads/alpha'
|| github.ref == 'refs/heads/experimental')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -63,7 +68,12 @@ jobs:
npm pkg delete 'engines'
npm pkg delete 'devDependencies'
- name: Build package
run: yarn build
run: |
if [ "${{ github.ref }}" = "refs/heads/experimental" ]; then
PREACT=true yarn build
else
yarn build
fi
- name: Release package
run: yarn semantic-release
env:
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@
"release": {
"branches": [
"main",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
},
{
"name": "beta",
"name": "experimental",
"prerelease": true
}
]
Expand Down
24 changes: 21 additions & 3 deletions scripts/preact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (process.env.PREACT !== 'true') process.exit();
const reactFilesPath = './src/react';
const preactFilesPath = './src/preact';

async function copyAndReplace() {
const copyAndReplace = async () => {
try {
const files = await readdir(reactFilesPath);

Expand Down Expand Up @@ -46,6 +46,24 @@ async function copyAndReplace() {
} catch (error) {
console.error('An error occurred:', error);
}
}
};

copyAndReplace();
const updatePackageJson = async () => {
const packageJsonContent = await readFile('./package.json', 'utf8');
const packageJson = JSON.parse(packageJsonContent);
packageJson.exports['./preact'] = {
types: './lib/preact/index.d.ts',
import: {
types: './esm/preact/index.d.ts',
default: './esm/preact/index.js',
},
module: './esm/preact/index.js',
default: './lib/preact/index.js',
};
await writeFile('./package.json', JSON.stringify(packageJson, null, 2), 'utf8');
};

(async () => {
await copyAndReplace();
await updatePackageJson();
})();

0 comments on commit c5f25d9

Please sign in to comment.