-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.mjs
47 lines (39 loc) · 1.36 KB
/
build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable no-undef */
import prettyMs from 'pretty-ms';
import { rollup } from 'rollup';
import 'zx/globals';
import configs from './rollup.config.cjs';
await fs.mkdir('./dist', { recursive: true });
await measure(`public-typings → ./dist/`, `copied in`, async () => {
await fs.copyFile('./public-types/reflect.d.ts', './dist/index.d.ts');
// `@effector/reflect/scope` types - this export is deprecated
await fs.copyFile('./public-types/reflect.d.ts', './dist/scope.d.ts');
});
for (const config of configs) {
await measure(
`${config.input} → ${config.output.file ?? config.output.dir}`,
`created in`,
async () => {
const bundle = await rollup(config);
await bundle.write(config.output);
},
);
}
await measure(`package.json → ./dist/package.json`, `created in`, async () => {
const Package = JSON.parse(
await fs.readFile('./package.json', { encoding: 'utf-8' }),
);
delete Package.devDependencies;
delete Package.scripts;
await fs.writeFile('./dist/package.json', JSON.stringify(Package), {
encoding: 'utf-8',
});
});
await fs.copyFile('./Readme.md', './dist/Readme.md');
console.log(`Copied Readme.md → ./dist/Readme.md`);
async function measure(start, end, fn) {
console.log(start);
const time = performance.now();
await fn();
console.log('↳', end, prettyMs(performance.now() - time), '\r\n');
}