forked from gram-js/gramjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_generate.js
More file actions
44 lines (38 loc) · 1.05 KB
/
Copy path_generate.js
File metadata and controls
44 lines (38 loc) · 1.05 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
// Temporary script to run generation with ts-node
require('ts-node').register({
transpileOnly: true,
compilerOptions: {
module: 'commonjs',
esModuleInterop: true
}
});
// Now require the generate script
require('./gramjs/tl/types-generator/generate');
// Generate the TL modules
const fs = require('fs');
const path = require('path');
function stripTl(tl) {
return tl
.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "")
.replace(/\n\s*\n/g, "\n")
.replace(/`/g, "\\`");
}
const apiTl = fs.readFileSync(
path.resolve(__dirname, './gramjs/tl/static/api.tl'),
"utf-8"
);
fs.writeFileSync(
path.resolve(__dirname, './gramjs/tl/apiTl.js'),
`module.exports = \`${stripTl(apiTl)}\`;`
);
console.log('Generated apiTl.js');
const schemaTl = fs.readFileSync(
path.resolve(__dirname, './gramjs/tl/static/schema.tl'),
"utf-8"
);
fs.writeFileSync(
path.resolve(__dirname, './gramjs/tl/schemaTl.js'),
`module.exports = \`${stripTl(schemaTl)}\`;`
);
console.log('Generated schemaTl.js');
console.log('Done!');