Skip to content

Instantly share code, notes, and snippets.

@fkorotkov
Last active October 29, 2017 16:27
Show Gist options
  • Save fkorotkov/a694e5deee7c3b037e4a4b5952dd9033 to your computer and use it in GitHub Desktop.
Save fkorotkov/a694e5deee7c3b037e4a4b5952dd9033 to your computer and use it in GitHub Desktop.
Buck RN JS bundle generation
# workaround to make rule key to depend on node and npm versions
NODE_NPM_VERSIONS = 'cat $(location //:node_version) && cat $(location //:npm_version) && '
# prepopulated modules
# for example CI fails to clone react-native-permissions fork due to ssh permissions
export_file(
name = 'locale_node_modules',
src = 'node_modules',
out = 'node_modules',
)
genrule(
name = 'node_modules',
visibility = ['PUBLIC'],
srcs = [
'.babelrc',
'.npmrc',
'.nvmrc',
'npm-shrinkwrap.json',
'package.json',
],
bash = NODE_NPM_VERSIONS + '' \
'rsync $SRCDIR/ $TMP/ -a --copy-links -v && ' \
'mkdir -p $TMP/node_modules/ && ' \
'rsync $(location :locale_node_modules)/ $TMP/node_modules/ -a --copy-links -v && ' \
'cd $TMP && npm install && ' \
'mv $TMP/node_modules $OUT && ' \
'rm -rf $TMP',
out = 'node_modules',
)
PLATFORMS = [
'ios',
# TODO(fedor): add android
]
for platform in PLATFORMS:
genrule(
name = 'bundle-' + platform,
visibility = ['PUBLIC'],
srcs = [
'.babelrc',
'.flowconfig',
] + glob([
'**/*.ejs',
'**/*.gif',
'**/*.js',
'**/*.json',
'**/*.jpg',
'**/*.png',
'**/*.sh',
], excludes = [
'node_modules/**'
]),
bash = NODE_NPM_VERSIONS + '' \
'mkdir -p $OUT && ' \
'rsync $SRCDIR/ $TMP/ -a --copy-links -v && ' \
'cp -r $(location :node_modules) $TMP && ' \
'cd $TMP && ' \
'node ./node_modules/react-native/local-cli/cli.js bundle ' \
'--platform ' + platform + ' ' \
'--dev false ' \
'--entry-file index.js ' \
'--bundle-output $OUT/main.jsbundle ' \
'--assets-dest $OUT && ' \
'rm -rf $TMP',
out = 'Assets',
)
@fkorotkov
Copy link
Author

Here are some root rules for NPM and Node

PROGRAMS = [
  'node',
  'npm',
]

for program in PROGRAMS:
  genrule(
    visibility = ['PUBLIC'],
    name = program + '_version',
    bash = program + ' --version >> $OUT',
    out  = program + '_version.txt'
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment