forked from Elytro-eth/soulwalletlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-package-json.ts
29 lines (25 loc) · 1.08 KB
/
create-package-json.ts
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
import { writeFileSync, readFileSync } from 'node:fs';
import { resolve } from 'node:path';
export class BaseCreatePackageJson {
static createPackageJson(basePath: string) {
const packageJson = JSON.parse(readFileSync(resolve(basePath, 'package.json')).toString('utf8'));
let browser = '';
if (typeof packageJson.browser === 'object') {
browser += '"browser":'
browser += JSON.stringify(packageJson.browser, null, 2).replace(/\/lib\.esm/g, '');
browser += ',';
}
const cjsPackageJson = JSON.stringify(JSON.parse(`{
${browser}
"type": "commonjs"
}`), null, 2);
const esmPackageJson = JSON.stringify(JSON.parse(`{
${browser}
"type": "module"
}`), null, 2);
const cjsPackageJsonPath = resolve(basePath, 'lib.cjs', 'package.json');
const esmPackageJsonPath = resolve(basePath, 'lib.esm', 'package.json');
writeFileSync(cjsPackageJsonPath, cjsPackageJson);
writeFileSync(esmPackageJsonPath, esmPackageJson);
}
}