Files
react-native-community-cli/scripts/helpers.js
Kacper WiszczukandMichał Pierzchała b03f7413cc chore: migrate tools to TypeScript (#296)
* Migrate tools package to Typescript

* Prebuild ts

* Improve yarn build-clean

* Remove unnecessary statements

* Fix linting

* Fix eslint

* Update packages/tools/src/isPackagerRunning.ts

Co-Authored-By: Michał Pierzchała <[email protected]>

* adjust package.json

* add vscode helper settings

* remove dead node-fetch references
2019-05-17 22:32:54 +02:00

44 lines
1.1 KiB
JavaScript

/**
* 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.
*/
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const stringLength = require('string-length');
const PACKAGES_DIR = path.resolve(__dirname, '../packages');
const OK = chalk.reset.inverse.bold.green(' DONE ');
function getPackages() {
return fs
.readdirSync(PACKAGES_DIR)
.map(file => path.resolve(PACKAGES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
}
function 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');
}
module.exports = {
getPackages,
PACKAGES_DIR,
adjustToTerminalWidth,
OK,
};