16a23e08bSopenharmony_ci/* 26a23e08bSopenharmony_ci * Copyright (c) 2021 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_ci 196a23e08bSopenharmony_ciconst exists = function(src, dst, callback) { 206a23e08bSopenharmony_ci if (src.match(/\/test$/)) { 216a23e08bSopenharmony_ci return; 226a23e08bSopenharmony_ci } 236a23e08bSopenharmony_ci fs.exists(dst, function(exists) { 246a23e08bSopenharmony_ci if(exists){ 256a23e08bSopenharmony_ci callback(src, dst); 266a23e08bSopenharmony_ci } else{ 276a23e08bSopenharmony_ci fs.mkdir(dst, function() { 286a23e08bSopenharmony_ci callback(src, dst); 296a23e08bSopenharmony_ci }); 306a23e08bSopenharmony_ci } 316a23e08bSopenharmony_ci }); 326a23e08bSopenharmony_ci} 336a23e08bSopenharmony_ci 346a23e08bSopenharmony_cistat = fs.stat; 356a23e08bSopenharmony_ciconst copy = function(src, dst){ 366a23e08bSopenharmony_ci fs.readdir(src, function(err, paths){ 376a23e08bSopenharmony_ci if(err){ 386a23e08bSopenharmony_ci throw err; 396a23e08bSopenharmony_ci } 406a23e08bSopenharmony_ci paths.forEach(function(_path){ 416a23e08bSopenharmony_ci var _src = src + '/' + _path, 426a23e08bSopenharmony_ci _dst = dst + '/' + _path, 436a23e08bSopenharmony_ci readable, writable; 446a23e08bSopenharmony_ci stat(_src, function(err, st){ 456a23e08bSopenharmony_ci if(err){ 466a23e08bSopenharmony_ci throw err; 476a23e08bSopenharmony_ci } 486a23e08bSopenharmony_ci if(st.isFile()){ 496a23e08bSopenharmony_ci const pathInfo = path.parse(_src); 506a23e08bSopenharmony_ci if (pathInfo.name == 'gulpfile' || pathInfo.ext != '.js') { 516a23e08bSopenharmony_ci return; 526a23e08bSopenharmony_ci } 536a23e08bSopenharmony_ci readable = fs.createReadStream(_src); 546a23e08bSopenharmony_ci writable = fs.createWriteStream(_dst); 556a23e08bSopenharmony_ci readable.pipe(writable); 566a23e08bSopenharmony_ci } else if(st.isDirectory()){ 576a23e08bSopenharmony_ci exists(_src, _dst, copy); 586a23e08bSopenharmony_ci } 596a23e08bSopenharmony_ci }); 606a23e08bSopenharmony_ci }); 616a23e08bSopenharmony_ci }); 626a23e08bSopenharmony_ci}; 636a23e08bSopenharmony_ci 646a23e08bSopenharmony_cifunction copyResource(src, dist) { 656a23e08bSopenharmony_ci exists(path.resolve(__dirname, src), dist, copy); 666a23e08bSopenharmony_ci} 676a23e08bSopenharmony_ci 686a23e08bSopenharmony_cicopyResource(path.resolve(__dirname, './plugin/templater'), process.argv[2] + '/templater'); 696a23e08bSopenharmony_cicopyResource(path.resolve(__dirname, './plugin/theme'), process.argv[2] + '/theme'); 706a23e08bSopenharmony_cicopyResource(path.resolve(__dirname, './plugin/codegen'), process.argv[2] + '/codegen'); 716a23e08bSopenharmony_ci 726a23e08bSopenharmony_cimodule.exports = { 736a23e08bSopenharmony_ci copyResource 746a23e08bSopenharmony_ci}; 75