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-extended.js
69 lines (61 loc) · 2.22 KB
/
build-npm-extended.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
import fse from 'fs-extra';
import path from 'path';
import packageJSON from '../package.json';
const SRC = path.resolve(__dirname, '../src/js');
const TS = path.resolve(__dirname, '../src/ts/types');
const NPM = path.resolve(__dirname, '../npm-extended');
const LIB = path.resolve(__dirname, '../npm-extended/lib');
const DATA_SRC = path.resolve(__dirname, '../src/data');
const DATA = path.resolve(__dirname, '../npm-extended/data');
const CONNECT_COMMON_DATA = path.resolve(__dirname, '../node_modules/@trezor/connect-common/files');
const ignored = ['__tests__', '__fixtures__', '_old', 'icons', 'udev'];
const shouldIgnore = src => ignored.find(i => src.indexOf(i) >= 0);
// copy all js files any make a copy with .flow extension
fse.copySync(SRC, LIB, {
filter: (src, dest) => {
if (shouldIgnore(src)) return false;
const ext = src.split('.').pop();
if (ext === 'js') {
fse.copySync(src, `${dest}.flow`);
}
return true;
},
});
// copy typescript
fse.copySync(TS, `${LIB}/typescript`, {
filter: (src, _dest) => {
if (shouldIgnore(src)) return false;
if (src.indexOf('.json') >= 0) return false;
return true;
},
});
// copy assets (only json)
fse.copySync(DATA_SRC, DATA, {
filter: (src, _dest) => !shouldIgnore(src),
});
// copy bridge and firmware releases
fse.copySync(CONNECT_COMMON_DATA, DATA);
// modify package.json
packageJSON.dependencies = {
...packageJSON.dependencies,
...packageJSON.extendedDependencies,
};
delete packageJSON.devDependencies;
delete packageJSON.extendedDependencies;
delete packageJSON.scripts;
delete packageJSON.bin;
delete packageJSON.private;
if (packageJSON.version.indexOf('-') < 0) {
packageJSON.version += '-extended';
}
packageJSON.main = 'lib/index.js';
packageJSON.types = 'lib/typescript/index.d.ts';
fse.writeFileSync(
path.resolve(NPM, 'package.json'),
JSON.stringify(packageJSON, null, ' '),
'utf-8',
);
// copy static files
fse.copySync(path.resolve(__dirname, '../README.md'), path.resolve(NPM, 'README.md'));
fse.copySync(path.resolve(__dirname, '../LICENSE.md'), path.resolve(NPM, 'LICENSE.md'));
fse.copySync(path.resolve(__dirname, '../CHANGELOG.md'), path.resolve(NPM, 'CHANGELOG.md'));