-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
47 lines (43 loc) · 1.26 KB
/
rollup.config.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json from 'rollup-plugin-json';
import { exec } from 'child_process';
import { appendFile } from 'fs';
import validatorGenerated from './amphtml-validator-rules.json';
export default {
input: './amphtml-validator-rules.json',
output: {
file: './dist/index.js',
format: 'cjs',
exports: 'named',
outro: `exports.version = '${process.env.VERSION}';`,
},
plugins: [
json(),
{
writeBundle: async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
await new Promise((resolve, reject) => {
exec(
'npm run quicktype',
{ cwd: __dirname, env: process.env },
(err, stdout, stderr) => {
process.stdout.write(stdout);
process.stderr.write(stderr);
return err ? reject(err) : resolve();
},
);
});
const code = Object.keys(validatorGenerated).reduce(
(acc, key) => `${acc}\nexport const ${key}: IndexD['${key}'];`,
'\nexport const version: string;',
);
await new Promise((resolve, reject) => {
appendFile(
'./dist/index.d.ts',
code,
err => (err ? reject(err) : resolve()),
);
});
}
},
],
};