-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafter-build-type.mjs
29 lines (26 loc) · 1.29 KB
/
after-build-type.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
/* eslint-disable unicorn/prevent-abbreviations */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { fs, path } from 'zx';
const repoDir = path.join(__dirname, '..');
const distDir = path.join(__dirname, '..', 'dist');
const distLibDir = path.join(distDir, 'lib');
const pluginCopyOptions = {
filter: (source, destination) => {
// allow folder (otherwise it will stop at first step) and .d.ts files
if (path.extname(source) === '' || source.endsWith('.d.ts')) {
// Return true to copy the item
return true;
}
},
};
await fs.copy(path.join(repoDir, 'src'), distLibDir, pluginCopyOptions);
// manually add this, otherwise it will be changed by tsc to `/// <reference types="src/type" />` which is totally wrong.
const distributionIndexFilePath = path.join(distLibDir, './index.d.ts');
const stringToPrepend = '/// <reference types="./type.d.ts" />';
const data = await fs.readFile(distributionIndexFilePath, 'utf8');
const newData = `${stringToPrepend}\n${data}`;
await fs.writeFile(distributionIndexFilePath, newData);