ssr
Version:
cli for react/vue2/vue3 ssr deploy on serverless or tradtional web server
38 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanOutDir = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
const shelljs_1 = require("shelljs");
const cleanOutDir = async (argv) => {
const { accessFile, getCwd } = await Promise.resolve().then(() => require('ssr-common-utils'));
const cwd = getCwd();
const staticConfigPath = (0, path_1.resolve)(cwd, './build/staticConfig.js');
if (!(await accessFile((0, path_1.resolve)(cwd, './build')))) {
(0, shelljs_1.mkdir)((0, path_1.resolve)(cwd, './build'));
}
const buildDir = await fs_1.promises.readdir((0, path_1.resolve)(cwd, './build'));
if (argv.noclean) {
return;
}
for (const f of buildDir) {
const fpath = (0, path_1.resolve)(cwd, `./build/${f}`);
if (fpath !== staticConfigPath) {
(0, shelljs_1.rm)('-rf', fpath);
}
}
// clean dist folder
const tsconfigExist = await accessFile((0, path_1.resolve)(cwd, './tsconfig.json'));
if (tsconfigExist && process.env.CLEAN !== 'false') {
try {
const outDir = require((0, path_1.resolve)(cwd, './tsconfig.json')).compilerOptions.outDir;
(0, shelljs_1.rm)('-rf', (0, path_1.resolve)(cwd, outDir));
}
catch (_error) {
// 有可能 json 文件存在注释导致 require 失败,这里 catch 一下
console.log('检测到当前目录 tsconfig.json 文件可能存在语法错误');
}
}
};
exports.cleanOutDir = cleanOutDir;
//# sourceMappingURL=clean.js.map