Skip to content

Commit 4ec63fb

Browse files
authored
Merge pull request #10 from codingtools/release/release-v0.1
Sync Master for release-v0.1
2 parents 71250d3 + 3619898 commit 4ec63fb

File tree

10 files changed

+258
-65
lines changed

10 files changed

+258
-65
lines changed

.circleci/config.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: 2
2+
jobs:
3+
build_and_test:
4+
working_directory: ~/mern-starter
5+
# The primary container is an instance of the first image listed. The job's commands run in this container.
6+
docker:
7+
- image: circleci/node:latest
8+
# The secondary container is an instance of the second listed image which is run in a common network where ports exposed on the primary container are available on localhost.
9+
steps:
10+
- checkout
11+
- run:
12+
name: Update npm
13+
command: 'sudo npm install -g npm@latest'
14+
- restore_cache:
15+
key: dependency-cache-{{ checksum "package-lock.json" }}
16+
- run:
17+
name: Install npm dependencies
18+
command: npm install
19+
- save_cache:
20+
key: dependency-cache-{{ checksum "package-lock.json" }}
21+
paths:
22+
- node_modules
23+
- run:
24+
name: Test
25+
command: npm test
26+
- run:
27+
name: Generate code coverage
28+
command: './node_modules/.bin/nyc report --reporter=text-lcov'
29+
- store_artifacts:
30+
path: test-results.xml
31+
prefix: tests
32+
- store_artifacts:
33+
path: coverage
34+
prefix: coverage
35+
36+
workflows:
37+
version: 2
38+
build_and_test:
39+
jobs:
40+
- build_and_test

.circleci/config_2jobs.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: ~/mern-starter
5+
# The primary container is an instance of the first image listed. The job's commands run in this container.
6+
docker:
7+
- image: circleci/node:latest
8+
# The secondary container is an instance of the second listed image which is run in a common network where ports exposed on the primary container are available on localhost.
9+
steps:
10+
- checkout
11+
- run:
12+
name: Update npm
13+
command: 'sudo npm install -g npm@latest'
14+
- restore_cache:
15+
key: dependency-cache-{{ checksum "package-lock.json" }}
16+
- run:
17+
name: Install npm dependencies
18+
command: npm install
19+
- save_cache:
20+
key: dependency-cache-{{ checksum "package-lock.json" }}
21+
paths:
22+
- node_modules
23+
test:
24+
docker:
25+
- image: circleci/node:latest
26+
steps:
27+
- checkout
28+
# needed to add here also as both install and test are different docker instances and need to do same thing again in different instance
29+
- run:
30+
name: Update npm
31+
command: 'sudo npm install -g npm@latest'
32+
- restore_cache:
33+
key: dependency-cache-{{ checksum "package-lock.json" }}
34+
- run:
35+
name: Install npm dependencies
36+
command: npm install
37+
- save_cache:
38+
key: dependency-cache-{{ checksum "package-lock.json" }}
39+
paths:
40+
- node_modules
41+
- run:
42+
name: Test
43+
command: npm test
44+
- run:
45+
name: Generate code coverage
46+
command: './node_modules/.bin/nyc report --reporter=text-lcov'
47+
- store_artifacts:
48+
path: test-results.xml
49+
prefix: tests
50+
- store_artifacts:
51+
path: coverage
52+
prefix: coverage
53+
54+
workflows:
55+
version: 2
56+
build_and_test:
57+
jobs:
58+
- build
59+
- test:
60+
requires:
61+
- build

.circleci/config_tmp.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
version: 2
2+
jobs:
3+
node-latest: &test
4+
docker:
5+
- image: node:latest
6+
working_directory: ~/cli
7+
steps:
8+
- checkout
9+
- restore_cache: &restore_cache
10+
keys:
11+
- v1-npm-{{checksum ".circleci/config_tmp.yml"}}-{{ checksum "package-lock.json"}}
12+
- v1-npm-{{checksum ".circleci/config_tmp.yml"}}
13+
- run:
14+
name: Install dependencies
15+
command: .circleci/greenkeeper
16+
- run: ./bin/run --version
17+
- run: ./bin/run --help
18+
- run:
19+
name: Testing
20+
command: npm test
21+
- run:
22+
name: Submitting code coverage to codecov
23+
command: |
24+
./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov
25+
curl -s https://codecov.io/bash | bash
26+
node-8:
27+
<<: *test
28+
docker:
29+
- image: node:8
30+
release:
31+
<<: *test
32+
steps:
33+
- add_ssh_keys
34+
- checkout
35+
- restore_cache: *restore_cache
36+
- run:
37+
name: Install dependencies
38+
command: |
39+
npm install -g @oclif/semantic-release@3 semantic-release@15
40+
npm install
41+
- run:
42+
name: Cutting release
43+
command: |
44+
semantic-release -e @oclif/semantic-release
45+
- save_cache:
46+
key: v1-npm-{{checksum ".circleci/config_tmp.yml"}}-{{checksum "package-lock.json"}}
47+
paths:
48+
- ~/cli/node_modules
49+
- ~/.npm
50+
- /usr/local/lib/node_modules
51+
52+
workflows:
53+
version: 2
54+
"cdt":
55+
jobs:
56+
- node-latest
57+
- node-8
58+
- release:
59+
context: org-global
60+
filters:
61+
branches: {only: master}
62+
requires:
63+
- node-latest
64+
- node-8

.circleci/greenkeeper

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
PATH=/usr/local/share/.config/npm/global/node_modules/.bin:$PATH
6+
7+
if [[ "$CIRCLE_BRANCH" != greenkeeper/* ]]; then
8+
npm install
9+
exit 0
10+
fi
11+
12+
if [[ ! -z "$GIT_EMAIL" ]] & [[ ! -z "$GIT_USERNAME" ]]; then
13+
git config --global push.default simple
14+
git config --global user.email "$GIT_EMAIL"
15+
git config --global user.name "$GIT_USERNAME"
16+
fi
17+
18+
if [[ ! -x "$(command -v greenkeeper-lockfile-update)" ]]; then
19+
npm install -g greenkeeper-lockfile@1
20+
fi
21+
22+
greenkeeper-lockfile-update
23+
npm install
24+
greenkeeper-lockfile-upload

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"@oclif/config": "^1.13.3",
1313
"@oclif/plugin-help": "^2.2.1",
1414
"jshashes": "^1.0.7",
15-
"tslib": "^1.10.0"
15+
"tslib": "^1.10.0",
16+
"nyc": "^13.3.0"
1617
},
1718
"devDependencies": {
1819
"@oclif/dev-cli": "^1.22.2",
@@ -24,7 +25,6 @@
2425
"chai": "^4.2.0",
2526
"globby": "^10.0.1",
2627
"mocha": "^5.2.0",
27-
"nyc": "^13.3.0",
2828
"ts-node": "^8.4.1",
2929
"tslint": "^5.20.0",
3030
"typescript": "^3.6.4"
@@ -56,7 +56,7 @@
5656
"postpack": "rm -f oclif.manifest.json",
5757
"posttest": "tslint -p test -t stylish",
5858
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
59-
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
59+
"test": "./node_modules/.bin/nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
6060
"version": "oclif-dev readme && git add README.md"
6161
},
6262
"types": "lib/index.d.ts"

src/commands/hash.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Command, flags} from '@oclif/command'
2+
import * as fs from 'fs'
23
// @ts-ignore
34
import * as Hashes from 'jshashes'
45

@@ -22,32 +23,62 @@ export default class Hash extends Command {
2223

2324
const type: string = flags.type || 'sha1' //by default let it be sha1
2425

25-
// if -s is not passed we will take it from args
26+
// if -s or -f is not passed we will take it from args
27+
let str = ''
2628

27-
let str: string
28-
29-
if (flags.string)
29+
if (flags.string) //if -s given
3030
str = flags.string
31-
else
32-
str = args.string
31+
else if (flags.file) {
32+
str = this.getStringFromFile(flags.file)
33+
} else
34+
str = args.string
35+
36+
this.calculateHash(type, str)
37+
}
3338

39+
private calculateHash(type: string, str: string) {
3440
let hash: Hashes
3541
switch (type.toUpperCase()) {
3642
case 'SHA1':
37-
hash = new Hashes.SHA1(); break
43+
hash = new Hashes.SHA1()
44+
break
3845
case 'SHA256':
39-
hash = new Hashes.SHA256(); break
46+
hash = new Hashes.SHA256()
47+
break
4048
case 'SHA512':
41-
hash = new Hashes.SHA512(); break
49+
hash = new Hashes.SHA512()
50+
break
4251
case 'MD5':
43-
hash = new Hashes.MD5(); break
52+
hash = new Hashes.MD5()
53+
break
4454
case 'RMD160':
45-
hash = new Hashes.RMD160(); break
55+
hash = new Hashes.RMD160()
56+
break
4657
default:
4758
hash = undefined
4859
}
4960

50-
let hashed: string = hash.hex(str)
51-
this.log(`[HASH]: ${hashed}`)
61+
if (hash) {
62+
let hashed: string = hash.hex(str)
63+
this.log(`[${type.toUpperCase()}]: ${hashed}`)
64+
} else {
65+
this.log('[ERROR]: invalid hash type')
66+
}
67+
}
68+
69+
private getStringFromFile(filePath: string) {
70+
let fileStr = ''
71+
if (!fs.existsSync(filePath)) {
72+
this.error('reading File') // this will output error and exit command
73+
} else {
74+
fileStr = fs.readFileSync(filePath, 'utf8')
75+
76+
// TODO: fix this Issue #3
77+
if (fileStr.charAt(fileStr.length - 1) === '\n') {
78+
fileStr = fileStr.substring(0, fileStr.length - 1)
79+
}
80+
}
81+
return fileStr
82+
5283
}
5384
}

src/commands/hello.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/commands/hash.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('hash', () => {
1111
// passing sha1 as option
1212
test
1313
.stdout()
14-
.command(['hash', 'ashish' ,'-t','sha1'])
14+
.command(['hash', 'ashish' , '-t', 'sha1'])
1515
.it("cdt hash 'ashish' -t 'sha1'", ctx => {
1616
expect(ctx.stdout).to.contain('428b6da53085b8fd7b37e9fb259c0c609bd09984')
1717
})
@@ -63,4 +63,23 @@ describe('hash', () => {
6363
.it("cdt hash --type rmd160 'ashish'", ctx => {
6464
expect(ctx.stdout).to.contain('a85a72b0a240abecdf27f127aa75fd8663d6d5be')
6565
})
66+
67+
//file input - file not found TODO: solve issue #4
68+
/*
69+
test
70+
.stderr()
71+
.command(['hash', '-f', 'test/resources/filenotfound.txt'])
72+
.it("cdt hash -f 'test/resources/filenotfound.txt'", ctx => {
73+
expect(ctx.stderr).to.contain('Error: reading File')
74+
})
75+
*/
76+
77+
//file input
78+
test
79+
.stdout()
80+
.command(['hash', '-f', 'test/resources/test.txt'])
81+
.it("cdt hash -f 'test/resources/test.txt'", ctx => {
82+
expect(ctx.stdout).to.contain('97ee6255ffc855e79e2324d5495b6538e29034f9')
83+
})
84+
6685
})

test/commands/hello.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/resources/test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
2+
t is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

0 commit comments

Comments
 (0)