2
* Copyright (c) 2024 Huawei Device Co., Ltd.
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
7
* http://www.apache.org/licenses/LICENSE-2.0
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.
16
import * as fs from "fs"
17
import * as path from "path"
18
import { IDLEntry } from "../idl"
19
import * as webidl2 from "webidl2"
20
import { toIDLNode } from "./deserialize";
21
import { zip } from "../util";
23
export function fromIDL(
25
inputFile: string | undefined,
29
transform: (name: string, content: string) => string
31
inputDir = path.resolve(inputDir)
32
const files: string[] =
34
? [path.join(inputDir, inputFile)]
35
: fs.readdirSync(inputDir)
36
.map((elem: string) => path.join(inputDir, elem))
38
const results: string[] =
40
.map((file: string) => transform(file, fs.readFileSync(file).toString()))
43
.forEach(([fileName, output]: [string, string]) => {
44
fs.mkdirSync(outputDir, { recursive : true })
45
const outFile = path.join(
47
path.basename(fileName).replace(".idl", extension)
49
if (verbose) console.log(output)
50
fs.writeFileSync(outFile, licence.concat(output))
54
export function scanIDL(
56
inputFile: string | undefined,
58
inputDir = path.resolve(inputDir)
59
const files: string[] =
61
? [path.join(inputDir, inputFile)]
62
: fs.readdirSync(inputDir)
63
.map((elem: string) => path.join(inputDir, elem))
66
.map((file: string) => {
67
let content = fs.readFileSync(file).toString()
68
let parsed = webidl2.parse(content)
69
return parsed.map(it => toIDLNode(file, it))
75
* Copyright (c) 2024 Huawei Device Co., Ltd.
76
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
78
* You may obtain a copy of the License at
80
* http://www.apache.org/licenses/LICENSE-2.0
82
* Unless required by applicable law or agreed to in writing, software
83
* distributed under the License is distributed on an "AS IS" BASIS,
84
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85
* See the License for the specific language governing permissions and
86
* limitations under the License.