-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-package-json.cjs
38 lines (30 loc) · 1.02 KB
/
update-package-json.cjs
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
const fs = require('fs');
const path = require('path');
// Read the package.json file
const pkgPath = path.resolve(__dirname, 'package.json');
const pkg = require(pkgPath);
// Get the version from package.json
const version = pkg.version;
// Define the new paths based on the version
const mainFile = `dist/packages/index.${version}.cjs.js`;
const moduleFile = `dist/packages/index.${version}.es.js`;
const browserFile = `dist/packages/index.${version}.umd.js`;
const typesFile = 'dist/types/index.d.ts'
// Update the package.json fields
pkg.main = mainFile;
pkg.module = moduleFile;
pkg.browser = browserFile;
pkg.types = typesFile;
// Update the exports field
pkg.exports = {
".": {
"import": `./${moduleFile}`,
"require": `./${mainFile}`,
"default": `./${browserFile}`,
"types": `./${typesFile}`
},
"./package.json": "./package.json"
};
// Write the updated package.json back to the file system
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), 'utf-8');
console.log('package.json updated successfully');