schema.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. const {execSync} = require('child_process');
  2. const {readFileSync, writeFileSync} = require('fs');
  3. const willPaste = process.argv[2] === '1';
  4. const sourceFile = process.argv[2];
  5. let sourceContent = (() => {
  6. if(willPaste) {
  7. return execSync('pbpaste', {encoding: 'utf8'});
  8. }
  9. if(sourceFile) {
  10. return readFileSync(sourceFile, 'utf8');
  11. }
  12. })();
  13. if(sourceContent) {
  14. const path = `${__dirname}/src/scripts/in/schema.json`;
  15. const schemaIn = readFileSync(path, 'utf8');
  16. const replaced = schemaIn.replace(/("API": ).+?(,\n)/, `$1${sourceContent}$2`);
  17. writeFileSync(path, replaced);
  18. }
  19. execSync(`node ${__dirname}/src/scripts/format_schema.js`);
  20. const formattedSchema = readFileSync(`${__dirname}/src/scripts/out/schema.json`, 'utf8');
  21. const schemaTsPath = `${__dirname}/src/lib/mtproto/schema.ts`;
  22. const schemaTs = readFileSync(schemaTsPath, 'utf8');
  23. const replaced = schemaTs.replace(/(export default )\{.+?( as )/, `$1${formattedSchema}$2`);
  24. writeFileSync(schemaTsPath, replaced);
  25. execSync(`npm run generate-mtproto-types`);