Skip to content

Commit b54b84d

Browse files
author
Claudia Sun
committed
fix some comments
1 parent aa8a154 commit b54b84d

File tree

7 files changed

+60
-53
lines changed

7 files changed

+60
-53
lines changed

apps/notifications/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
"version": "1.0.0",
55
"private": true,
66
"main": "lib/start.js",
7-
"types": "dist/heft.d.ts",
8-
"bin": {
9-
"heft": "./bin/heft"
10-
},
117
"scripts": {
128
"build": "heft build --clean",
139
"start": "heft test --clean --watch",

apps/notifications/src/AddNotifications.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { JsonFile, Executable } from '@rushstack/node-core-library';
1+
import { JsonFile } from '@rushstack/node-core-library';
22
import * as inquirer from 'inquirer';
3-
import { SpawnSyncReturns } from 'child_process';
4-
5-
export interface IAnswers {
6-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7-
[key: string]: any;
8-
}
3+
import * as path from 'path';
4+
import { IAnswers, INotificationJson } from './configurations';
95

106
export class AddNotifications {
117
public constructor() {}
@@ -22,29 +18,18 @@ export class AddNotifications {
2218
}
2319
])
2420
.then((answers: IAnswers) => {
25-
// the branch will be changed to main once pr is in
26-
const spawnResult: SpawnSyncReturns<string> = Executable.spawnSync(
27-
'git',
28-
[
29-
'cat-file',
30-
'blob',
31-
'refs/remotes/origin/zhas/cli-notification:common/config/notifications/notifications.json'
32-
],
33-
{
34-
currentWorkingDirectory: process.cwd()
35-
}
21+
const pathToJson: string = path.join(
22+
process.cwd(),
23+
'..',
24+
'..',
25+
'common/config/notifications/notifications.json'
3626
);
37-
38-
if (spawnResult.status !== 0) {
39-
throw new Error(`git cat-file exited with status ${spawnResult.status}: ${spawnResult.stderr}`);
40-
}
41-
42-
const notificationJson: IAnswers = JSON.parse(spawnResult.stdout);
27+
const notificationJson: INotificationJson = JsonFile.load(pathToJson);
4328
const notifications: IAnswers[] = notificationJson.notifications;
4429

4530
// insert new notification
4631
const currentDate: Date = new Date();
47-
answers.timeStamp = this._setExpirationDate(currentDate, 3).toISOString();
32+
answers.expiration = this._setExpirationDate(currentDate, 3).toISOString();
4833
notifications.splice(notifications.length, 0, answers);
4934

5035
JsonFile.save(notificationJson, '../../common/config/notifications/notifications.json', {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ConsoleTerminalProvider, Terminal, Executable } from '@rushstack/node-core-library';
2+
import { SpawnSyncReturns } from 'child_process';
3+
import { IAnswers, INotificationJson } from './configurations';
4+
5+
// the branch will be changed to main once pr is in
6+
const spawnResult: SpawnSyncReturns<string> = Executable.spawnSync(
7+
'git',
8+
[
9+
'cat-file',
10+
'blob',
11+
'refs/remotes/origin/zhas/cli-notification:common/config/notifications/notifications.json'
12+
],
13+
{
14+
currentWorkingDirectory: process.cwd()
15+
}
16+
);
17+
18+
if (spawnResult.status !== 0) {
19+
throw new Error(`git cat-file exited with status ${spawnResult.status}: ${spawnResult.stderr}`);
20+
}
21+
22+
const notificationJson: INotificationJson = JSON.parse(spawnResult.stdout);
23+
const notifications: IAnswers[] = notificationJson.notifications;
24+
25+
// for display
26+
const terminal: Terminal = new Terminal(new ConsoleTerminalProvider());
27+
const currentDate: Date = new Date();
28+
terminal.writeLine(`=====================================`);
29+
30+
notifications.forEach((announcement) => {
31+
// check if the announcement is expired, we only display the unexpired ones
32+
if (new Date(announcement.expiration).getTime() > currentDate.getTime()) {
33+
terminal.writeLine(`${announcement.message}`);
34+
}
35+
});
36+
37+
terminal.writeLine(`=====================================`);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface IAnswers {
2+
message: string;
3+
expiration: string;
4+
}
5+
6+
export interface INotificationJson {
7+
notifications: IAnswers[];
8+
}

apps/notifications/src/displayNotifications.js

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"notifications": [
33
{
4-
"timeStamp": "2022-02-15T18:56:25.322Z",
5-
"message": "test 1"
4+
"message": "test 1",
5+
"expiration": "2022-02-15T18:56:25.322Z"
66
},
77
{
8-
"timeStamp": "2022-02-15T18:56:25.322Z",
9-
"message": "test 2"
8+
"message": "test 2",
9+
"expiration": "2022-02-15T18:56:25.322Z"
1010
}
1111
]
1212
}

rush.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
/**
325325
* The list of shell commands to run after the Rush build command finishes
326326
*/
327-
"postRushBuild": ["node apps/notifications/src/displayNotifications.js"]
327+
"postRushBuild": ["node apps/notifications/lib/DisplayNotifications.js"]
328328
},
329329

330330
/**

0 commit comments

Comments
 (0)