|
| 1 | +/* |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + or more contributor license agreements. See the NOTICE file |
| 4 | + distributed with this work for additional information |
| 5 | + regarding copyright ownership. The ASF licenses this file |
| 6 | + to you under the Apache License, Version 2.0 (the |
| 7 | + "License"); you may not use this file except in compliance |
| 8 | + with the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, |
| 13 | + software distributed under the License is distributed on an |
| 14 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + KIND, either express or implied. See the License for the |
| 16 | + specific language governing permissions and limitations |
| 17 | + under the License. |
| 18 | +*/ |
| 19 | + |
| 20 | +const fs = require('node:fs'); |
| 21 | +const path = require('node:path'); |
| 22 | +const peg = require('pegjs'); |
| 23 | + |
| 24 | +const ROOT_DIR = path.join(__dirname, '..'); |
| 25 | +const parserDir = path.join(ROOT_DIR, 'lib/parser'); |
| 26 | + |
| 27 | +// Path to grammar file |
| 28 | +const grammarFilePath = path.join(parserDir, 'pbxproj.pegjs'); |
| 29 | +// Path to where the parser file is outputted |
| 30 | +const outputFilePath = path.join(parserDir, 'pbxproj.js'); |
| 31 | + |
| 32 | +// Fetches the grammar file content and builds the output data. |
| 33 | +const grammarData = fs.readFileSync(grammarFilePath, 'utf8'); |
| 34 | +const outputData = peg.generate(grammarData, { |
| 35 | + output: 'source', |
| 36 | + format: 'commonjs' |
| 37 | +}); |
| 38 | + |
| 39 | +const asfLicenseHeader = `/* |
| 40 | + Licensed to the Apache Software Foundation (ASF) under one |
| 41 | + or more contributor license agreements. See the NOTICE file |
| 42 | + distributed with this work for additional information |
| 43 | + regarding copyright ownership. The ASF licenses this file |
| 44 | + to you under the Apache License, Version 2.0 (the |
| 45 | + "License"); you may not use this file except in compliance |
| 46 | + with the License. You may obtain a copy of the License at |
| 47 | +
|
| 48 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 49 | +
|
| 50 | + Unless required by applicable law or agreed to in writing, |
| 51 | + software distributed under the License is distributed on an |
| 52 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 53 | + KIND, either express or implied. See the License for the |
| 54 | + specific language governing permissions and limitations |
| 55 | + under the License. |
| 56 | +*/ |
| 57 | +`; |
| 58 | + |
| 59 | +// Append the Apache license header to the top of the built file. |
| 60 | +fs.writeFileSync(outputFilePath, `${asfLicenseHeader}${outputData}`); |
0 commit comments