Skip to content

Commit

Permalink
Merge branch 'release/v0.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelBinpar committed May 4, 2020
2 parents 3028dc8 + f235183 commit b0ac341
Show file tree
Hide file tree
Showing 64 changed files with 9,441 additions and 4,897 deletions.
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"no-plusplus": "off",
"no-underscore-dangle": "off",
"import/extensions": "off",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{ "overrides": { "constructors": "no-public" } }
],
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
Expand All @@ -50,7 +54,6 @@
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/explicit-member-accessibility": "error",
"@typescript-eslint/member-delimiter-style": "error",
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
Expand All @@ -63,6 +66,6 @@
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/type-annotation-spacing": "error"
}
}
8 changes: 8 additions & 0 deletions .snyk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.14.1
ignore: {}
# patches apply the minimum changes required to fix a vulnerability
patch:
SNYK-JS-LODASH-567746:
- winston > async > lodash:
patched: '2020-04-30T17:10:55.970Z'
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"cSpell.words": [
"Dirent",
"Interop",
"Snyk",
"Unexisting",
"acttoreact",
"binpar",
Expand Down
4 changes: 4 additions & 0 deletions @types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Type used to omit props from interface
*/
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A2R API Watcher

[![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)
[![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)

A2R Framework API Watcher
52 changes: 42 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import path from 'path';
import chokidar from 'chokidar';

import { targetPath, runtimePath } from './settings';
import initWatchers from './utils/initWatchers';
import { ensureDir } from './tools/fs';
import isJest from './tools/isJest';

export const activeWatchers: chokidar.FSWatcher[] = [];

const serverPath = path.resolve(__dirname, './server');
/**
* API Watcher process
*/
interface Process {
type: 'start' | 'stop';
callback: (watchers: chokidar.FSWatcher[]) => void;
}

const pendingProcesses: Process[] = [];
const serverPath = path.resolve(__dirname, targetPath);
const runtimeDestPath = path.resolve(__dirname, runtimePath);

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

/**
* Current active watchers
*/
export const activeWatchers: chokidar.FSWatcher[] = [];

/**
* Executes pending processes
*/
const executeProcess = async (): Promise<void> => {
if (!runningProcess) {
const pendingProcess = pendingProcesses.shift();
if (pendingProcess) {
const { type, callback } = pendingProcess;
runningProcess = type;
// eslint-disable-next-line no-console
console.log('Running process', type, activeWatchers.length);
if (activeWatchers.length) {
await Promise.all(
activeWatchers.map(async (watcher) => {
Expand All @@ -31,18 +43,19 @@ const executeProcess = async (): Promise<void> => {
activeWatchers.splice(0, activeWatchers.length);
}
if (type === 'start') {
const watchers = await initWatchers(serverPath);
const watchers = await initWatchers(serverPath, __dirname);
activeWatchers.push(...watchers);
}
callback(activeWatchers);
runningProcess = null;
// eslint-disable-next-line no-console
console.log('Process ended', type, activeWatchers.length);
executeProcess();
}
}
};

/**
* Adds a new process to queue
*/
const addProcessToQueue = (
type: 'start' | 'stop',
callback?: (watchers: chokidar.FSWatcher[]) => void,
Expand All @@ -51,20 +64,39 @@ const addProcessToQueue = (
executeProcess();
};

/**
* Stops watchers
*/
export const stop = (): Promise<void> =>
new Promise((resolve) => {
addProcessToQueue('stop', () => {
resolve();
});
});

/**
* Starts watchers
*/
export const start = async (): Promise<chokidar.FSWatcher[]> =>
new Promise((resolve) => {
addProcessToQueue('start', (watchers) => {
resolve(watchers);
});
});

export const restart = async (): Promise<chokidar.FSWatcher[]> => start();
/**
* Restarts watchers
*/
export const restart = start;

/**
* Inits API Watcher by ensuring destination path and running start process
*/
const init = async (): Promise<void> => {
await ensureDir(runtimeDestPath);
await start();
};

start();
if (!isJest()) {
init();
}
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
collectCoverageFrom: [
"**/*.{ts,tsx}",
"!**/node_modules/**",
"!**/dist/**"
"!**/dist/**",
"!**/test/mocks/**"
],
coverageReporters: ['text', 'lcov', 'json', 'html'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
Expand Down
13 changes: 13 additions & 0 deletions model/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ts from 'typescript';

/**
* For typescript nodes casting as docs container purposes
*/
export interface JSDocContainer {
/**
* Optional JSDoc array
* @type {ts.JSDoc[]}
* @memberof JSDocContainer
*/
jsDoc?: ts.JSDoc[];
}
22 changes: 15 additions & 7 deletions model/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ export type OnReady = (
export interface WatcherOptions {
/**
* Path that should be watched for changes
* @type {string}
* @memberof WatcherOptions
*/
targetPath: string;
/**
* Detected changes handler
* @memberof WatcherOptions
*/
handler: Handler;
/**
* Errors handler
* @memberof WatcherOptions
Expand All @@ -74,8 +68,22 @@ export interface WatcherOptions {
/**
* Internal watcher options:
* WatchOptions from [chokidar](https://github.com/paulmillr/chokidar#api)
* @type {chokidar.WatchOptions}
* @memberof WatcherOptions
*/
options?: chokidar.WatchOptions;
}

/**
* Process info resulting from watcher event
*/
export interface ProcessInfo {
/**
* Event type
* @type
*/
type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
/**
* Target path
*/
targetPath: string;
}
Loading

0 comments on commit b0ac341

Please sign in to comment.