Skip to content

Commit 00818b9

Browse files
authored
chore(gatsby): revert progressbar functionality (#14884)
This reverts commit 967597c.
1 parent 7ca4089 commit 00818b9

File tree

17 files changed

+126
-429
lines changed

17 files changed

+126
-429
lines changed

packages/gatsby-cli/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"object.entries": "^1.1.0",
3434
"opentracing": "^0.14.3",
3535
"pretty-error": "^2.1.1",
36-
"progress": "^2.0.3",
3736
"prompts": "^2.1.0",
3837
"react": "^16.8.4",
3938
"resolve-cwd": "^2.0.0",

packages/gatsby-cli/src/reporter/index.js

+3-78
Original file line numberDiff line numberDiff line change
@@ -93,88 +93,13 @@ const reporter: Reporter = {
9393
const spanArgs = parentSpan ? { childOf: parentSpan } : {}
9494
const span = tracer.startSpan(name, spanArgs)
9595

96-
const activity = reporterInstance.createActivity({
97-
type: `spinner`,
98-
id: name,
99-
status: ``,
100-
})
96+
const activity = reporterInstance.createActivity(name)
10197

10298
return {
103-
start() {
104-
activity.update({
105-
startTime: process.hrtime(),
106-
})
107-
},
108-
setStatus(status) {
109-
activity.update({
110-
status: status,
111-
})
112-
},
99+
...activity,
113100
end() {
114101
span.finish()
115-
activity.done()
116-
},
117-
span,
118-
}
119-
},
120-
121-
/**
122-
* Create a progress bar for an activity
123-
* @param {string} name - Name of activity.
124-
* @param {number} total - Total items to be processed.
125-
* @param {number} start - Start count to show.
126-
* @param {ActivityArgs} activityArgs - optional object with tracer parentSpan
127-
* @returns {ActivityTracker} The activity tracker.
128-
*/
129-
createProgress(
130-
name: string,
131-
total,
132-
start = 0,
133-
activityArgs: ActivityArgs = {}
134-
): ActivityTracker {
135-
const { parentSpan } = activityArgs
136-
const spanArgs = parentSpan ? { childOf: parentSpan } : {}
137-
const span = tracer.startSpan(name, spanArgs)
138-
139-
let hasStarted = false
140-
let current = start
141-
const activity = reporterInstance.createActivity({
142-
type: `progress`,
143-
id: name,
144-
current,
145-
total,
146-
})
147-
148-
return {
149-
start() {
150-
if (hasStarted) {
151-
return
152-
}
153-
154-
hasStarted = true
155-
activity.update({
156-
startTime: process.hrtime(),
157-
})
158-
},
159-
setStatus(status) {
160-
activity.update({
161-
status: status,
162-
})
163-
},
164-
tick() {
165-
activity.update({
166-
current: ++current,
167-
})
168-
},
169-
done() {
170-
span.finish()
171-
activity.done()
172-
},
173-
set total(value) {
174-
total = value
175-
activity.update({
176-
total: value,
177-
})
102+
activity.end()
178103
},
179104
span,
180105
}

packages/gatsby-cli/src/reporter/reporters/ink/components/spinner.js renamed to packages/gatsby-cli/src/reporter/reporters/ink/components/activity.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import React from "react"
2+
import convertHrtime from "convert-hrtime"
23
import { Box } from "ink"
34
import Spinner from "ink-spinner"
45

6+
export const calcElapsedTime = startTime => {
7+
const elapsed = process.hrtime(startTime)
8+
9+
return convertHrtime(elapsed)[`seconds`].toFixed(3)
10+
}
11+
512
export default function Activity({ name, status }) {
613
let statusText = name
714
if (status) {

packages/gatsby-cli/src/reporter/reporters/ink/components/progress-bar.js

-43
This file was deleted.

packages/gatsby-cli/src/reporter/reporters/ink/reporter.js

+46-73
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
import React from "react"
22
import { Static, Box } from "ink"
3+
import { isCI } from "ci-info"
34
import chalk from "chalk"
4-
import Spinner from "./components/spinner"
5-
import ProgressBar from "./components/progress-bar"
5+
import Activity, { calcElapsedTime } from "./components/activity"
66
import { Message } from "./components/messages"
7-
import isTTY from "../../../util/is-tty"
8-
import calcElapsedTime from "../../../util/calc-elapsed-time"
9-
10-
const showProgress = isTTY
11-
12-
const successTextGenerator = {
13-
spinner: activity => {
14-
let successText = `${activity.id} - ${calcElapsedTime(
15-
activity.startTime
16-
)} s`
17-
if (activity.status) {
18-
successText += ` — ${activity.status}`
19-
}
207

21-
return successText
22-
},
23-
progress: activity =>
24-
`${activity.id}${activity.current}/${activity.total} - ${calcElapsedTime(
25-
activity.startTime
26-
)} s`,
8+
const showProgress = process.stdout.isTTY && !isCI
9+
10+
const generateActivityFinishedText = (name, activity) => {
11+
let successText = `${name} - ${calcElapsedTime(activity.startTime)} s`
12+
if (activity.status) {
13+
successText += ` — ${activity.status}`
14+
}
15+
16+
return successText
2717
}
2818

2919
export default class GatsbyReporter extends React.Component {
@@ -36,40 +26,44 @@ export default class GatsbyReporter extends React.Component {
3626

3727
format = chalk
3828

39-
createActivity = ({ id, ...options }) => {
40-
this.setState(state => {
41-
return {
42-
activities: {
43-
...state.activities,
44-
[id]: {
45-
id,
46-
...options,
47-
},
48-
},
49-
}
50-
})
51-
29+
createActivity = name => {
5230
return {
53-
update: newState => {
31+
start: () => {
32+
this.setState(state => {
33+
return {
34+
activities: {
35+
...state.activities,
36+
[name]: {
37+
status: ``,
38+
startTime: process.hrtime(),
39+
},
40+
},
41+
}
42+
})
43+
},
44+
setStatus: status => {
5445
this.setState(state => {
46+
const activity = state.activities[name]
47+
5548
return {
5649
activities: {
5750
...state.activities,
58-
[id]: {
59-
...state.activities[id],
60-
...newState,
51+
[name]: {
52+
...activity,
53+
status: status,
6154
},
6255
},
6356
}
6457
})
6558
},
66-
done: () => {
67-
const activity = this.state.activities[id]
68-
this.success(successTextGenerator[activity.type]({ id, ...activity }))
59+
end: () => {
60+
const activity = this.state.activities[name]
61+
62+
this.success(generateActivityFinishedText(name, activity))
6963

7064
this.setState(state => {
7165
const activities = { ...state.activities }
72-
delete activities[id]
66+
delete activities[name]
7367

7468
return {
7569
activities,
@@ -122,48 +116,27 @@ export default class GatsbyReporter extends React.Component {
122116
}
123117

124118
render() {
125-
const { activities, messages, disableColors } = this.state
126-
127-
const spinners = []
128-
const progressBars = []
129-
if (showProgress) {
130-
Object.keys(activities).forEach(activityName => {
131-
const activity = activities[activityName]
132-
if (activity.type === `spinner`) {
133-
spinners.push(activity)
134-
}
135-
if (activity.type === `progress` && activity.startTime) {
136-
progressBars.push(activity)
137-
}
138-
})
139-
}
140-
141119
return (
142120
<Box flexDirection="column">
143121
<Box flexDirection="column">
144122
<Static>
145-
{messages.map((msg, index) => (
123+
{this.state.messages.map((msg, index) => (
146124
<Box textWrap="wrap" key={index}>
147-
<Message type={msg.type} hideColors={disableColors}>
125+
<Message type={msg.type} hideColors={this.state.disableColors}>
148126
{msg.text}
149127
</Message>
150128
</Box>
151129
))}
152130
</Static>
153131

154-
{spinners.map(activity => (
155-
<Spinner key={activity.id} name={activity.id} {...activity} />
156-
))}
157-
158-
{progressBars.map(activity => (
159-
<ProgressBar
160-
key={activity.id}
161-
message={activity.id}
162-
total={activity.total}
163-
current={activity.current}
164-
startTime={activity.startTime}
165-
/>
166-
))}
132+
{showProgress &&
133+
Object.keys(this.state.activities).map(activityName => (
134+
<Activity
135+
key={activityName}
136+
name={activityName}
137+
{...this.state.activities[activityName]}
138+
/>
139+
))}
167140
</Box>
168141
</Box>
169142
)

0 commit comments

Comments
 (0)