Skip to content

Commit

Permalink
docs: ✏️ update README for the packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kucherenko committed May 2, 2020
1 parent c0ab855 commit 76492e6
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 70 deletions.
50 changes: 46 additions & 4 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
# `@jscpd/core`

> TODO: description
> core package for detect duplicates, depends only on eventemmiter3.
## Usage
## Installation

```
const core = require('@jscpd/core');
npm install @jscpd/core --save
```

## Usage

```typescript
import {Tokenizer} from '@jscpd/tokenizer';
import {
Detector,
MemoryStore,
IOptions,
IClone,
IStore,
ITokenizer
} from '@jscpd/core';

const options: IOptions = {
minLines: 5,
maxLines: 500,
}

const tokenizer: ITokenizer = new Tokenizer();

// here you can use any store what implement IStore interface
const store: IStore = new MemoryStore();

// list of validators, implemented IValidator interface, validate clones
const validators = [];

const detector = new Detector(tokenizer, store, validators, options);

( async () => {
const format = 'javascript';
const code: string = '...string with code...';
const clones: IClone[] = await detector.detect('source_id', code, format);

console.log(clones);
})();

// TODO: DEMONSTRATE API
```

![ga tracker](https://www.google-analytics.com/collect?v=1&a=257770996&t=pageview&dl=https%3A%2F%2Fgithub.com%2Fkucherenko%2Fjscpd&ul=en-us&de=UTF-8&cid=978224512.1377738459&tid=UA-730549-17&z=887657232 "ga tracker")

## License

[MIT](LICENSE) © Andrey Kucherenko
8 changes: 3 additions & 5 deletions packages/core/src/detector.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import {RabinKarp} from './rabin-karp';
import {IClone, ICloneValidator, IOptions, IStore, ITokenizer, ITokensMap} from './interfaces';
import {IClone, ICloneValidator, IMapFrame, IOptions, IStore, ITokenizer, ITokensMap} from './interfaces';
import {LinesLengthCloneValidator} from './validators';
// TODO replace to own event emitter
import EventEmitter = require('eventemitter3');


export type DetectorEvents = 'CLONE_FOUND' | 'CLONE_SKIPPED' | 'START_DETECTION';


export class Detector extends EventEmitter<DetectorEvents> {

private algorithm: RabinKarp;

constructor(
private tokenizer: ITokenizer,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly store: IStore<any>,
private readonly store: IStore<IMapFrame>,
private cloneValidators: ICloneValidator[] = [],
private readonly options: IOptions) {
super();
Expand Down
46 changes: 42 additions & 4 deletions packages/finder/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
# `@jscpd/finder`

> TODO: description
> core package for detect duplicates, depends only on eventemmiter3.
## Usage
## Installation

```
const core = require('@jscpd/finder');
npm install @jscpd/finder --save
```

## Usage

```typescript
import {Tokenizer} from '@jscpd/tokenizer';
import {
MemoryStore,
IOptions,
IClone,
IStore,
ITokenizer
} from '@jscpd/core';
import {EntryWithContent, getFilesToDetect, InFilesDetector} from '@jscpd/finder';

const options: IOptions = {
minLines: 5,
maxLines: 500,
path: ['list of folders and files to analyse for clones']
}

const tokenizer: ITokenizer = new Tokenizer();
// here you can use any store what implement IStore interface
const store: IStore = new MemoryStore();
const statistic = new Statistic(options);

// TODO: DEMONSTRATE API
const files: EntryWithContent[] = getFilesToDetect(options);

const detector = new InFilesDetector(tokenizer, store, statistic, options);

( async () => {
const clones: IClone[] = await detector.detect(files);
})();
```


![ga tracker](https://www.google-analytics.com/collect?v=1&a=257770996&t=pageview&dl=https%3A%2F%2Fgithub.com%2Fkucherenko%2Fjscpd&ul=en-us&de=UTF-8&cid=978224512.1377738459&tid=UA-730549-17&z=887657232 "ga tracker")

## License

[MIT](LICENSE) © Andrey Kucherenko
60 changes: 14 additions & 46 deletions packages/jscpd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The jscpd tool implements [Rabin-Karp](https://en.wikipedia.org/wiki/Rabin%E2%80
- [Badge](#badge)
- [PMD CPD XML](#pmd-cpd-xml)
- [JSON](#json-reporters)
- [API](#api)
- [Changelog](#changelog)
- [Who uses jscpd](#who-uses-jscpd)
- [Contributors](#contributors)
Expand Down Expand Up @@ -304,14 +305,13 @@ import {UserService} from './services';
-->
```

## JSCPD Reporters
## Reporters

### HTML

[Demo report](http://kucherenko.github.io/jscpd-report.html)
### Badge

![jscpd](assets/jscpd-badge.svg)
![jscpd](../../assets/jscpd-badge.svg)

More info [jscpd-badge-reporter](https://github.com/kucherenko/jscpd-badge-reporter)
### PMD CPD XML
Expand Down Expand Up @@ -398,59 +398,27 @@ More info [jscpd-badge-reporter](https://github.com/kucherenko/jscpd-badge-repor
"percentage": 45.33,
"newDuplicatedLines": 0,
"newClones": 0
},
"threshold": 10
}
}
}
```
## API

For run cli version use following code:
```typescript
import {
JSCPD,
IClone,
IOptions,
MATCH_SOURCE_EVENT,
CLONE_FOUND_EVENT,
SOURCE_SKIPPED_EVENT,
END_EVENT
} from 'jscpd';

const options: IOptions = {};

const cpd = new JSCPD(options);

const code = '...string with my code...';

cpd.on(MATCH_SOURCE_EVENT, (source) => {
// new source detection started
console.log(source);
});
import {IClone} from '@jscpd/core';
import {jscpd} from 'jscpd';

cpd.on(CLONE_FOUND_EVENT, (clone: IClone) => {
// clone found event
console.log(clone);
});

cpd.on(SOURCE_SKIPPED_EVENT, (stat) => {
// skipped source due size (see max-size, min-lines and max-lines options)
console.log(stat);
});

cpd.on(END_EVENT, (clones: IClone[]) => {
// detection process finished
console.log(clones);
});

cpd.detect(code, { id: 'test', format: 'markup' })
.then((clones: IClone[]) => console.log(clones));


cpd.detectInFiles(['./src', './tests'])
.then((clones: IClone[]) => console.log(clones));
const clones: Promise<IClone[]> = jscpd(process.argv);

(async () => {
const clones: IClone[] = await jscpd(['', '', '/path/to/file/or/folder', '-m', 'weak', '--silent']);
})();
```

If you are going to detect clones in file system you can use [@jscpd/finder](../finder) for make a powerful detector.
In case of detect clones in browser or not node.js environment you can build you own solution base on [@jscpd/code](../core)

## Changelog
[Changelog](CHANGELOG.md)

Expand Down
38 changes: 34 additions & 4 deletions packages/leveldb-store/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
# `@jscpd/core`
# `@jscpd/leveldb-store`

> TODO: description
> store for jscpd, used for large repositories
## Installation

```
npm install @jscpd/leveldb-store --save
```

## Usage

```
const core = require('@jscpd/core');
import {Tokenizer} from '@jscpd/tokenizer';
import {
Detector,
IOptions,
IClone,
IStore,
ITokenizer
} from '@jscpd/core';
import LeveldbStore from '@jscpd/leveldb-store';
const options: IOptions = {
minLines: 5,
maxLines: 500,
}
const tokenizer: ITokenizer = new Tokenizer();
const store: IStore = new LeveldbStore();
const detector = new Detector(tokenizer, store, [], options);
// TODO: DEMONSTRATE API
```

![ga tracker](https://www.google-analytics.com/collect?v=1&a=257770996&t=pageview&dl=https%3A%2F%2Fgithub.com%2Fkucherenko%2Fjscpd&ul=en-us&de=UTF-8&cid=978224512.1377738459&tid=UA-730549-17&z=887657232 "ga tracker")

## License

[MIT](LICENSE) © Andrey Kucherenko
40 changes: 36 additions & 4 deletions packages/redis-store/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
# `@jscpd/core`
# `@jscpd/leveldb-store`

> TODO: description
**!NOT implemented yet**

> store for jscpd, used [redis](https://redis.io/) data store for hashes
## Installation

```
npm install @jscpd/redis-store --save
```

## Usage

```
const core = require('@jscpd/core');
import {Tokenizer} from '@jscpd/tokenizer';
import {
Detector,
IOptions,
IClone,
IStore,
ITokenizer
} from '@jscpd/core';
import RedisdbStore from '@jscpd/redis-store';
const options: IOptions = {
minLines: 5,
maxLines: 500,
}
const tokenizer: ITokenizer = new Tokenizer();
const store: IStore = new RedisdbStore();
const detector = new Detector(tokenizer, store, [], options);
// TODO: DEMONSTRATE API
```

![ga tracker](https://www.google-analytics.com/collect?v=1&a=257770996&t=pageview&dl=https%3A%2F%2Fgithub.com%2Fkucherenko%2Fjscpd&ul=en-us&de=UTF-8&cid=978224512.1377738459&tid=UA-730549-17&z=887657232 "ga tracker")

## License

[MIT](LICENSE) © Andrey Kucherenko
24 changes: 21 additions & 3 deletions packages/tokenizer/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# `@jscpd/tokenizer`

> TODO: description
> tokenizer is package from @jscpd used for convert programming code to list of tokens

## Installation

```
npm install @jscpd/tokenizer --save
```

## Usage

```
const core = require('@jscpd/tokenizer');
import {IOptions, ITokensMap} from '@jscpd/core';
import {Tokenizer} from '@jscpd/tokenizer';
const tokenizer = new Tokenizer();
const options: IOptions = {};
const maps: ITokensMap[] = tokenizer.generateMaps('source_id', 'let a = "11"', 'javascript', options);
// TODO: DEMONSTRATE API
```

![ga tracker](https://www.google-analytics.com/collect?v=1&a=257770996&t=pageview&dl=https%3A%2F%2Fgithub.com%2Fkucherenko%2Fjscpd&ul=en-us&de=UTF-8&cid=978224512.1377738459&tid=UA-730549-17&z=887657232 "ga tracker")

## License

[MIT](LICENSE) © Andrey Kucherenko

0 comments on commit 76492e6

Please sign in to comment.