-
Notifications
You must be signed in to change notification settings - Fork 110
/
copy-builtin-modules.js
119 lines (104 loc) · 3.48 KB
/
copy-builtin-modules.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const fs = require('fs')
const path = require('path')
const browserify = require('browserify')
const rootdir = './'
const assetsdir = path.join(rootdir, 'src/assets')
const airgapModules = [
// { path: path.join(rootdir, 'node_modules/@airgap/aeternity') },
// {
// path: path.join(rootdir, 'node_modules/@airgap/astar'),
// jsenv: {
// android: 'webview'
// }
// },
// { path: path.join(rootdir, 'node_modules/@airgap/bitcoin') },
// { path: path.join(rootdir, 'node_modules/@airgap/cosmos') },
// {
// path: path.join(rootdir, 'node_modules/@airgap/ethereum'),
// jsenv: {
// android: 'webview'
// }
// },
// { path: path.join(rootdir, 'node_modules/@airgap/groestlcoin') },
// {
// path: path.join(rootdir, 'node_modules/@airgap/icp'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/moonbeam'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/optimism'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/polkadot'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/tezos'),
// jsenv: {
// android: 'webview'
// }
// }
]
const communityModules = [
{ path: path.join(rootdir, 'node_modules/@airgap-community/iso-rootstock') }
]
function createAirGapModule(module) {
const packageJson = require(`./${path.join(module.path, 'package.json')}`)
const namespace = module.path.split('/').slice(-1)[0]
const outputDir = path.join(assetsdir, `protocol_modules/${namespace}`)
const outputFile = 'index.browserify.js'
fs.mkdirSync(outputDir, { recursive: true })
browserify(`${module.path}/v1/module.js`, { standalone: namespace })
.bundle()
.pipe(fs.createWriteStream(path.join(outputDir, outputFile)))
const manifest = {
name: packageJson.name,
version: packageJson.version,
author: packageJson.author,
publicKey: "" /* TODO */,
description: "",
src: {
namespace
},
include: [
outputFile
],
jsenv: module.jsenv
}
fs.writeFileSync(path.join(outputDir, 'manifest.json'), JSON.stringify(manifest, null, 2), 'utf8')
}
function copyCommunityModule(module) {
const namespace = module.path.split('/').slice(-1)[0]
const outputDir = path.join(assetsdir, `protocol_modules/${namespace}`)
fs.mkdirSync(outputDir, { recursive: true })
const manifestPath = path.join(module.path, 'manifest.json')
const manifest = require(`./${manifestPath}`)
manifest.include.forEach((file) => {
fs.copyFileSync(path.join(module.path, file), path.join(outputDir, file))
})
fs.copyFileSync(manifestPath, path.join(outputDir, 'manifest.json'))
fs.copyFileSync(path.join(module.path, 'module.sig'), path.join(outputDir, 'module.sig'))
Object.entries(manifest.res?.symbol ?? {}).forEach(([key, value]) => {
// TODO: improve robustness of the solution
if (!value.startsWith('file://')) {
return
}
const symbolPath = value.slice(7)
const symbolExtension = symbolPath.split('.').slice(-1)
fs.copyFileSync(path.join(module.path, symbolPath), path.join(rootdir, 'node_modules/@airgap/angular-core/src/assets/symbols', `${key}.${symbolExtension}`))
})
}
airgapModules.forEach((module) => createAirGapModule(module))
communityModules.forEach((module) => copyCommunityModule(module))