generated from kuraydev/react-native-typescript-library-starter
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcopy-package.mjs
More file actions
58 lines (50 loc) · 1.58 KB
/
copy-package.mjs
File metadata and controls
58 lines (50 loc) · 1.58 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
52
53
54
55
56
57
58
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import ora from 'ora';
try { console.clear(); } catch {}
// Clear npm's two lifecycle lines
try {
if (process.stdout.isTTY) {
process.stdout.write('\x1b[2A');
process.stdout.write('\x1b[2K');
process.stdout.write('\x1b[1B');
process.stdout.write('\x1b[2K');
process.stdout.write('\x1b[1B');
process.stdout.write('\r');
}
} catch {}
const spinner = ora(chalk.cyan('Writing dist package.json...')).start();
spinner.color = 'cyan';
try {
const root = process.cwd();
const pkgPath = path.resolve(root, 'package.json');
const distDir = path.resolve(root, 'build', 'dist');
const pkgRaw = fs.readFileSync(pkgPath, 'utf-8');
const pkg = JSON.parse(pkgRaw);
const distPkg = {
...pkg,
main: './index.js',
module: './index.js',
'react-native': './index.js',
types: './index.d.ts',
exports: {
'.': {
types: './index.d.ts',
'react-native': './index.js',
import: './index.js',
default: './index.js'
}
}
};
// Ensure minimal fields for dist package
delete distPkg.files; // not needed inside dist
delete distPkg.devDependencies; // avoid leaking build-time deps
delete distPkg.scripts; // avoid running scripts from dependency
fs.mkdirSync(distDir, { recursive: true });
fs.writeFileSync(path.resolve(distDir, 'package.json'), JSON.stringify(distPkg, null, 2));
spinner.succeed(chalk.cyanBright('dist/package.json written.'));
} catch (e) {
spinner.fail(chalk.bgRed(`copy-package error: ${e.message}`));
process.exit(1);
}