xref: /aosp_15_r20/external/perfetto/infra/perfetto.dev/src/gen_ui_reference.js (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1// Copyright (C) 2023 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Generation of UI API references
16
17'use strict';
18
19const fs = require('fs');
20const path = require('path');
21const argv = require('yargs').argv
22
23const PROJECT_ROOT =
24    path.dirname(path.dirname(path.dirname(path.dirname(__filename))));
25
26function main() {
27  const inputPath = argv['i'];
28  const outputPath = argv['o'];
29  if (!inputPath) {
30    console.error('Usage: -i ui/src/public/index.ts [-o out.md]');
31    process.exit(1);
32  }
33
34  const text = fs.readFileSync(inputPath, 'UTF8');
35
36  const generatedMd = '```\n' + text + '```\n';
37
38  if (outputPath) {
39    fs.writeFileSync(outputPath, generatedMd);
40  } else {
41    console.log(generatedMd);
42  }
43  process.exit(0);
44}
45
46main();
47