This repository was archived by the owner on Mar 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathprepareManifest.ts
More file actions
104 lines (85 loc) · 3.06 KB
/
Copy pathprepareManifest.ts
File metadata and controls
104 lines (85 loc) · 3.06 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import fs from 'fs';
import http from 'http';
import path from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Read package.json dynamically to avoid ESM import issues
const packageJson = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8')
);
const { version } = packageJson;
const PROJECT_ROOT = path.resolve(__dirname, '..');
const args = process.argv.slice(2);
const mode = args[0];
dotenv.config({ path: `.env.${mode}` });
const IS_BETA = process.env.IS_BETA === 'true';
const OAUTH2_SCOPES = process.env.OAUTH2_SCOPES || '';
const DEVTOOLS_URL = 'http://localhost:8097';
async function fetchDevTools(): Promise<string> {
return new Promise((resolve, reject) => {
const request = http.get(DEVTOOLS_URL, (response) => {
if (response.statusCode !== 200) {
reject(new Error(`Failed to fetch: ${response.statusCode}`));
return;
}
let data = '';
response.on('data', (chunk) => (data += chunk));
response.on('end', () => {
const modifiedScript = `
// React DevTools for Chrome Extension
(function() {
${data}
})();
`;
resolve(modifiedScript);
});
});
request.on('error', reject);
});
}
async function prepare() {
const manifestPath = path.resolve(PROJECT_ROOT, '_raw', 'manifest.json');
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
manifest.oauth2 = {
client_id: process.env.OAUTH2_CLIENT_ID,
scopes: OAUTH2_SCOPES.split(','),
};
// Update the version in the manifest
if (IS_BETA) {
const betaVersion = process.env.BETA_VERSION;
if (!betaVersion) {
throw new Error('BETA_VERSION is not set');
}
const betaBuildNumber = betaVersion.replace(/^(\d+\.\d+\.\d+).*beta[^\d]*(\d+).*/, '$2');
manifest.version = version.replace(/^(\d+)\.(\d+)\.(\d+).*/, `$1$2.$3.${betaBuildNumber}`);
manifest.name = '__MSG_appNameBeta__';
manifest.description = '__MSG_appDescriptionBeta__';
manifest.key = process.env.BETA_MANIFEST_KEY;
manifest.oauth2.client_id = process.env.BETA_OAUTH2_CLIENT_ID;
} else {
manifest.version = version;
manifest.name = '__MSG_appName__';
manifest.description = '__MSG_appDescription__';
}
if (mode === 'dev') {
manifest.key = process.env.MANIFEST_KEY;
manifest.name = 'Flow Wallet Dev';
try {
const devToolsScript = await fetchDevTools();
fs.writeFileSync(path.resolve(__dirname, '../_raw/react-devtools.js'), devToolsScript);
console.info('✅ React DevTools source fetched successfully');
} catch {
console.warn('⚠️ Failed to fetch React DevTools. Run the devtools server first');
// Write empty file if fetch fails
fs.writeFileSync(
path.resolve(__dirname, '../_raw/react-devtools.js'),
'// React DevTools not available'
);
}
}
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
return manifest;
}
prepare();