Skip to content

UILib Packages #723

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

Merged
merged 8 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"xcode": "open ./ios/uilib.xcodeproj",
"build:dev": "tsc --p tsconfig.dev.json",
"build:exports": "./node_modules/.bin/babel src --out-dir src --config-file ./src/.babelrc.json --extensions '.ts,.tsx' --ignore 'src/index.ts'",
"build": "tsc --p tsconfig.build.json && npm run build:exports",
"build:packages": "node scripts/buildPackages.js",
"build": "tsc --p tsconfig.build.json && npm run build:exports && npm run build:packages",
"log": "react-native log-ios | grep 'ethan -'",
"docs:install": "(cd ./uilib-docs && rm -rf node_modules && rm -rf package-lock.json && npm install)",
"docs:deploy": "(cd ./uilib-docs && gatsby build --prefix-paths && gh-pages -d public --branch gh-pages)",
Expand Down
47 changes: 47 additions & 0 deletions scripts/buildPackages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');
const _ = require('lodash');

const packages = [
{
filename: 'keyboard.js',
content: `module.exports = require('./lib/components/Keyboard').default;\n`
Copy link
Collaborator

@Inbal-Tish Inbal-Tish Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use 'components: [keyboard]'? It's clearer and you can add other keyboard components in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at ./lib/components/Keyboard
It already contains all the various Keyboard components we have.
The user will be able to import it like this

import {KeyboardTrackingView, KeyboardAwareInsetsView, KeyboardRegistry, ...} from 'react-native-ui-lib/keyobard';

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. mmm... I still think it's clearer to use the same object format, seems less random. Your call.

},
{
filename: 'core.js',
components: ['View', 'Text', 'Image', 'TouchableOpacity', 'Button']
}
];

/* Write custom packages */
packages.forEach((package) => {
let content = package.content || '';

if (package.components) {
content += 'module.exports = {\n';
package.components.forEach((component) => {
content += `get ${component}() {\n`;
content += `return require('./src/components/${_.camelCase(
component
)}').default;`;
content += `},\n`;
});
content += '};\n';
}

fs.writeFileSync(package.filename, content);
});

/* Write all components as separate packages */
const path = './src/components';
fs.readdir(path, (err, files) => {
if (!err) {
files
.filter((f) => f !== 'index.js')
.forEach((file) => {
fs.writeFileSync(
`${file}.js`,
`module.exports = require('${path}/${file}').default;\n`
);
});
}
});