Skip to content

Commit

Permalink
build(common): setup env configurations (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
artyorsh authored and 32penkin committed May 20, 2019
1 parent 1e0b287 commit 361a62f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ npm-debug.log
docs/docs.json
docs/src/input.json

# config
config/index.js

.expo
dist
10 changes: 10 additions & 0 deletions config/dev.env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');

const evaPath = path.resolve(__dirname, '../../eva');

module.exports = {
ENV: 'dev',
KITTEN_PATH: path.resolve(__dirname, '../src/framework'),
MAPPING_PATH: path.resolve(evaPath, 'packages/mapping/eva'),
THEME_PATH: path.resolve(evaPath, 'packages/theme/eva'),
};
10 changes: 10 additions & 0 deletions config/prod.env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');

const playgroundPath = path.resolve(__dirname, '../src/playground');

module.exports = {
ENV: 'prod',
KITTEN_PATH: path.resolve(__dirname, '../src/framework'),
MAPPING_PATH: path.resolve(playgroundPath, 'node_modules/@eva/eva'),
THEME_PATH: path.resolve(playgroundPath, 'node_modules/@eva/theme-eva'),
};
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@
"url": "https://github.com/akveo/react-native-ui-kitten/issues"
},
"scripts": {
"start": "npm run build:pg && npm start --prefix ./src/playground",
"start": "npm run start:pg:dev",
"start:pg": "npm start --prefix ./src/playground",
"start:pg:prod": "npm run env:set -- prod && npm run start:pg",
"start:pg:dev": "npm run env:set -- dev && npm run start:pg",
"env:set": "sh ./scripts/environment/set-env.sh",
"build": "npm run build:src",
"build:src": "tsc -p ./src/framework/tsconfig.json",
"build:pg": "( cd ./src/playground && npm install ) && tsc -p ./src/playground/tsconfig.json",
"build": "npm run build:src && npm run build:pg",
"clean:src": "rimraf ./dist/src/framework",
"clean:pg": "rimraf ./dist/src/playground",
"build:pg": "tsc -p ./src/playground/tsconfig.json",
"clean": "rimraf ./dist",
"docs:parse": "gulp docs",
"docs:serve": "cd docs && npm start",
"docs:start": "npm run docs:parse && npm run docs:serve",
"lint:src": "tslint -p ./src/framework/tsconfig.json",
"lint:src-fix": "npm run lint:src -- --fix",
"lint:pg": "tslint -p ./src/playground/tsconfig.json",
"lint:pg-fix": "npm run lint:pg -- --fix",
"lint": "npm run lint:src && npm run lint:pg",
"lint:fix": "npm run lint:src-fix && npm run lint:pg-fix",
"lint:src": "tslint -p ./src/framework/tsconfig.json --fix",
"lint:pg": "tslint -p ./src/playground/tsconfig.json --fix",
"ci:lint": "npm run lint",
"ci:build": "npm run build:pg",
"ci:test": "npm test -- --coverage && cat ./dist/jest/coverage/lcov.info | coveralls",
"ci:build": "npm run build:src && npm run build:pg",
"ci:test": "npm t -- --coverage && cat ./dist/jest/coverage/lcov.info | coveralls",
"install:pg": "( cd ./src/playground && npm i )",
"install": "npm run install:pg",
"test": "jest"
},
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions scripts/environment/set-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

env=${1}
cp ./config/${env}.env.js ./config/index.js
45 changes: 15 additions & 30 deletions src/playground/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
const path = require('path');

const kittenPath = path.resolve('../framework');
const Config = require('../../config');

// FIXME: Resolve `transform[stderr]: Could not resolve` command-line warnings.
// FIXME: Reproducible when starting with clearing cache (npm start -- -c)

const productionConfig = {
mappingPath: path.resolve('./node_modules/@eva/eva'),
themePath: path.resolve('./node_modules/@eva/theme-eva'),
};

const developmentConfig = {
mappingPath: path.resolve(__dirname, '../../../eva/packages/mapping/eva'),
themePath: path.resolve(__dirname, '../../../eva/packages/theme/eva'),
//
// TODO: Framework path aliasing even not needed here. Replace?
// TODO: Replace nested package.json-s with aliases

const moduleResolverConfig = {
root: path.resolve('./'),
alias: {
'@kitten/theme': path.resolve(Config.KITTEN_PATH, 'theme'),
'@kitten/ui': path.resolve(Config.KITTEN_PATH, 'ui'),
'@eva/eva': path.resolve(Config.MAPPING_PATH),
'@eva/theme-eva': path.resolve(Config.THEME_PATH),
},
};

const environment = {
prod: productionConfig,
dev: developmentConfig,
};

function moduleResolverConfig(env) {
return {
root: path.resolve('./'),
alias: {
'@kitten/theme': path.resolve(kittenPath, 'theme'),
'@kitten/ui': path.resolve(kittenPath, 'ui'),
'@eva/eva': path.resolve(env.mappingPath),
'@eva/theme-eva': path.resolve(env.themePath),
},
}
}

module.exports = function (api) {
api.cache(true);

Expand All @@ -40,7 +25,7 @@ module.exports = function (api) {
];

const plugins = [
['module-resolver', moduleResolverConfig(environment.prod)],
['module-resolver', moduleResolverConfig],
];

const devPlugins = [
Expand All @@ -53,5 +38,5 @@ module.exports = function (api) {
},
};

return { presets, env, plugins };
return { presets, plugins, env };
};
46 changes: 10 additions & 36 deletions src/playground/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
const path = require('path');

const kittenPath = path.resolve('../framework');

// FIXME: Resolve `transform[stderr]: Could not resolve` command-line warnings.
// FIXME: Reproducible when starting with clearing cache (npm start -- -c)

const productionConfig = {
mappingPath: path.resolve('./node_modules/@eva/eva'),
themePath: path.resolve('./node_modules/@eva/theme-eva'),
};

const developmentConfig = {
mappingPath: path.resolve(__dirname, '../../../eva/packages/mapping/eva'),
themePath: path.resolve(__dirname, '../../../eva/packages/theme/eva'),
};

const environment = {
prod: productionConfig,
dev: developmentConfig,
};

function envWatchFolders(env) {
return [
env.mappingPath,
env.themePath,
];
}
const Config = require('../../config');

module.exports = {
resolver: {
extraNodeModules: {
'@babel/runtime': path.resolve(__dirname, './node_modules/@babel/runtime'),
'react': path.resolve(__dirname, './node_modules/react'),
'react-native': path.resolve(__dirname, './node_modules/react-native'),
},
sourceExts: [
'js',
'ts',
'tsx',
],
extraNodeModules: {
'@babel/runtime': path.resolve(__dirname, './node_modules/@babel/runtime'),
'react': path.resolve(__dirname, './node_modules/react'),
'react-native': path.resolve(__dirname, './node_modules/react-native'),
},
},
transformer: {
babelTransformerPath: require.resolve('react-native-typescript-transformer'),
},
projectRoot: path.resolve(__dirname),
watchFolders: [
...envWatchFolders(environment.prod),
path.resolve(kittenPath, 'ui'),
path.resolve(kittenPath, 'theme'),
path.resolve(Config.KITTEN_PATH, 'theme'),
path.resolve(Config.KITTEN_PATH, 'ui'),
path.resolve(Config.MAPPING_PATH),
path.resolve(Config.THEME_PATH),

// FIXME(playground): unable to resolve
path.resolve(__dirname, '../../node_modules/@eva/processor-kitten'),
Expand All @@ -57,4 +32,3 @@ module.exports = {
path.resolve(__dirname, '../../node_modules/lodash.merge'),
],
};

2 changes: 1 addition & 1 deletion src/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "./node_modules/expo/AppEntry.js",
"private": true,
"scripts": {
"start": "expo start"
"start": "expo start -c"
},
"dependencies": {
"@eva/eva": "github:akveo/eva#package/mapping-eva",
Expand Down
2 changes: 0 additions & 2 deletions src/playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"es2016"
],
"paths": {
"@eva/eva": ["../../../eva/packages/mapping/eva"],
"@eva/theme-eva": ["../../../eva/packages/theme/eva"],
"@kitten/*": ["../framework/*"]
}
}
Expand Down

0 comments on commit 361a62f

Please sign in to comment.