Skip to content

Commit

Permalink
Replace date-fns by date-and-time-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj committed Sep 23, 2023
1 parent a61ef39 commit 7fd13e6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 56 deletions.
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ concurrently [options] <command ...>
General
-m, --max-processes How many processes should run at once.
Exact number or a percent of CPUs available (for example "50%").
New processes only spawn after all restart tries
of a process. [string]
of a process.
Exact number or a percent of CPUs available (for
example "50%") [string]
-n, --names List of custom names to be used in prefix
template.
Example names: "main,browser,server" [string]
Expand Down Expand Up @@ -202,7 +203,7 @@ Prefix styling
in prefix. The option can be used to shorten the
prefix when it is set to "command"
[number] [default: 10]
-t, --timestamp-format Specify the timestamp in moment/date-fns format.
-t, --timestamp-format Specify the timestamp in Unicode LDML format.
[string] [default: "yyyy-MM-dd HH:mm:ss.SSS"]
Input handling
Expand All @@ -219,8 +220,9 @@ Killing other processes
-k, --kill-others Kill other processes if one exits or dies.[boolean]
--kill-others-on-fail Kill other processes if one exits with non zero
status code. [boolean]
--kill-signal Signal to send to other processes if one exits or dies.
(SIGTERM/SIGKILL, defaults to SIGTERM) [string]
--kill-signal, --ks Signal to send to other processes if one exits or
dies. (SIGTERM/SIGKILL, defaults to SIGTERM)
[string]
Restarting
--restart-tries How many times a process that died should restart.
Expand All @@ -238,73 +240,73 @@ Examples:
- Output nothing more than stdout+stderr of child processes
$ concurrently --raw "npm run watch-less" "npm run watch-js"
$ concurrently.js --raw "npm run watch-less" "npm run watch-js"
- Normal output but without colors e.g. when logging to file
$ concurrently --no-color "grunt watch" "http-server" > log
$ concurrently.js --no-color "grunt watch" "http-server" > log
- Custom prefix
$ concurrently --prefix "{time}-{pid}" "npm run watch" "http-server"
$ concurrently.js --prefix "{time}-{pid}" "npm run watch" "http-server"
- Custom names and colored prefixes
$ concurrently --names "HTTP,WATCH" -c "bgBlue.bold,bgMagenta.bold"
$ concurrently.js --names "HTTP,WATCH" -c "bgBlue.bold,bgMagenta.bold"
"http-server" "npm run watch"
- Auto varying colored prefixes
$ concurrently -c "auto" "npm run watch" "http-server"
$ concurrently.js -c "auto" "npm run watch" "http-server"
- Mixing auto and manual colored prefixes
$ concurrently -c "red,auto" "npm run watch" "http-server" "echo hello"
$ concurrently.js -c "red,auto" "npm run watch" "http-server" "echo hello"
- Configuring via environment variables with CONCURRENTLY_ prefix
$ CONCURRENTLY_RAW=true CONCURRENTLY_KILL_OTHERS=true concurrently "echo
$ CONCURRENTLY_RAW=true CONCURRENTLY_KILL_OTHERS=true concurrently.js "echo
hello" "echo world"
- Send input to default
$ concurrently --handle-input "nodemon" "npm run watch-js"
$ concurrently.js --handle-input "nodemon" "npm run watch-js"
rs # Sends rs command to nodemon process
- Send input to specific child identified by index
$ concurrently --handle-input "npm run watch-js" nodemon
$ concurrently.js --handle-input "npm run watch-js" nodemon
1:rs
- Send input to specific child identified by name
$ concurrently --handle-input -n js,srv "npm run watch-js" nodemon
$ concurrently.js --handle-input -n js,srv "npm run watch-js" nodemon
srv:rs
- Shortened NPM run commands
$ concurrently npm:watch-node npm:watch-js npm:watch-css
$ concurrently.js npm:watch-node npm:watch-js npm:watch-css
- Shortened NPM run command with wildcard (make sure to wrap it in quotes!)
$ concurrently "npm:watch-*"
$ concurrently.js "npm:watch-*"
- Exclude patterns so that between "lint:js" and "lint:fix:js", only "lint:js"
is ran
$ concurrently "npm:*(!fix)"
$ concurrently.js "npm:*(!fix)"
- Passthrough some additional arguments via '{<number>}' placeholder
$ concurrently -P "echo {1}" -- foo
$ concurrently.js -P "echo {1}" -- foo
- Passthrough all additional arguments via '{@}' placeholder
$ concurrently -P "npm:dev-* -- {@}" -- --watch --noEmit
$ concurrently.js -P "npm:dev-* -- {@}" -- --watch --noEmit
- Passthrough all additional arguments combined via '{*}' placeholder
$ concurrently -P "npm:dev-* -- {*}" -- --watch --noEmit
$ concurrently.js -P "npm:dev-* -- {*}" -- --watch --noEmit
For more details, visit https://github.com/open-cli-tools/concurrently
```
Expand Down Expand Up @@ -346,7 +348,7 @@ For more details, visit https://github.com/open-cli-tools/concurrently
Anything else means all processes should exit successfully.
- `restartTries`: how many attempts to restart a process that dies will be made. Default: `0`.
- `restartDelay`: how many milliseconds to wait between process restarts. Default: `0`.
- `timestampFormat`: a [date-fns format](https://date-fns.org/v2.0.1/docs/format)
- `timestampFormat`: a [Unicode LDML format](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)
to use when prefixing with `time`. Default: `yyyy-MM-dd HH:mm:ss.ZZZ`
- `additionalArguments`: list of additional arguments passed that will get replaced in each command. If not defined, no argument replacing will happen.

Expand Down
2 changes: 1 addition & 1 deletion bin/concurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const args = yargs(argsBeforeSep)
},
'timestamp-format': {
alias: 't',
describe: 'Specify the timestamp in moment/date-fns format.',
describe: 'Specify the timestamp in Unicode LDML format.',
default: defaults.timestampFormat,
type: 'string',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"license": "MIT",
"dependencies": {
"chalk": "^4.1.2",
"date-fns": "^2.30.0",
"date-and-time-formatter": "^1.0.0",
"lodash": "^4.17.21",
"rxjs": "^7.8.1",
"shell-quote": "^1.8.1",
Expand Down
25 changes: 6 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const success = 'all' as SuccessCondition;

/**
* Date format used when logging date/time.
* @see https://date-fns.org/v2.0.1/docs/format
* @see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
*/
export const timestampFormat = 'yyyy-MM-dd HH:mm:ss.SSS';

Expand Down
10 changes: 5 additions & 5 deletions src/flow-control/log-timings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import formatDate from 'date-fns/format';
import { formatDateTime } from 'date-and-time-formatter';
import { createMockInstance } from 'jest-create-mock-instance';

import { CloseEvent } from '../command';
Expand Down Expand Up @@ -79,22 +79,22 @@ it('logs the timings at the start and end (ie complete or error) event of each c

expect(logger.logCommandEvent).toHaveBeenCalledTimes(4);
expect(logger.logCommandEvent).toHaveBeenCalledWith(
`${commands[0].command} started at ${formatDate(startDate0, timestampFormat)}`,
`${commands[0].command} started at ${formatDateTime(startDate0, timestampFormat)}`,
commands[0],
);
expect(logger.logCommandEvent).toHaveBeenCalledWith(
`${commands[1].command} started at ${formatDate(startDate1, timestampFormat)}`,
`${commands[1].command} started at ${formatDateTime(startDate1, timestampFormat)}`,
commands[1],
);
expect(logger.logCommandEvent).toHaveBeenCalledWith(
`${commands[1].command} stopped at ${formatDate(
`${commands[1].command} stopped at ${formatDateTime(
endDate1,
timestampFormat,
)} after ${command1DurationTextMs}`,
commands[1],
);
expect(logger.logCommandEvent).toHaveBeenCalledWith(
`${commands[0].command} stopped at ${formatDate(
`${commands[0].command} stopped at ${formatDateTime(
endDate0,
timestampFormat,
)} after ${command0DurationTextMs}`,
Expand Down
6 changes: 3 additions & 3 deletions src/flow-control/log-timings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from 'assert';
import formatDate from 'date-fns/format';
import { formatDateTime } from 'date-and-time-formatter';
import _ from 'lodash';
import * as Rx from 'rxjs';
import { bufferCount, combineLatestWith, take } from 'rxjs/operators';
Expand Down Expand Up @@ -77,14 +77,14 @@ export class LogTimings implements FlowController {
commands.forEach((command) => {
command.timer.subscribe(({ startDate, endDate }) => {
if (!endDate) {
const formattedStartDate = formatDate(startDate, this.timestampFormat);
const formattedStartDate = formatDateTime(startDate, this.timestampFormat);
logger.logCommandEvent(
`${command.command} started at ${formattedStartDate}`,
command,
);
} else {
const durationMs = endDate.getTime() - startDate.getTime();
const formattedEndDate = formatDate(endDate, this.timestampFormat);
const formattedEndDate = formatDateTime(endDate, this.timestampFormat);
logger.logCommandEvent(
`${
command.command
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type ConcurrentlyOptions = BaseConcurrentlyOptions & {

/**
* Date format used when logging date/time.
* @see https://date-fns.org/v2.0.1/docs/format
* @see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
*/
timestampFormat?: string;

Expand Down
6 changes: 3 additions & 3 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import formatDate from 'date-fns/format';
import { formatDateTime } from 'date-and-time-formatter';
import _ from 'lodash';
import * as Rx from 'rxjs';

Expand Down Expand Up @@ -56,7 +56,7 @@ export class Logger {

/**
* Date format used when logging date/time.
* @see https://date-fns.org/v2.0.1/docs/format
* @see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
*/
timestampFormat?: string;
}) {
Expand Down Expand Up @@ -93,7 +93,7 @@ export class Logger {
index: String(command.index),
name: command.name,
command: this.shortenText(command.command),
time: formatDate(Date.now(), this.timestampFormat),
time: formatDateTime(new Date(), this.timestampFormat),
};
}

Expand Down

0 comments on commit 7fd13e6

Please sign in to comment.