188c88e8eSopenharmony_ci/* 288c88e8eSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 388c88e8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 488c88e8eSopenharmony_ci * you may not use this file except in compliance with the License. 588c88e8eSopenharmony_ci * You may obtain a copy of the License at 688c88e8eSopenharmony_ci * 788c88e8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 888c88e8eSopenharmony_ci * 988c88e8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1088c88e8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1188c88e8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1288c88e8eSopenharmony_ci * See the License for the specific language governing permissions and 1388c88e8eSopenharmony_ci * limitations under the License. 1488c88e8eSopenharmony_ci */ 1588c88e8eSopenharmony_ci 1688c88e8eSopenharmony_ciconst fs = require('fs'); 1788c88e8eSopenharmony_ciconst path = require('path'); 1888c88e8eSopenharmony_ci 1988c88e8eSopenharmony_ciconst exists = function(src, dst, callback) { 2088c88e8eSopenharmony_ci if (src.match(/\/test$/)) { 2188c88e8eSopenharmony_ci return; 2288c88e8eSopenharmony_ci } 2388c88e8eSopenharmony_ci fs.exists(dst, function(exists) { 2488c88e8eSopenharmony_ci if (exists) { 2588c88e8eSopenharmony_ci callback(src, dst); 2688c88e8eSopenharmony_ci } else { 2788c88e8eSopenharmony_ci fs.mkdir(dst, function() { 2888c88e8eSopenharmony_ci callback(src, dst); 2988c88e8eSopenharmony_ci }); 3088c88e8eSopenharmony_ci } 3188c88e8eSopenharmony_ci }); 3288c88e8eSopenharmony_ci}; 3388c88e8eSopenharmony_ci 3488c88e8eSopenharmony_cistat = fs.stat; 3588c88e8eSopenharmony_ciconst copy = function(src, dst) { 3688c88e8eSopenharmony_ci fs.readdir(src, function(err, paths) { 3788c88e8eSopenharmony_ci if (err) { 3888c88e8eSopenharmony_ci throw err; 3988c88e8eSopenharmony_ci } 4088c88e8eSopenharmony_ci paths.forEach(function(_path) { 4188c88e8eSopenharmony_ci const _src = src + '/' + _path; 4288c88e8eSopenharmony_ci const _dst = dst + '/' + _path; 4388c88e8eSopenharmony_ci let readable; 4488c88e8eSopenharmony_ci let writable; 4588c88e8eSopenharmony_ci stat(_src, function(err, st) { 4688c88e8eSopenharmony_ci if (err) { 4788c88e8eSopenharmony_ci throw err; 4888c88e8eSopenharmony_ci } 4988c88e8eSopenharmony_ci if (st.isFile()) { 5088c88e8eSopenharmony_ci const pathInfo = path.parse(_src); 5188c88e8eSopenharmony_ci if (pathInfo.name === 'gulpfile' || pathInfo.ext !== '.js') { 5288c88e8eSopenharmony_ci return; 5388c88e8eSopenharmony_ci } 5488c88e8eSopenharmony_ci readable = fs.createReadStream(_src); 5588c88e8eSopenharmony_ci writable = fs.createWriteStream(_dst); 5688c88e8eSopenharmony_ci readable.pipe(writable); 5788c88e8eSopenharmony_ci } else if (st.isDirectory()) { 5888c88e8eSopenharmony_ci exists(_src, _dst, copy); 5988c88e8eSopenharmony_ci } 6088c88e8eSopenharmony_ci }); 6188c88e8eSopenharmony_ci }); 6288c88e8eSopenharmony_ci }); 6388c88e8eSopenharmony_ci}; 6488c88e8eSopenharmony_ci 6588c88e8eSopenharmony_cifunction copyResource(src, dist) { 6688c88e8eSopenharmony_ci exists(path.resolve(__dirname, src), dist, copy); 6788c88e8eSopenharmony_ci} 6888c88e8eSopenharmony_ci 6988c88e8eSopenharmony_ciconst TARGET_POSITION = 2; 7088c88e8eSopenharmony_cicopyResource(path.resolve(__dirname, './deps/weex-scripter'), process.argv[TARGET_POSITION] + '/scripter'); 7188c88e8eSopenharmony_cicopyResource(path.resolve(__dirname, './deps/weex-styler'), process.argv[TARGET_POSITION] + '/styler'); 72