Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelBinpar committed May 14, 2020
2 parents 789953e + 3d7baff commit eda2b53
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ yarn-error.log*

# Compiled version
dist/
bin/

# Runtime data
pids
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"tslib"
],
"search.exclude": {
"**/bin": true,
"**/node_modules": true,
"**/docs/jsdocs": true
}
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ RUN npm install --production --silent
COPY . ./src
RUN cd ./src;npm install --silent;npm run build
# Copy de compiled version
RUN cp -r ./src/dist ./dist
RUN cp -r ./src/bin ./bin
# Remove the sources
RUN rm -rf ./src
# Enviroment por production
ENV NODE_ENV production
# Vulumes for mapping
VOLUME ["/usr/src/app/server"]
VOLUME ["/usr/src/app/bin/server"]
# Start command
CMD npm start
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-watcher",
"version": "0.1.0",
"version": "0.2.0",
"description": "API Watcher",
"engines": {
"node": ">=12"
Expand All @@ -11,7 +11,7 @@
"docker-build": "IMAGE=$npm_package_name:latest;docker build --rm --pull -f \"./Dockerfile\" -t $IMAGE \".\"",
"docker-start": "IMAGE=$npm_package_name:latest;docker run -it -v $INIT_CWD/server:/usr/src/app/server $IMAGE",
"docker-start-from-hub": "IMAGE=act2react/api-watcher:version-$npm_package_version;docker run -it -v $INIT_CWD/server:/usr/src/app/server $IMAGE",
"start": "node ./dist/index.js",
"start": "node ./bin/index.js",
"lint": "npx eslint --config ./.eslintrc ./**/*.ts",
"test": "jest",
"test-clear": "rm -rf coverage;rm -rf dist",
Expand Down
14 changes: 14 additions & 0 deletions test/tests/api/isClientContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import path from 'path';

import { readFile } from '../../../tools/fs';
import getIsClientContent from '../../../utils/getIsClientContent';

const isClientPath = path.resolve(__dirname, '../../../tools/isClient.ts');

/**
* isClient content should be the same as `isClient.ts` file
*/
test('isClient content', async (): Promise<void> => {
const fileContent = await readFile(isClientPath, 'utf8');
expect(getIsClientContent()).toBe(fileContent);
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"sourceMap": true,
"skipLibCheck": true,
"baseUrl": ".",
"outDir": "./dist",
"outDir": "./bin",
"rootDir": ".",
"extendedDiagnostics": true,
"typeRoots": [
Expand Down
9 changes: 4 additions & 5 deletions utils/apiProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import {
} from '../model/api';

import { defaultApiSourcePath, defaultProxyTargetPath } from '../settings';
import { getFilesRecursively, writeFile, copyFile } from '../tools/fs';
import { getFilesRecursively, writeFile } from '../tools/fs';
import getModuleInfo from './getModuleInfo';
import getGroupedModelImports from './getGroupedModelImports';
import getProxyMethod from './getProxyMethod';
import updateApiObject from './updateApiObject';
import getApiObjectText from './getApiObject';
import getMethodWrapper from './getMethodWrapper';
import getSocketProvider from './getSocketProvider';
import getIsClientContent from './getIsClientContent';

export const api: APIStructure = {};

const isClientInternalPath = path.resolve(__dirname, '../tools/isClient.ts');

/**
* Gets external needed imports
*/
Expand Down Expand Up @@ -84,10 +83,10 @@ export const build = async (
apiSourcePath = defaultApiSourcePath,
proxyTargetPath = defaultProxyTargetPath,
): Promise<void> => {
const files = await getFilesRecursively(apiSourcePath, ['.ts']);
const proxyIndexPath = path.resolve(proxyTargetPath, 'index.ts');
const socketFilePath = path.resolve(proxyTargetPath, 'socket.ts');
const isClientFilePath = path.resolve(proxyTargetPath, 'isClient.ts');
const files = await getFilesRecursively(apiSourcePath, ['.ts']);

const modulesInfo: ModuleInfo[] = await Promise.all(
files.map(file => getModuleInfo(file, apiSourcePath)),
Expand Down Expand Up @@ -129,7 +128,7 @@ export const build = async (
const groupedImports = getGroupedModelImports(imports);

await writeFile(socketFilePath, getSocketProvider());
await copyFile(isClientInternalPath, isClientFilePath);
await writeFile(isClientFilePath, getIsClientContent());
await writeFile(
proxyIndexPath,
[
Expand Down
23 changes: 23 additions & 0 deletions utils/getIsClientContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const getIsClientContent = (): string => `let forceServerSimulation = false;
/**
* Allows you to disable client detection
* @param {boolean} value True to force Server Side Simulation
*/
export const setForceServerSimulation = (value: boolean): void => {
forceServerSimulation = value;
};
/**
* Checks if the script is running on the client side
*/
const isClient = (): boolean => {
if (forceServerSimulation) {
return false;
}
return typeof window === 'object';
};
export default isClient;`

export default getIsClientContent;
4 changes: 3 additions & 1 deletion utils/initWatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const initWatchers = async (
): Promise<chokidar.FSWatcher[]> => {
const pathExists = await exists(serverPath);
if (!pathExists) {
throw new Error(`Provided server path doesn't exist`);
const error = `Provided server path doesn't exist: ${fullPath(serverPath)}`;
out.error(error);
throw new Error(error);
}

const proxyTargetPath = path.resolve(mainPath, proxyPath);
Expand Down

0 comments on commit eda2b53

Please sign in to comment.