just-task 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/cache.d.ts +4 -3
  2. package/lib/cache.d.ts.map +1 -1
  3. package/lib/cache.js +6 -128
  4. package/lib/cli.js +2 -2
  5. package/lib/config.js +6 -6
  6. package/lib/enableTypeScript.js +2 -2
  7. package/lib/interfaces.d.ts +1 -0
  8. package/lib/interfaces.d.ts.map +1 -1
  9. package/lib/logger.d.ts +16 -1
  10. package/lib/logger.d.ts.map +1 -1
  11. package/lib/logger.js +52 -11
  12. package/lib/task.d.ts.map +1 -1
  13. package/lib/task.js +0 -10
  14. package/lib/undertaker.d.ts.map +1 -1
  15. package/lib/undertaker.js +0 -2
  16. package/package.json +1 -3
  17. package/src/cache.ts +5 -168
  18. package/src/cli.ts +1 -1
  19. package/src/config.ts +1 -1
  20. package/src/enableTypeScript.ts +1 -1
  21. package/src/interfaces.ts +1 -0
  22. package/src/logger.ts +85 -1
  23. package/src/task.ts +0 -10
  24. package/src/undertaker.ts +0 -3
  25. package/CHANGELOG.json +0 -1314
  26. package/CHANGELOG.md +0 -629
  27. package/lib/package/findDependents.d.ts +0 -7
  28. package/lib/package/findDependents.d.ts.map +0 -1
  29. package/lib/package/findDependents.js +0 -56
  30. package/lib/package/findGitRoot.d.ts +0 -2
  31. package/lib/package/findGitRoot.d.ts.map +0 -1
  32. package/lib/package/findGitRoot.js +0 -26
  33. package/lib/package/findPackageRoot.d.ts +0 -2
  34. package/lib/package/findPackageRoot.d.ts.map +0 -1
  35. package/lib/package/findPackageRoot.js +0 -11
  36. package/lib/paths.d.ts +0 -2
  37. package/lib/paths.d.ts.map +0 -1
  38. package/lib/paths.js +0 -9
  39. package/src/package/findDependents.ts +0 -68
  40. package/src/package/findGitRoot.ts +0 -28
  41. package/src/package/findPackageRoot.ts +0 -8
  42. package/src/paths.ts +0 -6
package/src/logger.ts CHANGED
@@ -1 +1,85 @@
1
- export * from 'just-task-logger';
1
+ import chalk = require('chalk');
2
+ import * as parser from 'yargs-parser';
3
+
4
+ const argv = parser(process.argv.slice(2));
5
+
6
+ function logInternal(method: 'info' | 'warn' | 'error', symbol: string, ...args: any[]) {
7
+ const now = new Date();
8
+ const timestamp = chalk.gray(`[${now.toLocaleTimeString()}]`);
9
+
10
+ console[method](timestamp, symbol, ...args);
11
+ }
12
+
13
+ const markers: { [marker: string]: [number, number] } = {};
14
+
15
+ export function mark(marker: string): void {
16
+ markers[marker] = process.hrtime();
17
+ }
18
+
19
+ function getDeltaAndClearMark(marker: string): [number, number] | null {
20
+ if (markers[marker]) {
21
+ const delta = process.hrtime(markers[marker]);
22
+ delete markers[marker];
23
+ return delta;
24
+ }
25
+
26
+ return null;
27
+ }
28
+
29
+ export interface Logger {
30
+ /** Whether verbose logging is enabled. Default false unless --verbose arg is given. */
31
+ enableVerbose: boolean;
32
+ /** Log to `console.info` with a timestamp, but only if verbose logging is enabled. */
33
+ verbose(...args: any[]): void;
34
+ /** Log to `console.info` with a timestamp. */
35
+ info(...args: any[]): void;
36
+ /** Log to `console.warn` with a timestamp. */
37
+ warn(...args: any[]): void;
38
+ /** Log to `console.error` with a timestamp. */
39
+ error(...args: any[]): void;
40
+ /** Log perf marker data to `consold.info` with timestamp, only if verbose is enabled */
41
+ perf(marker: string, ...args: any[]): void;
42
+ }
43
+
44
+ const emptySquare = '\u25a1';
45
+ const square = '\u25a0';
46
+ const triangle = '\u25b2';
47
+
48
+ export const logger: Logger = {
49
+ enableVerbose: !!argv.verbose,
50
+
51
+ verbose(...args: any[]) {
52
+ if (logger.enableVerbose) {
53
+ logInternal('info', chalk.gray(emptySquare), ...args);
54
+ }
55
+ },
56
+
57
+ info(...args: any[]) {
58
+ logInternal('info', chalk.green(square), ...args);
59
+ },
60
+
61
+ warn(...args: any[]) {
62
+ logInternal('warn', chalk.yellow(triangle), ...args);
63
+ },
64
+
65
+ error(...args: any[]) {
66
+ logInternal('error', chalk.redBright('x'), ...args);
67
+ },
68
+
69
+ perf(marker: string, ...args: any[]) {
70
+ if (logger.enableVerbose) {
71
+ const delta = getDeltaAndClearMark(marker);
72
+
73
+ if (delta) {
74
+ const ns = delta[0] * 1e9 + delta[1];
75
+ const deltaMsg = `${ns / 1e9}s`;
76
+ logInternal(
77
+ 'info',
78
+ chalk.cyan(square),
79
+ `mark(${chalk.cyanBright(marker)}): took ${chalk.cyanBright(deltaMsg)}`,
80
+ ...args,
81
+ );
82
+ }
83
+ }
84
+ },
85
+ };
package/src/task.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { undertaker } from './undertaker';
2
2
  import { wrapTask } from './wrapTask';
3
3
  import { TaskFunction } from './interfaces';
4
- import { registerCachedTask } from './cache';
5
4
 
6
5
  export function task(
7
6
  firstParam: string | TaskFunction,
@@ -16,9 +15,6 @@ export function task(
16
15
  // task('default', 'build');
17
16
 
18
17
  const wrapped = wrapTask(undertaker.series(secondParam));
19
- wrapped.cached = () => {
20
- registerCachedTask(firstParam);
21
- };
22
18
 
23
19
  undertaker.task(firstParam, wrapped);
24
20
 
@@ -27,9 +23,6 @@ export function task(
27
23
  // task('pretter', prettierTask());
28
24
  // task('custom', () => { ... });
29
25
  const wrapped = wrapTask(secondParam as TaskFunction) as TaskFunction;
30
- wrapped.cached = () => {
31
- registerCachedTask(firstParam);
32
- };
33
26
 
34
27
  undertaker.task(firstParam, wrapped);
35
28
 
@@ -37,9 +30,6 @@ export function task(
37
30
  } else if (argCount === 3 && isString(firstParam) && isString(secondParam) && isTaskFunction(thirdParam)) {
38
31
  // task('custom', 'describes this thing', () => { ... })
39
32
  const wrapped = wrapTask(thirdParam);
40
- wrapped.cached = () => {
41
- registerCachedTask(firstParam);
42
- };
43
33
 
44
34
  wrapped.description = secondParam;
45
35
 
package/src/undertaker.ts CHANGED
@@ -2,7 +2,6 @@ import { logger } from './logger';
2
2
  import chalk = require('chalk');
3
3
  import { wrapTask } from './wrapTask';
4
4
  import { Task } from './interfaces';
5
- import { clearCache } from './cache';
6
5
  import Undertaker = require('undertaker');
7
6
 
8
7
  const undertaker = new Undertaker();
@@ -84,8 +83,6 @@ undertaker.on('error', function (args: any) {
84
83
 
85
84
  logger.error(chalk.yellow('------------------------------------'));
86
85
 
87
- clearCache();
88
-
89
86
  process.exitCode = 1;
90
87
  } else if (shouldLog(args)) {
91
88
  const duration = args.duration;