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_ciconst uglifyJS = require('uglify-js'); 1988c88e8eSopenharmony_ci 2088c88e8eSopenharmony_ciconst SOURCE_POSITION = 2; 2188c88e8eSopenharmony_cireadCode(process.argv[SOURCE_POSITION]); 2288c88e8eSopenharmony_ci 2388c88e8eSopenharmony_cifunction readCode(inputPath) { 2488c88e8eSopenharmony_ci if (fs.existsSync(inputPath)) { 2588c88e8eSopenharmony_ci const files = fs.readdirSync(inputPath); 2688c88e8eSopenharmony_ci files.forEach(function(file) { 2788c88e8eSopenharmony_ci const filePath = path.join(inputPath, file); 2888c88e8eSopenharmony_ci if (fs.existsSync(filePath)) { 2988c88e8eSopenharmony_ci const fileStat = fs.statSync(filePath); 3088c88e8eSopenharmony_ci if (fileStat.isFile()) { 3188c88e8eSopenharmony_ci const code = fs.readFileSync(filePath, 'utf-8'); 3288c88e8eSopenharmony_ci uglifyCode(code, filePath); 3388c88e8eSopenharmony_ci } 3488c88e8eSopenharmony_ci if (fileStat.isDirectory()) { 3588c88e8eSopenharmony_ci readCode(filePath); 3688c88e8eSopenharmony_ci } 3788c88e8eSopenharmony_ci } 3888c88e8eSopenharmony_ci }); 3988c88e8eSopenharmony_ci } 4088c88e8eSopenharmony_ci} 4188c88e8eSopenharmony_ci 4288c88e8eSopenharmony_cifunction uglifyCode(code, outPath) { 4388c88e8eSopenharmony_ci const uglifyCode = uglifyJS.minify(code).code; 4488c88e8eSopenharmony_ci fs.writeFileSync(outPath, uglifyCode); 4588c88e8eSopenharmony_ci} 46