Skip to content

Commit

Permalink
drop moment replace by dayjs -200kb
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Apr 12, 2020
2 parents 7319a7f + ac2ca92 commit 8b0417b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/API.js
Expand Up @@ -625,11 +625,11 @@ class API {
}

if (opts && opts.rawArgs && opts.rawArgs.indexOf('--watch') > -1) {
var moment = require('moment');
var dayjs = require('dayjs');
function show() {
process.stdout.write('\x1b[2J');
process.stdout.write('\x1b[0f');
console.log('Last refresh: ', moment().format('LTS'));
console.log('Last refresh: ', dayjs().format());
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
UX.list(list, null);
});
Expand Down
8 changes: 4 additions & 4 deletions lib/API/Extra.js
Expand Up @@ -12,7 +12,7 @@ var chalk = require('chalk');
var path = require('path');
var fs = require('fs');
var fmt = require('../tools/fmt.js');
var moment = require('moment');
var dayjs = require('dayjs');
var pkg = require('../../package.json');
const semver = require('semver');

Expand Down Expand Up @@ -104,7 +104,7 @@ module.exports = function(CLI) {
fmt.field('user', report.user);
fmt.field('uid', report.uid);
fmt.field('gid', report.gid);
fmt.field('uptime', moment(new Date()).diff(report.started_at, 'minute') + 'min');
fmt.field('uptime', dayjs(new Date()).diff(report.started_at, 'minute') + 'min');

fmt.sep();
fmt.title(chalk.bold.blue('CLI'));
Expand Down Expand Up @@ -195,7 +195,7 @@ module.exports = function(CLI) {
*/
CLI.prototype.profile = function(type, time, cb) {
var that = this;
var moment = require('moment');
var dayjs = require('dayjs');
var cmd

if (type == 'cpu') {
Expand All @@ -211,7 +211,7 @@ module.exports = function(CLI) {
}
}

var file = path.join(process.cwd(), moment().format('dd-HH:mm:ss') + cmd.ext);
var file = path.join(process.cwd(), dayjs().format('dd-HH:mm:ss') + cmd.ext);
time = time || 10000

console.log(`Starting ${cmd.action} profiling for ${time}ms...`)
Expand Down
16 changes: 8 additions & 8 deletions lib/API/Log.js
Expand Up @@ -7,7 +7,7 @@ var fs = require('fs'),
util = require('util'),
chalk = require('chalk'),
forEachLimit = require('async/forEachLimit'),
moment = require('moment');
dayjs = require('dayjs');

var Log = module.exports = {};

Expand Down Expand Up @@ -89,7 +89,7 @@ Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) {
socket.on('reconnect attempt', function() {
if (global._auto_exit === true) {
if (timestamp)
process.stdout.write(chalk['dim'](chalk.grey(moment().format(timestamp) + ' ')));
process.stdout.write(chalk['dim'](chalk.grey(dayjs().format(timestamp) + ' ')));
process.stdout.write(chalk.blue(pad(DEFAULT_PADDING, 'PM2') + ' | ') + '[[[ Target PM2 killed. ]]]');
process.exit(0);
}
Expand Down Expand Up @@ -122,7 +122,7 @@ Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) {
return type === 'err' ? process.stderr.write(util.format(line) + '\n') : process.stdout.write(util.format(line) + '\n');

if (timestamp)
process.stdout.write(chalk['dim'](chalk.grey(moment().format(timestamp) + ' ')));
process.stdout.write(chalk['dim'](chalk.grey(dayjs().format(timestamp) + ' ')));

var name = packet.process.pm_id + '|' + packet.process.name;

Expand All @@ -137,7 +137,7 @@ Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) {
process.stdout.write(chalk.blue(pad(' '.repeat(min_padding), 'PM2') + ' | '));
if (highlight)
process.stdout.write(util.format(line).replace(highlight, chalk.bgBlackBright(highlight)) + '\n');
else
else
process.stdout.write(util.format(line)+ '\n');
});
});
Expand Down Expand Up @@ -188,7 +188,7 @@ Log.devStream = function(Client, id, raw, timestamp, exclusive) {
return process.stdout.write(util.format(line) + '\n');

if (timestamp)
process.stdout.write(chalk['dim'](chalk.grey(moment().format(timestamp) + ' ')));
process.stdout.write(chalk['dim'](chalk.grey(dayjs().format(timestamp) + ' ')));

var name = packet.process.name + '-' + packet.process.pm_id;

Expand All @@ -215,7 +215,7 @@ Log.jsonStream = function(Client, id) {

bus.on('process:event', function(packet) {
process.stdout.write(JSON.stringify({
timestamp : moment(packet.at),
timestamp : dayjs(packet.at),
type : 'process_event',
status : packet.event,
app_name : packet.process.name
Expand All @@ -237,7 +237,7 @@ Log.jsonStream = function(Client, id) {

process.stdout.write(JSON.stringify({
message : packet.data,
timestamp : moment(packet.at),
timestamp : dayjs(packet.at),
type : type,
process_id : packet.process.pm_id,
app_name : packet.process.name
Expand Down Expand Up @@ -280,7 +280,7 @@ Log.formatStream = function(Client, id, raw, timestamp, exclusive, highlight) {

if (!raw) {
if (timestamp)
process.stdout.write('timestamp=' + moment().format(timestamp) + ' ');
process.stdout.write('timestamp=' + dayjs().format(timestamp) + ' ');
if (packet.process.name === 'PM2')
process.stdout.write('app=pm2 ');
if (packet.process.name !== 'PM2')
Expand Down
6 changes: 3 additions & 3 deletions lib/Common.js
Expand Up @@ -15,7 +15,7 @@ var util = require('util');
var chalk = require('chalk');
var fclone = require('fclone');
var semver = require('semver');
var moment = require('moment');
var dayjs = require('dayjs');
var isBinary = require('./tools/isbinaryfile.js');
var cst = require('../constants.js');
var extItps = require('./API/interpreter.json');
Expand Down Expand Up @@ -86,15 +86,15 @@ Common.lockReload = function() {
// Check if content and if time < 30 return locked
// Else if content detected (lock file staled), allow and rewritte
if (t1 && t1 != '') {
var diff = moment().diff(parseInt(t1));
var diff = dayjs().diff(parseInt(t1));
if (diff < cst.RELOAD_LOCK_TIMEOUT)
return diff;
}
} catch(e) {}

try {
// Write latest timestamp
fs.writeFileSync(cst.PM2_RELOAD_LOCKFILE, moment.now());
fs.writeFileSync(cst.PM2_RELOAD_LOCKFILE, dayjs().valueOf());
return 0;
} catch(e) {
console.error(e.message || e);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -182,9 +182,9 @@
"enquirer": "^2.3.2",
"eventemitter2": "5.0.1",
"fclone": "1.0.11",
"lodash": "4.17.14",
"mkdirp": "1.0.4",
"moment": "2.24.0",
"lodash": "4.17.14",
"dayjs": "1.8.24",
"needle": "2.4.0",
"pidusage": "2.0.18",
"pm2-axon": "3.3.0",
Expand Down

0 comments on commit 8b0417b

Please sign in to comment.