Skip to content

Commit fdd25bd

Browse files
author
jonatansalas
committed
Minor changes
1 parent d53d689 commit fdd25bd

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"ink-progress-bar": "^2.0.0",
3939
"ink-spinner": "^1.0.0",
4040
"isomorphic-fetch": "^2.2.1",
41+
"progress-stream": "^2.0.0",
4142
"prop-types": "^15.5.10",
4243
"react": "^15.6.1",
4344
"unzip": "^0.1.11"

src/cli/index.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { h, Component, Text } from 'ink';
2-
import Progress from 'ink-progress-bar';
2+
//import Progress from 'ink-progress-bar';
33
import PropTypes from 'prop-types';
44
import Spinner from 'ink-spinner';
55
import readLine from 'readline';
@@ -26,7 +26,8 @@ export default class Cli extends Component {
2626
state = {
2727
error: null,
2828
result: null,
29-
projectName: null
29+
projectName: null,
30+
progress: false
3031
};
3132

3233
async componentDidMount() {
@@ -42,9 +43,12 @@ export default class Cli extends Component {
4243

4344
return (
4445
<Container>
45-
<Conditional expression={!state.error && !state.result}>
46+
<Conditional expression={!state.error && !state.result && !state.progress}>
4647
<Spinner green /> Fetching base project from GitHub.
4748
</Conditional>
49+
<Conditional expression={state.progress}>
50+
<Spinner green /> Unzipping starter project to {props.projectName}
51+
</Conditional>
4852
<Conditional expression={state.error !== null}>
4953
<Text red>
5054
{state.error && state.error.message}
@@ -60,14 +64,19 @@ export default class Cli extends Component {
6064
}
6165

6266
createScaffold = async path => {
67+
const gitHubUrl = 'https://github.com/BlackBoxVision/typescript-hapi-starter/archive/master.zip';
6368
const gitHubFolderName = 'typescript-hapi-starter-master';
6469

6570
try {
66-
const stream = await ZipUtils.download(
67-
'https://github.com/BlackBoxVision/typescript-hapi-starter/archive/master.zip'
68-
);
71+
const stream = await ZipUtils.download(gitHubUrl);
72+
73+
await ZipUtils.writeStream(stream, path, progress => {
74+
//console.info('Progress', JSON.stringify(progress, null, 2));
6975

70-
await ZipUtils.writeStream(stream, path);
76+
this.setState(state => ({
77+
progress: true
78+
}));
79+
});
7180

7281
if (await FileUtils.exists(path)) {
7382
await this.handleError(
@@ -82,7 +91,8 @@ export default class Cli extends Component {
8291

8392
this.setState(state => ({
8493
projectName: path,
85-
result: 'ok'
94+
result: 'ok',
95+
progress: false
8696
}));
8797

8898
this.exitWithDelay(Types.EXIT_WITH_SUCCESS);
@@ -96,7 +106,8 @@ export default class Cli extends Component {
96106
await FileUtils.remove(path);
97107

98108
this.setState(state => ({
99-
error: error
109+
error: error,
110+
progress: false
100111
}));
101112

102113
this.exitWithDelay(Types.EXIT_WITH_ERROR);

src/cli/util/Zip.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import progress from 'progress-stream';
12
import fetch from 'isomorphic-fetch';
23
import unzip from 'unzip';
34
import fs from 'fs';
@@ -14,9 +15,12 @@ export default class ZipUtils {
1415
return response.body;
1516
}
1617

17-
static async writeStream(stream, value) {
18+
static async writeStream(stream, value, onProgress) {
19+
const progressTracker = progress({ time: 100 }, onProgress);
20+
1821
return new Promise((resolve, reject) => {
1922
stream
23+
.pipe(progressTracker)
2024
.pipe(fs.createWriteStream(`${value}.zip`))
2125
.on('error', error => reject(error))
2226
.on('close', () => resolve('file written'));

yarn.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,13 @@ process-nextick-args@~1.0.6:
11941194
version "1.0.7"
11951195
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"
11961196

1197+
progress-stream:
1198+
version "2.0.0"
1199+
resolved "https://registry.yarnpkg.com/progress-stream/-/progress-stream-2.0.0.tgz#fac63a0b3d11deacbb0969abcc93b214bce19ed5"
1200+
dependencies:
1201+
speedometer "~1.0.0"
1202+
through2 "~2.0.3"
1203+
11971204
promise@^7.1.1:
11981205
version "7.3.1"
11991206
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
@@ -1250,7 +1257,7 @@ react:
12501257
object-assign "^4.1.0"
12511258
prop-types "^15.5.10"
12521259

1253-
readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4:
1260+
readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5:
12541261
version "2.3.3"
12551262
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c"
12561263
dependencies:
@@ -1399,6 +1406,10 @@ source-map@^0.5.0, source-map@^0.5.6:
13991406
version "0.5.6"
14001407
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
14011408

1409+
speedometer@~1.0.0:
1410+
version "1.0.0"
1411+
resolved "https://registry.yarnpkg.com/speedometer/-/speedometer-1.0.0.tgz#cd671cb06752c22bca3370e2f334440be4fc62e2"
1412+
14021413
sshpk@^1.7.0:
14031414
version "1.13.1"
14041415
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.13.1.tgz#512df6da6287144316dc4c18fe1cf1d940739be3"
@@ -1476,6 +1487,13 @@ tar@^2.2.1:
14761487
fstream "^1.0.2"
14771488
inherits "2"
14781489

1490+
through2@~2.0.3:
1491+
version "2.0.3"
1492+
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be"
1493+
dependencies:
1494+
readable-stream "^2.1.5"
1495+
xtend "~4.0.1"
1496+
14791497
to-fast-properties@^1.0.1:
14801498
version "1.0.3"
14811499
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
@@ -1561,3 +1579,7 @@ wrappy@1:
15611579
version "1.0.2"
15621580
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
15631581

1582+
xtend@~4.0.1:
1583+
version "4.0.1"
1584+
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
1585+

0 commit comments

Comments
 (0)