Repository navigation
Expand file tree
/
Copy pathnative-sdk-source.js
More file actions
88 lines (75 loc) · 2.18 KB
/
Copy pathnative-sdk-source.js
File metadata and controls
88 lines (75 loc) · 2.18 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
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
const { execFileSync } = require('child_process');
const { readFileSync, realpathSync } = require('fs');
const { join } = require('path');
const { diditNativeSdkVersions } = require('./package.json');
function git(sourcePath, args) {
return execFileSync('git', ['-C', sourcePath, ...args], {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
}).trim();
}
function verifySource(sourcePath, pin) {
if (git(sourcePath, ['rev-parse', 'HEAD']) !== pin.revision) {
throw new Error(
`Didit native source must match ${pin.branch} at ${pin.revision}.`
);
}
if (git(sourcePath, ['status', '--porcelain'])) {
throw new Error(
'Didit native source has local changes; use the pinned checkout.'
);
}
}
function resolveNativeSdkSource(platform) {
const pin = diditNativeSdkVersions.source;
const sourcePath = process.env.DIDIT_SDK_SOURCE_PATH;
if (!pin) return '';
if (!sourcePath) {
throw new Error(
'Set DIDIT_SDK_SOURCE_PATH to the pinned native source checkout. Released binaries cannot provide these steps.'
);
}
verifySource(sourcePath, pin);
return realpathSync(
join(sourcePath, platform === 'ios' ? 'ios/sdk' : 'android')
);
}
function androidRepositoryPath() {
return join(
__dirname,
'.native-sdk',
diditNativeSdkVersions.source.revision,
'maven'
);
}
function verifyAndroidArtifacts(repository) {
const marker = JSON.parse(
readFileSync(join(repository, 'source.json'), 'utf8')
);
if (marker.revision !== diditNativeSdkVersions.source.revision) {
throw new Error(
'Native Android artifacts do not match the pin. Run yarn native:android.'
);
}
}
function resolveAndroidRepository() {
const repository = diditNativeSdkVersions.source
? androidRepositoryPath()
: '';
if (!repository) return '';
resolveNativeSdkSource('android');
verifyAndroidArtifacts(repository);
return repository;
}
module.exports = {
resolveNativeSdkSource,
resolveAndroidRepository,
androidRepositoryPath,
};
if (require.main === module) {
process.stdout.write(
process.argv[2] === 'android-repository'
? resolveAndroidRepository()
: resolveNativeSdkSource(process.argv[2])
);
}