16a23e08bSopenharmony_ci/* 26a23e08bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 36a23e08bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 46a23e08bSopenharmony_ci * you may not use this file except in compliance with the License. 56a23e08bSopenharmony_ci * You may obtain a copy of the License at 66a23e08bSopenharmony_ci * 76a23e08bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 86a23e08bSopenharmony_ci * 96a23e08bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 106a23e08bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 116a23e08bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 126a23e08bSopenharmony_ci * See the License for the specific language governing permissions and 136a23e08bSopenharmony_ci * limitations under the License. 146a23e08bSopenharmony_ci */ 156a23e08bSopenharmony_ci 166a23e08bSopenharmony_ciconst fs = require('fs'); 176a23e08bSopenharmony_ciconst path = require('path'); 186a23e08bSopenharmony_ciconst moduleSource = require('./module-source'); 196a23e08bSopenharmony_ci 206a23e08bSopenharmony_ciconst exists = function(src, dst, callback) { 216a23e08bSopenharmony_ci if (src.match(/\/test$/)) { 226a23e08bSopenharmony_ci return; 236a23e08bSopenharmony_ci } 246a23e08bSopenharmony_ci fs.exists(dst, function(exists) { 256a23e08bSopenharmony_ci if (exists) { 266a23e08bSopenharmony_ci callback(src, dst); 276a23e08bSopenharmony_ci } else { 286a23e08bSopenharmony_ci fs.mkdir(dst, function() { 296a23e08bSopenharmony_ci callback(src, dst); 306a23e08bSopenharmony_ci }); 316a23e08bSopenharmony_ci } 326a23e08bSopenharmony_ci }); 336a23e08bSopenharmony_ci}; 346a23e08bSopenharmony_ci 356a23e08bSopenharmony_cistat = fs.stat; 366a23e08bSopenharmony_ciconst copy = function(src, dst) { 376a23e08bSopenharmony_ci fs.readdir(src, function(err, paths) { 386a23e08bSopenharmony_ci if (err) { 396a23e08bSopenharmony_ci throw err; 406a23e08bSopenharmony_ci } 416a23e08bSopenharmony_ci paths.forEach(function(_path) { 426a23e08bSopenharmony_ci copyForEach(src, dst, _path); 436a23e08bSopenharmony_ci }); 446a23e08bSopenharmony_ci }); 456a23e08bSopenharmony_ci}; 466a23e08bSopenharmony_ci 476a23e08bSopenharmony_cifunction copyForEach(src, dst, _path) { 486a23e08bSopenharmony_ci let _src = src + '/' + _path; 496a23e08bSopenharmony_ci let _dst = dst + '/' + _path; 506a23e08bSopenharmony_ci let readable = null; 516a23e08bSopenharmony_ci let writable = null; 526a23e08bSopenharmony_ci stat(_src, function(err, st) { 536a23e08bSopenharmony_ci if (err) { 546a23e08bSopenharmony_ci throw err; 556a23e08bSopenharmony_ci } 566a23e08bSopenharmony_ci if (st.isFile()) { 576a23e08bSopenharmony_ci const pathInfo = path.parse(_src); 586a23e08bSopenharmony_ci if (pathInfo.name === 'gulpfile' || pathInfo.ext !== '.js') { 596a23e08bSopenharmony_ci return; 606a23e08bSopenharmony_ci } 616a23e08bSopenharmony_ci readable = fs.createReadStream(_src); 626a23e08bSopenharmony_ci writable = fs.createWriteStream(_dst); 636a23e08bSopenharmony_ci readable.pipe(writable); 646a23e08bSopenharmony_ci } else if (st.isDirectory()) { 656a23e08bSopenharmony_ci exists(_src, _dst, copy); 666a23e08bSopenharmony_ci } 676a23e08bSopenharmony_ci }); 686a23e08bSopenharmony_ci} 696a23e08bSopenharmony_ci 706a23e08bSopenharmony_cimoduleSource.copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-scripter'), process.argv[2] + '/scripter'); 716a23e08bSopenharmony_cimoduleSource.copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-styler'), process.argv[2] + '/styler'); 726a23e08bSopenharmony_cimoduleSource.copyResource(path.resolve(__dirname, './third_party/parse5/packages/parse5/dist/cjs'), process.argv[2] + '/parse'); 73