Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better typescript setup for monorepo #17

Merged
merged 15 commits into from
Sep 3, 2019
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"scripts": {
"build": "lerna run build",
"lint": "lerna run lint --parallel --stream",
"clean": "lerna run clean --parallel",
"build:static": "lerna run build:static --parallel",
"run:demo": "lerna run start --scope @energyweb/utils-demo --stream",
"run:backend": "lerna run start --scope @energyweb/utils-testbackend --stream",
"run:ui": "lerna run start --scope @energyweb/origin-ui --stream",
Expand Down
6 changes: 4 additions & 2 deletions packages/asset-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"build-schema:ProducingAssetPropertiesOffChain": "typescript-json-schema --ignoreErrors --required src/blockchain-facade/ProducingAsset.ts IOffChainProperties > schemas/ProducingAssetPropertiesOffChain.schema.json",
"prebuild-schemas": "rm -rf dist/schemas && mkdir -p dist/schemas && rm -rf schemas && mkdir schemas",
"build-schemas": "npm run build-schema:AssetPropertiesOffChain && npm run build-schema:ProducingAssetPropertiesOffChain && cp -R schemas dist/schemas",
"build-ts": "npm run build-schemas && rm -rf dist/js && tsc",
"build-ts": "npm run build-schemas && rm -rf dist/js && tsc -b tsconfig.build.json --verbose --pretty",
"compile": "truffle compile",
"compile-contracts": "node build/ts/utils/deployment/compile",
"deploy-contracts": "truffle migrate",
Expand All @@ -38,7 +38,9 @@
"start-test-backend": "node ../../node_modules/@energyweb/utils-testbackend/dist/js/src/index.js",
"test": "npm run build-schemas && npm run build && mocha dist/js/src/test/ --timeout 60000",
"prettier": "prettier --write --config-precedence file-override './src/**/*'",
"test-contracts": "concurrently --success first --kill-others -n eth,backend,test \"yarn start-ganache\" \"yarn start-test-backend\" \"yarn test\""
"test-contracts": "concurrently --success first --kill-others -n eth,backend,test \"yarn start-ganache\" \"yarn start-test-backend\" \"yarn test\"",
"clean": "rm -rf build dist",
"build:static": "yarn compile && yarn build-schemas"
},
"types": "dist/js/src/index.d.ts",
"dependencies": {
Expand Down
83 changes: 41 additions & 42 deletions packages/asset-registry/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,66 @@ const path = require('path');
const fs = require('fs-extra');

function relativePath(pathToAdd) {
return path.join(__dirname, pathToAdd);
return path.join(__dirname, pathToAdd);
}

function getRootDirectory() {
const PATHS_TO_TEST = [
relativePath('../')
];
const PATHS_TO_TEST = [relativePath('../')];

for (const path of PATHS_TO_TEST) {
if (fs.existsSync(path)) {
return path;
for (const path of PATHS_TO_TEST) {
if (fs.existsSync(path)) {
return path;
}
}
}

throw `Can't find contracts directory`;
throw `Can't find contracts directory`;
}

const ROOT_DIRECTORY = getRootDirectory();

async function executeCommand(command, directory) {
const options = {};

if (directory) {
options.cwd = directory;
}

try {
const { stdout, stderr } = await exec(command, options);

console.log(stdout);
console.error(stderr);
} catch (error) {
if (error && error.stdout) {
console.error(error.stdout);
} else {
console.error(error);
const options = {};

if (directory) {
options.cwd = directory;
}

try {
const { stdout, stderr } = await exec(command, options);

console.log(stdout);
console.error(stderr);
} catch (error) {
if (error && error.stdout) {
console.error(error.stdout);
} else {
console.error(error);
}
process.exit(1);
}
}
}

async function run() {
console.log('EW-ASSET-REGISTRY-LIB: Building...');
console.log('EW-ASSET-REGISTRY-LIB: Building...');

await executeCommand('yarn compile', ROOT_DIRECTORY)
await executeCommand('yarn build-ts', ROOT_DIRECTORY)
await executeCommand('yarn compile', ROOT_DIRECTORY);
await executeCommand('yarn build-ts', ROOT_DIRECTORY);

if (!(await fs.pathExists(`${ROOT_DIRECTORY}/dist/js/src`))) {
await fs.move(`${ROOT_DIRECTORY}/dist/js`, `${ROOT_DIRECTORY}/dist/js-temp`);
await fs.ensureDir(`${ROOT_DIRECTORY}/dist/js`);
await fs.move(`${ROOT_DIRECTORY}/dist/js-temp`, `${ROOT_DIRECTORY}/dist/js/src`);
}
if (!(await fs.pathExists(`${ROOT_DIRECTORY}/dist/js/src`))) {
await fs.move(`${ROOT_DIRECTORY}/dist/js`, `${ROOT_DIRECTORY}/dist/js-temp`);
await fs.ensureDir(`${ROOT_DIRECTORY}/dist/js`);
await fs.move(`${ROOT_DIRECTORY}/dist/js-temp`, `${ROOT_DIRECTORY}/dist/js/src`);
}

if (!(await fs.pathExists(`${ROOT_DIRECTORY}/dist/js/schemas`))) {
await fs.move(`${ROOT_DIRECTORY}/schemas`, `${ROOT_DIRECTORY}/dist/js/schemas`);
}
if (!(await fs.pathExists(`${ROOT_DIRECTORY}/dist/js/schemas`))) {
await fs.move(`${ROOT_DIRECTORY}/schemas`, `${ROOT_DIRECTORY}/dist/js/schemas`);
}

if (!(await fs.pathExists(`${ROOT_DIRECTORY}/dist/js/build`))) {
await fs.move(`${ROOT_DIRECTORY}/build`, `${ROOT_DIRECTORY}/dist/js/build`);
}
if (!(await fs.pathExists(`${ROOT_DIRECTORY}/dist/js/build`))) {
await fs.move(`${ROOT_DIRECTORY}/build`, `${ROOT_DIRECTORY}/dist/js/build`);
}

console.log('EW-ASSET-REGISTRY-LIB: Done.');
console.log('EW-ASSET-REGISTRY-LIB: Done.');
}

run();
run();
20 changes: 20 additions & 0 deletions packages/asset-registry/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"composite": true,
"rootDir": "./",
"outDir": "./dist/js"
},
"include": ["./src/**/*", "./schemas/*.json", "./build/**/*.json"],
"references": [
{
"path": "../user-registry/tsconfig.build.json"
},
{
"path": "../utils-general/tsconfig.build.json"
},
{
"path": "../utils-testbackend/tsconfig.build.json"
}
]
}
6 changes: 2 additions & 4 deletions packages/asset-registry/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/js"
},
"include": ["./src/**/*"]
}
}
}
12 changes: 7 additions & 5 deletions packages/market-matcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@
"url": "https://github.com/energywebfoundation/ewf-monorepo/issues"
},
"version": "1.1.0",
"main": "dist/js/src/exports.js",
"main": "dist/js/src/index.js",
"scripts": {
"build": "scripts/build.js",
"build-ts": "rm -rf dist && tsc",
"debug": "node --inspect-brk dist/js/src/index.js",
"build-ts": "rm -rf dist && tsc -b tsconfig.build.json --verbose --pretty",
"debug": "node --inspect-brk dist/js/src/main.js",
"generate-conf-schema": "typescript-json-schema --required --ignoreErrors tsconfig.json IMatcherConf > schemas/conf.schema.json",
"generate-rule-schema": "typescript-json-schema --required --ignoreErrors tsconfig.json IRuleConf > schemas/rule.schema.json",
"generate-schemas": "rm -rf schemas/ && mkdir schemas/ && npm run generate-sim-flow-schema && npm run generate-rule-schema && npm run generate-conf-schema",
"generate-sim-flow-schema": "typescript-json-schema --required --ignoreErrors tsconfig.json ISimulationFlow > schemas/simulation-description.schema.json",
"lint": "tslint 'src/**/*{.ts,.tsx}'",
"lint-fix": "tslint --fix 'src/**/*{.ts,.tsx}'",
"prepare": "scripts/build.js",
"start": "npm run build && node dist/js/src/index.js",
"start": "npm run build && node dist/js/src/main.js",
"start-ganache": "ganache-cli -m 'chalk park staff buzz chair purchase wise oak receive avoid avoid home' -l 8000000 -e 1000000 -a 20",
"start-test-backend": "node ../../node_modules/@energyweb/utils-testbackend/dist/js/src/index.js",
"prettier": "prettier --write --config-precedence file-override './src/**/*'",
"test": "concurrently --success first --kill-others -n eth,backend,test \"yarn start-ganache\" \"yarn start-test-backend\" \"yarn build && mocha --exit dist/js/src/test/\"",
"test-ts": "concurrently --success first --kill-others -n eth,backend,test \"yarn start-ganache\" \"yarn start-test-backend\" \"yarn generate-schemas && mocha --exit -r ts-node/register src/test/*.ts\""
"test-ts": "concurrently --success first --kill-others -n eth,backend,test \"yarn start-ganache\" \"yarn start-test-backend\" \"yarn generate-schemas && mocha --exit -r ts-node/register src/test/*.ts\"",
"clean": "rm -rf build dist",
"build:static": "yarn generate-schemas"
},
"types": "dist/js/src/exports.d.ts",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
createBlockchainProperties as issuerCreateBlockchainProperties
} from '@energyweb/origin';
import { Configuration, ContractEventHandler, EventHandlerManager } from '@energyweb/utils-general';
import { EthAccount } from '@energyweb/utils-general/dist/js/blockchain-facade/Configuration';
import Web3 from 'web3';

import { logger } from '../Logger';
Expand Down Expand Up @@ -67,7 +66,7 @@ export const initMatchingManager = async (controller: Controller, conf: Configur

export const createBlockchainConf = async (
blockchainSectionConfFile: IBlockchainDataSource,
matcherAccount: EthAccount
matcherAccount: Configuration.EthAccount
): Promise<Configuration.Entity> => {
const web3 = new Web3(blockchainSectionConfFile.web3Url);
const marketConf = await marketCreateBlockchainProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Agreement, Demand, Supply } from '@energyweb/market';
import { Certificate } from '@energyweb/origin';
import { Configuration, TimeFrame } from '@energyweb/utils-general';

import { METHOD_NOT_IMPLEMENTED } from '../exports';
import { METHOD_NOT_IMPLEMENTED } from '..';
import { logger } from '../Logger';
import * as SimulationFlowDef from '../schema-defs/simulation-flow';
import { initEventHandling, initMatchingManager } from './BlockchainConnection';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { TimeFrame } from '@energyweb/utils-general';
import * as fs from 'fs';
import * as LogSymbols from 'log-symbols';

import { METHOD_NOT_IMPLEMENTED } from '..';
import * as SimulationDescriptionSchema from '../../schemas/simulation-description.schema.json';
import { METHOD_NOT_IMPLEMENTED } from '../exports';
import { logger } from '../Logger';
import { ISimulationDataSource } from '../schema-defs/MatcherConf';
import * as SimulationFlowDef from '../schema-defs/simulation-flow/';
Expand Down
98 changes: 0 additions & 98 deletions packages/market-matcher/src/exports.ts

This file was deleted.