Skip to content

Commit a429713

Browse files
committed
Added build:all and install-all scripts
1 parent bae55a6 commit a429713

File tree

7 files changed

+190
-19
lines changed

7 files changed

+190
-19
lines changed

.github/workflows/ci.yaml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Update npm
3737
run: npm install -g npm@^${{ matrix.npm }}
3838

39-
- name: Set up cache
39+
- name: Cache
4040
uses: actions/cache@v4
4141
with:
4242
path: ~/.npm
@@ -46,14 +46,8 @@ jobs:
4646
${{ runner.os }}-node-
4747
${{ runner.os }}-
4848
49-
- name: Install library dependencies
50-
run: npm ci
51-
- name: Install examples/react-17 dependencies
52-
run: cd examples/react-17 && npm ci
53-
- name: Install examples/nextjs dependencies
54-
run: cd examples/nextjs && npm ci
55-
- name: Install examples/typescript dependencies
56-
run: cd examples/typescript && npm ci
49+
- name: Install
50+
run: node scripts/install-all.js ci
5751

5852
- name: Lint
5953
uses: wearerequired/lint-action@v2
@@ -64,14 +58,23 @@ jobs:
6458
eslint_args: '--max-warnings 0'
6559
eslint_extensions: js,jsx,ts,tsx
6660

67-
- name: Build library
68-
run: npm run build
69-
- name: Build examples/react-17
70-
run: cd examples/react-17 && npm run build
71-
- name: Build examples/nextjs
72-
run: cd examples/nextjs && npm run build
73-
- name: Build examples/typescript
74-
run: cd examples/typescript && npm run build
61+
- name: Build
62+
run: npm run build:all
7563

7664
- name: Test
7765
run: npm run test
66+
67+
install:
68+
runs-on: ubuntu-latest
69+
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@v4
73+
74+
- name: Set up node 20
75+
uses: actions/setup-node@v4
76+
with:
77+
node-version: 20
78+
79+
- name: Install
80+
run: node scripts/install-all.js

examples/nextjs/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/react-17/package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"lint": "eslint src babel.config.js index.d.ts",
2424
"build:clean": "rimraf dist lib bundles",
2525
"build:files": "rollup --config",
26-
"build": "npm run build:clean && npm run build:files"
26+
"build": "npm run build:clean && npm run build:files",
27+
"build:examples": "ts-node ./scripts/build-examples.ts",
28+
"build:all": "npm run build && ts-node ./scripts/build-examples.ts"
2729
},
2830
"repository": {
2931
"type": "git",
@@ -87,6 +89,7 @@
8789
"rollup": "^4.12.0",
8890
"rollup-plugin-peer-deps-external": "^2.2.4",
8991
"ts-jest": "^29.1.2",
92+
"ts-node": "^10.9.2",
9093
"typescript": "^5"
9194
},
9295
"peerDependencies": {

scripts/build-examples.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { execSync } from 'child_process';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
5+
const examples = path.join(__dirname, '..', 'examples');
6+
7+
fs.readdirSync(examples)
8+
.map((p) => path.join(examples, p))
9+
.filter((p) => fs.statSync(p).isDirectory())
10+
.forEach((p) => {
11+
console.log(`\n\x1b[32mBuilding \x1b[1m${p}\x1b[0m`);
12+
execSync('npm run build', {
13+
stdio: 'inherit',
14+
cwd: p,
15+
});
16+
});

scripts/install-all.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { execSync } = require('child_process');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const cmd = process.argv.includes('ci') ? 'npm ci' : 'npm install';
6+
7+
const root = path.join(__dirname, '..');
8+
const examples = path.join(root, 'examples');
9+
10+
fs.readdirSync(examples)
11+
.map((p) => path.join(examples, p))
12+
.concat(root)
13+
.filter((p) => fs.statSync(p).isDirectory())
14+
.forEach((p) => {
15+
console.log(`\n\x1b[32mInstalling (${cmd}) \x1b[1m${p}\x1b[0m`);
16+
execSync(cmd, {
17+
stdio: 'inherit',
18+
cwd: p,
19+
});
20+
});

0 commit comments

Comments
 (0)