Skip to content

Commit 1d0428c

Browse files
committed
Merge branch 'release/release-v0.1' of https://github.com/codingtools/cdt into feature/test-encryption-decryption-together
2 parents 6f115e2 + 3853271 commit 1d0428c

21 files changed

+225
-73
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
patreon: ashishpatel0720

.github/workflows/npmpublish.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: GithubPublish
2+
3+
on:
4+
push:
5+
tags:
6+
- v0.1.*
7+
- v0.2.*
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v1
15+
with:
16+
node-version: 12
17+
- run: npm ci
18+
- run: npm test
19+
20+
publish-npm:
21+
needs: build
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-node@v1
26+
with:
27+
node-version: 12
28+
registry-url: https://registry.npmjs.org/
29+
- run: npm ci
30+
- run: npm publish
31+
env:
32+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
33+
34+
# publish-gpr:
35+
# needs: build
36+
# runs-on: ubuntu-latest
37+
# steps:
38+
# - uses: actions/checkout@v2
39+
# - uses: actions/setup-node@v1
40+
# with:
41+
# node-version: 12
42+
# registry-url: https://npm.pkg.github.com/
43+
# scope: '@codingtools/cdt'
44+
# - run: npm ci
45+
# - run: npm publish
46+
# env:
47+
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ node_modules
99
/.idea
1010
cdt.iml
1111
**/.DS_Store
12-
output/*
13-
!output/.gitkeep
12+
13+
output
14+
output/**.json
15+
output/**.avro
16+
output/**.avsc
17+
1418
coverage/*.json
19+
20+

README.md

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $ npm install -g @codingtools/cdt
4040
$ cdt COMMAND
4141
running command...
4242
$ cdt (-v|--version|version)
43-
@codingtools/cdt/0.1.6 darwin-x64 node-v12.9.0
43+
@codingtools/cdt/0.1.8 darwin-x64 node-v12.9.0
4444
$ cdt --help [COMMAND]
4545
USAGE
4646
$ cdt COMMAND
@@ -96,7 +96,7 @@ OPTIONS
9696
-t, --schemaType=schemaType schema type file path
9797
```
9898

99-
_See code: [src/commands/avro.ts](https://github.com/codingtools/cdt/blob/v0.1.6/src/commands/avro.ts)_
99+
_See code: [src/commands/avro.ts](https://github.com/codingtools/cdt/blob/v0.1.8/src/commands/avro.ts)_
100100

101101
## `cdt bundlephobia [PACKAGE]`
102102

@@ -112,7 +112,7 @@ OPTIONS
112112
-p, --packages=packages packages for which cost is required, can pass more than one separated by space
113113
```
114114

115-
_See code: [src/commands/bundlephobia.ts](https://github.com/codingtools/cdt/blob/v0.1.6/src/commands/bundlephobia.ts)_
115+
_See code: [src/commands/bundlephobia.ts](https://github.com/codingtools/cdt/blob/v0.1.8/src/commands/bundlephobia.ts)_
116116

117117
## `cdt crypto [STRING]`
118118

@@ -132,7 +132,7 @@ OPTIONS
132132
-s, --string=string string to be encrypted/decrypted
133133
```
134134

135-
_See code: [src/commands/crypto.ts](https://github.com/codingtools/cdt/blob/v0.1.6/src/commands/crypto.ts)_
135+
_See code: [src/commands/crypto.ts](https://github.com/codingtools/cdt/blob/v0.1.8/src/commands/crypto.ts)_
136136

137137
## `cdt datetime [DATE]`
138138

@@ -150,7 +150,7 @@ OPTIONS
150150
-z, --timezone=timezone Timezone for Datetime parsing, default: Your timezone
151151
```
152152

153-
_See code: [src/commands/datetime.ts](https://github.com/codingtools/cdt/blob/v0.1.6/src/commands/datetime.ts)_
153+
_See code: [src/commands/datetime.ts](https://github.com/codingtools/cdt/blob/v0.1.8/src/commands/datetime.ts)_
154154

155155
## `cdt hash [STRING]`
156156

@@ -161,14 +161,14 @@ USAGE
161161
$ cdt hash [STRING]
162162
163163
OPTIONS
164-
-f, --file=file file to be hashed
165-
-h, --help show CLI help
166-
-o, --outputFile=outputFile output file path
167-
-s, --string=string string to be hashed
168-
-t, --type=type type of hash [SHA1(default), MD5, SHA256, SHA512, RMD160 or RIPEMD160]
164+
-f, --file=file file to be hashed
165+
-h, --help show CLI help
166+
-o, --output=output output file path
167+
-s, --string=string string to be hashed
168+
-t, --type=type type of hash [SHA1(default), MD5, SHA256, SHA512, RMD160 or RIPEMD160]
169169
```
170170

171-
_See code: [src/commands/hash.ts](https://github.com/codingtools/cdt/blob/v0.1.6/src/commands/hash.ts)_
171+
_See code: [src/commands/hash.ts](https://github.com/codingtools/cdt/blob/v0.1.8/src/commands/hash.ts)_
172172

173173
## `cdt help [COMMAND]`
174174

@@ -196,15 +196,13 @@ USAGE
196196
$ cdt minify [FILE]
197197
198198
OPTIONS
199-
-f, --file=file file to be minified
200-
-h, --help show CLI help
201-
-o, --outputFile=outputFile output file path
202-
203-
-t, --type=type type of file to be minified, it will try to find type with extension supported: JS,
204-
HTML/HTM, CSS
199+
-f, --file=file file to be minified
200+
-h, --help show CLI help
201+
-o, --output=output output file path
202+
-t, --type=type type of file to be minified, it will try to find type with extension supported: JS, HTML/HTM, CSS
205203
```
206204

207-
_See code: [src/commands/minify.ts](https://github.com/codingtools/cdt/blob/v0.1.6/src/commands/minify.ts)_
205+
_See code: [src/commands/minify.ts](https://github.com/codingtools/cdt/blob/v0.1.8/src/commands/minify.ts)_
208206
<!-- commandsstop -->
209207

210208
## Acknowledgement
@@ -227,16 +225,38 @@ This Project is created and supported by [Ashish Patel](http://ashish.live/)
227225

228226
## Releasing Version
229227
* this needs to be done from release* branch
228+
229+
### Increasing Version
230+
230231
```bash
231232
npm version patch
232233
```
233234
it will update readme.md and update package.json, also will create tag and commit.
234235

236+
### Publishing to NPM
237+
235238
```bash
236239
npm publish --access public
237240
```
238241
this will publish package to **npm** starting with updating README and publishing tarballs
239242

243+
> Already a Github Action is there to publish on pushing a tag.
244+
245+
### Creating Standalone Tarballs
246+
247+
```bash
248+
oclif-dev pack
249+
```
250+
this will release standalone tarballs for linux, macos and windows which we can extract and uses.
251+
252+
### Creating Installers
253+
254+
```bash
255+
oclif-dev pack:macos
256+
oclif-dev pack:win
257+
```
258+
these will create installers for macos and windows
259+
240260
## License
241261

242262
[MIT](https://raw.githubusercontent.com/codingtools/cdt/master/LICENSE)

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@codingtools/cdt",
33
"description": "CLI for Developers",
4-
"version": "0.1.6",
4+
"version": "0.1.8",
55
"author": "Ashish Patel @ashishpatel0720",
66
"bin": {
77
"cdt": "./bin/run"
@@ -20,10 +20,11 @@
2020
"axios": "^0.19.0",
2121
"chalk": "^3.0.0",
2222
"codecov": "^3.6.5",
23-
"crypto-js": "^3.1.9-1",
23+
"crypto-js": "^4.0.0",
2424
"detect-character-encoding": "^0.8.0",
2525
"encoding-japanese": "^1.0.30",
2626
"jshashes": "^1.0.7",
27+
"json-2-csv": "^3.5.9",
2728
"minify": "^5.0.0",
2829
"moment": "^2.24.0",
2930
"moment-timezone": "^0.5.27",
@@ -37,14 +38,15 @@
3738
"@oclif/dev-cli": "^1.22.2",
3839
"@oclif/test": "^1.2.5",
3940
"@oclif/tslint": "^3.1.1",
40-
"@types/chai": "^4.2.3",
41+
"@types/chai": "^4.2.9",
4142
"@types/mocha": "^7.0.0",
4243
"@types/moment-timezone": "^0.5.12",
43-
"@types/node": "^13.1.0",
44+
"@types/node": "13.9.2",
4445
"@types/crypto-js": "^3.1.43",
4546
"@types/signale": "^1.2.1",
4647
"chai": "^4.2.0",
4748
"globby": "^10.0.1",
49+
"mocha": "^7.0.1",
4850
"jest": "^24.9.0",
4951
"jest-mock": "^24.9.0",
5052
"mocha": "^6.2.2",

src/commands/avro.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Command, flags} from '@oclif/command'
22
import * as avro from 'avsc'
33
import * as chalk from 'chalk'
44
import * as fs from 'fs' // includes all from avro-js and some more
5+
import * as Json2Csv from 'json-2-csv'
56

67
import Logger from '../utilities/logger'
78
import Utilities from '../utilities/utilities'
@@ -12,9 +13,10 @@ export default class Avro extends Command {
1213
static GET_SCHEMA = 'get_schema'
1314
static TO_JSON = 'to_json'
1415
static TO_AVRO = 'to_avro'
16+
static TO_CSV = 'to_csv'
1517

1618
// do not change order otherwise we need to change order in getCommand() also
17-
static SupportedCommands = [Avro.GET_SCHEMA, Avro.TO_JSON, Avro.TO_AVRO]
19+
static SupportedCommands = [Avro.GET_SCHEMA, Avro.TO_JSON, Avro.TO_AVRO, Avro.TO_CSV]
1820
static flags = {
1921
help: flags.help({char: 'h'}),
2022
file: flags.string({char: 'f' , description: 'input file path'}),
@@ -52,12 +54,14 @@ export default class Avro extends Command {
5254

5355
private executeCommand(flags: any, args: any) {
5456
switch (args.command) {
55-
case Avro.SupportedCommands[0]:
57+
case Avro.GET_SCHEMA:
5658
return this.getSchema(flags, args)
57-
case Avro.SupportedCommands[1]:
59+
case Avro.TO_JSON:
5860
return this.toJson(flags, args)
59-
case Avro.SupportedCommands[2]:
61+
case Avro.TO_AVRO:
6062
return this.toAvro(flags, args)
63+
case Avro.TO_CSV:
64+
return this.toCsv(flags, args)
6165
default:
6266
Logger.error(this, 'Unsupported Command, supported: ' + Avro.SupportedCommands)
6367
}
@@ -83,19 +87,55 @@ export default class Avro extends Command {
8387

8488
// tslint:disable-next-line:no-unused
8589
private toJson(flags: any, args: any) {
90+
Logger.progressStart(this, 'Converting Avro To Json')
91+
// setTimeout(() => {
92+
Logger.progressStop(this, ' Converting Avro To Json')
8693
Utilities.truncateFile(this, flags.output)
8794
avro.createFileDecoder(flags.file)
8895
.on('data', function (recordStr) {
8996
// @ts-ignore
9097
Utilities.appendStringToFile(this, flags.output, JSON.stringify(recordStr))
9198
})
9299
Logger.success(this, `${chalk.blue('Json')} written to file: ${chalk.green(flags.output)}`) // this will output error and exit command
100+
// }, 1000)
101+
}
102+
103+
// tslint:disable-next-line:no-unused
104+
private toCsv(flags: any, args: any) {
105+
Logger.progressStart(this, 'Converting Avro To Csv')
106+
107+
// setTimeout(() => {
108+
Logger.progressStop(this, ' Converting Avro To Csv')
109+
Utilities.truncateFile(this, flags.output)
110+
let prependHeader = true // only write on the first line
111+
avro.createFileDecoder(flags.file)
112+
.on('data', function (recordStr) {
113+
// @ts-ignore
114+
let json = JSON.parse(JSON.stringify(recordStr))
115+
Json2Csv.json2csv(json, (err?: Error, csv?: string) => {
116+
if (csv) {
117+
// @ts-ignore
118+
Utilities.appendStringToFile(this, flags.output, csv + '\n')
119+
}
120+
if (err) {
121+
// @ts-ignore
122+
Logger.error(this, err.toString())
123+
}
124+
}, {prependHeader})
125+
prependHeader = false
126+
})
127+
Logger.success(this, `${chalk.blue('Csv')} written to file: ${chalk.green(flags.output)}`) // this will output error and exit command
128+
// }, 300)
93129
}
94130

95131
private toAvro(flags: any, args: any) {
96132
if (!flags.schemaType)
97133
Logger.error(this, 'Schema file is not provided')
98134

135+
Logger.progressStart(this, 'Generating Avro')
136+
// setTimeout(() => {
137+
Logger.progressStop(this, ' Generating Avro')
138+
99139
let schema = avro.parse(flags.schemaType)
100140
let avroEncoder = new avro.streams.BlockEncoder(schema)
101141

@@ -104,9 +144,9 @@ export default class Avro extends Command {
104144
// We write the records to the block encoder, which will take care of serializing them
105145
// into an object container file.
106146

107-
let jsonStr = '[' + Utilities.getInputString(this, flags, args) + ']'
108-
jsonStr = jsonStr.replace(/[\s\n]+/mg, '')
109-
jsonStr = jsonStr.replace(/\}\{/mg, '},{')
147+
let inputString = Utilities.getInputString(this, flags, args)
148+
let jsonStr = this.convertAvroJsonToValidJson(inputString)
149+
110150
let jsonObjects = JSON.parse(jsonStr)
111151

112152
jsonObjects.forEach(function (data: any) {
@@ -119,5 +159,14 @@ export default class Avro extends Command {
119159
})
120160
Logger.success(this, `${chalk.blue('Avro')} written to file: ${chalk.green(flags.output)}`) // this will output error and exit command
121161
avroEncoder.end()
162+
// }, 300)
163+
164+
}
165+
166+
private convertAvroJsonToValidJson(json: string) {
167+
let jsonStr = '[' + json + ']'
168+
jsonStr = jsonStr.replace(/[\s\n]+/mg, '')
169+
jsonStr = jsonStr.replace(/\}\{/mg, '},{')
170+
return jsonStr
122171
}
123172
}

0 commit comments

Comments
 (0)