2021-08-28 08:48:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2024-05-19 03:21:53 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const uglifyJS = require('uglify-js');
|
2021-08-28 08:48:39 +00:00
|
|
|
|
2024-05-19 03:21:53 +00:00
|
|
|
readCode(process.argv[2]);
|
2021-08-28 08:48:39 +00:00
|
|
|
|
|
|
|
function readCode(inputPath) {
|
|
|
|
if (fs.existsSync(inputPath)) {
|
2024-05-19 03:21:53 +00:00
|
|
|
const files = fs.readdirSync(inputPath);
|
2021-08-28 08:48:39 +00:00
|
|
|
files.forEach(function(file) {
|
2024-05-19 03:21:53 +00:00
|
|
|
const filePath = path.join(inputPath, file);
|
2021-08-28 08:48:39 +00:00
|
|
|
if (fs.existsSync(filePath)) {
|
2024-05-19 03:21:53 +00:00
|
|
|
const fileStat = fs.statSync(filePath);
|
2021-08-28 08:48:39 +00:00
|
|
|
if (fileStat.isFile()) {
|
2024-05-19 03:21:53 +00:00
|
|
|
const code = fs.readFileSync(filePath, 'utf-8');
|
|
|
|
uglifyCode(code, filePath);
|
2021-08-28 08:48:39 +00:00
|
|
|
}
|
|
|
|
if (fileStat.isDirectory()) {
|
2024-05-19 03:21:53 +00:00
|
|
|
readCode(filePath);
|
2021-08-28 08:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-19 03:21:53 +00:00
|
|
|
});
|
2021-08-28 08:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uglifyCode(code, outPath) {
|
2024-05-19 03:21:53 +00:00
|
|
|
const uglifyCode = uglifyJS.minify(code).code;
|
|
|
|
fs.writeFileSync(outPath, uglifyCode);
|
2021-08-28 08:48:39 +00:00
|
|
|
}
|