-
Notifications
You must be signed in to change notification settings - Fork 661
/
Copy pathschema.js
31 lines (25 loc) · 1.02 KB
/
schema.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
const {execSync} = require('child_process');
const {readFileSync, writeFileSync} = require('fs');
const willPaste = process.argv[2] === '1';
const sourceFile = process.argv[2];
let sourceContent = (() => {
if(willPaste) {
return execSync('pbpaste', {encoding: 'utf8'});
}
if(sourceFile) {
return readFileSync(sourceFile, 'utf8');
}
})();
if(sourceContent) {
const path = `${__dirname}/src/scripts/in/schema.json`;
const schemaIn = readFileSync(path, 'utf8');
const replaced = schemaIn.replace(/("API": ).+?(,\n)/, `$1${sourceContent}$2`);
writeFileSync(path, replaced);
}
execSync(`node ${__dirname}/src/scripts/format_schema.js`);
const formattedSchema = readFileSync(`${__dirname}/src/scripts/out/schema.json`, 'utf8');
const schemaTsPath = `${__dirname}/src/lib/mtproto/schema.ts`;
const schemaTs = readFileSync(schemaTsPath, 'utf8');
const replaced = schemaTs.replace(/(export default )\{.+?( as )/, `$1${formattedSchema}$2`);
writeFileSync(schemaTsPath, replaced);
execSync(`npm run generate-mtproto-types`);