Skip to content

Commit b0ac341

Browse files
committed
Merge branch 'release/v0.0.5'
2 parents 3028dc8 + f235183 commit b0ac341

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9441
-4897
lines changed

.eslintrc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
"no-plusplus": "off",
4343
"no-underscore-dangle": "off",
4444
"import/extensions": "off",
45+
"@typescript-eslint/explicit-member-accessibility": [
46+
"error",
47+
{ "overrides": { "constructors": "no-public" } }
48+
],
4549
"@typescript-eslint/no-unused-vars": "error",
4650
"@typescript-eslint/adjacent-overload-signatures": "error",
4751
"@typescript-eslint/array-type": "error",
@@ -50,7 +54,6 @@
5054
"@typescript-eslint/class-name-casing": "error",
5155
"@typescript-eslint/consistent-type-definitions": "error",
5256
"@typescript-eslint/explicit-function-return-type": "error",
53-
"@typescript-eslint/explicit-member-accessibility": "error",
5457
"@typescript-eslint/member-delimiter-style": "error",
5558
"@typescript-eslint/no-array-constructor": "error",
5659
"@typescript-eslint/no-empty-interface": "error",
@@ -63,6 +66,6 @@
6366
"@typescript-eslint/no-use-before-define": "error",
6467
"@typescript-eslint/no-var-requires": "error",
6568
"@typescript-eslint/prefer-namespace-keyword": "error",
66-
"@typescript-eslint/type-annotation-spacing": "error",
69+
"@typescript-eslint/type-annotation-spacing": "error"
6770
}
6871
}

.snyk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2+
version: v1.14.1
3+
ignore: {}
4+
# patches apply the minimum changes required to fix a vulnerability
5+
patch:
6+
SNYK-JS-LODASH-567746:
7+
- winston > async > lodash:
8+
patched: '2020-04-30T17:10:55.970Z'

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"cSpell.words": [
3+
"Dirent",
34
"Interop",
5+
"Snyk",
46
"Unexisting",
57
"acttoreact",
68
"binpar",

@types/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Type used to omit props from interface
3+
*/
4+
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A2R API Watcher
22

3-
[![Build Status](https://travis-ci.org/acttoreact/api-watcher.svg?branch=master)](https://travis-ci.org/acttoreact/api-watcher) [![Coverage Status](https://coveralls.io/repos/github/acttoreact/api-watcher/badge.svg?branch=master)](https://coveralls.io/github/acttoreact/api-watcher) [![Docker Image Version (latest by date)](https://img.shields.io/docker/v/act2react/api-watcher?sort=date)](https://hub.docker.com/r/act2react/api-watcher) [![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/act2react/api-watcher?sort=date)](https://hub.docker.com/r/act2react/api-watcher) [![GitHub](https://img.shields.io/github/license/acttoreact/api-watcher)](https://github.com/acttoreact/api-watcher/blob/develop/license.md) [![Documentation](https://img.shields.io/badge/documentation-ready-green)](https://htmlpreview.github.io/?https://github.com/acttoreact/api-watcher/blob/develop/docs/jsdocs/index.html#readDir)
3+
[![Build Status](https://travis-ci.org/acttoreact/api-watcher.svg?branch=master)](https://travis-ci.org/acttoreact/api-watcher) [![Coverage Status](https://coveralls.io/repos/github/acttoreact/api-watcher/badge.svg?branch=master)](https://coveralls.io/github/acttoreact/api-watcher) [![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/acttoreact/api-watcher)](https://snyk.io/test/github/acttoreact/api-watcher) [![Docker Image Version (latest by date)](https://img.shields.io/docker/v/act2react/api-watcher?sort=date)](https://hub.docker.com/r/act2react/api-watcher) [![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/act2react/api-watcher?sort=date)](https://hub.docker.com/r/act2react/api-watcher) [![GitHub](https://img.shields.io/github/license/acttoreact/api-watcher)](https://github.com/acttoreact/api-watcher/blob/develop/license.md) [![Documentation](https://img.shields.io/badge/documentation-ready-green)](https://htmlpreview.github.io/?https://github.com/acttoreact/api-watcher/blob/develop/docs/jsdocs/index.html#readDir)
44

55
A2R Framework API Watcher

index.ts

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
import path from 'path';
22
import chokidar from 'chokidar';
33

4+
import { targetPath, runtimePath } from './settings';
45
import initWatchers from './utils/initWatchers';
6+
import { ensureDir } from './tools/fs';
7+
import isJest from './tools/isJest';
58

6-
export const activeWatchers: chokidar.FSWatcher[] = [];
7-
8-
const serverPath = path.resolve(__dirname, './server');
9+
/**
10+
* API Watcher process
11+
*/
912
interface Process {
1013
type: 'start' | 'stop';
1114
callback: (watchers: chokidar.FSWatcher[]) => void;
1215
}
16+
1317
const pendingProcesses: Process[] = [];
18+
const serverPath = path.resolve(__dirname, targetPath);
19+
const runtimeDestPath = path.resolve(__dirname, runtimePath);
1420

1521
let runningProcess: 'start' | 'stop' = null;
1622

23+
/**
24+
* Current active watchers
25+
*/
26+
export const activeWatchers: chokidar.FSWatcher[] = [];
27+
28+
/**
29+
* Executes pending processes
30+
*/
1731
const executeProcess = async (): Promise<void> => {
1832
if (!runningProcess) {
1933
const pendingProcess = pendingProcesses.shift();
2034
if (pendingProcess) {
2135
const { type, callback } = pendingProcess;
2236
runningProcess = type;
23-
// eslint-disable-next-line no-console
24-
console.log('Running process', type, activeWatchers.length);
2537
if (activeWatchers.length) {
2638
await Promise.all(
2739
activeWatchers.map(async (watcher) => {
@@ -31,18 +43,19 @@ const executeProcess = async (): Promise<void> => {
3143
activeWatchers.splice(0, activeWatchers.length);
3244
}
3345
if (type === 'start') {
34-
const watchers = await initWatchers(serverPath);
46+
const watchers = await initWatchers(serverPath, __dirname);
3547
activeWatchers.push(...watchers);
3648
}
3749
callback(activeWatchers);
3850
runningProcess = null;
39-
// eslint-disable-next-line no-console
40-
console.log('Process ended', type, activeWatchers.length);
4151
executeProcess();
4252
}
4353
}
4454
};
4555

56+
/**
57+
* Adds a new process to queue
58+
*/
4659
const addProcessToQueue = (
4760
type: 'start' | 'stop',
4861
callback?: (watchers: chokidar.FSWatcher[]) => void,
@@ -51,20 +64,39 @@ const addProcessToQueue = (
5164
executeProcess();
5265
};
5366

67+
/**
68+
* Stops watchers
69+
*/
5470
export const stop = (): Promise<void> =>
5571
new Promise((resolve) => {
5672
addProcessToQueue('stop', () => {
5773
resolve();
5874
});
5975
});
6076

77+
/**
78+
* Starts watchers
79+
*/
6180
export const start = async (): Promise<chokidar.FSWatcher[]> =>
6281
new Promise((resolve) => {
6382
addProcessToQueue('start', (watchers) => {
6483
resolve(watchers);
6584
});
6685
});
6786

68-
export const restart = async (): Promise<chokidar.FSWatcher[]> => start();
87+
/**
88+
* Restarts watchers
89+
*/
90+
export const restart = start;
91+
92+
/**
93+
* Inits API Watcher by ensuring destination path and running start process
94+
*/
95+
const init = async (): Promise<void> => {
96+
await ensureDir(runtimeDestPath);
97+
await start();
98+
};
6999

70-
start();
100+
if (!isJest()) {
101+
init();
102+
}

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = {
99
collectCoverageFrom: [
1010
"**/*.{ts,tsx}",
1111
"!**/node_modules/**",
12-
"!**/dist/**"
12+
"!**/dist/**",
13+
"!**/test/mocks/**"
1314
],
1415
coverageReporters: ['text', 'lcov', 'json', 'html'],
1516
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],

model/docs.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import ts from 'typescript';
2+
3+
/**
4+
* For typescript nodes casting as docs container purposes
5+
*/
6+
export interface JSDocContainer {
7+
/**
8+
* Optional JSDoc array
9+
* @type {ts.JSDoc[]}
10+
* @memberof JSDocContainer
11+
*/
12+
jsDoc?: ts.JSDoc[];
13+
}

model/watcher.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ export type OnReady = (
5252
export interface WatcherOptions {
5353
/**
5454
* Path that should be watched for changes
55-
* @type {string}
5655
* @memberof WatcherOptions
5756
*/
5857
targetPath: string;
59-
/**
60-
* Detected changes handler
61-
* @memberof WatcherOptions
62-
*/
63-
handler: Handler;
6458
/**
6559
* Errors handler
6660
* @memberof WatcherOptions
@@ -74,8 +68,22 @@ export interface WatcherOptions {
7468
/**
7569
* Internal watcher options:
7670
* WatchOptions from [chokidar](https://github.com/paulmillr/chokidar#api)
77-
* @type {chokidar.WatchOptions}
7871
* @memberof WatcherOptions
7972
*/
8073
options?: chokidar.WatchOptions;
74+
}
75+
76+
/**
77+
* Process info resulting from watcher event
78+
*/
79+
export interface ProcessInfo {
80+
/**
81+
* Event type
82+
* @type
83+
*/
84+
type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
85+
/**
86+
* Target path
87+
*/
88+
targetPath: string;
8189
}

0 commit comments

Comments
 (0)