-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare-package.ts
More file actions
51 lines (45 loc) · 1.35 KB
/
prepare-package.ts
File metadata and controls
51 lines (45 loc) · 1.35 KB
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
48
49
50
51
import fs from 'fs';
import path from 'path';
const devPkg = JSON.parse(
fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8')
);
const readme = fs.readFileSync(path.join(process.cwd(), 'README.md'), 'utf-8');
(function prepare() {
const distPkg = cleanPkg(devPkg);
const { name, version } = distPkg;
console.log(`🎬 Preparing ${name} for publish to NPM`);
console.log(`⚡️ Upgraded to version ${version}`);
const distPkgPath = path.join(process.cwd(), 'dist', 'package.json');
fs.writeFileSync(
distPkgPath,
Buffer.from(JSON.stringify(distPkg, null, 2)),
'utf-8',
);
console.log(`✅ Finished preparing ${name}`);
console.log(`📋 Copying README`);
const distReadmePath = path.join(process.cwd(), 'dist', 'README.md');
fs.writeFileSync(
distReadmePath,
Buffer.from(readme),
'utf-8',
);
console.log(`✅ Finished copying README`);
})();
function cleanPkg(config: any): any {
const { name, version, main, types, exports, scripts, devDependencies, ...rest } = config;
return {
name,
version,
main: main.replace(/dist\//, ''),
types: types.replace(/dist\//, ''),
...rest,
exports: {
...exports,
'.': {
...exports['.'],
import: exports['.'].import.replace(/dist\//, ''),
types: exports['.'].types.replace(/dist\//, ''),
},
},
};
}