-
Notifications
You must be signed in to change notification settings - Fork 899
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
chore: setup monorepo with Lerna #109
Merged
Esemesek
merged 4 commits into
react-native-community:master
from
thymikee:chore/lerna-monorepo
Jan 23, 2019
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
module.exports = { | ||
babelrcRoots: ['packages/*'], | ||
presets: [ | ||
[ | ||
require.resolve('@babel/preset-env'), | ||
{ | ||
targets: { node: 8 }, | ||
useBuiltIns: 'entry', | ||
}, | ||
], | ||
require.resolve('@babel/preset-flow'), | ||
], | ||
plugins: [require.resolve('@babel/plugin-transform-strict-mode')], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"lerna": "3.10.6", | ||
"version": "independent", | ||
"npmClient": "yarn", | ||
"useWorkspaces": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/** | ||
* script to build (transpile) files. | ||
* By default it transpiles js files for all packages and writes them | ||
* into `build/` directory. | ||
* Non-js files not matching IGNORE_PATTERN will be copied without transpiling. | ||
* | ||
* Example: | ||
* node ./scripts/build.js | ||
* node ./scripts/build.js /users/123/jest/packages/jest-111/src/111.js | ||
* | ||
* NOTE: this script is node@4 compatible | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const mkdirp = require('mkdirp'); | ||
const babel = require('@babel/core'); | ||
const chalk = require('chalk'); | ||
const micromatch = require('micromatch'); | ||
const prettier = require('prettier'); | ||
const stringLength = require('string-length'); | ||
|
||
const OK = chalk.reset.inverse.bold.green(' DONE '); | ||
const SRC_DIR = 'src'; | ||
const BUILD_DIR = 'build'; | ||
const JS_FILES_PATTERN = '**/*.js'; | ||
const IGNORE_PATTERN = '**/__{tests,mocks,fixtures}__/**'; | ||
const PACKAGES_DIR = path.resolve(__dirname, '../packages'); | ||
|
||
const transformOptions = require('../babel.config.js'); | ||
|
||
const prettierConfig = prettier.resolveConfig.sync(__filename); | ||
prettierConfig.trailingComma = 'none'; | ||
prettierConfig.parser = 'babel'; | ||
|
||
function getPackages() { | ||
return fs | ||
.readdirSync(PACKAGES_DIR) | ||
.map(file => path.resolve(PACKAGES_DIR, file)) | ||
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory()); | ||
} | ||
|
||
const adjustToTerminalWidth = str => { | ||
const columns = process.stdout.columns || 80; | ||
const WIDTH = columns - stringLength(OK) + 1; | ||
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g')); | ||
let lastString = strs[strs.length - 1]; | ||
if (lastString.length < WIDTH) { | ||
lastString += Array(WIDTH - lastString.length).join(chalk.dim('.')); | ||
} | ||
return strs | ||
.slice(0, -1) | ||
.concat(lastString) | ||
.join('\n'); | ||
}; | ||
|
||
function getPackageName(file) { | ||
return path.relative(PACKAGES_DIR, file).split(path.sep)[0]; | ||
} | ||
|
||
function getBuildPath(file, buildFolder) { | ||
const pkgName = getPackageName(file); | ||
const pkgSrcPath = path.resolve(PACKAGES_DIR, pkgName, SRC_DIR); | ||
const pkgBuildPath = path.resolve(PACKAGES_DIR, pkgName, buildFolder); | ||
const relativeToSrcPath = path.relative(pkgSrcPath, file); | ||
return path.resolve(pkgBuildPath, relativeToSrcPath); | ||
} | ||
|
||
function buildNodePackage(p) { | ||
const srcDir = path.resolve(p, SRC_DIR); | ||
const pattern = path.resolve(srcDir, '**/*'); | ||
const files = glob.sync(pattern, { | ||
nodir: true, | ||
}); | ||
|
||
process.stdout.write(adjustToTerminalWidth(`${path.basename(p)}\n`)); | ||
|
||
files.forEach(file => buildFile(file, true)); | ||
process.stdout.write(`${OK}\n`); | ||
} | ||
|
||
function buildFile(file, silent) { | ||
const destPath = getBuildPath(file, BUILD_DIR); | ||
|
||
if (micromatch.isMatch(file, IGNORE_PATTERN)) { | ||
silent || | ||
process.stdout.write( | ||
`${chalk.dim(' \u2022 ') + | ||
path.relative(PACKAGES_DIR, file)} (ignore)\n` | ||
); | ||
return; | ||
} | ||
|
||
mkdirp.sync(path.dirname(destPath), '777'); | ||
|
||
if (!micromatch.isMatch(file, JS_FILES_PATTERN)) { | ||
fs.createReadStream(file).pipe(fs.createWriteStream(destPath)); | ||
silent || | ||
process.stdout.write( | ||
`${chalk.red(' \u2022 ') + | ||
path.relative(PACKAGES_DIR, file) + | ||
chalk.red(' \u21D2 ') + | ||
path.relative(PACKAGES_DIR, destPath)} (copy)\n` | ||
); | ||
} else { | ||
const options = Object.assign({}, transformOptions); | ||
const transformed = babel.transformFileSync(file, options).code; | ||
const prettyCode = prettier.format(transformed, prettierConfig); | ||
|
||
fs.writeFileSync(destPath, prettyCode); | ||
|
||
silent || | ||
process.stdout.write( | ||
`${chalk.green(' \u2022 ') + | ||
path.relative(PACKAGES_DIR, file) + | ||
chalk.green(' \u21D2 ') + | ||
path.relative(PACKAGES_DIR, destPath)}\n` | ||
); | ||
} | ||
} | ||
|
||
const files = process.argv.slice(2); | ||
|
||
if (files.length) { | ||
files.forEach(buildFile); | ||
} else { | ||
const packages = getPackages(); | ||
process.stdout.write(chalk.inverse(' Building packages \n')); | ||
packages.forEach(buildNodePackage); | ||
process.stdout.write('\n'); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently packages are a bit disconnected (local cli at 1.1 and global at 2.0) so until we reach parity Lerna will ask you which version would you like to bump to