1/* 2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 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*/ 15const { writeFile } = require("../tools/FileRW"); 16const re = require("../tools/re"); 17 18let gypTemplete = ` 19{ 20 "targets": [ 21 { 22 "target_name": "[implName]", 23 "sources": [ 24 "./[implName].cpp", 25 "./[implName]_middle.cpp", 26 "./tool_utility.cpp"], 27 "include_dirs": ["."], 28 "cflags_cc": [ "-frtti","-std=c++17" ] 29 } 30 ] 31} 32` 33 34/**创建nodejs编译文件,用于在ubuntu测试 */ 35function generateGYP(destDir, implName, license) { 36 let ss = gypTemplete.replaceAll("[implName]", implName) 37 if (license) { 38 let s2 = license.substring(2, license.length - 2).split("\n"); 39 license = ""; 40 for (let i = 1; i < s2.length; i++) { 41 if (s2[i].length > 0) { 42 while (s2[i][0] == " ") s2[i] = s2[i].substring(1); 43 if (s2[i].length > 3 && s2[i][0] == "*") { 44 license += "#" + s2[i].substring(1) + "\n"; 45 } 46 } 47 } 48 } 49 writeFile(re.pathJoin(destDir, "binding.gyp"), null != license ? (license + "\n" + ss) : ss) 50 51 writeFile(re.pathJoin(destDir, "test.sh"), "node-gyp configure build && sleep 0.5 && node --expose-gc test.js") 52 53} 54 55module.exports = { 56 generateGYP 57}