1/* 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 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 16const fs = require('fs'); 17const path = require('path'); 18const moduleSource = require('./module-source'); 19 20const exists = function(src, dst, callback) { 21 if (src.match(/\/test$/)) { 22 return; 23 } 24 fs.exists(dst, function(exists) { 25 if (exists) { 26 callback(src, dst); 27 } else { 28 fs.mkdir(dst, function() { 29 callback(src, dst); 30 }); 31 } 32 }); 33}; 34 35stat = fs.stat; 36const copy = function(src, dst) { 37 fs.readdir(src, function(err, paths) { 38 if (err) { 39 throw err; 40 } 41 paths.forEach(function(_path) { 42 copyForEach(src, dst, _path); 43 }); 44 }); 45}; 46 47function copyForEach(src, dst, _path) { 48 let _src = src + '/' + _path; 49 let _dst = dst + '/' + _path; 50 let readable = null; 51 let writable = null; 52 stat(_src, function(err, st) { 53 if (err) { 54 throw err; 55 } 56 if (st.isFile()) { 57 const pathInfo = path.parse(_src); 58 if (pathInfo.name === 'gulpfile' || pathInfo.ext !== '.js') { 59 return; 60 } 61 readable = fs.createReadStream(_src); 62 writable = fs.createWriteStream(_dst); 63 readable.pipe(writable); 64 } else if (st.isDirectory()) { 65 exists(_src, _dst, copy); 66 } 67 }); 68} 69 70moduleSource.copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-scripter'), process.argv[2] + '/scripter'); 71moduleSource.copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-styler'), process.argv[2] + '/styler'); 72moduleSource.copyResource(path.resolve(__dirname, './third_party/parse5/packages/parse5/dist/cjs'), process.argv[2] + '/parse'); 73