Skip to content

Commit bb47e87

Browse files
author
Martynas Žilinskas
authored
Release v0.1.0 (#3)
* Added -v argument. * Updated package.json. * Updated readme.
1 parent 9ebd017 commit bb47e87

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
"optimist": "^0.6.1"
2020
},
2121
"bin": {
22-
"cleanup-package-json": "./dist/cli.js"
22+
"cpj": "./dist/cli.js"
2323
}
24-
}
24+
}

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ cleanup-package-json
33

44
## Get started
55
```sh
6-
$ npm install cleanup-package-json -g
6+
$ npm install cpj -g
77
```
88

99
## Features
1010
- Removes unnecessary parts of `package.json`.
1111

1212
## Usage
1313
```sh
14-
$ cleanup-package-json -h
14+
$ cpj -h
1515
```
1616

1717
### Examples
@@ -20,12 +20,12 @@ _Default config:_
2020
Default config name is `cpj.config.json`.
2121

2222
```sh
23-
$ cleanup-package-json
23+
$ cpj
2424
```
2525

2626
_With custom file config:_
2727
```sh
28-
$ cleanup-package-json -c custom-config.json
28+
$ cpj -c custom-config.json
2929
```
3030

3131
## Config example

src/cli.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@ let opt = optimist
1616
alias: 'config',
1717
describe: 'Path to config.'
1818
})
19+
.options('v', {
20+
alias: 'version',
21+
describe: 'Prints version.'
22+
})
1923
.usage('Usage: cleanup-package-json [options]')
2024
.boolean(['h', 'v'])
2125
.string(['c']);
2226

2327
class Cli {
28+
private package: Contracts.PackageJSONSkeleton = {};
29+
2430
constructor(opt: optimist.Parser) {
31+
let packageJSONPath = path.join(__dirname, '../package.json');
32+
this.package = JSON.parse(fs.readFileSync(packageJSONPath, 'utf8'));
2533
let argv = opt.argv as Contracts.Arguments;
2634

2735
if (argv.help) {
36+
this.printVersion();
2837
console.info(opt.help());
38+
} else if (argv.version) {
39+
this.printVersion();
2940
} else {
3041
let configFileName = argv.config || DEFAULT_CONFIG_NAME;
3142
this.main(configFileName);
@@ -45,7 +56,7 @@ class Cli {
4556
let cleanup = new Cleanup(config);
4657
cleanup.Clean();
4758
console.info('[Success] Done cleaning up');
48-
} catch(e) {
59+
} catch (e) {
4960
this.throwError(`[Failed] ${e}`);
5061
}
5162
} else {
@@ -89,6 +100,10 @@ class Cli {
89100
});
90101
});
91102
}
103+
104+
private printVersion() {
105+
console.info(`Version ${this.package['version']} \n`);
106+
}
92107
}
93108

94109
new Cli(opt);

src/contracts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export interface Arguments {
22
[arg: string]: string | boolean;
33
config: string;
44
help: boolean;
5+
version: boolean;
56
}
67

78
export interface ConfigItems {

0 commit comments

Comments
 (0)