This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathbuild-npm.js
73 lines (64 loc) · 2.24 KB
/
build-npm.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import fs from 'fs-extra';
import path from 'path';
import { collectImportsSync } from './babel-collect-imports';
import packageJSON from '../package.json';
const { internal } = collectImportsSync(
path.resolve(__dirname, '../src/js/index.js'),
undefined,
undefined,
{
// replace default, node import by browser import
pathFilter: (_pkg, _path, relativePath) => {
if (relativePath === 'src/js/env/node') {
return 'src/js/env/browser';
}
if (relativePath === 'src/js/env/node/index') {
return 'src/js/env/browser/index';
}
},
},
);
const SRC = path.resolve(__dirname, '../src/js');
const TS = path.resolve(__dirname, '../src/ts/types');
const NPM = path.resolve(__dirname, '../npm');
const LIB = path.resolve(__dirname, '../npm/lib');
internal.forEach(file => {
const libFile = file.replace(SRC, LIB);
fs.copySync(file, libFile);
fs.copySync(file, `${libFile}.flow`);
});
const ignored = ['__tests__', '__fixtures__', '_old', 'icons', 'udev'];
const shouldIgnore = src => ignored.find(i => src.indexOf(i) >= 0);
// copy typescript
fs.copySync(TS, `${LIB}/typescript`, {
filter: (src, _dest) => {
if (shouldIgnore(src)) return false;
if (src.indexOf('.json') >= 0) return false;
return true;
},
});
delete packageJSON.devDependencies;
delete packageJSON.extendedDependencies;
delete packageJSON.scripts;
delete packageJSON.bin;
delete packageJSON['react-native'];
delete packageJSON.private;
delete packageJSON.extendedDependencies;
packageJSON.main = 'lib/index.js';
packageJSON.types = 'lib/typescript/index.d.ts';
fs.writeFileSync(
path.resolve(NPM, 'package.json'),
JSON.stringify(packageJSON, null, ' '),
'utf-8',
);
fs.copySync(
path.resolve(SRC, 'env/node/index-empty.js'),
path.resolve(NPM, 'lib/env/node/index.js'),
);
fs.copySync(
path.resolve(SRC, 'env/node/index-empty.js'),
path.resolve(NPM, 'lib/env/node/index.js.flow'),
);
fs.copySync(path.resolve(NPM, '../README.md'), path.resolve(NPM, 'README.md'));
fs.copySync(path.resolve(NPM, '../LICENSE.md'), path.resolve(NPM, 'LICENSE.md'));
fs.copySync(path.resolve(NPM, '../CHANGELOG.md'), path.resolve(NPM, 'CHANGELOG.md'));