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