Skip to content

Commit 3c2c50a

Browse files
authored
UILib Packages (#723)
* Create an entry file for core sub module of rnuilib * create a script that generate sub packages * add build:packages script * remove core.js * build separate package per each component * cleanup and add proper comments
1 parent 98a9a79 commit 3c2c50a

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"xcode": "open ./ios/uilib.xcodeproj",
2828
"build:dev": "tsc --p tsconfig.dev.json",
2929
"build:exports": "./node_modules/.bin/babel src --out-dir src --config-file ./src/.babelrc.json --extensions '.ts,.tsx' --ignore 'src/index.ts'",
30-
"build": "tsc --p tsconfig.build.json && npm run build:exports",
30+
"build:packages": "node scripts/buildPackages.js",
31+
"build": "tsc --p tsconfig.build.json && npm run build:exports && npm run build:packages",
3132
"log": "react-native log-ios | grep 'ethan -'",
3233
"docs:install": "(cd ./uilib-docs && rm -rf node_modules && rm -rf package-lock.json && npm install)",
3334
"docs:deploy": "(cd ./uilib-docs && gatsby build --prefix-paths && gh-pages -d public --branch gh-pages)",

scripts/buildPackages.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const fs = require('fs');
2+
const _ = require('lodash');
3+
4+
const packages = [
5+
{
6+
filename: 'keyboard.js',
7+
content: `module.exports = require('./lib/components/Keyboard').default;\n`
8+
},
9+
{
10+
filename: 'core.js',
11+
components: ['View', 'Text', 'Image', 'TouchableOpacity', 'Button']
12+
}
13+
];
14+
15+
/* Write custom packages */
16+
packages.forEach((package) => {
17+
let content = package.content || '';
18+
19+
if (package.components) {
20+
content += 'module.exports = {\n';
21+
package.components.forEach((component) => {
22+
content += `get ${component}() {\n`;
23+
content += `return require('./src/components/${_.camelCase(
24+
component
25+
)}').default;`;
26+
content += `},\n`;
27+
});
28+
content += '};\n';
29+
}
30+
31+
fs.writeFileSync(package.filename, content);
32+
});
33+
34+
/* Write all components as separate packages */
35+
const path = './src/components';
36+
fs.readdir(path, (err, files) => {
37+
if (!err) {
38+
files
39+
.filter((f) => f !== 'index.js')
40+
.forEach((file) => {
41+
fs.writeFileSync(
42+
`${file}.js`,
43+
`module.exports = require('${path}/${file}').default;\n`
44+
);
45+
});
46+
}
47+
});

0 commit comments

Comments
 (0)