#! /usr/bin/node

const fs = require('fs');
const dayjs = require('dayjs');
const shell = require('shelljs');

const is_numeric = (value) => {
  if (typeof (value) === 'object') {
    return false;
  } else {
    return !Number.isNaN(Number(value));
  }
};

const startPath = "/data/docker/applog/psip";

fs.readdirSync(startPath).forEach(item => {
  fs.readdirSync(`${startPath}/${item}/Logs`).forEach(logDir => {
    if (is_numeric(logDir)) {

      var date = dayjs(logDir.toString());

      if (date.isBefore(dayjs().subtract(7, 'day'))) {

        const deleteDir = `${startPath}/${item}/Logs/${logDir}`;

        shell.exec(`rm -rf ${deleteDir}`);

        console.log(`删除文件夹${deleteDir}`);
      }
    }

  })
});

