-
Notifications
You must be signed in to change notification settings - Fork 128
/
browserify-coinlib.js
87 lines (81 loc) · 2.12 KB
/
browserify-coinlib.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const fs = require('fs')
const path = require('path')
const browserify = require('browserify')
const esmify = require('esmify')
const rootdir = './'
const assetsdir = path.join(rootdir, 'src/assets')
const modules = [
{
import: '../../../node_modules/@airgap/coinlib-core'
},
{
namespace: 'aeternity',
import: '../../../node_modules/@airgap/aeternity'
},
{
namespace: 'astar',
import: '../../../node_modules/@airgap/astar'
},
{
namespace: 'bitcoin',
import: '../../../node_modules/@airgap/bitcoin'
},
{
namespace: 'coreum',
import: '../../../node_modules/@airgap/coreum'
},
{
namespace: 'cosmos',
import: '../../../node_modules/@airgap/cosmos'
},
{
namespace: 'ethereum',
import: '../../../node_modules/@airgap/ethereum'
},
{
namespace: 'groestlcoin',
import: '../../../node_modules/@airgap/groestlcoin'
},
{
namespace: 'icp',
import: '../../../node_modules/@airgap/icp'
},
{
namespace: 'moonbeam',
import: '../../../node_modules/@airgap/moonbeam'
},
{
namespace: 'optimism',
import: '../../../node_modules/@airgap/optimism'
},
{
namespace: 'polkadot',
import: '../../../node_modules/@airgap/polkadot'
},
{
namespace: 'tezos',
import: '../../../node_modules/@airgap/tezos'
},
{
namespace: 'acurast',
import: '../../../node_modules/@airgap/acurast'
}
]
function browserifyModules(modules) {
const outputDir = path.join(assetsdir, `libs`)
const combinedSourceFile = 'coinlib-all.js'
const combinedSource = modules
.map((module) =>
module.namespace
? `import * as ${module.namespace} from '${module.import}';\nexport { ${module.namespace} };`
: `export * from '${module.import}';`
)
.join('\n')
fs.mkdirSync(outputDir, { recursive: true })
fs.writeFileSync(path.join(outputDir, combinedSourceFile), combinedSource, 'utf-8')
browserify(`${outputDir}/${combinedSourceFile}`, { standalone: 'airgapCoinLib' })
.plugin(esmify)
.bundle()
.pipe(fs.createWriteStream(path.join(outputDir, 'airgap-coin-lib.browserify.js')))
}
browserifyModules(modules)